Skip to content

fix(spanner): export built-in metrics per project - #18750

Open
hippi345 wants to merge 1 commit into
googleapis:mainfrom
hippi345:fix/18155-spanner-metrics-per-project
Open

hippi345 wants to merge 1 commit into
googleapis:mainfrom
hippi345:fix/18155-spanner-metrics-per-project

Conversation

@hippi345

Copy link
Copy Markdown

Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Make sure to open an issue as a bug/issue before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)

Fixes #18155 🦕

Description

When a process creates Spanner clients for more than one GCP project, built-in client metrics are exported through a single CloudMonitoringMetricsExporter. That exporter previously sent every time series in one CreateTimeSeries request named projects/<first-client-project>. Cloud Monitoring then rejects the batch with 400 because resource.labels.project_id does not match the request name, so neither project receives metrics.

This change groups time series by resource.labels.project_id and issues one CreateTimeSeries request per project (name=projects/<id>), still batched at 200 series. Series without a resource project label keep falling back to the exporter's configured project. Client wiring is unchanged: each client's metric points already carry their own project_id.

This PR does not add a custom exporter or meter-provider hook.

Testing

  • Regression: test_export_groups_time_series_by_project_id exports points for project-a and project-b via a mock MetricServiceClient and asserts two requests, each named projects/<id> with matching series.
  • On main the test failed (AssertionError: 1 != 2). After the grouping fix it passed.
  • Nearby metrics unit tests: 117 passed.
  • Lint on the touched files: ruff check / ruff format --check / flake8 clean. Package nox -s lint was not practical here (session requires Python 3.14).

This change was prepared with AI assistance and reviewed by the author.

Group Cloud Monitoring time series by resource.labels.project_id and
send one CreateTimeSeries request per project so mixed-project clients
in one process are not rejected.

@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 updates the metrics exporter to group time series by their resource project ID before exporting them to Cloud Monitoring, preventing mixed-project batches from being rejected. It also adds a corresponding unit test to verify this grouping behavior. I have no feedback to provide.

@hippi345
hippi345 marked this pull request as ready for review October 17, 2026 17:06
@hippi345
hippi345 requested a review from a team as a code owner October 17, 2026 17:06

This branch has not been deployed

No deployments
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.

(google-cloud-spanner) Built-in metrics fail when one process uses databases in different projects

1 participant