mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Add instrumentation for grafana_loki_plugin_parse_response_duration_seconds_bucket
(#75570)
* Add metric for loki parsing response duration * Rename and add exemplars * Fix lint
This commit is contained in:
parent
0b77db0b74
commit
5510a0d8d1
@ -20,6 +20,7 @@ import (
|
|||||||
|
|
||||||
"github.com/grafana/grafana/pkg/infra/log"
|
"github.com/grafana/grafana/pkg/infra/log"
|
||||||
"github.com/grafana/grafana/pkg/infra/tracing"
|
"github.com/grafana/grafana/pkg/infra/tracing"
|
||||||
|
"github.com/grafana/grafana/pkg/tsdb/loki/instrumentation"
|
||||||
"github.com/grafana/grafana/pkg/util/converter"
|
"github.com/grafana/grafana/pkg/util/converter"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -206,10 +207,11 @@ func (api *LokiAPI) DataQuery(ctx context.Context, query lokiQuery, responseOpts
|
|||||||
if res.Error != nil {
|
if res.Error != nil {
|
||||||
span.RecordError(res.Error)
|
span.RecordError(res.Error)
|
||||||
span.SetStatus(codes.Error, err.Error())
|
span.SetStatus(codes.Error, err.Error())
|
||||||
|
instrumentation.UpdatePluginParsingResponseDurationSeconds(ctx, time.Since(start), "error")
|
||||||
api.log.Error("Error parsing response from loki", "error", res.Error, "metricDataplane", responseOpts.metricDataplane, "duration", time.Since(start), "stage", stageParseResponse)
|
api.log.Error("Error parsing response from loki", "error", res.Error, "metricDataplane", responseOpts.metricDataplane, "duration", time.Since(start), "stage", stageParseResponse)
|
||||||
return nil, res.Error
|
return nil, res.Error
|
||||||
}
|
}
|
||||||
|
instrumentation.UpdatePluginParsingResponseDurationSeconds(ctx, time.Since(start), "ok")
|
||||||
api.log.Info("Response parsed from loki", "duration", time.Since(start), "metricDataplane", responseOpts.metricDataplane, "framesLength", len(res.Frames), "stage", stageParseResponse)
|
api.log.Info("Response parsed from loki", "duration", time.Since(start), "metricDataplane", responseOpts.metricDataplane, "framesLength", len(res.Frames), "stage", stageParseResponse)
|
||||||
|
|
||||||
return res.Frames, nil
|
return res.Frames, nil
|
||||||
|
33
pkg/tsdb/loki/instrumentation/instrumentation.go
Normal file
33
pkg/tsdb/loki/instrumentation/instrumentation.go
Normal file
@ -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: "loki_plugin_parse_response_duration_seconds",
|
||||||
|
Help: "Duration of Loki 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())
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user