diff --git a/pkg/api/datasources.go b/pkg/api/datasources.go index d7dc89d248f..0fe733ea1b5 100644 --- a/pkg/api/datasources.go +++ b/pkg/api/datasources.go @@ -204,7 +204,7 @@ func (hs *HTTPServer) DeleteDataSourceById(c *contextmodel.ReqContext) response. func (hs *HTTPServer) GetDataSourceByUID(c *contextmodel.ReqContext) response.Response { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("legacy", "GetDataSourceByUID"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("GetDataSourceByUID"), time.Since(start).Seconds()) }() ds, err := hs.getRawDataSourceByUID(c.Req.Context(), web.Params(c.Req)[":uid"], c.GetOrgID()) @@ -240,7 +240,7 @@ func (hs *HTTPServer) GetDataSourceByUID(c *contextmodel.ReqContext) response.Re func (hs *HTTPServer) DeleteDataSourceByUID(c *contextmodel.ReqContext) response.Response { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("legacy", "DeleteDataSourceByUID"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("DeleteDataSourceByUID"), time.Since(start).Seconds()) }() uid := web.Params(c.Req)[":uid"] @@ -375,7 +375,7 @@ func validateJSONData(jsonData *simplejson.Json, cfg *setting.Cfg) error { func (hs *HTTPServer) AddDataSource(c *contextmodel.ReqContext) response.Response { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("legacy", "AddDataSource"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("AddDataSource"), time.Since(start).Seconds()) }() cmd := datasources.AddDataSourceCommand{} @@ -497,7 +497,7 @@ func (hs *HTTPServer) UpdateDataSourceByID(c *contextmodel.ReqContext) response. func (hs *HTTPServer) UpdateDataSourceByUID(c *contextmodel.ReqContext) response.Response { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("legacy", "UpdateDataSourceByUID"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(c.Req.Context(), hs.dsConfigHandlerRequestsDuration.WithLabelValues("UpdateDataSourceByUID"), time.Since(start).Seconds()) }() cmd := datasources.UpdateDataSourceCommand{} if err := web.Bind(c.Req, &cmd); err != nil { diff --git a/pkg/api/datasources_test.go b/pkg/api/datasources_test.go index dd0b39e13a7..8a0e27639d4 100644 --- a/pkg/api/datasources_test.go +++ b/pkg/api/datasources_test.go @@ -91,7 +91,7 @@ func setupDsConfigHandlerMetrics() (prometheus.Registerer, *prometheus.Histogram Namespace: "grafana", Name: "ds_config_handler_requests_duration_seconds", Help: "Duration of requests handled by datasource configuration handlers", - }, []string{"code_path", "handler"}) + }, []string{"handler"}) promRegister.MustRegister(dsConfigHandlerRequestsDuration) return promRegister, dsConfigHandlerRequestsDuration } diff --git a/pkg/api/http_server.go b/pkg/api/http_server.go index 0898a5ecb66..591941d8bf5 100644 --- a/pkg/api/http_server.go +++ b/pkg/api/http_server.go @@ -387,7 +387,7 @@ func ProvideHTTPServer(opts ServerOptions, cfg *setting.Cfg, routeRegister routi Namespace: "grafana", Name: "ds_config_handler_requests_duration_seconds", Help: "Duration of requests handled by datasource configuration handlers", - }, []string{"code_path", "handler"}), + }, []string{"handler"}), } promRegister.MustRegister(hs.htmlHandlerRequestsDuration) diff --git a/pkg/registry/apis/datasource/legacy_store.go b/pkg/registry/apis/datasource/legacy_store.go index e0526dd2409..c263129a157 100644 --- a/pkg/registry/apis/datasource/legacy_store.go +++ b/pkg/registry/apis/datasource/legacy_store.go @@ -57,6 +57,12 @@ func (s *legacyStorage) ConvertToTable(ctx context.Context, object runtime.Objec } func (s *legacyStorage) List(ctx context.Context, options *internalversion.ListOptions) (runtime.Object, error) { + if s.dsConfigHandlerRequestsDuration != nil { + start := time.Now() + defer func() { + metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("legacyStorage.List"), time.Since(start).Seconds()) + }() + } return s.datasources.ListDataSources(ctx) } @@ -64,7 +70,7 @@ func (s *legacyStorage) Get(ctx context.Context, name string, options *metav1.Ge if s.dsConfigHandlerRequestsDuration != nil { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("new", "Get"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("legacyStorage.Get"), time.Since(start).Seconds()) }() } @@ -76,7 +82,7 @@ func (s *legacyStorage) Create(ctx context.Context, obj runtime.Object, createVa if s.dsConfigHandlerRequestsDuration != nil { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("new", "Create"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("legacyStorage.Create"), time.Since(start).Seconds()) }() } @@ -92,7 +98,7 @@ func (s *legacyStorage) Update(ctx context.Context, name string, objInfo rest.Up if s.dsConfigHandlerRequestsDuration != nil { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("new", "Create"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("legacyStorage.Update"), time.Since(start).Seconds()) }() } @@ -135,7 +141,7 @@ func (s *legacyStorage) Delete(ctx context.Context, name string, deleteValidatio if s.dsConfigHandlerRequestsDuration != nil { start := time.Now() defer func() { - metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("new", "Create"), time.Since(start).Seconds()) + metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("legacyStorage.Delete"), time.Since(start).Seconds()) }() } @@ -145,6 +151,13 @@ func (s *legacyStorage) Delete(ctx context.Context, name string, deleteValidatio // DeleteCollection implements rest.CollectionDeleter. func (s *legacyStorage) DeleteCollection(ctx context.Context, deleteValidation rest.ValidateObjectFunc, options *metav1.DeleteOptions, listOptions *internalversion.ListOptions) (runtime.Object, error) { + if s.dsConfigHandlerRequestsDuration != nil { + start := time.Now() + defer func() { + metricutil.ObserveWithExemplar(ctx, s.dsConfigHandlerRequestsDuration.WithLabelValues("legacyStorage.DeleteCollection"), time.Since(start).Seconds()) + }() + } + dss, err := s.datasources.ListDataSources(ctx) if err != nil { return nil, err diff --git a/pkg/registry/apis/datasource/register.go b/pkg/registry/apis/datasource/register.go index 4b6f27da5c0..9222c020681 100644 --- a/pkg/registry/apis/datasource/register.go +++ b/pkg/registry/apis/datasource/register.go @@ -21,6 +21,7 @@ import ( datasourceV0 "github.com/grafana/grafana/pkg/apis/datasource/v0alpha1" queryV0 "github.com/grafana/grafana/pkg/apis/query/v0alpha1" grafanaregistry "github.com/grafana/grafana/pkg/apiserver/registry/generic" + "github.com/grafana/grafana/pkg/infra/metrics" "github.com/grafana/grafana/pkg/infra/metrics/metricutil" "github.com/grafana/grafana/pkg/plugins" "github.com/grafana/grafana/pkg/plugins/manager/sources" @@ -69,10 +70,10 @@ func RegisterAPIService( dataSourceCRUDMetric := metricutil.NewHistogramVec(prometheus.HistogramOpts{ Namespace: "grafana", - Name: "ds_config_handler_requests_duration_seconds", - Help: "Duration of requests handled by datasource configuration handlers", - }, []string{"code_path", "handler"}) - regErr := reg.Register(dataSourceCRUDMetric) + Name: "ds_config_handler_apis_requests_duration_seconds", + Help: "Duration of requests handled by new k8s style APIs datasource configuration handlers", + }, []string{"handler"}) + regErr := metrics.ProvideRegisterer().Register(dataSourceCRUDMetric) if regErr != nil && !errors.As(regErr, &prometheus.AlreadyRegisteredError{}) { return nil, regErr }