diff --git a/agent/grpc/client.go b/agent/grpc/client.go index 6a3feaf7a..7eb80070f 100644 --- a/agent/grpc/client.go +++ b/agent/grpc/client.go @@ -61,7 +61,7 @@ func (c *ClientConnPool) ClientConn(datacenter string) (*grpc.ClientConn, error) grpc.WithInsecure(), grpc.WithContextDialer(c.dialer), grpc.WithDisableRetry(), - grpc.WithStatsHandler(newStatsHandler(defaultMetrics)), + grpc.WithStatsHandler(newStatsHandler(defaultMetrics())), // nolint:staticcheck // there is no other supported alternative to WithBalancerName grpc.WithBalancerName("pick_first")) if err != nil { diff --git a/agent/grpc/handler.go b/agent/grpc/handler.go index d381b9da8..388954dc4 100644 --- a/agent/grpc/handler.go +++ b/agent/grpc/handler.go @@ -14,11 +14,12 @@ import ( // The register function will be called with the grpc.Server to register // gRPC services with the server. func NewHandler(addr net.Addr, register func(server *grpc.Server)) *Handler { + metrics := defaultMetrics() // We don't need to pass tls.Config to the server since it's multiplexed // behind the RPC listener, which already has TLS configured. srv := grpc.NewServer( - grpc.StatsHandler(newStatsHandler(defaultMetrics)), - grpc.StreamInterceptor((&activeStreamCounter{metrics: defaultMetrics}).Intercept), + grpc.StatsHandler(newStatsHandler(metrics)), + grpc.StreamInterceptor((&activeStreamCounter{metrics: metrics}).Intercept), ) register(srv) diff --git a/agent/grpc/stats.go b/agent/grpc/stats.go index add3195f1..eeb8eb379 100644 --- a/agent/grpc/stats.go +++ b/agent/grpc/stats.go @@ -9,7 +9,7 @@ import ( "google.golang.org/grpc/stats" ) -var defaultMetrics = metrics.Default() +var defaultMetrics = metrics.Default // statsHandler is a grpc/stats.StatsHandler which emits connection and // request metrics to go-metrics. diff --git a/agent/grpc/stats_test.go b/agent/grpc/stats_test.go index de83e2e20..475bbf6df 100644 --- a/agent/grpc/stats_test.go +++ b/agent/grpc/stats_test.go @@ -113,11 +113,14 @@ func patchGlobalMetrics(t *testing.T) (*fakeMetricsSink, func()) { FilterDefault: true, } var err error - defaultMetrics, err = metrics.New(cfg, sink) + defaultMetrics = func() *metrics.Metrics { + m, _ := metrics.New(cfg, sink) + return m + } require.NoError(t, err) reset := func() { t.Helper() - defaultMetrics, err = metrics.New(cfg, &metrics.BlackholeSink{}) + defaultMetrics = metrics.Default require.NoError(t, err, "failed to reset global metrics") } return sink, reset