@@ -30,8 +30,7 @@ import (
3030 cmapi "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
3131 "github.com/cert-manager/cert-manager/pkg/util/pki"
3232 "github.com/go-logr/logr"
33- grpcprom "github.com/grpc-ecosystem/go-grpc-prometheus"
34- prom "github.com/prometheus/client_golang/prometheus"
33+ grpcprom "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
3534 "google.golang.org/grpc"
3635 "google.golang.org/grpc/codes"
3736 "google.golang.org/grpc/credentials"
@@ -150,16 +149,21 @@ func (s *Server) Start(ctx context.Context) error {
150149 }
151150
152151 // Setup the grpc server using the provided TLS config
153- srvmetrics := grpcprom .NewServerMetrics (func (op * prom.CounterOpts ) { op .Namespace = "cert_manager_istio_csr" })
154- srvmetrics .EnableHandlingTimeHistogram (func (op * prom.HistogramOpts ) { op .Namespace = "cert_manager_istio_csr" })
152+ srvmetrics := grpcprom .NewServerMetrics (
153+ grpcprom .WithServerCounterOptions (grpcprom .WithNamespace ("cert_manager_istio_csr" )),
154+ grpcprom .WithServerHandlingTimeHistogram (grpcprom .WithHistogramNamespace ("cert_manager_istio_csr" )),
155+ )
155156 creds := credentials .NewTLS (tlsConfig )
156157 grpcServer := grpc .NewServer (
157158 grpc .UnaryInterceptor (srvmetrics .UnaryServerInterceptor ()),
158159 grpc .Creds (creds ),
159160 )
160161
162+ // register certificate service grpc API
163+ securityapi .RegisterIstioCertificateServiceServer (grpcServer , s )
164+
161165 // Register gRPC Prometheus metrics
162- grpcprom . Register (grpcServer )
166+ srvmetrics . InitializeMetrics (grpcServer )
163167 if err := metrics .Registry .Register (srvmetrics ); err != nil {
164168 return fmt .Errorf ("failed to register gRPC Prometheus metrics: %w" , err )
165169 }
@@ -171,9 +175,6 @@ func (s *Server) Start(ctx context.Context) error {
171175 return fmt .Errorf ("failed to listen %s: %v" , s .opts .ServingAddress , err )
172176 }
173177
174- // register certificate service grpc API
175- securityapi .RegisterIstioCertificateServiceServer (grpcServer , s )
176-
177178 // handle termination gracefully
178179 go func () {
179180 <- ctx .Done ()
0 commit comments