From 5c90cefd30d4ccf72d752ad389a299385e225ce8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 8 Nov 2023 10:56:53 +0100 Subject: [PATCH 1/3] otelgrpc: Use net.Listen in TestStatsHandler --- .../otelgrpc/test/grpc_stats_handler_test.go | 8 +++---- .../grpc/otelgrpc/test/grpc_test.go | 21 ++++++++++--------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go index d84d1e62e6a..f9905d18787 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_stats_handler_test.go @@ -16,13 +16,13 @@ package test import ( "context" + "net" "testing" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" "google.golang.org/grpc" "google.golang.org/grpc/codes" - "google.golang.org/grpc/test/bufconn" "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "go.opentelemetry.io/otel/attribute" @@ -47,9 +47,9 @@ func TestStatsHandler(t *testing.T) { serverMetricReader := metric.NewManualReader() serverMP := metric.NewMeterProvider(metric.WithReader(serverMetricReader)) - listener := bufconn.Listen(bufSize) - defer listener.Close() - err := newGrpcTest( + listener, err := net.Listen("tcp", "127.0.0.1:0") + require.NoError(t, err, "failed to open port") + err = newGrpcTest( listener, []grpc.DialOption{ grpc.WithStatsHandler(otelgrpc.NewClientHandler(otelgrpc.WithTracerProvider(clientTP), otelgrpc.WithMeterProvider(clientMP))), diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index 6d8a82676ba..242f62f48c6 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -107,16 +107,17 @@ func TestInterceptors(t *testing.T) { listener, err := net.Listen("tcp", "127.0.0.1:0") require.NoError(t, err, "failed to open port") - err = newGrpcTest(listener, []grpc.DialOption{ - grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor( - otelgrpc.WithTracerProvider(clientUnaryTP), - otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents), - )), - grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor( - otelgrpc.WithTracerProvider(clientStreamTP), - otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents), - )), - }, + err = newGrpcTest(listener, + []grpc.DialOption{ + grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor( + otelgrpc.WithTracerProvider(clientUnaryTP), + otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents), + )), + grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor( + otelgrpc.WithTracerProvider(clientStreamTP), + otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents), + )), + }, []grpc.ServerOption{ grpc.UnaryInterceptor(otelgrpc.UnaryServerInterceptor( otelgrpc.WithTracerProvider(serverUnaryTP), From 6bd7091db37c431ca40ad9b97b8d39e16fff1efc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Wed, 8 Nov 2023 11:06:24 +0100 Subject: [PATCH 2/3] Remove unused bufSize --- .../google.golang.org/grpc/otelgrpc/test/grpc_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index 242f62f48c6..4718ea5b820 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -45,8 +45,6 @@ var wantInstrumentationScope = instrumentation.Scope{ Version: otelgrpc.Version(), } -const bufSize = 2048 - // newGrpcTest creats a grpc server, starts it, and executes all the calls, closes everything down. func newGrpcTest(listener net.Listener, cOpt []grpc.DialOption, sOpt []grpc.ServerOption) error { grpcServer := grpc.NewServer(sOpt...) From 0fab498a540c81e28cbd804de66b939d51e0dc1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Paj=C4=85k?= Date: Thu, 9 Nov 2023 07:57:55 +0100 Subject: [PATCH 3/3] Update grpc_test.go --- .../google.golang.org/grpc/otelgrpc/test/grpc_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go index e576916b2bb..1c8cc790a2f 100644 --- a/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go +++ b/instrumentation/google.golang.org/grpc/otelgrpc/test/grpc_test.go @@ -108,10 +108,12 @@ func TestInterceptors(t *testing.T) { require.NoError(t, err, "failed to open port") err = newGrpcTest(listener, []grpc.DialOption{ + //nolint:staticcheck // Interceptors are deprecated and will be removed in the next release. grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor( otelgrpc.WithTracerProvider(clientUnaryTP), otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents), )), + //nolint:staticcheck // Interceptors are deprecated and will be removed in the next release. grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor( otelgrpc.WithTracerProvider(clientStreamTP), otelgrpc.WithMessageEvents(otelgrpc.ReceivedEvents, otelgrpc.SentEvents),