Skip to content

fix(spanner): disable default built-in metrics for non-standard endpoints and custom channel providers - #15272

Merged
sakthivelmanii merged 2 commits into
mainfrom
fix/spanner-builtin-metrics-custom-channel-provider
Dec 1, 2026
Merged

sakthivelmanii merged 2 commits into
mainfrom
fix/spanner-builtin-metrics-custom-channel-provider

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Problem Statement

  • Default-on built-in Cloud Monitoring metrics could still attempt to export telemetry and credentials to monitoring.googleapis.com when a client configured a custom TransportChannelProvider (such as an InstantiatingGrpcChannelProvider with a custom endpoint or an opaque provider) or a non-standard setHost(...) endpoint (including regional, private/restricted, non-443, or non-HTTPS endpoints) without an explicit monitoringHost.

Solution

  • Automatically disable default-on built-in Cloud Monitoring metrics unless the effective Spanner endpoint matches the standard endpoint for the resolved universe domain (spanner.<universeDomain>:443 for InstantiatingGrpcChannelProvider, or https://spanner.<universeDomain>[:443] for setHost(...)), or monitoringHost (SpannerOptions.Builder.setMonitoringHost(...) / SPANNER_MONITORING_HOST) is explicitly configured.
  • Mirror runtime channel selection precedence: an opaque TransportChannelProvider or an InstantiatingGrpcChannelProvider with an explicit endpoint takes precedence over setHost(...); an endpoint-less InstantiatingGrpcChannelProvider falls back to setHost(...).
  • Suppress the auto-disable warning log when plaintext or NoCredentials are configured.
  • Document the unified endpoint and custom channel provider behavior in SpannerOptions.isEnableBuiltInMetrics() Javadoc and the Spanner README.

Behavior Changes

  • setHost(...) with regional (*.rep.googleapis.com), private.googleapis.com, restricted.googleapis.com, non-443, or non-HTTPS endpoints now auto-disables built-in Cloud Monitoring metrics unless monitoringHost / SPANNER_MONITORING_HOST is explicitly set.
  • setHost(...) combined with setUniverseDomain(...) keeps built-in Cloud Monitoring metrics enabled only when the host matches https://spanner.<universeDomain>[:443].
  • Auto-disable WARNING logs are also suppressed when NoCredentials (or null credentials) are configured.

@sakthivelmanii
sakthivelmanii requested review from a team as code owners November 28, 2026 19:06

@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 refactors the logic in SpannerOptions to determine when built-in Cloud Monitoring metrics should be enabled. It introduces a more robust resolution mechanism that automatically disables built-in metrics when non-standard endpoints or custom channel providers are configured, unless an explicit monitoring host is specified. This prevents potential telemetry or credential leaks. The changes also update the README documentation and add extensive unit tests to validate these behaviors. No review comments were provided, so there is no feedback to address.

@sakthivelmanii
sakthivelmanii force-pushed the fix/spanner-builtin-metrics-custom-channel-provider branch from d76f99a to 52ec3aa Compare November 30, 2026 19:56
Comment thread java-spanner/.readme-partials.yaml Resolved
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) December 1, 2026 14:52
…ints and custom channel providers

- Default-on built-in Cloud Monitoring metrics could still attempt to export telemetry and credentials to `monitoring.googleapis.com` when a client configured a custom `TransportChannelProvider` (such as an `InstantiatingGrpcChannelProvider` with a custom endpoint or an opaque provider) or a non-standard `setHost(...)` endpoint (including regional, private/restricted, non-443, or non-HTTPS endpoints) without an explicit `monitoringHost`.

- Automatically disable default-on built-in Cloud Monitoring metrics unless the effective Spanner endpoint matches the standard endpoint for the resolved universe domain (`spanner.<universeDomain>:443` for `InstantiatingGrpcChannelProvider`, or `https://spanner.<universeDomain>[:443]` for `setHost(...)`), or `monitoringHost` (`SpannerOptions.Builder.setMonitoringHost(...)` / `SPANNER_MONITORING_HOST`) is explicitly configured.
- Mirror runtime channel selection precedence: an opaque `TransportChannelProvider` or an `InstantiatingGrpcChannelProvider` with an explicit endpoint takes precedence over `setHost(...)`; an endpoint-less `InstantiatingGrpcChannelProvider` falls back to `setHost(...)`.
- Suppress the auto-disable warning log when plaintext or `NoCredentials` are configured.
- Document the unified endpoint and custom channel provider behavior in `SpannerOptions.isEnableBuiltInMetrics()` Javadoc and the Spanner README.

- `setHost(...)` with regional (`*.rep.googleapis.com`), `private.googleapis.com`, `restricted.googleapis.com`, non-443, or non-HTTPS endpoints now auto-disables built-in Cloud Monitoring metrics unless `monitoringHost` / `SPANNER_MONITORING_HOST` is explicitly set.
- `setHost(...)` combined with `setUniverseDomain(...)` keeps built-in Cloud Monitoring metrics enabled only when the host matches `https://spanner.<universeDomain>[:443]`.
- Auto-disable `WARNING` logs are also suppressed when `NoCredentials` (or null credentials) are configured.
@sakthivelmanii
sakthivelmanii force-pushed the fix/spanner-builtin-metrics-custom-channel-provider branch from 3cc68bc to 49384e2 Compare December 1, 2026 15:24
@sakthivelmanii
sakthivelmanii enabled auto-merge (squash) December 1, 2026 15:27
@sakthivelmanii
sakthivelmanii merged commit 3fd923e into main Dec 1, 2026
198 checks passed
@sakthivelmanii
sakthivelmanii deleted the fix/spanner-builtin-metrics-custom-channel-provider branch December 1, 2026 15:55
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