mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Caching: Fix concurrent HTTP Header read/write in caching middleware (#67231)
read the response header synchronously, defer the metric only
This commit is contained in:
parent
2a67b8ad32
commit
1421f388ae
@ -56,16 +56,16 @@ func (m *CachingMiddleware) QueryData(ctx context.Context, req *backend.QueryDat
|
||||
// First look in the query cache if enabled
|
||||
hit, cr := m.caching.HandleQueryRequest(ctx, req)
|
||||
|
||||
defer func() {
|
||||
// record request duration if caching was used
|
||||
if ch := reqCtx.Resp.Header().Get(caching.XCacheHeader); ch != "" {
|
||||
// record request duration if caching was used
|
||||
if ch := reqCtx.Resp.Header().Get(caching.XCacheHeader); ch != "" {
|
||||
defer func() {
|
||||
QueryCachingRequestHistogram.With(prometheus.Labels{
|
||||
"datasource_type": req.PluginContext.DataSourceInstanceSettings.Type,
|
||||
"cache": ch,
|
||||
"query_type": getQueryType(reqCtx),
|
||||
}).Observe(time.Since(start).Seconds())
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
// Cache hit; return the response
|
||||
if hit {
|
||||
@ -102,15 +102,15 @@ func (m *CachingMiddleware) CallResource(ctx context.Context, req *backend.CallR
|
||||
// First look in the resource cache if enabled
|
||||
hit, cr := m.caching.HandleResourceRequest(ctx, req)
|
||||
|
||||
defer func() {
|
||||
// record request duration if caching was used
|
||||
if ch := reqCtx.Resp.Header().Get(caching.XCacheHeader); ch != "" {
|
||||
// record request duration if caching was used
|
||||
if ch := reqCtx.Resp.Header().Get(caching.XCacheHeader); ch != "" {
|
||||
defer func() {
|
||||
ResourceCachingRequestHistogram.With(prometheus.Labels{
|
||||
"plugin_id": req.PluginContext.PluginID,
|
||||
"cache": ch,
|
||||
}).Observe(time.Since(start).Seconds())
|
||||
}
|
||||
}()
|
||||
}()
|
||||
}
|
||||
|
||||
// Cache hit; send the response and return
|
||||
if hit {
|
||||
|
Loading…
Reference in New Issue
Block a user