Skip to content

chore(spanner): detect client location for built-in metrics and align client_hash - #6445

Open
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-client-location-detection
Open

chore(spanner): detect client location for built-in metrics and align client_hash#6445
olavloite wants to merge 2 commits into
googleapis:mainfrom
olavloite:spanner-client-location-detection

Conversation

@olavloite

@olavloite olavloite commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Do not merge: Needs #6446 first

Detect the client location (e.g. us-central1) for Spanner built-in metrics using environment variables or the GCP metadata server, falling back to global if unreachable or when using the emulator. The detected location is cached so it is only fetched once per process.

Also update client_hash to use the 10 most significant bits of the hash to keep resource cardinality within Cloud Monitoring limits.

@olavloite
olavloite requested review from a team as code owners August 18, 2026 16:17
@product-auto-label product-auto-label Bot added the api: spanner Issues related to the Spanner API. label Aug 18, 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 dynamic GCP client location detection for Spanner metrics by querying the Google Cloud Metadata Server (MDS) or environment variables, caching the result process-wide. It also updates the client hash generation to use a 10-bit prefix to reduce resource cardinality. The feedback suggests adding a short connection timeout to the metadata service HTTP client to prevent startup delays when running in non-GCP environments where the metadata server is unreachable.

Comment thread src/spanner/src/observability/metrics.rs Outdated
… client_hash

Detect the client location (e.g. `us-central1`) for Spanner built-in metrics using environment variables or the GCP metadata server, falling back to `global` if unreachable or when using the emulator. The detected location is cached so it is only fetched once per process.

Also update `client_hash` to use the 10 most significant bits of the hash to keep resource cardinality within Cloud Monitoring limits.
@olavloite
olavloite force-pushed the spanner-client-location-detection branch from 4ad9500 to 206c24f Compare August 18, 2026 16:54
@codecov

codecov Bot commented Aug 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.38710% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 96.11%. Comparing base (60c6e48) to head (206c24f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/spanner/src/observability/metrics.rs 98.38% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6445      +/-   ##
==========================================
+ Coverage   96.09%   96.11%   +0.01%     
==========================================
  Files         289      289              
  Lines       77540    77720     +180     
==========================================
+ Hits        74514    74699     +185     
+ Misses       3026     3021       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

olavloite added a commit that referenced this pull request Aug 21, 2026
…st (#6446)

Re-export `reqwest::Client` and `reqwest::ClientBuilder` from
`gaxi::http::reqwest`. It does not bump the gax-internal version number,
as that version has already been updated for the next release by other
pull requests.

This allows client libraries to construct HTTP clients with custom
connection timeouts (such as for querying the Compute Engine Metadata
Service) without declaring direct dependencies on `reqwest`.

Needed for #6445
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the Spanner API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant