From ba5fe2840c8715dc0c2614e93d7ca4aa688bf07f Mon Sep 17 00:00:00 2001 From: Alex Boten <223565+codeboten@users.noreply.github.com> Date: Wed, 22 May 2024 13:07:10 -0700 Subject: [PATCH] [chore] more deprecated grpc call updates (#33194) Updating grpc.Dial to grpc.NewClient and removing WithBlock as per https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#the-wrong-way-grpcdial --------- Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com> --- examples/demo/client/go.mod | 2 +- examples/demo/client/main.go | 4 +--- examples/demo/server/go.mod | 2 +- examples/demo/server/main.go | 4 +--- .../solarwindsapmsettingsextension/extension.go | 2 +- receiver/jaegerreceiver/trace_receiver_test.go | 4 ++-- receiver/lokireceiver/loki_test.go | 2 +- .../internal/ocmetrics/opencensus_test.go | 2 +- .../internal/octrace/opencensus_test.go | 2 +- receiver/opencensusreceiver/opencensus.go | 2 +- receiver/opencensusreceiver/opencensus_test.go | 4 ++-- .../otelarrowreceiver/internal/logs/otlp_test.go | 2 +- .../otelarrowreceiver/internal/metrics/otlp_test.go | 2 +- .../otelarrowreceiver/internal/trace/otlp_test.go | 2 +- receiver/otelarrowreceiver/otelarrow_test.go | 12 ++++++------ 15 files changed, 22 insertions(+), 26 deletions(-) diff --git a/examples/demo/client/go.mod b/examples/demo/client/go.mod index 7f8c8dbd58b5..2f09763d8e54 100644 --- a/examples/demo/client/go.mod +++ b/examples/demo/client/go.mod @@ -11,7 +11,6 @@ require ( go.opentelemetry.io/otel/metric v1.26.0 go.opentelemetry.io/otel/sdk v1.26.0 go.opentelemetry.io/otel/sdk/metric v1.26.0 - google.golang.org/grpc v1.63.2 ) require ( @@ -27,6 +26,7 @@ require ( golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect + google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/examples/demo/client/main.go b/examples/demo/client/main.go index f311c045b74b..35304293da7b 100644 --- a/examples/demo/client/main.go +++ b/examples/demo/client/main.go @@ -27,7 +27,6 @@ import ( "go.opentelemetry.io/otel/sdk/resource" sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" - "google.golang.org/grpc" ) // Initializes an OTLP exporter, and configures the corresponding trace and @@ -72,8 +71,7 @@ func initProvider() func() { traceClient := otlptracegrpc.NewClient( otlptracegrpc.WithInsecure(), - otlptracegrpc.WithEndpoint(otelAgentAddr), - otlptracegrpc.WithDialOption(grpc.WithBlock())) + otlptracegrpc.WithEndpoint(otelAgentAddr)) sctx, cancel := context.WithTimeout(ctx, time.Second) defer cancel() traceExp, err := otlptrace.New(sctx, traceClient) diff --git a/examples/demo/server/go.mod b/examples/demo/server/go.mod index 1b0caf955bee..fc4d92e556ed 100644 --- a/examples/demo/server/go.mod +++ b/examples/demo/server/go.mod @@ -12,7 +12,6 @@ require ( go.opentelemetry.io/otel/sdk v1.26.0 go.opentelemetry.io/otel/sdk/metric v1.26.0 go.opentelemetry.io/otel/trace v1.26.0 - google.golang.org/grpc v1.63.2 ) require ( @@ -27,6 +26,7 @@ require ( golang.org/x/text v0.14.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20240227224415-6ceb2ff114de // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240401170217-c3f982113cda // indirect + google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/examples/demo/server/main.go b/examples/demo/server/main.go index 9f584b647399..c345f152e406 100644 --- a/examples/demo/server/main.go +++ b/examples/demo/server/main.go @@ -27,7 +27,6 @@ import ( sdktrace "go.opentelemetry.io/otel/sdk/trace" semconv "go.opentelemetry.io/otel/semconv/v1.4.0" "go.opentelemetry.io/otel/trace" - "google.golang.org/grpc" ) var rng = rand.New(rand.NewSource(time.Now().UnixNano())) @@ -73,8 +72,7 @@ func initProvider() func() { traceClient := otlptracegrpc.NewClient( otlptracegrpc.WithInsecure(), - otlptracegrpc.WithEndpoint(otelAgentAddr), - otlptracegrpc.WithDialOption(grpc.WithBlock())) + otlptracegrpc.WithEndpoint(otelAgentAddr)) traceExp, err := otlptrace.New(ctx, traceClient) handleErr(err, "Failed to create the collector trace exporter") diff --git a/extension/solarwindsapmsettingsextension/extension.go b/extension/solarwindsapmsettingsextension/extension.go index 60ba0c88df1a..04bd1b75cc56 100644 --- a/extension/solarwindsapmsettingsextension/extension.go +++ b/extension/solarwindsapmsettingsextension/extension.go @@ -37,7 +37,7 @@ func (extension *solarwindsapmSettingsExtension) Start(_ context.Context, _ comp ctx := context.Background() ctx, extension.cancel = context.WithCancel(ctx) var err error - extension.conn, err = grpc.Dial(extension.config.Endpoint, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) + extension.conn, err = grpc.NewClient(extension.config.Endpoint, grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{}))) if err != nil { return err } diff --git a/receiver/jaegerreceiver/trace_receiver_test.go b/receiver/jaegerreceiver/trace_receiver_test.go index 24c582c3e4db..320484313fec 100644 --- a/receiver/jaegerreceiver/trace_receiver_test.go +++ b/receiver/jaegerreceiver/trace_receiver_test.go @@ -157,7 +157,7 @@ func TestGRPCReception(t *testing.T) { require.NoError(t, jr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, jr.Shutdown(context.Background())) }) - conn, err := grpc.NewClient(config.GRPCServerConfig.NetAddr.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + conn, err := grpc.NewClient(config.GRPCServerConfig.NetAddr.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) defer conn.Close() @@ -217,7 +217,7 @@ func TestGRPCReceptionWithTLS(t *testing.T) { creds, err := credentials.NewClientTLSFromFile(filepath.Join("testdata", "server.crt"), "localhost") require.NoError(t, err) - conn, err := grpc.NewClient(grpcServerSettings.NetAddr.Endpoint, grpc.WithTransportCredentials(creds), grpc.WithBlock()) + conn, err := grpc.NewClient(grpcServerSettings.NetAddr.Endpoint, grpc.WithTransportCredentials(creds)) require.NoError(t, err) defer conn.Close() diff --git a/receiver/lokireceiver/loki_test.go b/receiver/lokireceiver/loki_test.go index bb927ea5887d..8dbe7a4edc21 100644 --- a/receiver/lokireceiver/loki_test.go +++ b/receiver/lokireceiver/loki_test.go @@ -106,7 +106,7 @@ func startGRPCServer(t *testing.T) (*grpc.ClientConn, *consumertest.LogsSink) { require.NoError(t, lr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, lr.Shutdown(context.Background())) }) - conn, err := grpc.NewClient(config.GRPC.NetAddr.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + conn, err := grpc.NewClient(config.GRPC.NetAddr.Endpoint, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) return conn, sink } diff --git a/receiver/opencensusreceiver/internal/ocmetrics/opencensus_test.go b/receiver/opencensusreceiver/internal/ocmetrics/opencensus_test.go index 4f12e68cf799..8d34dfbb3c09 100644 --- a/receiver/opencensusreceiver/internal/ocmetrics/opencensus_test.go +++ b/receiver/opencensusreceiver/internal/ocmetrics/opencensus_test.go @@ -332,7 +332,7 @@ func TestExportProtocolConformation_metricsInFirstMessage(t *testing.T) { // Helper functions from here on below func makeMetricsServiceClient(addr net.Addr) (agentmetricspb.MetricsService_ExportClient, func(), error) { - cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, nil, err } diff --git a/receiver/opencensusreceiver/internal/octrace/opencensus_test.go b/receiver/opencensusreceiver/internal/octrace/opencensus_test.go index 3b146f099b97..e9c0f4b3c1a1 100644 --- a/receiver/opencensusreceiver/internal/octrace/opencensus_test.go +++ b/receiver/opencensusreceiver/internal/octrace/opencensus_test.go @@ -345,7 +345,7 @@ func TestExportProtocolConformation_spansInFirstMessage(t *testing.T) { // Helper functions from here on below func makeTraceServiceClient(addr net.Addr) (agenttracepb.TraceService_ExportClient, func(), error) { - cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, nil, err } diff --git a/receiver/opencensusreceiver/opencensus.go b/receiver/opencensusreceiver/opencensus.go index 4573d73ee11d..fa37d0b6cf48 100644 --- a/receiver/opencensusreceiver/opencensus.go +++ b/receiver/opencensusreceiver/opencensus.go @@ -162,7 +162,7 @@ func (ocr *ocReceiver) Start(ctx context.Context, host component.Host) error { startWG.Wait() - opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()} + opts := []grpc.DialOption{grpc.WithTransportCredentials(insecure.NewCredentials())} if err := agenttracepb.RegisterTraceServiceHandlerFromEndpoint(c, ocr.gatewayMux, endpoint, opts); err != nil { return err } diff --git a/receiver/opencensusreceiver/opencensus_test.go b/receiver/opencensusreceiver/opencensus_test.go index bee43c3d4f9d..feea73158439 100644 --- a/receiver/opencensusreceiver/opencensus_test.go +++ b/receiver/opencensusreceiver/opencensus_test.go @@ -481,7 +481,7 @@ func TestOCReceiverTrace_HandleNextConsumerResponse(t *testing.T) { require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) - cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { t.Errorf("grpc.NewClient: %v", err) } @@ -639,7 +639,7 @@ func TestOCReceiverMetrics_HandleNextConsumerResponse(t *testing.T) { require.Nil(t, ocr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) - cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { t.Errorf("grpc.NewClient: %v", err) } diff --git a/receiver/otelarrowreceiver/internal/logs/otlp_test.go b/receiver/otelarrowreceiver/internal/logs/otlp_test.go index 8519d715848b..90b7792535cb 100644 --- a/receiver/otelarrowreceiver/internal/logs/otlp_test.go +++ b/receiver/otelarrowreceiver/internal/logs/otlp_test.go @@ -58,7 +58,7 @@ func TestExport_ErrorConsumer(t *testing.T) { func makeLogsServiceClient(t *testing.T, lc consumer.Logs) plogotlp.GRPCClient { addr := otlpReceiverOnGRPCServer(t, lc) - cc, err := grpc.Dial(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err, "Failed to create the TraceServiceClient: %v", err) t.Cleanup(func() { require.NoError(t, cc.Close()) diff --git a/receiver/otelarrowreceiver/internal/metrics/otlp_test.go b/receiver/otelarrowreceiver/internal/metrics/otlp_test.go index 61d4c0412ff1..3ae973573ab4 100644 --- a/receiver/otelarrowreceiver/internal/metrics/otlp_test.go +++ b/receiver/otelarrowreceiver/internal/metrics/otlp_test.go @@ -59,7 +59,7 @@ func TestExport_ErrorConsumer(t *testing.T) { func makeMetricsServiceClient(t *testing.T, mc consumer.Metrics) pmetricotlp.GRPCClient { addr := otlpReceiverOnGRPCServer(t, mc) - cc, err := grpc.Dial(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err, "Failed to create the MetricsServiceClient: %v", err) t.Cleanup(func() { require.NoError(t, cc.Close()) diff --git a/receiver/otelarrowreceiver/internal/trace/otlp_test.go b/receiver/otelarrowreceiver/internal/trace/otlp_test.go index 826aa28bbc30..81c618868568 100644 --- a/receiver/otelarrowreceiver/internal/trace/otlp_test.go +++ b/receiver/otelarrowreceiver/internal/trace/otlp_test.go @@ -56,7 +56,7 @@ func TestExport_ErrorConsumer(t *testing.T) { func makeTraceServiceClient(t *testing.T, tc consumer.Traces) ptraceotlp.GRPCClient { addr := otlpReceiverOnGRPCServer(t, tc) - cc, err := grpc.Dial(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr.String(), grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err, "Failed to create the TraceServiceClient: %v", err) t.Cleanup(func() { require.NoError(t, cc.Close()) diff --git a/receiver/otelarrowreceiver/otelarrow_test.go b/receiver/otelarrowreceiver/otelarrow_test.go index 9a480e6b44ba..cd92f09c71a2 100644 --- a/receiver/otelarrowreceiver/otelarrow_test.go +++ b/receiver/otelarrowreceiver/otelarrow_test.go @@ -107,7 +107,7 @@ func TestOTLPReceiverGRPCTracesIngestTest(t *testing.T) { require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) - cc, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) defer func() { assert.NoError(t, cc.Close()) @@ -176,7 +176,7 @@ func TestGRPCMaxRecvSize(t *testing.T) { require.NotNil(t, ocr) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) - cc, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) td := testdata.GenerateTraces(50000) @@ -192,7 +192,7 @@ func TestGRPCMaxRecvSize(t *testing.T) { require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) t.Cleanup(func() { require.NoError(t, ocr.Shutdown(context.Background())) }) - cc, err = grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err = grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) defer func() { assert.NoError(t, cc.Close()) @@ -251,7 +251,7 @@ func TestShutdown(t *testing.T) { require.NotNil(t, r) require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost())) - conn, err := grpc.Dial(endpointGrpc, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + conn, err := grpc.NewClient(endpointGrpc, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) defer conn.Close() @@ -410,7 +410,7 @@ func TestGRPCArrowReceiver(t *testing.T) { require.NotNil(t, ocr) require.NoError(t, ocr.Start(context.Background(), componenttest.NewNopHost())) - cc, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) ctx, cancel := context.WithCancel(context.Background()) @@ -539,7 +539,7 @@ func TestGRPCArrowReceiverAuth(t *testing.T) { require.NoError(t, ocr.Start(context.Background(), host)) - cc, err := grpc.Dial(addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock()) + cc, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) require.NoError(t, err) ctx, cancel := context.WithCancel(context.Background())