From 2b0d1be617929e656340b7853636f2e902f01e88 Mon Sep 17 00:00:00 2001 From: Curtis Robert Date: Wed, 10 Apr 2024 13:09:18 -0700 Subject: [PATCH] [chore][cmd/telemetrygen] Fix deprecated method usage (#32300) `grpc.DialContext` has been deprecated in favor of `grpc.NewClient`. The only difference relevant to our usage is that the context is no longer passed in. I investigated, and the context being cancelled and exiting the running sub-goroutine is [handled internally](https://github.com/grpc/grpc-go/blob/d32e66ce27447a0a217464a36fdd3935801c0453/clientconn.go#L135) in an equivalent way to how we were using `grpc.DialContext`, so there shouldn't be any impact here. Resolves #32297 --- cmd/telemetrygen/internal/logs/exporter.go | 6 +++--- cmd/telemetrygen/internal/logs/logs.go | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/telemetrygen/internal/logs/exporter.go b/cmd/telemetrygen/internal/logs/exporter.go index 187cfe78e9db..2e886e65823c 100644 --- a/cmd/telemetrygen/internal/logs/exporter.go +++ b/cmd/telemetrygen/internal/logs/exporter.go @@ -22,7 +22,7 @@ type exporter interface { export(plog.Logs) error } -func newExporter(ctx context.Context, cfg *Config) (exporter, error) { +func newExporter(cfg *Config) (exporter, error) { // Exporter with HTTP if cfg.UseHTTP { @@ -46,7 +46,7 @@ func newExporter(ctx context.Context, cfg *Config) (exporter, error) { var err error var clientConn *grpc.ClientConn if cfg.Insecure { - clientConn, err = grpc.DialContext(ctx, cfg.Endpoint(), grpc.WithTransportCredentials(insecure.NewCredentials())) + clientConn, err = grpc.NewClient(cfg.Endpoint(), grpc.WithTransportCredentials(insecure.NewCredentials())) if err != nil { return nil, err } @@ -55,7 +55,7 @@ func newExporter(ctx context.Context, cfg *Config) (exporter, error) { if err != nil { return nil, fmt.Errorf("failed to get TLS credentials: %w", err) } - clientConn, err = grpc.DialContext(ctx, cfg.Endpoint(), grpc.WithTransportCredentials(creds)) + clientConn, err = grpc.NewClient(cfg.Endpoint(), grpc.WithTransportCredentials(creds)) if err != nil { return nil, err } diff --git a/cmd/telemetrygen/internal/logs/logs.go b/cmd/telemetrygen/internal/logs/logs.go index 0906851d9f04..b4349021425f 100644 --- a/cmd/telemetrygen/internal/logs/logs.go +++ b/cmd/telemetrygen/internal/logs/logs.go @@ -4,7 +4,6 @@ package logs import ( - "context" "fmt" "sync" "sync/atomic" @@ -26,7 +25,7 @@ func Start(cfg *Config) error { return err } - e, err := newExporter(context.Background(), cfg) + e, err := newExporter(cfg) if err != nil { return err }