Folders: Add metric for listing subfolders duration (#81144)

This commit is contained in:
Alexander Zobnin 2024-01-24 16:15:32 +03:00 committed by GitHub
parent 57ba8dc75d
commit 7872a128a2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 1 deletions

View File

@ -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")
}

View File

@ -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"},
),
}
}