Skip to content

Commit 7e1a3c4

Browse files
authored
feat(api): enable request time histogram (#396)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent 0112612 commit 7e1a3c4

File tree

2 files changed

+8
-0
lines changed
  • app
    • artifact-cas/internal/server
    • controlplane/internal/server

2 files changed

+8
-0
lines changed

app/artifact-cas/internal/server/grpc.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
jwtMiddleware "github.com/go-kratos/kratos/v2/middleware/auth/jwt"
3333
"github.com/go-kratos/kratos/v2/middleware/selector"
3434
jwt "github.com/golang-jwt/jwt/v4"
35+
"github.com/prometheus/client_golang/prometheus"
3536
"google.golang.org/genproto/googleapis/bytestream"
3637

3738
"github.com/go-kratos/kratos/v2/log"
@@ -92,6 +93,10 @@ func NewGRPCServer(c *conf.Server, authConf *conf.Auth, byteService *service.Byt
9293
grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),
9394
}
9495

96+
// Opt-in histogram metrics for the interceptor
97+
// Since we track uploads / downloads we'll increase the buckets
98+
grpc_prometheus.EnableHandlingTimeHistogram(grpc_prometheus.WithHistogramBuckets(prometheus.ExponentialBucketsRange(0.5, 60, 8)))
99+
95100
if c.Grpc.Network != "" {
96101
opts = append(opts, grpc.Network(c.Grpc.Network))
97102
}

app/controlplane/internal/server/grpc.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ type Opts struct {
7474

7575
// NewGRPCServer new a gRPC server.
7676
func NewGRPCServer(opts *Opts) (*grpc.Server, error) {
77+
// Opt-in histogram metrics for the interceptor
78+
grpc_prometheus.EnableHandlingTimeHistogram()
79+
7780
var serverOpts = []grpc.ServerOption{
7881
grpc.Middleware(craftMiddleware(opts)...),
7982
grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor),

0 commit comments

Comments
 (0)