From fa026aac37b5b8d27709cb9511c3be078faf8206 Mon Sep 17 00:00:00 2001 From: rahul yadav Date: Wed, 4 Sep 2024 14:31:33 +0530 Subject: [PATCH] skip holding client connection on wrapper --- spanner/apiv1/spanner_client_options.go | 8 ------ spanner/grpc_client.go | 35 ++----------------------- spanner/spannertest/integration_test.go | 5 +++- 3 files changed, 6 insertions(+), 42 deletions(-) diff --git a/spanner/apiv1/spanner_client_options.go b/spanner/apiv1/spanner_client_options.go index 1e370cfdf1c0..5b924b5d1d74 100644 --- a/spanner/apiv1/spanner_client_options.go +++ b/spanner/apiv1/spanner_client_options.go @@ -23,11 +23,3 @@ import "google.golang.org/api/option" func DefaultClientOptions() []option.ClientOption { return defaultGRPCClientOptions() } - -// Returns the default call options used by the generated Spanner client. -// -// This function is only intended for use by the client library, and may be -// removed at any time without any warning. -func DefaultCallOptions() *CallOptions { - return defaultCallOptions() -} diff --git a/spanner/grpc_client.go b/spanner/grpc_client.go index eb35731f767e..04545b60a925 100644 --- a/spanner/grpc_client.go +++ b/spanner/grpc_client.go @@ -18,14 +18,11 @@ package spanner import ( "context" - "strings" vkit "cloud.google.com/go/spanner/apiv1" "cloud.google.com/go/spanner/apiv1/spannerpb" - "cloud.google.com/go/spanner/internal" "github.com/googleapis/gax-go/v2" "google.golang.org/api/option" - gtransport "google.golang.org/api/transport/grpc" "google.golang.org/grpc" "google.golang.org/grpc/peer" "google.golang.org/grpc/status" @@ -44,7 +41,6 @@ const metricsTracerKey contextKey = "metricsTracer" type spannerClient interface { CallOptions() *vkit.CallOptions Close() error - setGoogleClientInfo(...string) Connection() *grpc.ClientConn CreateSession(context.Context, *spannerpb.CreateSessionRequest, ...gax.CallOption) (*spannerpb.Session, error) BatchCreateSessions(context.Context, *spannerpb.BatchCreateSessionsRequest, ...gax.CallOption) (*spannerpb.BatchCreateSessionsResponse, error) @@ -68,9 +64,6 @@ type spannerClient interface { // spannerClient interface. type grpcSpannerClient struct { raw *vkit.Client - connPool gtransport.ConnPool - client spannerpb.SpannerClient - xGoogHeaders []string metricsTracerFactory *builtinMetricsTracerFactory } @@ -86,23 +79,8 @@ func newGRPCSpannerClient(ctx context.Context, sc *sessionClient, opts ...option if err != nil { return nil, err } - clientOpts := vkit.DefaultClientOptions() - connPool, err := gtransport.DialPool(ctx, append(clientOpts, opts...)...) - if err != nil { - return nil, err - } - clientInfo := []string{"gccl", internal.Version} - if sc.userAgent != "" { - agentWithVersion := strings.SplitN(sc.userAgent, "/", 2) - if len(agentWithVersion) == 2 { - clientInfo = append(clientInfo, agentWithVersion[0], agentWithVersion[1]) - } - } - if sc.callOptions != nil { - raw.CallOptions = mergeCallOptions(raw.CallOptions, sc.callOptions) - } - g := &grpcSpannerClient{raw: raw, metricsTracerFactory: sc.metricsTracerFactory, connPool: connPool, client: spannerpb.NewSpannerClient(connPool)} - g.setGoogleClientInfo(clientInfo...) + + g := &grpcSpannerClient{raw: raw, metricsTracerFactory: sc.metricsTracerFactory} return g, nil } @@ -115,15 +93,6 @@ func (g *grpcSpannerClient) CallOptions() *vkit.CallOptions { return g.raw.CallOptions } -func (g *grpcSpannerClient) setGoogleClientInfo(keyval ...string) { - g.raw.SetGoogleClientInfo(keyval...) - kv := append([]string{"gl-go", gax.GoVersion}, keyval...) - kv = append(kv, "gapic", internal.Version, "gax", gax.Version, "grpc", grpc.Version) - g.xGoogHeaders = []string{ - "x-goog-api-client", gax.XGoogHeader(kv...), - } -} - func (g *grpcSpannerClient) Close() error { return g.raw.Close() } diff --git a/spanner/spannertest/integration_test.go b/spanner/spannertest/integration_test.go index e0207c39607b..ec9a039152b9 100644 --- a/spanner/spannertest/integration_test.go +++ b/spanner/spannertest/integration_test.go @@ -142,7 +142,10 @@ func makeClient(t *testing.T) (*spanner.Client, *dbadmin.DatabaseAdminClient, *v client, _, err = spanner.NewMultiEndpointClient(ctx, dbName(), gmeCfg, opts...) os.Setenv("SPANNER_EMULATOR_HOST", old) } else { - opts = append(opts, option.WithGRPCConn(conn)) + opts = append(opts, + option.WithGRPCDialOption(grpc.WithTransportCredentials(insecure.NewCredentials())), + option.WithoutAuthentication(), + option.WithEndpoint(srv.Addr)) client, err = spanner.NewClient(ctx, dbName(), opts...) } if err != nil {