Skip to content

Commit

Permalink
Merge pull request #2210 from kartikaysaxena/spanner-prom-metrics-flag
Browse files Browse the repository at this point in the history
bug fix: implement flag for spanner
  • Loading branch information
tstirrat15 authored Jan 23, 2025
2 parents ec216dc + e5e1d58 commit 20d90b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 7 additions & 0 deletions internal/datastore/spanner/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type spannerOptions struct {
filterMaximumIDCount uint16
columnOptimizationOption common.ColumnOptimizationOption
expirationDisabled bool
enableDatastoreMetrics bool
}

type migrationPhase uint8
Expand Down Expand Up @@ -176,6 +177,12 @@ func EmulatorHost(uri string) Option {
}
}

func EnableDatastoreMetrics(enable bool) Option {
return func(po *spannerOptions) {
po.enableDatastoreMetrics = enable
}
}

// DisableStats disables recording counts to the stats table
func DisableStats(disable bool) Option {
return func(po *spannerOptions) {
Expand Down
16 changes: 9 additions & 7 deletions internal/datastore/spanner/spanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,15 @@ func NewSpannerDatastore(ctx context.Context, database string, opts ...Option) (
}

// TODO(jschorr): Replace with OpenTelemetry instrumentation once available.
err = spanner.EnableStatViews() // nolint: staticcheck
if err != nil {
return nil, fmt.Errorf("failed to enable spanner session metrics: %w", err)
}
err = spanner.EnableGfeLatencyAndHeaderMissingCountViews() // nolint: staticcheck
if err != nil {
return nil, fmt.Errorf("failed to enable spanner GFE metrics: %w", err)
if config.enableDatastoreMetrics {
err = spanner.EnableStatViews() // nolint: staticcheck
if err != nil {
return nil, fmt.Errorf("failed to enable spanner session metrics: %w", err)
}
err = spanner.EnableGfeLatencyAndHeaderMissingCountViews() // nolint: staticcheck
if err != nil {
return nil, fmt.Errorf("failed to enable spanner GFE metrics: %w", err)
}
}

// Register Spanner client gRPC metrics (include round-trip latency, received/sent bytes...)
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/datastore/datastore.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,7 @@ func newSpannerDatastore(ctx context.Context, opts Config) (datastore.Datastore,
spanner.WatchBufferWriteTimeout(opts.WatchBufferWriteTimeout),
spanner.EmulatorHost(opts.SpannerEmulatorHost),
spanner.DisableStats(opts.DisableStats),
spanner.EnableDatastoreMetrics(opts.EnableDatastoreMetrics),
spanner.ReadConnsMaxOpen(opts.ReadConnPool.MaxOpenConns),
spanner.WriteConnsMaxOpen(opts.WriteConnPool.MaxOpenConns),
spanner.MinSessionCount(opts.SpannerMinSessions),
Expand Down

0 comments on commit 20d90b6

Please sign in to comment.