Skip to content

Commit

Permalink
feat(spanner): add better version metadata to calls (#5515)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
codyoss authored Feb 14, 2022
1 parent aa167bd commit dcab7c4
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 18 deletions.
3 changes: 2 additions & 1 deletion spanner/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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...)
Expand Down
5 changes: 0 additions & 5 deletions spanner/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
4 changes: 2 additions & 2 deletions spanner/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
}
}
4 changes: 2 additions & 2 deletions spanner/oc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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])
}
}
4 changes: 2 additions & 2 deletions spanner/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions spanner/sessionclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions spanner/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -297,7 +297,7 @@ func getCommonTags(sc *sessionClient) *commonTags {
clientID: sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
libVersion: internal.Version,
}
}

Expand Down

0 comments on commit dcab7c4

Please sign in to comment.