Skip to content

Commit

Permalink
[chore] replace deprecated calls (open-telemetry#10211)
Browse files Browse the repository at this point in the history
Updating grpc.Dial -> grpc.NewClient, removing grpc.WithBlock as it's
not recommended
https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#the-wrong-way-grpcdial.
We may need to add code in the future to wait for state to be connected,
but in my local tests, there was no flakiness introduced with this
change.

Fixes
open-telemetry#10194

---------

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
  • Loading branch information
codeboten authored and steves-canva committed Jun 13, 2024
1 parent 4f70f4c commit cc7fc06
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
12 changes: 6 additions & 6 deletions pdata/plog/plogotlp/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"

Expand All @@ -36,12 +37,12 @@ func TestGrpc(t *testing.T) {
wg.Wait()
})

cc, err := grpc.Dial("bufnet",
resolver.SetDefaultScheme("passthrough")
cc, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return lis.Dial()
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, cc.Close())
Expand Down Expand Up @@ -69,12 +70,11 @@ func TestGrpcError(t *testing.T) {
wg.Wait()
})

cc, err := grpc.Dial("bufnet",
cc, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return lis.Dial()
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, cc.Close())
Expand Down
12 changes: 6 additions & 6 deletions pdata/pmetric/pmetricotlp/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"

Expand All @@ -36,12 +37,12 @@ func TestGrpc(t *testing.T) {
wg.Wait()
})

cc, err := grpc.Dial("bufnet",
resolver.SetDefaultScheme("passthrough")
cc, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return lis.Dial()
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, cc.Close())
Expand Down Expand Up @@ -69,12 +70,11 @@ func TestGrpcError(t *testing.T) {
wg.Wait()
})

cc, err := grpc.Dial("bufnet",
cc, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return lis.Dial()
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, cc.Close())
Expand Down
12 changes: 6 additions & 6 deletions pdata/ptrace/ptraceotlp/grpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/status"
"google.golang.org/grpc/test/bufconn"

Expand All @@ -36,12 +37,12 @@ func TestGrpc(t *testing.T) {
wg.Wait()
})

cc, err := grpc.Dial("bufnet",
resolver.SetDefaultScheme("passthrough")
cc, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return lis.Dial()
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, cc.Close())
Expand Down Expand Up @@ -69,12 +70,11 @@ func TestGrpcError(t *testing.T) {
wg.Wait()
})

cc, err := grpc.Dial("bufnet",
cc, err := grpc.NewClient("bufnet",
grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) {
return lis.Dial()
}),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithBlock())
grpc.WithTransportCredentials(insecure.NewCredentials()))
assert.NoError(t, err)
t.Cleanup(func() {
assert.NoError(t, cc.Close())
Expand Down
2 changes: 1 addition & 1 deletion receiver/otlpreceiver/internal/logs/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestExport_PermanentErrorConsumer(t *testing.T) {

func makeLogsServiceClient(t *testing.T, lc consumer.Logs) plogotlp.GRPCClient {
addr := otlpReceiverOnGRPCServer(t, lc)
cc, err := grpc.NewClient(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/otlpreceiver/internal/metrics/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestExport_PermanentErrorConsumer(t *testing.T) {
func makeMetricsServiceClient(t *testing.T, mc consumer.Metrics) pmetricotlp.GRPCClient {
addr := otlpReceiverOnGRPCServer(t, mc)

cc, err := grpc.NewClient(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/otlpreceiver/internal/trace/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestExport_PermanentErrorConsumer(t *testing.T) {

func makeTraceServiceClient(t *testing.T, tc consumer.Traces) ptraceotlp.GRPCClient {
addr := otlpReceiverOnGRPCServer(t, tc)
cc, err := grpc.NewClient(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
8 changes: 4 additions & 4 deletions receiver/otlpreceiver/otlp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ func TestOTLPReceiverGRPCTracesIngestTest(t *testing.T) {
require.NoError(t, recv.Start(context.Background(), componenttest.NewNopHost()))
t.Cleanup(func() { require.NoError(t, recv.Shutdown(context.Background())) })

cc, err := grpc.NewClient(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 @@ -722,7 +722,7 @@ func TestGRPCMaxRecvSize(t *testing.T) {
recv := newReceiver(t, componenttest.NewNopTelemetrySettings(), cfg, otlpReceiverID, sink)
require.NoError(t, recv.Start(context.Background(), componenttest.NewNopHost()))

cc, err := grpc.NewClient(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 @@ -735,7 +735,7 @@ func TestGRPCMaxRecvSize(t *testing.T) {
require.NoError(t, recv.Start(context.Background(), componenttest.NewNopHost()))
t.Cleanup(func() { require.NoError(t, recv.Shutdown(context.Background())) })

cc, err = grpc.NewClient(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 @@ -1008,7 +1008,7 @@ func TestShutdown(t *testing.T) {
require.NotNil(t, r)
require.NoError(t, r.Start(context.Background(), componenttest.NewNopHost()))

conn, err := grpc.NewClient(endpointGrpc, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
conn, err := grpc.NewClient(endpointGrpc, grpc.WithTransportCredentials(insecure.NewCredentials()))
require.NoError(t, err)
t.Cleanup(func() {
require.NoError(t, conn.Close())
Expand Down

0 comments on commit cc7fc06

Please sign in to comment.