Skip to content

Commit

Permalink
replace dial with newclient
Browse files Browse the repository at this point in the history
  • Loading branch information
janardhankrishna-sai committed Dec 26, 2024
1 parent 724f450 commit 9650b1a
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 33 deletions.
2 changes: 1 addition & 1 deletion admin/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func RunRegisterTests(t *testing.T, ec ExpectedStatusCodes) {
server.Serve(lis)
}()

conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatalf("cannot connect to server: %v", err)
}
Expand Down
5 changes: 3 additions & 2 deletions balancer/grpclb/grpclb_remote_balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,11 @@ func (lb *lbBalancer) newRemoteBalancerCCWrapper() error {
// The grpclb server addresses will set field ServerName, and creds will
// receive ServerName as authority.
target := lb.manualResolver.Scheme() + ":///grpclb.subClientConn"
cc, err := grpc.Dial(target, dopts...)
cc, err := grpc.NewClient(target, dopts...)
if err != nil {
return fmt.Errorf("grpc.Dial(%s): %v", target, err)
return fmt.Errorf("grpc.NewClient(%s): %v", target, err)

Check warning on line 265 in balancer/grpclb/grpclb_remote_balancer.go

View check run for this annotation

Codecov / codecov/patch

balancer/grpclb/grpclb_remote_balancer.go#L265

Added line #L265 was not covered by tests
}
cc.Connect()
ccw := &remoteBalancerCCWrapper{
cc: cc,
lb: lb,
Expand Down
3 changes: 2 additions & 1 deletion balancer/rls/control_channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,11 @@ func newControlChannel(rlsServerName, serviceConfig string, rpcTimeout time.Dura
if err != nil {
return nil, err
}
ctrlCh.cc, err = grpc.Dial(rlsServerName, dopts...)
ctrlCh.cc, err = grpc.NewClient(rlsServerName, dopts...)
if err != nil {
return nil, err
}
ctrlCh.cc.Connect()
ctrlCh.client = rlsgrpc.NewRouteLookupServiceClient(ctrlCh.cc)
ctrlCh.logger.Infof("Control channel created to RLS server at: %v", rlsServerName)

Expand Down
4 changes: 2 additions & 2 deletions benchmark/benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,8 @@ func NewClientConn(addr string, opts ...grpc.DialOption) *grpc.ClientConn {
}

// NewClientConnWithContext creates a gRPC client connection to addr using ctx.
func NewClientConnWithContext(ctx context.Context, addr string, opts ...grpc.DialOption) *grpc.ClientConn {
conn, err := grpc.DialContext(ctx, addr, opts...)
func NewClientConnWithContext(_ context.Context, addr string, opts ...grpc.DialOption) *grpc.ClientConn {
conn, err := grpc.NewClient(addr, opts...)
if err != nil {
logger.Fatalf("NewClientConn(%q) failed to create a ClientConn: %v", addr, err)
}
Expand Down
2 changes: 1 addition & 1 deletion credentials/alts/internal/handshaker/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func Dial(hsAddress string) (*grpc.ClientConn, error) {
// Disable the service config to avoid unnecessary TXT record lookups that
// cause timeouts with some versions of systemd-resolved.
var err error
hsConn, err = grpc.Dial(hsAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDisableServiceConfig())
hsConn, err = grpc.NewClient(hsAddress, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDisableServiceConfig())
if err != nil {
return nil, err
}
Expand Down
5 changes: 3 additions & 2 deletions internal/stubserver/stubserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,11 @@ func (ss *StubServer) StartClient(dopts ...grpc.DialOption) error {
opts = append(opts, grpc.WithResolvers(ss.R))
}

cc, err := grpc.Dial(ss.Target, opts...)
cc, err := grpc.NewClient(ss.Target, opts...)
if err != nil {
return fmt.Errorf("grpc.Dial(%q) = %v", ss.Target, err)
return fmt.Errorf("grpc.NewClient(%q) = %v", ss.Target, err)

Check warning on line 219 in internal/stubserver/stubserver.go

View check run for this annotation

Codecov / codecov/patch

internal/stubserver/stubserver.go#L219

Added line #L219 was not covered by tests
}
cc.Connect()
ss.CC = cc
if ss.R != nil {
ss.R.UpdateState(resolver.State{Addresses: []resolver.Address{{Addr: ss.Address}}})
Expand Down
4 changes: 2 additions & 2 deletions interop/alts/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ func main() {
}
altsTC := alts.NewClientCreds(opts)
// Block until the server is ready.
conn, err := grpc.Dial(*serverAddr, grpc.WithTransportCredentials(altsTC), grpc.WithBlock())
conn, err := grpc.NewClient(*serverAddr, grpc.WithTransportCredentials(altsTC), grpc.WithBlock())
if err != nil {
logger.Fatalf("gRPC Client: failed to dial the server at %v: %v", *serverAddr, err)
logger.Fatalf("gRPC Client: NewClient() failed %v: %v", *serverAddr, err)
}
defer conn.Close()
grpcClient := testgrpc.NewTestServiceClient(conn)
Expand Down
4 changes: 2 additions & 2 deletions interop/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,9 @@ func main() {
}
opts = append(opts, grpc.WithUnaryInterceptor(unaryAddMd), grpc.WithStreamInterceptor(streamingAddMd))
}
conn, err := grpc.Dial(serverAddr, opts...)
conn, err := grpc.NewClient(serverAddr, opts...)
if err != nil {
logger.Fatalf("Fail to dial: %v", err)
logger.Fatalf("NewClient() failed: %v", err)
}
defer conn.Close()
tc := testgrpc.NewTestServiceClient(conn)
Expand Down
4 changes: 2 additions & 2 deletions interop/grpclb_fallback/client_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ func createTestConn() *grpc.ClientConn {
default:
errorLog.Fatalf("Invalid --custom_credentials_type:%v", *customCredentialsType)
}
conn, err := grpc.Dial(*serverURI, opts...)
conn, err := grpc.NewClient(*serverURI, opts...)
if err != nil {
errorLog.Fatalf("Fail to dial: %v", err)
errorLog.Fatalf("NewClient() failed: %v", err)
}
return conn
}
Expand Down
4 changes: 2 additions & 2 deletions interop/http2/negative_http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,9 @@ func main() {
serverAddr := net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort))
var opts []grpc.DialOption
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.Dial(serverAddr, opts...)
conn, err := grpc.NewClient(serverAddr, opts...)
if err != nil {
logger.Fatalf("Fail to dial: %v", err)
logger.Fatalf("NewClient() failed: %v", err)
}
defer conn.Close()
tc := testgrpc.NewTestServiceClient(conn)
Expand Down
4 changes: 2 additions & 2 deletions interop/observability/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func main() {
if *serverPort != 0 {
serverAddr = net.JoinHostPort(*serverHost, strconv.Itoa(*serverPort))
}
conn, err := grpc.Dial(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(serverAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
log.Fatalf("Fail to dial: %v", err)
log.Fatalf("NewClient() failed: %v", err)
}
defer conn.Close()
tc := testgrpc.NewTestServiceClient(conn)
Expand Down
2 changes: 1 addition & 1 deletion interop/stress/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func newConn(address string, useTLS, testCA bool, tlsServerName string) (*grpc.C
} else {
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
return grpc.Dial(address, opts...)
return grpc.NewClient(address, opts...)
}

func main() {
Expand Down
2 changes: 1 addition & 1 deletion interop/stress/metrics_client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func main() {
logger.Fatal("-metrics_server_address is unset")
}

conn, err := grpc.Dial(*metricsServerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
conn, err := grpc.NewClient(*metricsServerAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
logger.Fatalf("cannot connect to metrics server: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion interop/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ func doOneSoakIteration(ctx context.Context, tc testgrpc.TestServiceClient, rese
client := tc
if resetChannel {
var conn *grpc.ClientConn
conn, err = grpc.Dial(serverAddr, dopts...)
conn, err = grpc.NewClient(serverAddr, dopts...)
if err != nil {
return
}
Expand Down
4 changes: 2 additions & 2 deletions interop/xds/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,9 +437,9 @@ func main() {

clients := make([]testgrpc.TestServiceClient, *numChannels)
for i := 0; i < *numChannels; i++ {
conn, err := grpc.Dial(*server, grpc.WithTransportCredentials(creds))
conn, err := grpc.NewClient(*server, grpc.WithTransportCredentials(creds))
if err != nil {
logger.Fatalf("Fail to dial: %v", err)
logger.Fatalf("NewClient() failed: %v", err)
}
defer conn.Close()
clients[i] = testgrpc.NewTestServiceClient(conn)
Expand Down
4 changes: 2 additions & 2 deletions interop/xds_federation/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ func main() {
case insecureCredsName:
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
cc, err := grpc.Dial(uris[i], opts...)
cc, err := grpc.NewClient(uris[i], opts...)
if err != nil {
logger.Fatalf("Fail to dial %v: %v", uris[i], err)
logger.Fatalf("NewClient() failed %v: %v", uris[i], err)
}
defer cc.Close()
clients = append(clients, clientConfig{
Expand Down
4 changes: 2 additions & 2 deletions profiling/cmd/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ func remoteCommand() error {
}

logger.Infof("dialing %s", *flagAddress)
cc, err := grpc.Dial(*flagAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))
cc, err := grpc.NewClient(*flagAddress, grpc.WithTransportCredentials(insecure.NewCredentials()))

Check warning on line 82 in profiling/cmd/remote.go

View check run for this annotation

Codecov / codecov/patch

profiling/cmd/remote.go#L82

Added line #L82 was not covered by tests
if err != nil {
logger.Errorf("cannot dial %s: %v", *flagAddress, err)
logger.Errorf("NewClient() failed %s: %v", *flagAddress, err)

Check warning on line 84 in profiling/cmd/remote.go

View check run for this annotation

Codecov / codecov/patch

profiling/cmd/remote.go#L84

Added line #L84 was not covered by tests
return err
}
defer cc.Close()
Expand Down
4 changes: 2 additions & 2 deletions resolver/manual/manual.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *Resolver) UpdateState(s resolver.State) {
defer r.mu.Unlock()
var err error
if r.CC == nil {
panic("cannot update state as grpc.Dial with resolver has not been called")
panic("cannot update state as grpc.NewClient with resolver has not been called")
}
err = r.CC.UpdateState(s)
r.lastSeenState = &s
Expand All @@ -122,7 +122,7 @@ func (r *Resolver) ReportError(err error) {
r.mu.Lock()
defer r.mu.Unlock()
if r.CC == nil {
panic("cannot report error as grpc.Dial with resolver has not been called")
panic("cannot report error as grpc.NewClient with resolver has not been called")
}
r.CC.ReportError(err)
}
4 changes: 2 additions & 2 deletions resolver/manual/manual_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestResolver(t *testing.T) {

t.Run("update_state_panics", func(t *testing.T) {
defer func() {
want := "cannot update state as grpc.Dial with resolver has not been called"
want := "cannot update state as grpc.NewClient with resolver has not been called"
if r := recover(); r != want {
t.Errorf("expected panic %q, got %q", want, r)
}
Expand All @@ -50,7 +50,7 @@ func TestResolver(t *testing.T) {
})
t.Run("report_error_panics", func(t *testing.T) {
defer func() {
want := "cannot report error as grpc.Dial with resolver has not been called"
want := "cannot report error as grpc.NewClient with resolver has not been called"
if r := recover(); r != want {
t.Errorf("expected panic %q, got %q", want, r)
}
Expand Down
2 changes: 1 addition & 1 deletion xds/internal/test/e2e/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func newClient(target, binaryPath, bootstrap string, logger io.Writer, flags ...
)
cmd.Start()

cc, err := grpc.Dial(fmt.Sprintf("localhost:%d", clientStatsPort), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.WaitForReady(true)))
cc, err := grpc.NewClient(fmt.Sprintf("localhost:%d", clientStatsPort), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithDefaultCallOptions(grpc.WaitForReady(true)))

Check warning on line 74 in xds/internal/test/e2e/e2e.go

View check run for this annotation

Codecov / codecov/patch

xds/internal/test/e2e/e2e.go#L74

Added line #L74 was not covered by tests
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 9650b1a

Please sign in to comment.