From 7872a128a2dfde2a0bb17a08ba602e60e04ef256 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Wed, 24 Jan 2024 16:15:32 +0300 Subject: [PATCH] Folders: Add metric for listing subfolders duration (#81144) --- pkg/services/folder/folderimpl/folder.go | 10 +++++++++- pkg/services/folder/folderimpl/metrics.go | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkg/services/folder/folderimpl/folder.go b/pkg/services/folder/folderimpl/folder.go index b088d3f4774..6d45f4d5627 100644 --- a/pkg/services/folder/folderimpl/folder.go +++ b/pkg/services/folder/folderimpl/folder.go @@ -9,10 +9,10 @@ import ( "sync" "time" + "github.com/grafana/dskit/concurrency" "github.com/prometheus/client_golang/prometheus" "golang.org/x/exp/slices" - "github.com/grafana/dskit/concurrency" "github.com/grafana/grafana/pkg/bus" "github.com/grafana/grafana/pkg/events" "github.com/grafana/grafana/pkg/infra/db" @@ -196,6 +196,14 @@ func (s *Service) Get(ctx context.Context, q *folder.GetFolderQuery) (*folder.Fo } func (s *Service) GetChildren(ctx context.Context, q *folder.GetChildrenQuery) ([]*folder.Folder, error) { + defer func(t time.Time) { + parent := q.UID + if q.UID != folder.SharedWithMeFolderUID { + parent = "folder" + } + s.metrics.foldersGetChildrenRequestsDuration.WithLabelValues(parent).Observe(time.Since(t).Seconds()) + }(time.Now()) + if q.SignedInUser == nil { return nil, folder.ErrBadRequest.Errorf("missing signed in user") } diff --git a/pkg/services/folder/folderimpl/metrics.go b/pkg/services/folder/folderimpl/metrics.go index 7e569e84ed8..2f72c1ac643 100644 --- a/pkg/services/folder/folderimpl/metrics.go +++ b/pkg/services/folder/folderimpl/metrics.go @@ -12,6 +12,7 @@ const ( type foldersMetrics struct { sharedWithMeFetchFoldersRequestsDuration *prometheus.HistogramVec + foldersGetChildrenRequestsDuration *prometheus.HistogramVec } func newFoldersMetrics(r prometheus.Registerer) *foldersMetrics { @@ -26,5 +27,15 @@ func newFoldersMetrics(r prometheus.Registerer) *foldersMetrics { }, []string{"status"}, ), + foldersGetChildrenRequestsDuration: promauto.With(r).NewHistogramVec( + prometheus.HistogramOpts{ + Name: "get_children_duration_seconds", + Help: "Duration of listing subfolders in specific folder", + Buckets: []float64{.005, .01, .025, .05, .1, .25, .5, 1, 2.5, 5, 10, 25, 50, 100}, + Namespace: metricsNamespace, + Subsystem: metricsSubSystem, + }, + []string{"parent"}, + ), } }