From dcab7c4a98ebecfef1f75ec5bddfd7782b28a7c5 Mon Sep 17 00:00:00 2001 From: Cody Oss <6331106+codyoss@users.noreply.github.com> Date: Mon, 14 Feb 2022 14:45:37 -0700 Subject: [PATCH] feat(spanner): add better version metadata to calls (#5515) This new version file will automatically be maintained by release-please. We just landed a similar change in storage recently in #5507. This will be rolling out to all modules soon. Fixes: #5515 Updates: #2749 --- spanner/client.go | 3 ++- spanner/doc.go | 5 ----- spanner/integration_test.go | 4 ++-- spanner/oc_test.go | 4 ++-- spanner/session.go | 4 ++-- spanner/sessionclient.go | 8 ++++---- spanner/stats.go | 4 ++-- 7 files changed, 14 insertions(+), 18 deletions(-) diff --git a/spanner/client.go b/spanner/client.go index 97a1d2ed4f3a..fbca1421cf15 100644 --- a/spanner/client.go +++ b/spanner/client.go @@ -26,6 +26,7 @@ import ( "cloud.google.com/go/internal/trace" vkit "cloud.google.com/go/spanner/apiv1" + "cloud.google.com/go/spanner/internal" "google.golang.org/api/option" "google.golang.org/api/option/internaloption" gtransport "google.golang.org/api/transport/grpc" @@ -217,7 +218,7 @@ func allClientOpts(numChannels int, userOpts ...option.ClientOption) []option.Cl generatedDefaultOpts := vkit.DefaultClientOptions() clientDefaultOpts := []option.ClientOption{ option.WithGRPCConnectionPool(numChannels), - option.WithUserAgent(clientUserAgent), + option.WithUserAgent(fmt.Sprintf("spanner-go/v%s", internal.Version)), internaloption.EnableDirectPath(true), } allDefaultOpts := append(generatedDefaultOpts, clientDefaultOpts...) diff --git a/spanner/doc.go b/spanner/doc.go index 5471ef290577..39850ebaa0a7 100644 --- a/spanner/doc.go +++ b/spanner/doc.go @@ -371,8 +371,3 @@ at https://godoc.org/go.opencensus.io/trace. OpenCensus tracing requires Go 1.8 or higher. */ package spanner // import "cloud.google.com/go/spanner" - -// clientUserAgent identifies the version of this package. -// It should be the same as https://pkg.go.dev/cloud.google.com/go/spanner. -// TODO: We will want to automate the version with a bash script. -const clientUserAgent = "spanner-go/v1.12.0" diff --git a/spanner/integration_test.go b/spanner/integration_test.go index 088c97048fda..160fe071d5c1 100644 --- a/spanner/integration_test.go +++ b/spanner/integration_test.go @@ -37,9 +37,9 @@ import ( "cloud.google.com/go/civil" "cloud.google.com/go/internal/testutil" "cloud.google.com/go/internal/uid" - "cloud.google.com/go/internal/version" database "cloud.google.com/go/spanner/admin/database/apiv1" instance "cloud.google.com/go/spanner/admin/instance/apiv1" + "cloud.google.com/go/spanner/internal" "go.opencensus.io/stats/view" "go.opencensus.io/tag" "google.golang.org/api/iterator" @@ -3737,7 +3737,7 @@ func checkCommonTagsGFELatency(t *testing.T, m map[tag.Key]string) { if !strings.HasPrefix(m[tagKeyClientID], "client") { t.Fatalf("Incorrect client ID: %v", m[tagKeyClientID]) } - if m[tagKeyLibVersion] != version.Repo { + if m[tagKeyLibVersion] != internal.Version { t.Fatalf("Incorrect library version: %v", m[tagKeyLibVersion]) } } diff --git a/spanner/oc_test.go b/spanner/oc_test.go index aac2fb916c9a..a7ea7ffe2e13 100644 --- a/spanner/oc_test.go +++ b/spanner/oc_test.go @@ -23,7 +23,7 @@ import ( "time" "cloud.google.com/go/internal/testutil" - "cloud.google.com/go/internal/version" + "cloud.google.com/go/spanner/internal" stestutil "cloud.google.com/go/spanner/internal/testutil" structpb "github.com/golang/protobuf/ptypes/struct" "go.opencensus.io/stats/view" @@ -369,7 +369,7 @@ func checkCommonTags(t *testing.T, m map[tag.Key]string) { if m[tagKeyDatabase] != "[DATABASE]" { t.Fatalf("Incorrect database ID: %v", m[tagKeyDatabase]) } - if m[tagKeyLibVersion] != version.Repo { + if m[tagKeyLibVersion] != internal.Version { t.Fatalf("Incorrect library version: %v", m[tagKeyLibVersion]) } } diff --git a/spanner/session.go b/spanner/session.go index a41276026b66..0937f53870b8 100644 --- a/spanner/session.go +++ b/spanner/session.go @@ -29,8 +29,8 @@ import ( "time" "cloud.google.com/go/internal/trace" - "cloud.google.com/go/internal/version" vkit "cloud.google.com/go/spanner/apiv1" + "cloud.google.com/go/spanner/internal" "go.opencensus.io/stats" "go.opencensus.io/tag" octrace "go.opencensus.io/trace" @@ -625,7 +625,7 @@ func newSessionPool(sc *sessionClient, config SessionPoolConfig) (*sessionPool, tag.Upsert(tagKeyClientID, sc.id), tag.Upsert(tagKeyDatabase, database), tag.Upsert(tagKeyInstance, instance), - tag.Upsert(tagKeyLibVersion, version.Repo), + tag.Upsert(tagKeyLibVersion, internal.Version), ) if err != nil { logf(pool.sc.logger, "Failed to create tag map, error: %v", err) diff --git a/spanner/sessionclient.go b/spanner/sessionclient.go index 2ebef2b5b5e4..559c104e92b3 100644 --- a/spanner/sessionclient.go +++ b/spanner/sessionclient.go @@ -25,8 +25,8 @@ import ( "time" "cloud.google.com/go/internal/trace" - "cloud.google.com/go/internal/version" vkit "cloud.google.com/go/spanner/apiv1" + "cloud.google.com/go/spanner/internal" "github.com/googleapis/gax-go/v2" "go.opencensus.io/tag" "google.golang.org/api/option" @@ -147,7 +147,7 @@ func (sc *sessionClient) createSession(ctx context.Context) (*session, error) { tag.Upsert(tagKeyClientID, sc.id), tag.Upsert(tagKeyDatabase, database), tag.Upsert(tagKeyInstance, instance), - tag.Upsert(tagKeyLibVersion, version.Repo), + tag.Upsert(tagKeyLibVersion, internal.Version), ) if err != nil { trace.TracePrintf(ctx, nil, "Error in recording GFE Latency. Try disabling and rerunning. Error: %v", ToSpannerError(err)) @@ -270,7 +270,7 @@ func (sc *sessionClient) executeBatchCreateSessions(client *vkit.Client, createC tag.Upsert(tagKeyClientID, sc.id), tag.Upsert(tagKeyDatabase, database), tag.Upsert(tagKeyInstance, instance), - tag.Upsert(tagKeyLibVersion, version.Repo), + tag.Upsert(tagKeyLibVersion, internal.Version), ) if err != nil { trace.TracePrintf(ctx, nil, "Error in adding tags in BatchCreateSessions for GFE Latency: %v", err) @@ -322,7 +322,7 @@ func (sc *sessionClient) nextClient() (*vkit.Client, error) { if err != nil { return nil, err } - client.SetGoogleClientInfo("gccl", version.Repo) + client.SetGoogleClientInfo("gccl", internal.Version) if sc.callOptions != nil { client.CallOptions = mergeCallOptions(client.CallOptions, sc.callOptions) } diff --git a/spanner/stats.go b/spanner/stats.go index 95eaacf5bf2e..0de66134dff4 100644 --- a/spanner/stats.go +++ b/spanner/stats.go @@ -20,7 +20,7 @@ import ( "strings" "sync" - "cloud.google.com/go/internal/version" + "cloud.google.com/go/spanner/internal" "go.opencensus.io/stats" "go.opencensus.io/stats/view" "go.opencensus.io/tag" @@ -297,7 +297,7 @@ func getCommonTags(sc *sessionClient) *commonTags { clientID: sc.id, database: database, instance: instance, - libVersion: version.Repo, + libVersion: internal.Version, } }