Skip to content

feat(bigtable): client side metrics handlers - #16760

Merged
daniel-sanche merged 51 commits into
mainfrom
bigtable_csm_3_handlers
Aug 11, 2026
Merged

feat(bigtable): client side metrics handlers#16760
daniel-sanche merged 51 commits into
mainfrom
bigtable_csm_3_handlers

Conversation

@daniel-sanche

@daniel-sanche daniel-sanche commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Migrate googleapis/python-bigtable#1189 to the monorepo

This PR builds off of googleapis/python-bigtable#1187 to add handlers to the client-side metrics system, which can subscribe to the metrics stream, and export the results into different collection systems

We add two handlers to the system:

  • GoogleCloudMetricsHandler: sends metrics to a private OpenTelemetry meter, and then periodically exports them to GCP. Built on top of OpenTelemetryMetricsHandler
  • OpenTelemetryMetricsHandler: sends metrics to the root MeterProvider, so the user can access the exported metrics for their own systems. This will be off by default, but can be added alongside GoogleCloudMetricsHandler if needed

@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 implements client-side metrics for the Bigtable library using OpenTelemetry, including a custom exporter for Google Cloud Monitoring. The review feedback focuses on improving resource efficiency by moving the MeterProvider and client_uid generation to the client level to avoid thread leaks and inconsistent identifiers across tables. Additionally, recommendations were made to handle potential KeyError exceptions in the exporter, improve logging for background export failures, and ensure non-negative timeouts during batch writes.

Comment thread packages/google-cloud-bigtable/google/cloud/bigtable/data/_async/client.py Outdated
write_ind = 0
while write_ind < len(series):
# find time left for next batch
timeout = deadline - time.time() if deadline else gapic_v1.method.DEFAULT

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.

why do we need to calculate the remaining deadline for each batch? I think each batch should just use the default timeout.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The intention here is to be consistent with the OpenTelemetry exporter spec, which passes in a timeout value for exporters to conform to.

I'm not entirely sure what happens if we ignore it, but I can look into it if needed. Does Java not have anything similar?

Base automatically changed from bigtable_csm_2_instrumentation_advanced to main June 5, 2026 15:54
@daniel-sanche

Copy link
Copy Markdown
Contributor Author

/gemini review

@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 client-side metrics collection and exporting to Google Cloud Monitoring for the Bigtable Python client by adding GoogleCloudMetricsHandler and BigtableMetricsExporter. Feedback on the changes highlights several critical issues, including potential KeyError and TypeError exceptions during metric label processing and protobuf serialization, broad exception handling that silently masks export failures, and side-effects from instantiating OpenTelemetry instruments as default arguments. Additionally, corrections are needed in the system tests to resolve mismatches in metric names and type prefixes.

daniel-sanche and others added 3 commits July 23, 2026 17:13
…rics/handlers/opentelemetry.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…rics/handlers/gcp_exporter.py

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@daniel-sanche daniel-sanche changed the title [DRAFT] feat: client side metrics handlers feat: client side metrics handlers Jul 24, 2026
@daniel-sanche
daniel-sanche marked this pull request as ready for review July 28, 2026 22:02
@daniel-sanche
daniel-sanche requested a review from a team as a code owner July 28, 2026 22:02
@daniel-sanche daniel-sanche changed the title feat: client side metrics handlers feat(bigtable): client side metrics handlers Aug 7, 2026
self,
project_id: str,
series: list[TimeSeries],
deadline=None,

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.

SHould we have a deadline for the write?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My interpretation is yes, we should follow a deadline, and we pass it down here (the None in the code above your comment is just the function default value)

The MetricExporter base class has a timeout_millis argument, so our timeout policy is just making sure we are following the expectations of the base class

But let me know if you think we need to handle anything differently

@daniel-sanche
daniel-sanche merged commit 43b786c into main Aug 11, 2026
46 checks passed
@daniel-sanche
daniel-sanche deleted the bigtable_csm_3_handlers branch August 11, 2026 20:30
@ohmayr
ohmayr restored the bigtable_csm_3_handlers branch August 12, 2026 22:18
hebaalazzeh pushed a commit that referenced this pull request Aug 13, 2026
Updates the client post-processing configuration for
`google-cloud-bigtable` in
`.librarian/generator-input/client-post-processing/bigtable-integration.yaml`
to ensure code generation produces zero diff.

Required as a result of the change in
#16760
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants