Repository navigation
Conversation
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.
Contributor
There was a problem hiding this comment.
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
marked this pull request as ready for review
October 17, 2026 17:06
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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 oneCreateTimeSeriesrequest namedprojects/<first-client-project>. Cloud Monitoring then rejects the batch with400becauseresource.labels.project_iddoes not match the request name, so neither project receives metrics.This change groups time series by
resource.labels.project_idand issues oneCreateTimeSeriesrequest 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 ownproject_id.This PR does not add a custom exporter or meter-provider hook.
Testing
test_export_groups_time_series_by_project_idexports points forproject-aandproject-bvia a mockMetricServiceClientand asserts two requests, each namedprojects/<id>with matching series.mainthe test failed (AssertionError: 1 != 2). After the grouping fix it passed.117 passed.ruff check/ruff format --check/flake8clean. Packagenox -s lintwas not practical here (session requires Python 3.14).This change was prepared with AI assistance and reviewed by the author.