Skip to content

Commit

Permalink
[chore] more deprecated grpc call updates (#33194)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
codeboten authored May 22, 2024
1 parent b700b34 commit ba5fe28
Show file tree
Hide file tree
Showing 15 changed files with 22 additions and 26 deletions.
2 changes: 1 addition & 1 deletion examples/demo/client/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
)

Expand Down
4 changes: 1 addition & 3 deletions examples/demo/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion examples/demo/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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
)

Expand Down
4 changes: 1 addition & 3 deletions examples/demo/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
Expand Down Expand Up @@ -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")

Expand Down
2 changes: 1 addition & 1 deletion extension/solarwindsapmsettingsextension/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions receiver/jaegerreceiver/trace_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion receiver/lokireceiver/loki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/opencensusreceiver/opencensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions receiver/opencensusreceiver/opencensus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion receiver/otelarrowreceiver/internal/logs/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion receiver/otelarrowreceiver/internal/metrics/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion receiver/otelarrowreceiver/internal/trace/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
12 changes: 6 additions & 6 deletions receiver/otelarrowreceiver/otelarrow_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit ba5fe28

Please sign in to comment.