Skip to content

Commit

Permalink
[chore][cmd/telemetrygen] Fix deprecated method usage (#32300)
Browse files Browse the repository at this point in the history
`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
  • Loading branch information
crobert-1 authored Apr 10, 2024
1 parent 1ad0b31 commit 2b0d1be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions cmd/telemetrygen/internal/logs/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/telemetrygen/internal/logs/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package logs

import (
"context"
"fmt"
"sync"
"sync/atomic"
Expand All @@ -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
}
Expand Down

0 comments on commit 2b0d1be

Please sign in to comment.