From e13b6b88ebd9ef3f647afbc002debda4b9e6a693 Mon Sep 17 00:00:00 2001 From: congqixia Date: Wed, 9 Aug 2023 13:37:16 +0800 Subject: [PATCH] Replace deprecated grpc WithInsecure option (#26226) Signed-off-by: Congqi Xia --- internal/distributed/connection_manager.go | 8 ++++++-- internal/distributed/proxy/service_test.go | 3 ++- internal/querycoordv2/session/cluster_test.go | 3 ++- internal/util/grpcclient/client.go | 5 ++--- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/internal/distributed/connection_manager.go b/internal/distributed/connection_manager.go index c0c8855ab0..e43d1817e9 100644 --- a/internal/distributed/connection_manager.go +++ b/internal/distributed/connection_manager.go @@ -39,6 +39,7 @@ import ( "go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc" "google.golang.org/grpc" "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" "go.uber.org/zap" ) @@ -378,8 +379,11 @@ func (bct *buildClientTask) Run() { connectGrpcFunc := func() error { opts := tracer.GetInterceptorOpts() log.Debug("Grpc connect", zap.String("Address", bct.sess.Address)) - conn, err := grpc.DialContext(bct.ctx, bct.sess.Address, - grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(30*time.Second), + ctx, cancel := context.WithTimeout(bct.ctx, 30*time.Second) + defer cancel() + conn, err := grpc.DialContext(ctx, bct.sess.Address, + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithBlock(), grpc.WithDisableRetry(), grpc.WithUnaryInterceptor( grpc_middleware.ChainUnaryClient( diff --git a/internal/distributed/proxy/service_test.go b/internal/distributed/proxy/service_test.go index 3ea8c45e74..1570cc0f05 100644 --- a/internal/distributed/proxy/service_test.go +++ b/internal/distributed/proxy/service_test.go @@ -38,6 +38,7 @@ import ( "go.uber.org/zap" "google.golang.org/grpc" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/health/grpc_health_v1" "github.com/milvus-io/milvus-proto/go-api/v2/commonpb" @@ -971,7 +972,7 @@ func waitForGrpcReady(opt *WaitOption) { conn.Close() return } - if conn, err := grpc.Dial(address, grpc.WithBlock(), grpc.WithInsecure()); true { + if conn, err := grpc.Dial(address, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())); true { ch <- err conn.Close() } diff --git a/internal/querycoordv2/session/cluster_test.go b/internal/querycoordv2/session/cluster_test.go index 3df65f9566..d888387e45 100644 --- a/internal/querycoordv2/session/cluster_test.go +++ b/internal/querycoordv2/session/cluster_test.go @@ -30,6 +30,7 @@ import ( "github.com/stretchr/testify/mock" "github.com/stretchr/testify/suite" "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" ) const bufSize = 1024 * 1024 @@ -78,7 +79,7 @@ func (suite *ClusterTestSuite) setupServers() { // check server ready to serve for _, lis := range suite.listeners { - conn, err := grpc.Dial(lis.Addr().String(), grpc.WithBlock(), grpc.WithInsecure()) + conn, err := grpc.Dial(lis.Addr().String(), grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials())) suite.NoError(err) suite.NoError(conn.Close()) } diff --git a/internal/util/grpcclient/client.go b/internal/util/grpcclient/client.go index 1acaadc9c8..a09561942e 100644 --- a/internal/util/grpcclient/client.go +++ b/internal/util/grpcclient/client.go @@ -32,6 +32,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/backoff" "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" "google.golang.org/grpc/keepalive" "github.com/milvus-io/milvus-proto/go-api/v2/milvuspb" @@ -189,7 +190,6 @@ func (c *ClientBase[T]) connect(ctx context.Context) error { conn, err = grpc.DialContext( dialContext, addr, - //grpc.WithInsecure(), // #nosec G402 grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), grpc.WithBlock(), @@ -229,8 +229,7 @@ func (c *ClientBase[T]) connect(ctx context.Context) error { conn, err = grpc.DialContext( dialContext, addr, - grpc.WithInsecure(), - //grpc.WithTransportCredentials(credentials.NewTLS(&tls.Config{})), + grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock(), grpc.WithDefaultCallOptions( grpc.MaxCallRecvMsgSize(c.ClientMaxRecvSize),