Remove use of prometheus.DefaultRegisterer from ProvideUnifiedStorageGrpcService. (#107315)

This commit is contained in:
Peter Štibraný
2025-06-27 15:58:00 +02:00
committed by GitHub
parent cacb9b8eaf
commit 6f3b619f59
2 changed files with 7 additions and 28 deletions
+5 -27
View File
@@ -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 {