Skip to content

fix: use per-adapter SdkMeterProvider with bounded lifecycle cleanup - #440

Merged
sakthivelmanii merged 4 commits into
mainfrom
refactor/per-adapter-builtin-metrics
Dec 4, 2026
Merged

sakthivelmanii merged 4 commits into
mainfrom
refactor/per-adapter-builtin-metrics

Conversation

@sakthivelmanii

Copy link
Copy Markdown
Contributor

Problem Statement

  • Built-in metrics previously used a single JVM-wide SdkMeterProvider singleton initialized with the first adapter's project and instance ID and closed only via a JVM shutdown hook.
  • Running multiple sessions or listeners in the same JVM could not isolate metrics exporters per adapter, avoid client_uid/client_hash collisions, or flush and release exporter threads when individual adapters stopped or failed to start.
  • Launcher.shutdown() only caught IOException per adapter, allowing an IllegalStateException from stopping a never-started adapter to skip stopping remaining healthy listeners.

Solution

  • Added BuiltInMetricsProvider.createMetricsRecorder(...) (@InternalApi) to create a dedicated per-adapter SdkMeterProvider with a unique client_uid and matching client_hash per adapter, lazily caching GCP resource attribute detection so per-adapter creation does not re-probe the metadata server, while retaining getOrCreateOpenTelemetry(...) for binary compatibility.
  • Added an idempotent, 2-second bounded close() lifecycle method to BuiltInMetricsRecorder and wired cleanup into Adapter.stop(), Adapter.start() failure paths, SpannerCqlSessionBuilder, and Launcher.
  • Updated Launcher.shutdown() to catch Exception per adapter so partial startup failures still stop all healthy listeners cleanly while letting fatal JVM Errors propagate.

…anup

- Added BuiltInMetricsProvider.createMetricsRecorder(...) (@internalapi) to create a dedicated per-adapter SdkMeterProvider with a unique client_uid and matching client_hash per adapter, lazily caching GCP resource attribute detection while retaining getOrCreateOpenTelemetry(...) for binary compatibility.
- Added an idempotent, 2-second bounded close() lifecycle method to BuiltInMetricsRecorder and wired cleanup into Adapter.stop(), Adapter.start() failure paths, SpannerCqlSessionBuilder, and Launcher.
- Updated Launcher.shutdown() to catch Exception per adapter so partial startup failures still stop all healthy listeners cleanly while letting fatal JVM Errors propagate.
@sakthivelmanii sakthivelmanii self-assigned this Dec 4, 2026
@sakthivelmanii sakthivelmanii changed the title refactor: use per-adapter SdkMeterProvider with bounded lifecycle cleanup fix: use per-adapter SdkMeterProvider with bounded lifecycle cleanup Dec 4, 2026
sakthivelmanii and others added 3 commits December 4, 2026 18:34
….com endpoint (#441)

* fix: propagate credentials and remove hardcoded monitoring.googleapis.com endpoint

- Updated BuiltInMetricsProvider.createMetricsRecorder(...) to accept caller Credentials and an optional universeDomain and configure the exporter via GAX MetricServiceSettings instead of a hardcoded monitoring.googleapis.com:443 endpoint (also removing the hardcoded endpoint from the legacy getOrCreateOpenTelemetry(...) path).
- Scoped unscoped GoogleCredentials to Monitoring default service scopes when createScopedRequired() is true, preserved already-scoped and custom Credentials, and returned a no-op recorder when NoCredentials is provided or MetricServiceSettings initialization fails with IOException.
- Propagated configured credentials from SpannerCqlSessionBuilder (and null for ADC from Launcher) into createMetricsRecorder(...).

* test: avoid mocking Credentials on JDK 8

* Addressed comments

* fix: disable built-in metrics for unsupported and custom-endpoint modes (#442)

* fix: disable built-in metrics for unsupported and custom-endpoint modes

* test: avoid mocking TransportChannelProvider on JDK 8

* Addressed comments

* feat: add universeDomain support and remove hardcoded spanner.googleapis.com endpoint (#443)

* feat: add universeDomain support and remove hardcoded spanner.googleapis.com endpoint

* Addressed comments

* Addressed comments
@sakthivelmanii
sakthivelmanii merged commit 89ee0a5 into main Dec 4, 2026
21 checks passed
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