Skip to content

Commit

Permalink
feat: linting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
asthamohta committed Dec 12, 2021
1 parent 444bd38 commit 7e2430f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
10 changes: 5 additions & 5 deletions spanner/batch.go
Expand Up @@ -146,7 +146,7 @@ func (t *BatchReadOnlyTransaction) PartitionReadUsingIndexWithOptions(ctx contex

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.txReadOnly.set == true {
ctxGFE, _ := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down Expand Up @@ -214,7 +214,7 @@ func (t *BatchReadOnlyTransaction) partitionQuery(ctx context.Context, statement

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.txReadOnly.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down Expand Up @@ -291,7 +291,7 @@ func (t *BatchReadOnlyTransaction) Cleanup(ctx context.Context) {

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.txReadOnly.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down Expand Up @@ -343,7 +343,7 @@ func (t *BatchReadOnlyTransaction) Execute(ctx context.Context, p *Partition) *R

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.txReadOnly.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down Expand Up @@ -374,7 +374,7 @@ func (t *BatchReadOnlyTransaction) Execute(ctx context.Context, p *Partition) *R

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.txReadOnly.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down
10 changes: 5 additions & 5 deletions spanner/client.go
Expand Up @@ -289,7 +289,7 @@ func (c *Client) Single() *ReadOnlyTransaction {
if err == nil {
t.txReadOnly.CommonTags = CommonTags{
set: true,
clientId: c.sc.id,
clientID: c.sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
Expand Down Expand Up @@ -323,7 +323,7 @@ func (c *Client) ReadOnlyTransaction() *ReadOnlyTransaction {
if err == nil {
t.txReadOnly.CommonTags = CommonTags{
set: true,
clientId: c.sc.id,
clientID: c.sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
Expand Down Expand Up @@ -408,7 +408,7 @@ func (c *Client) BatchReadOnlyTransaction(ctx context.Context, tb TimestampBound
if err == nil {
t.txReadOnly.CommonTags = CommonTags{
set: true,
clientId: c.sc.id,
clientID: c.sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
Expand Down Expand Up @@ -449,7 +449,7 @@ func (c *Client) BatchReadOnlyTransactionFromID(tid BatchReadOnlyTransactionID)
if err == nil {
t.txReadOnly.CommonTags = CommonTags{
set: true,
clientId: c.sc.id,
clientID: c.sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
Expand Down Expand Up @@ -548,7 +548,7 @@ func (c *Client) rwTransaction(ctx context.Context, f func(context.Context, *Rea
if err == nil {
t.txReadOnly.CommonTags = CommonTags{
set: true,
clientId: c.sc.id,
clientID: c.sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
Expand Down
20 changes: 15 additions & 5 deletions spanner/stats.go
Expand Up @@ -38,11 +38,12 @@ var (
tagKeyType = tag.MustNewKey("type")
tagCommonKeys = []tag.Key{tagKeyClientID, tagKeyDatabase, tagKeyInstance, tagKeyLibVersion}

tagNumInUseSessions = tag.Tag{Key: tagKeyType, Value: "num_in_use_sessions"}
tagNumBeingPrepared = tag.Tag{Key: tagKeyType, Value: "num_sessions_being_prepared"}
tagNumReadSessions = tag.Tag{Key: tagKeyType, Value: "num_read_sessions"}
tagNumWriteSessions = tag.Tag{Key: tagKeyType, Value: "num_write_prepared_sessions"}
tagKeyMethod = tag.MustNewKey("grpc_client_method")
tagNumInUseSessions = tag.Tag{Key: tagKeyType, Value: "num_in_use_sessions"}
tagNumBeingPrepared = tag.Tag{Key: tagKeyType, Value: "num_sessions_being_prepared"}
tagNumReadSessions = tag.Tag{Key: tagKeyType, Value: "num_read_sessions"}
tagNumWriteSessions = tag.Tag{Key: tagKeyType, Value: "num_write_prepared_sessions"}
tagKeyMethod = tag.MustNewKey("grpc_client_method")
// GFELatencyOrHeaderMissingCountEnabled is used to track if GFELatency and GFEHeaderMissingCount need to be recorded
GFELatencyOrHeaderMissingCountEnabled = false
)

Expand Down Expand Up @@ -162,12 +163,14 @@ var (
TagKeys: tagCommonKeys,
}

// GFELatency is the latency between Google's network receiving an RPC and reading back the first byte of the response
GFELatency = stats.Int64(
statsPrefix+"gfe_latency",
"Latency between Google's network receiving an RPC and reading back the first byte of the response",
stats.UnitMilliseconds,
)

// GFELatencyView is the view of distribution of GFELatency values
GFELatencyView = &view.View{
Name: "cloud.google.com/go/spanner/gfe_latency",
Measure: GFELatency,
Expand All @@ -179,12 +182,14 @@ var (
TagKeys: append(tagCommonKeys, tagKeyMethod),
}

// GFEHeaderMissingCount is the number of RPC responses received without the server-timing header, most likely means that the RPC never reached Google's network
GFEHeaderMissingCount = stats.Int64(
statsPrefix+"gfe_header_missing_count",
"Number of RPC responses received without the server-timing header, most likely means that the RPC never reached Google's network",
stats.UnitDimensionless,
)

// GFEHeaderMissingCountView is the view of number of GFEHeaderMissingCount
GFEHeaderMissingCountView = &view.View{
Name: "cloud.google.com/go/spanner/gfe_header_missing_count",
Measure: GFEHeaderMissingCount,
Expand All @@ -207,15 +212,19 @@ func EnableStatViews() error {
)
}

// EnableGfeLatencyView enables GFELatency metric
func EnableGfeLatencyView() error {
GFELatencyOrHeaderMissingCountEnabled = true
return view.Register(GFELatencyView)
}

// EnableGfeHeaderMissingCountView enables GFEHeaderMissingCount metric
func EnableGfeHeaderMissingCountView() error {
GFELatencyOrHeaderMissingCountEnabled = true
return view.Register(GFEHeaderMissingCountView)
}

// EnableGfeLatencyAndHeaderMissingCountViews enables GFEHeaderMissingCount and GFELatency metric
func EnableGfeLatencyAndHeaderMissingCountViews() error {
GFELatencyOrHeaderMissingCountEnabled = true
return view.Register(
Expand All @@ -224,6 +233,7 @@ func EnableGfeLatencyAndHeaderMissingCountViews() error {
)
}

// DisableGfeLatencyAndHeaderMissingCountViews disables GFEHeaderMissingCount and GFELatency metric
func DisableGfeLatencyAndHeaderMissingCountViews() {
GFELatencyOrHeaderMissingCountEnabled = false
view.Unregister(
Expand Down
14 changes: 7 additions & 7 deletions spanner/transaction.go
Expand Up @@ -92,7 +92,7 @@ type CommonTags struct {
// Common Tags value set
set bool
// Client ID
clientId string
clientID string
// Database Name
database string
// Instance ID
Expand Down Expand Up @@ -219,7 +219,7 @@ func (t *txReadOnly) ReadWithOptions(ctx context.Context, table string, keys Key

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.clientId),
tag.Upsert(tagKeyClientID, t.clientID),
tag.Upsert(tagKeyDatabase, t.database),
tag.Upsert(tagKeyInstance, t.instance),
tag.Upsert(tagKeyLibVersion, t.libVersion),
Expand Down Expand Up @@ -433,7 +433,7 @@ func (t *txReadOnly) query(ctx context.Context, statement Statement, options Que
md, _ = client.Header()
if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.clientId),
tag.Upsert(tagKeyClientID, t.clientID),
tag.Upsert(tagKeyDatabase, t.database),
tag.Upsert(tagKeyInstance, t.instance),
tag.Upsert(tagKeyLibVersion, t.libVersion),
Expand Down Expand Up @@ -623,7 +623,7 @@ func (t *ReadOnlyTransaction) begin(ctx context.Context) error {

if GFELatencyOrHeaderMissingCountEnabled && md != nil && t.set == true {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down Expand Up @@ -987,7 +987,7 @@ func (t *ReadWriteTransaction) update(ctx context.Context, stmt Statement, opts

if GFELatencyOrHeaderMissingCountEnabled && md != nil {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.clientId),
tag.Upsert(tagKeyClientID, t.clientID),
tag.Upsert(tagKeyDatabase, t.database),
tag.Upsert(tagKeyInstance, t.instance),
tag.Upsert(tagKeyLibVersion, t.libVersion),
Expand Down Expand Up @@ -1072,7 +1072,7 @@ func (t *ReadWriteTransaction) batchUpdateWithOptions(ctx context.Context, stmts

if GFELatencyOrHeaderMissingCountEnabled && md != nil {
ctxGFE, errGFE := tag.New(ctx,
tag.Upsert(tagKeyClientID, t.txReadOnly.clientId),
tag.Upsert(tagKeyClientID, t.txReadOnly.clientID),
tag.Upsert(tagKeyDatabase, t.txReadOnly.database),
tag.Upsert(tagKeyInstance, t.txReadOnly.instance),
tag.Upsert(tagKeyLibVersion, t.txReadOnly.libVersion),
Expand Down Expand Up @@ -1351,7 +1351,7 @@ func NewReadWriteStmtBasedTransactionWithOptions(ctx context.Context, c *Client,
if err == nil {
t.txReadOnly.CommonTags = CommonTags{
set: true,
clientId: c.sc.id,
clientID: c.sc.id,
database: database,
instance: instance,
libVersion: version.Repo,
Expand Down

0 comments on commit 7e2430f

Please sign in to comment.