mirror of
https://github.com/grafana/grafana.git
synced 2026-07-30 00:08:10 -05:00
Elasticsearch: Add instrumentation for elasticsearch_plugin_parse_response_duration_seconds (#75628)
* Elasticsearch: Add instrumentation for elasticsearch_plugin_parse_response_duration_seconds * Update error tracking
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package instrumentation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||
)
|
||||
|
||||
var (
|
||||
pluginParsingResponseDurationSeconds = promauto.NewHistogramVec(prometheus.HistogramOpts{
|
||||
Namespace: "grafana",
|
||||
Name: "elasticsearch_plugin_parse_response_duration_seconds",
|
||||
Help: "Duration of Elasticsearch parsing the response in seconds",
|
||||
Buckets: []float64{.001, 0.0025, .005, .0075, .01, .02, .03, .04, .05, .075, .1, .25, .5, 1, 5, 10, 25},
|
||||
}, []string{"status", "endpoint"})
|
||||
)
|
||||
|
||||
const (
|
||||
EndpointQueryData = "queryData"
|
||||
)
|
||||
|
||||
func UpdatePluginParsingResponseDurationSeconds(ctx context.Context, duration time.Duration, status string) {
|
||||
histogram := pluginParsingResponseDurationSeconds.WithLabelValues(status, EndpointQueryData)
|
||||
|
||||
if traceID := tracing.TraceIDFromContext(ctx, true); traceID != "" {
|
||||
histogram.(prometheus.ExemplarObserver).ObserveWithExemplar(duration.Seconds(), prometheus.Labels{"traceID": traceID})
|
||||
} else {
|
||||
histogram.Observe(duration.Seconds())
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||
es "github.com/grafana/grafana/pkg/tsdb/elasticsearch/client"
|
||||
"github.com/grafana/grafana/pkg/tsdb/elasticsearch/instrumentation"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -109,8 +110,9 @@ func parseResponse(ctx context.Context, responses []*es.SearchResponse, targets
|
||||
span.SetStatus(codes.Error, err.Error())
|
||||
resSpan.RecordError(err)
|
||||
resSpan.SetStatus(codes.Error, err.Error())
|
||||
logger.Error("Error processing buckets", "error", err, "query", string(mt), "aggregationsLength", len(res.Aggregations), "stage", es.StageParseResponse)
|
||||
instrumentation.UpdatePluginParsingResponseDurationSeconds(ctx, time.Since(start), "error")
|
||||
resSpan.End()
|
||||
logger.Error("Error processing buckets", "error", err, "query", string(mt), "aggregationsLength", len(res.Aggregations))
|
||||
return &backend.QueryDataResponse{}, err
|
||||
}
|
||||
nameFields(queryRes, target)
|
||||
@@ -118,8 +120,9 @@ func parseResponse(ctx context.Context, responses []*es.SearchResponse, targets
|
||||
|
||||
result.Responses[target.RefID] = queryRes
|
||||
}
|
||||
resSpan.End()
|
||||
instrumentation.UpdatePluginParsingResponseDurationSeconds(ctx, time.Since(start), "ok")
|
||||
logger.Info("Finished processing of response", "duration", time.Since(start), "stage", es.StageParseResponse)
|
||||
resSpan.End()
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user