Remove GRPC metrics

These conflict with other GRPC servers when running embedded

Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
Brad Davidson 2025-01-16 21:34:22 +00:00
parent b9ab7a3f49
commit 676ba43ad3
No known key found for this signature in database
GPG Key ID: FFB7A9376A9349B9

View File

@ -37,9 +37,7 @@ import (
"github.com/containerd/log" "github.com/containerd/log"
"github.com/containerd/ttrpc" "github.com/containerd/ttrpc"
"github.com/docker/go-metrics" "github.com/docker/go-metrics"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
v1 "github.com/opencontainers/image-spec/specs-go/v1" v1 "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/prometheus/client_golang/prometheus"
"go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/backoff" "google.golang.org/grpc/backoff"
@ -151,25 +149,10 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args, p.Env)) diff.RegisterProcessor(diff.BinaryHandler(id, p.Returns, p.Accepts, p.Path, p.Args, p.Env))
} }
var prometheusServerMetricsOpts []grpc_prometheus.ServerMetricsOption
if config.Metrics.GRPCHistogram {
// Enable grpc time histograms to measure rpc latencies
prometheusServerMetricsOpts = append(prometheusServerMetricsOpts, grpc_prometheus.WithServerHandlingTimeHistogram())
}
prometheusServerMetrics := grpc_prometheus.NewServerMetrics(prometheusServerMetricsOpts...)
prometheus.MustRegister(prometheusServerMetrics)
serverOpts := []grpc.ServerOption{ serverOpts := []grpc.ServerOption{
grpc.StatsHandler(otelgrpc.NewServerHandler()), grpc.StatsHandler(otelgrpc.NewServerHandler()),
grpc.ChainStreamInterceptor( grpc.StreamInterceptor(streamNamespaceInterceptor),
streamNamespaceInterceptor, grpc.UnaryInterceptor(unaryNamespaceInterceptor),
prometheusServerMetrics.StreamServerInterceptor(),
),
grpc.ChainUnaryInterceptor(
unaryNamespaceInterceptor,
prometheusServerMetrics.UnaryServerInterceptor(),
),
} }
if config.GRPC.MaxRecvMsgSize > 0 { if config.GRPC.MaxRecvMsgSize > 0 {
serverOpts = append(serverOpts, grpc.MaxRecvMsgSize(config.GRPC.MaxRecvMsgSize)) serverOpts = append(serverOpts, grpc.MaxRecvMsgSize(config.GRPC.MaxRecvMsgSize))
@ -229,7 +212,6 @@ func New(ctx context.Context, config *srvconfig.Config) (*Server, error) {
ttrpcServices []ttrpcService ttrpcServices []ttrpcService
s = &Server{ s = &Server{
prometheusServerMetrics: prometheusServerMetrics,
grpcServer: grpcServer, grpcServer: grpcServer,
tcpServer: tcpServer, tcpServer: tcpServer,
ttrpcServer: ttrpcServer, ttrpcServer: ttrpcServer,
@ -381,7 +363,6 @@ func recordConfigDeprecations(ctx context.Context, config *srvconfig.Config, set
// Server is the containerd main daemon // Server is the containerd main daemon
type Server struct { type Server struct {
prometheusServerMetrics *grpc_prometheus.ServerMetrics
grpcServer *grpc.Server grpcServer *grpc.Server
ttrpcServer *ttrpc.Server ttrpcServer *ttrpc.Server
tcpServer *grpc.Server tcpServer *grpc.Server
@ -392,7 +373,6 @@ type Server struct {
// ServeGRPC provides the containerd grpc APIs on the provided listener // ServeGRPC provides the containerd grpc APIs on the provided listener
func (s *Server) ServeGRPC(l net.Listener) error { func (s *Server) ServeGRPC(l net.Listener) error {
s.prometheusServerMetrics.InitializeMetrics(s.grpcServer)
return trapClosedConnErr(s.grpcServer.Serve(l)) return trapClosedConnErr(s.grpcServer.Serve(l))
} }
@ -414,7 +394,6 @@ func (s *Server) ServeMetrics(l net.Listener) error {
// ServeTCP allows services to serve over tcp // ServeTCP allows services to serve over tcp
func (s *Server) ServeTCP(l net.Listener) error { func (s *Server) ServeTCP(l net.Listener) error {
s.prometheusServerMetrics.InitializeMetrics(s.tcpServer)
return trapClosedConnErr(s.tcpServer.Serve(l)) return trapClosedConnErr(s.tcpServer.Serve(l))
} }