diff --git a/go.mod b/go.mod index f626dc05..54d5a792 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.22.6 require ( github.com/aws/aws-sdk-go-v2/credentials v1.17.47 github.com/aws/smithy-go v1.22.1 + github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 github.com/onsi/ginkgo/v2 v2.22.0 github.com/onsi/gomega v1.36.1 github.com/prometheus/client_golang v1.12.1 diff --git a/go.sum b/go.sum index 0886b381..158d5873 100644 --- a/go.sum +++ b/go.sum @@ -195,6 +195,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg= github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 h1:Ovs26xHkKqVztRpIrF/92BcuyuQ/YW4NSIpoGtfXNho= +github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk= github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/pkg/grpcfactory/server.go b/pkg/grpcfactory/server.go index ad64f2c9..9e8723cc 100644 --- a/pkg/grpcfactory/server.go +++ b/pkg/grpcfactory/server.go @@ -20,6 +20,7 @@ import ( "net" "net/url" + grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" "google.golang.org/grpc" "k8s.io/klog/v2" cosi "sigs.k8s.io/container-object-storage-interface-spec" @@ -49,9 +50,20 @@ func (s *COSIProvisionerServer) Run(ctx context.Context) error { return fmt.Errorf("failed to start server: %w", err) } defer listener.Close() + + // Add Prometheus gRPC interceptors for unary and streaming RPCs + s.listenOpts = append(s.listenOpts, + grpc.UnaryInterceptor(grpc_prometheus.UnaryServerInterceptor), + grpc.StreamInterceptor(grpc_prometheus.StreamServerInterceptor), + ) + server := grpc.NewServer(s.listenOpts...) cosi.RegisterIdentityServer(server, s.identityServer) cosi.RegisterProvisionerServer(server, s.provisionerServer) + + grpc_prometheus.Register(server) + grpc_prometheus.EnableHandlingTimeHistogram() + errChan := make(chan error, 1) go func() { errChan <- server.Serve(listener)