Skip to content

feat(bigtable): add Cloud Bigtable client uptime gauge metric#14653

Open
mgarolera wants to merge 2 commits into
googleapis:mainfrom
mgarolera:feat/bigtable/client-uptime-gauge
Open

feat(bigtable): add Cloud Bigtable client uptime gauge metric#14653
mgarolera wants to merge 2 commits into
googleapis:mainfrom
mgarolera:feat/bigtable/client-uptime-gauge

Conversation

@mgarolera

Copy link
Copy Markdown

Add reporting for CBT client uptime to help with observability and troubleshooting

@mgarolera mgarolera requested review from a team as code owners May 26, 2026 20:19
@product-auto-label product-auto-label Bot added the api: bigtable Issues related to the Bigtable API. label May 26, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new client uptime metric (uptime) as an Int64ObservableGauge and adds support for exporting Gauge[int64] and Gauge[float64] metrics to Cloud Monitoring. Feedback suggests ensuring that the StartTime of the TimeInterval is set equal to the EndTime for gauge metrics to comply with Cloud Monitoring API requirements. Additionally, a defensive check should be added to ensure tf.startTime is initialized before observing the uptime metric.

Comment thread bigtable/metrics_monitoring_exporter.go
Comment thread bigtable/metrics_monitoring_exporter.go
Comment thread bigtable/metrics.go Outdated
@mgarolera mgarolera force-pushed the feat/bigtable/client-uptime-gauge branch 3 times, most recently from 69ed0cd to 86bc9bc Compare June 1, 2026 16:21
)

const (
bigtableResourceType = "bigtable_client_raw"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs a bit more work. All the metrics exported from this exporter goes to bigtable_client_raw which maps to BigtableTable target instead of BigtableClient target, which is different from the internal metric definition.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This metric should be exported similar to client startup time.

clientStartupTime, err := meter.Float64Histogram(

this will use the cloud.BigtableClient schema.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes. I think we should move the definition of this metric to otel_metrics, something like:

  otelMeterProvider := metric.NewMeterProvider(meterOpts...) // existing code
  startTime := time.Now()
   _, err := meter.Int64ObservableGauge(
      "uptime",
      metric.WithDescription("Time since the Bigtable client was created."),
      metric.WithUnit("s"),
      metric.WithInt64Callback(func(_ context.Context, o metric.Int64Observer) error {
          o.Observe(int64(time.Since(startTime).Seconds()))
          return nil
      }),
  )

@mgarolera mgarolera force-pushed the feat/bigtable/client-uptime-gauge branch from 86bc9bc to 7b90cb2 Compare June 4, 2026 16:44
Register the client uptime metric directly on the otelMeterProvider in newOtelMetricsContext instead of metrics.go. This ensures that the metric is exported using the bigtable_client Monitored Resource (cloud.BigtableClient) instead of the fallback/legacy bigtable_client_raw, aligning with the internal metric definition.

Keep fallback registration in metrics.go for cases when otelMeterProvider is nil.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: bigtable Issues related to the Bigtable API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants