Skip to content

Commit 971ed1c

Browse files
committed
Change grpc_prometheus dependency source
Old source has been deprecated and we're expected to pull the dependency from go-grpc-middleware now Signed-off-by: Appu Goundan <[email protected]>
1 parent ecf697d commit 971ed1c

File tree

6 files changed

+76
-57
lines changed

6 files changed

+76
-57
lines changed

cmd/app/grpc.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ import (
3333
ctclient "github.com/google/certificate-transparency-go/client"
3434
grpcmw "github.com/grpc-ecosystem/go-grpc-middleware"
3535
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
36+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
3637
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
37-
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
3838
"github.com/prometheus/client_golang/prometheus"
3939
"github.com/sigstore/fulcio/pkg/ca"
4040
"github.com/sigstore/fulcio/pkg/config"
@@ -157,8 +157,10 @@ func (c *cachedTLSCert) GRPCCreds() grpc.ServerOption {
157157
}))
158158
}
159159

160-
func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, baseca ca.CertificateAuthority, algorithmRegistry *signature.AlgorithmRegistryConfig, ip identity.IssuerPool) (*grpcServer, error) {
160+
func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, baseca ca.CertificateAuthority, algorithmRegistry *signature.AlgorithmRegistryConfig, ip identity.IssuerPool, registry *prometheus.Registry) (*grpcServer, error) {
161161
logger, opts := log.SetupGRPCLogging()
162+
grpcMetrics := grpc_prometheus.NewServerMetrics(grpc_prometheus.WithServerHandlingTimeHistogram(grpc_prometheus.WithHistogramConstLabels(prometheus.Labels{"server_mode": "standard"})))
163+
registry.MustRegister(grpcMetrics)
162164

163165
serverOpts := []grpc.ServerOption{
164166
grpc.UnaryInterceptor(
@@ -167,7 +169,7 @@ func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, ba
167169
middleware.UnaryRequestID(middleware.UseXRequestIDMetadataOption(true), middleware.XRequestMetadataLimitOption(128)),
168170
grpc_zap.UnaryServerInterceptor(logger, opts...),
169171
PassFulcioConfigThruContext(cfg),
170-
grpc_prometheus.UnaryServerInterceptor,
172+
grpcMetrics.UnaryServerInterceptor(),
171173
)),
172174
grpc.KeepaliveParams(keepalive.ServerParameters{
173175
MaxConnectionIdle: viper.GetDuration("idle-connection-timeout"),
@@ -193,18 +195,12 @@ func createGRPCServer(cfg *config.FulcioConfig, ctClient *ctclient.LogClient, ba
193195
health.RegisterHealthServer(myServer, grpcCAServer)
194196
// Register your gRPC service implementations.
195197
gw.RegisterCAServer(myServer, grpcCAServer)
198+
grpcMetrics.InitializeMetrics(myServer)
196199

197200
grpcServerEndpoint := fmt.Sprintf("%s:%s", viper.GetString("grpc-host"), viper.GetString("grpc-port"))
198201
return &grpcServer{myServer, grpcServerEndpoint, grpcCAServer, tlsCertWatcher}, nil
199202
}
200203

201-
func (g *grpcServer) setupPrometheus(reg *prometheus.Registry) {
202-
grpcMetrics := grpc_prometheus.DefaultServerMetrics
203-
grpcMetrics.EnableHandlingTimeHistogram()
204-
reg.MustRegister(grpcMetrics, server.MetricLatency, server.RequestsCount)
205-
grpc_prometheus.Register(g.Server)
206-
}
207-
208204
func (g *grpcServer) startTCPListener(wg *sync.WaitGroup) {
209205
// lis is closed by g.Server.Serve() upon exit
210206
lis, err := net.Listen("tcp", g.grpcServerEndpoint)
@@ -271,23 +267,27 @@ func (g *grpcServer) ExposesGRPCTLS() bool {
271267
return viper.IsSet("grpc-tls-certificate") && viper.IsSet("grpc-tls-key")
272268
}
273269

274-
func createLegacyGRPCServer(cfg *config.FulcioConfig, unixDomainSocket string, v2Server gw.CAServer) (*grpcServer, error) {
270+
func createLegacyGRPCServer(cfg *config.FulcioConfig, unixDomainSocket string, v2Server gw.CAServer, reg *prometheus.Registry) (*grpcServer, error) {
275271
logger, opts := log.SetupGRPCLogging()
276272

273+
grpcMetrics := grpc_prometheus.NewServerMetrics(grpc_prometheus.WithServerHandlingTimeHistogram(grpc_prometheus.WithHistogramConstLabels(prometheus.Labels{"server_mode": "legacy"})))
274+
reg.MustRegister(grpcMetrics)
275+
277276
myServer := grpc.NewServer(grpc.UnaryInterceptor(
278277
grpcmw.ChainUnaryServer(
279278
grpc_recovery.UnaryServerInterceptor(grpc_recovery.WithRecoveryHandlerContext(panicRecoveryHandler)), // recovers from per-transaction panics elegantly, so put it first
280279
middleware.UnaryRequestID(middleware.UseXRequestIDMetadataOption(true), middleware.XRequestMetadataLimitOption(128)),
281280
grpc_zap.UnaryServerInterceptor(logger, opts...),
282281
PassFulcioConfigThruContext(cfg),
283-
grpc_prometheus.UnaryServerInterceptor,
282+
grpcMetrics.UnaryServerInterceptor(),
284283
)),
285284
grpc.MaxRecvMsgSize(int(maxMsgSize)))
286285

287286
legacyGRPCCAServer := server.NewLegacyGRPCCAServer(v2Server)
288287

289288
// Register your gRPC service implementations.
290289
gw_legacy.RegisterCAServer(myServer, legacyGRPCCAServer)
290+
grpcMetrics.InitializeMetrics(myServer)
291291

292292
return &grpcServer{myServer, unixDomainSocket, v2Server, nil}, nil
293293
}

cmd/app/http_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"sync"
3131
"testing"
3232

33+
"github.com/prometheus/client_golang/prometheus"
3334
"github.com/sigstore/fulcio/pkg/ca"
3435
"github.com/sigstore/fulcio/pkg/identity"
3536
v1 "github.com/sigstore/protobuf-specs/gen/pb-go/common/v1"
@@ -53,7 +54,8 @@ func setupHTTPServer(t *testing.T) (httpServer, string) {
5354
if err != nil {
5455
t.Error(err)
5556
}
56-
grpcServer, err := createGRPCServer(nil, nil, &TrivialCertificateAuthority{}, algorithmRegistry, nil)
57+
reg := prometheus.NewRegistry()
58+
grpcServer, err := createGRPCServer(nil, nil, &TrivialCertificateAuthority{}, algorithmRegistry, nil, reg)
5759
if err != nil {
5860
t.Error(err)
5961
}
@@ -103,7 +105,8 @@ func setupHTTPServerWithGRPCTLS(t *testing.T) (httpServer, string) {
103105
if err != nil {
104106
t.Error(err)
105107
}
106-
grpcServer, err := createGRPCServer(nil, nil, &TrivialCertificateAuthority{}, algorithmRegistry, nil)
108+
reg := prometheus.NewRegistry()
109+
grpcServer, err := createGRPCServer(nil, nil, &TrivialCertificateAuthority{}, algorithmRegistry, nil, reg)
107110
if err != nil {
108111
t.Error(err)
109112
}
@@ -119,7 +122,7 @@ func setupHTTPServerWithGRPCTLS(t *testing.T) (httpServer, string) {
119122
if err != nil {
120123
t.Error(err)
121124
}
122-
legacyGRPCServer, err := createLegacyGRPCServer(nil, LegacyUnixDomainSocket, grpcServer.caService)
125+
legacyGRPCServer, err := createLegacyGRPCServer(nil, LegacyUnixDomainSocket, grpcServer.caService, nil)
123126
if err != nil {
124127
t.Fatal(err)
125128
}

cmd/app/serve.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ import (
4242
"github.com/google/certificate-transparency-go/jsonclient"
4343
grpcmw "github.com/grpc-ecosystem/go-grpc-middleware"
4444
grpc_zap "github.com/grpc-ecosystem/go-grpc-middleware/logging/zap"
45+
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
4546
grpc_recovery "github.com/grpc-ecosystem/go-grpc-middleware/recovery"
46-
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
4747
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
4848
"github.com/prometheus/client_golang/prometheus"
4949
"github.com/prometheus/client_golang/prometheus/promhttp"
@@ -362,15 +362,16 @@ func runServeCmd(cmd *cobra.Command, args []string) { //nolint: revive
362362
httpServerEndpoint := fmt.Sprintf("%v:%v", viper.GetString("http-host"), viper.GetString("http-port"))
363363

364364
reg := prometheus.NewRegistry()
365+
server.InitMetrics(reg)
365366

366-
grpcServer, err := createGRPCServer(cfg, ctClient, baseca, algorithmRegistry, ip)
367+
grpcServer, err := createGRPCServer(cfg, ctClient, baseca, algorithmRegistry, ip, reg)
367368
if err != nil {
368369
log.Logger.Fatal(err)
369370
}
370-
grpcServer.setupPrometheus(reg)
371+
371372
grpcServer.startTCPListener(&wg)
372373

373-
legacyGRPCServer, err := createLegacyGRPCServer(cfg, viper.GetString("legacy-unix-domain-socket"), grpcServer.caService)
374+
legacyGRPCServer, err := createLegacyGRPCServer(cfg, viper.GetString("legacy-unix-domain-socket"), grpcServer.caService, reg)
374375
if err != nil {
375376
log.Logger.Fatal(err)
376377
}
@@ -444,6 +445,12 @@ func checkServeCmdConfigFile() error {
444445
func StartDuplexServer(ctx context.Context, cfg *config.FulcioConfig, ctClient *ctclient.LogClient, baseca certauth.CertificateAuthority, algorithmRegistry *signature.AlgorithmRegistryConfig, host string, port, metricsPort int, ip identity.IssuerPool) error {
445446
logger, opts := log.SetupGRPCLogging()
446447

448+
// configure Prometheus
449+
reg := prometheus.NewRegistry()
450+
server.InitMetrics(reg)
451+
grpcMetrics := grpc_prometheus.NewServerMetrics(grpc_prometheus.WithServerHandlingTimeHistogram(grpc_prometheus.WithHistogramConstLabels(prometheus.Labels{"server_mode": "duplex"})))
452+
reg.MustRegister(grpcMetrics)
453+
447454
d := duplex.New(
448455
port,
449456
grpc.WithTransportCredentials(insecure.NewCredentials()),
@@ -456,12 +463,14 @@ func StartDuplexServer(ctx context.Context, cfg *config.FulcioConfig, ctClient *
456463
middleware.UnaryRequestID(middleware.UseXRequestIDMetadataOption(true), middleware.XRequestMetadataLimitOption(128)),
457464
grpc_zap.UnaryServerInterceptor(logger, opts...),
458465
PassFulcioConfigThruContext(cfg),
459-
grpc_prometheus.UnaryServerInterceptor,
466+
grpcMetrics.UnaryServerInterceptor(),
460467
)),
461468
grpc.MaxRecvMsgSize(int(maxMsgSize)),
462469
runtime.WithForwardResponseOption(setResponseCodeModifier),
463470
)
464471

472+
grpcMetrics.InitializeMetrics(d.Server)
473+
465474
// GRPC server
466475
grpcCAServer := server.NewGRPCCAServer(ctClient, baseca, algorithmRegistry, ip)
467476
protobuf.RegisterCAServer(d.Server, grpcCAServer)
@@ -476,13 +485,6 @@ func StartDuplexServer(ctx context.Context, cfg *config.FulcioConfig, ctClient *
476485
return fmt.Errorf("registering legacy grpc ca handler: %w", err)
477486
}
478487

479-
// Prometheus
480-
reg := prometheus.NewRegistry()
481-
grpcMetrics := grpc_prometheus.DefaultServerMetrics
482-
grpcMetrics.EnableHandlingTimeHistogram()
483-
reg.MustRegister(grpcMetrics, server.MetricLatency, server.RequestsCount)
484-
grpc_prometheus.Register(d.Server)
485-
486488
// Register prometheus handle.
487489
d.RegisterListenAndServeMetrics(metricsPort, false)
488490

go.mod

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ require (
1818
github.com/google/certificate-transparency-go v1.3.1
1919
github.com/google/go-cmp v0.7.0
2020
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
21-
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99
22-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0
21+
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1
22+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1
2323
github.com/hashicorp/golang-lru v1.0.2
2424
github.com/magiconair/properties v1.8.9
2525
github.com/prometheus/client_golang v1.20.5
@@ -43,21 +43,21 @@ require (
4343
go.step.sm/crypto v0.57.0
4444
go.uber.org/zap v1.27.0
4545
google.golang.org/api v0.218.0
46-
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f
46+
google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489
4747
google.golang.org/grpc v1.70.0
4848
google.golang.org/protobuf v1.36.5
4949
gopkg.in/yaml.v3 v3.0.1
5050
sigs.k8s.io/release-utils v0.9.0
5151
)
5252

5353
require (
54-
cloud.google.com/go v0.116.0 // indirect
54+
cloud.google.com/go v0.118.0 // indirect
5555
cloud.google.com/go/auth v0.14.0 // indirect
5656
cloud.google.com/go/auth/oauth2adapt v0.2.7 // indirect
5757
cloud.google.com/go/compute/metadata v0.6.0 // indirect
58-
cloud.google.com/go/iam v1.2.2 // indirect
59-
cloud.google.com/go/kms v1.20.4 // indirect
60-
cloud.google.com/go/longrunning v0.6.2 // indirect
58+
cloud.google.com/go/iam v1.3.1 // indirect
59+
cloud.google.com/go/kms v1.20.5 // indirect
60+
cloud.google.com/go/longrunning v0.6.4 // indirect
6161
dario.cat/mergo v1.0.1 // indirect
6262
filippo.io/edwards25519 v1.1.0 // indirect
6363
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.17.0 // indirect
@@ -102,6 +102,8 @@ require (
102102
github.com/google/uuid v1.6.0 // indirect
103103
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
104104
github.com/googleapis/gax-go/v2 v2.14.1 // indirect
105+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 // indirect
106+
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99 // indirect
105107
github.com/hashicorp/errwrap v1.1.0 // indirect
106108
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
107109
github.com/hashicorp/go-multierror v1.1.1 // indirect
@@ -165,8 +167,8 @@ require (
165167
golang.org/x/term v0.29.0 // indirect
166168
golang.org/x/text v0.22.0 // indirect
167169
golang.org/x/time v0.9.0 // indirect
168-
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect
169-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f // indirect
170+
google.golang.org/genproto v0.0.0-20250124145028-65684f501c47 // indirect
171+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 // indirect
170172
gopkg.in/ini.v1 v1.67.0 // indirect
171173
k8s.io/klog/v2 v2.130.1 // indirect
172174
)

go.sum

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ chainguard.dev/go-grpc-kit v0.17.7/go.mod h1:JroMzTY9mdhKe/bvtyChgfECaNh80+bMZH3
33
chainguard.dev/sdk v0.1.29 h1:GNcCw5NoyvylhlUbVD8JMmrPaeYyrshaHHjEWnvcCGI=
44
chainguard.dev/sdk v0.1.29/go.mod h1:DqywTjZ5glB/gUCKkrecO0LywyfcAd5v7IPo2+d91qA=
55
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
6-
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
7-
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
6+
cloud.google.com/go v0.118.0 h1:tvZe1mgqRxpiVa3XlIGMiPcEUbP1gNXELgD4y/IXmeQ=
7+
cloud.google.com/go v0.118.0/go.mod h1:zIt2pkedt/mo+DQjcT4/L3NDxzHPR29j5HcclNH+9PM=
88
cloud.google.com/go/auth v0.14.0 h1:A5C4dKV/Spdvxcl0ggWwWEzzP7AZMJSEIgrkngwhGYM=
99
cloud.google.com/go/auth v0.14.0/go.mod h1:CYsoRL1PdiDuqeQpZE0bP2pnPrGqFcOkI0nldEQis+A=
1010
cloud.google.com/go/auth/oauth2adapt v0.2.7 h1:/Lc7xODdqcEw8IrZ9SvwnlLX6j9FHQM74z6cBk9Rw6M=
1111
cloud.google.com/go/auth/oauth2adapt v0.2.7/go.mod h1:NTbTTzfvPl1Y3V1nPpOgl2w6d/FjO7NNUQaWSox6ZMc=
1212
cloud.google.com/go/compute/metadata v0.6.0 h1:A6hENjEsCDtC1k8byVsgwvVcioamEHvZ4j01OwKxG9I=
1313
cloud.google.com/go/compute/metadata v0.6.0/go.mod h1:FjyFAW1MW0C203CEOMDTu3Dk1FlqW3Rga40jzHL4hfg=
14-
cloud.google.com/go/iam v1.2.2 h1:ozUSofHUGf/F4tCNy/mu9tHLTaxZFLOUiKzjcgWHGIA=
15-
cloud.google.com/go/iam v1.2.2/go.mod h1:0Ys8ccaZHdI1dEUilwzqng/6ps2YB6vRsjIe00/+6JY=
16-
cloud.google.com/go/kms v1.20.4 h1:CJ0hMpOg1ANN9tx/a/GPJ+Uxudy8k6f3fvGFuTHiE5A=
17-
cloud.google.com/go/kms v1.20.4/go.mod h1:gPLsp1r4FblUgBYPOcvI/bUPpdMg2Jm1ZVKU4tQUfcc=
18-
cloud.google.com/go/longrunning v0.6.2 h1:xjDfh1pQcWPEvnfjZmwjKQEcHnpz6lHjfy7Fo0MK+hc=
19-
cloud.google.com/go/longrunning v0.6.2/go.mod h1:k/vIs83RN4bE3YCswdXC5PFfWVILjm3hpEUlSko4PiI=
14+
cloud.google.com/go/iam v1.3.1 h1:KFf8SaT71yYq+sQtRISn90Gyhyf4X8RGgeAVC8XGf3E=
15+
cloud.google.com/go/iam v1.3.1/go.mod h1:3wMtuyT4NcbnYNPLMBzYRFiEfjKfJlLVLrisE7bwm34=
16+
cloud.google.com/go/kms v1.20.5 h1:aQQ8esAIVZ1atdJRxihhdxGQ64/zEbJoJnCz/ydSmKg=
17+
cloud.google.com/go/kms v1.20.5/go.mod h1:C5A8M1sv2YWYy1AE6iSrnddSG9lRGdJq5XEdBy28Lmw=
18+
cloud.google.com/go/longrunning v0.6.4 h1:3tyw9rO3E2XVXzSApn1gyEEnH2K9SynNQjMlBi3uHLg=
19+
cloud.google.com/go/longrunning v0.6.4/go.mod h1:ttZpLCe6e7EXvn9OxpBRx7kZEB0efv8yBO6YnVMfhJs=
2020
cloud.google.com/go/security v1.18.3 h1:ya9gfY1ign6Yy25VMMMgZ9xy7D/TczDB0ElXcyWmEVE=
2121
cloud.google.com/go/security v1.18.3/go.mod h1:NmlSnEe7vzenMRoTLehUwa/ZTZHDQE59IPRevHcpCe4=
2222
dario.cat/mergo v1.0.1 h1:Ra4+bf83h2ztPIQYNP99R6m+Y7KfnARDfID+a+vLl4s=
@@ -173,10 +173,14 @@ github.com/googleapis/gax-go/v2 v2.14.1 h1:hb0FFeiPaQskmvakKu5EbCbpntQn48jyHuvrk
173173
github.com/googleapis/gax-go/v2 v2.14.1/go.mod h1:Hb/NubMaVM88SrNkvl8X/o8XWwDJEPqouaLeN2IUxoA=
174174
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
175175
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
176+
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1 h1:qnpSQwGEnkcRpTqNOIR6bJbR0gAorgP9CSALpRcKoAA=
177+
github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus v1.0.1/go.mod h1:lXGCsh6c22WGtjr+qGHj1otzZpV/1kwTMAqkwZsnWRU=
178+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0 h1:pRhl55Yx1eC7BZ1N+BBWwnKaMyD8uC+34TLdndZMAKk=
179+
github.com/grpc-ecosystem/go-grpc-middleware/v2 v2.1.0/go.mod h1:XKMd7iuf/RGPSMJ/U4HP0zS2Z9Fh8Ps9a+6X26m/tmI=
176180
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99 h1:JYghRBlGCZyCF2wNUJ8W0cwaQdtpcssJ4CgC406g+WU=
177181
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.1-0.20210315223345-82c243799c99/go.mod h1:3bDW6wMZJB7tiONtC/1Xpicra6Wp5GgbTbQWCbI5fkc=
178-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0 h1:VD1gqscl4nYs1YxVuSdemTrSgTKrwOWDK0FVFMqm+Cg=
179-
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.0/go.mod h1:4EgsQoS4TOhJizV+JTFg40qx1Ofh3XmXEQNBpgvNT40=
182+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 h1:e9Rjr40Z98/clHv5Yg79Is0NtosR5LXRvdr7o/6NwbA=
183+
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1/go.mod h1:tIxuGz/9mpox++sgp9fJjHO0+q1X9/UOWd798aAm22M=
180184
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
181185
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
182186
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
@@ -518,12 +522,12 @@ google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
518522
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
519523
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
520524
google.golang.org/genproto v0.0.0-20200423170343-7949de9c1215/go.mod h1:55QSHmfGQM9UVYDPBsyGGes0y52j32PQ3BqQfXhyH3c=
521-
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk=
522-
google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc=
523-
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f h1:gap6+3Gk41EItBuyi4XX/bp4oqJ3UwuIMl25yGinuAA=
524-
google.golang.org/genproto/googleapis/api v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:Ic02D47M+zbarjYYUlK57y316f2MoN0gjAwI3f2S95o=
525-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f h1:OxYkA3wjPsZyBylwymxSHa7ViiW1Sml4ToBrncvFehI=
526-
google.golang.org/genproto/googleapis/rpc v0.0.0-20250115164207-1a7da9e5054f/go.mod h1:+2Yz8+CLJbIfL9z73EW45avw8Lmge3xVElCP9zEKi50=
525+
google.golang.org/genproto v0.0.0-20250124145028-65684f501c47 h1:SI8Hf7K4+uVYchXqZiMfP44PZ83xomMWovbcFfm0P8Q=
526+
google.golang.org/genproto v0.0.0-20250124145028-65684f501c47/go.mod h1:qbZzneIOXSq+KFAFut9krLfRLZiFLzZL5u2t8SV83EE=
527+
google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489 h1:fCuMM4fowGzigT89NCIsW57Pk9k2D12MMi2ODn+Nk+o=
528+
google.golang.org/genproto/googleapis/api v0.0.0-20250204164813-702378808489/go.mod h1:iYONQfRdizDB8JJBybql13nArx91jcUk7zCXEsOofM4=
529+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489 h1:5bKytslY8ViY0Cj/ewmRtrWHW64bNF03cAatUUFCdFI=
530+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250204164813-702378808489/go.mod h1:8BS3B93F/U1juMFq9+EDk+qOT5CO1R9IzXxG3PTqiRk=
527531
google.golang.org/grpc v1.18.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
528532
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
529533
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=

pkg/server/metrics.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,30 @@ import (
2222
)
2323

2424
var (
25-
metricNewEntries = promauto.NewCounter(prometheus.CounterOpts{
25+
metricNewEntries prometheus.Counter
26+
MetricLatency *prometheus.HistogramVec
27+
RequestsCount *prometheus.CounterVec
28+
)
29+
30+
// InitMetrics should only be called once
31+
func InitMetrics(reg prometheus.Registerer) {
32+
metricsFactory := promauto.With(reg)
33+
metricNewEntries = metricsFactory.NewCounter(prometheus.CounterOpts{
2634
Name: "fulcio_new_certs",
2735
Help: "The total number of certificates generated",
2836
})
2937

30-
MetricLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
38+
MetricLatency = metricsFactory.NewHistogramVec(prometheus.HistogramOpts{
3139
Name: "fulcio_api_latency",
3240
Help: "API Latency on calls",
3341
}, []string{"code", "method"})
3442

35-
RequestsCount = promauto.NewCounterVec(prometheus.CounterOpts{
43+
RequestsCount = metricsFactory.NewCounterVec(prometheus.CounterOpts{
3644
Name: "http_requests_total",
3745
Help: "Count all HTTP requests",
3846
}, []string{"code", "method"})
3947

40-
_ = promauto.NewGaugeFunc(
48+
_ = metricsFactory.NewGaugeFunc(
4149
prometheus.GaugeOpts{
4250
Namespace: "fulcio",
4351
Name: "build_info",
@@ -51,4 +59,4 @@ var (
5159
},
5260
func() float64 { return 1 },
5361
)
54-
)
62+
}

0 commit comments

Comments
 (0)