From 6f3b619f592f1927c1e107d5ff92789a6d823501 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20=C5=A0tibran=C3=BD?= Date: Fri, 27 Jun 2025 15:58:00 +0200 Subject: [PATCH] Remove use of prometheus.DefaultRegisterer from ProvideUnifiedStorageGrpcService. (#107315) --- pkg/server/module_server.go | 3 ++- pkg/storage/unified/sql/service.go | 32 +++++------------------------- 2 files changed, 7 insertions(+), 28 deletions(-) diff --git a/pkg/server/module_server.go b/pkg/server/module_server.go index 5c3838c9cdb..3c141d2e18d 100644 --- a/pkg/server/module_server.go +++ b/pkg/server/module_server.go @@ -16,6 +16,7 @@ import ( "github.com/prometheus/client_golang/prometheus" "github.com/grafana/dskit/services" + "github.com/grafana/grafana/pkg/api" "github.com/grafana/grafana/pkg/infra/log" "github.com/grafana/grafana/pkg/modules" @@ -173,7 +174,7 @@ func (s *ModuleServer) Run() error { if err != nil { return nil, err } - return sql.ProvideUnifiedStorageGrpcService(s.cfg, s.features, nil, s.log, nil, docBuilders, s.storageMetrics, s.indexMetrics, s.storageRing, s.MemberlistKVConfig) + return sql.ProvideUnifiedStorageGrpcService(s.cfg, s.features, nil, s.log, s.registerer, docBuilders, s.storageMetrics, s.indexMetrics, s.storageRing, s.MemberlistKVConfig) }) m.RegisterModule(modules.ZanzanaServer, func() (services.Service, error) { diff --git a/pkg/storage/unified/sql/service.go b/pkg/storage/unified/sql/service.go index e05047ba511..deaa2b177f6 100644 --- a/pkg/storage/unified/sql/service.go +++ b/pkg/storage/unified/sql/service.go @@ -7,10 +7,10 @@ import ( "net" "os" "strconv" - "sync" "time" "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/trace" @@ -87,11 +87,6 @@ func ProvideUnifiedStorageGrpcService( ) (UnifiedStorageGrpcService, error) { tracer := otel.Tracer("unified-storage") - // reg can be nil when running unified storage in standalone mode - if reg == nil { - reg = prometheus.DefaultRegisterer - } - // FIXME: This is a temporary solution while we are migrating to the new authn interceptor // grpcutils.NewGrpcAuthenticator should be used instead. authn := NewAuthenticatorWithFallback(cfg, reg, tracer, func(ctx context.Context) (context.Context, error) { @@ -279,31 +274,14 @@ func (f *authenticatorWithFallback) Authenticate(ctx context.Context) (context.C return newCtx, err } -const ( - metricsNamespace = "grafana" - metricsSubSystem = "grpc_authenticator_with_fallback" -) - -var once sync.Once - func newMetrics(reg prometheus.Registerer) *metrics { - m := &metrics{ - requestsTotal: prometheus.NewCounterVec( + return &metrics{ + requestsTotal: promauto.With(reg).NewCounterVec( prometheus.CounterOpts{ - Namespace: metricsNamespace, - Subsystem: metricsSubSystem, - Name: "requests_total", - Help: "Number requests using the authenticator with fallback", + Name: "grafana_grpc_authenticator_with_fallback_requests_total", + Help: "Number requests using the authenticator with fallback", }, []string{"fallback_used", "result"}), } - - if reg != nil { - once.Do(func() { - reg.MustRegister(m.requestsTotal) - }) - } - - return m } func ReadGrpcServerConfig(cfg *setting.Cfg) *grpcutils.AuthenticatorConfig {