fix(spanner): disable metrics tracer when built-in metrics are disabled#8170
fix(spanner): disable metrics tracer when built-in metrics are disabled#8170
Conversation
Ensure MetricsTracerFactory starts disabled and is synchronized with the built-in metrics configuration. This prevents MetricsTracer instances from being created when metrics are disabled via client options, environment, or insecure credentials.
There was a problem hiding this comment.
Code Review
This pull request updates the Spanner client to explicitly set the MetricsTracerFactory.enabled flag based on the instance's configuration and changes the default value of this static property to false. A significant issue was identified where setting a static property based on instance-specific logic creates a global side effect, potentially causing configuration conflicts in applications that utilize multiple Spanner clients with different settings.
Track built-in metrics enablement on each Spanner instance and use it to guard metric interceptors and MetricsTracer creation. This prevents clients that explicitly disable built-in metrics from creating or retaining metrics tracers without mutating global MetricsTracerFactory state for other clients.
e3f7913 to
910c701
Compare
|
/gemini review |
|
/gemini summary |
There was a problem hiding this comment.
Code Review
This pull request introduces an instance-level _metricsEnabled property to the Spanner class, replacing the global MetricsTracerFactory.enabled check to allow for more granular control over metrics collection. Feedback indicates a logic error in configureMetrics_ where _metricsEnabled fails to incorporate the _isInSecureCredentials check. This omission leads to inconsistent behavior when guarding tracer creation in the request and requestStream methods.
Summary of ChangesThis pull request refactors the metrics configuration logic in the Spanner client to move away from global state management. By introducing an instance-specific flag, it ensures that metrics settings are correctly isolated across different client instances, preventing side effects where one client's configuration could inadvertently affect others. The changes also improve the reliability of the metrics disabling mechanism by ensuring all relevant conditions are consistently evaluated. Highlights
Activity
|
Update the per-instance metrics flag to include insecure credentials so metric interceptors and tracers are not created when built-in metrics are disabled for that client. Keep the mock metrics tests using an explicit in-memory metrics override because they intentionally run against insecure test credentials.
|
/gemini review |
|
/gemini summary |
There was a problem hiding this comment.
Code Review
This pull request transitions the metrics enablement state from a global static property (MetricsTracerFactory.enabled) to an instance-specific property (_metricsEnabled) within the Spanner class. This change allows for independent metrics configuration across different Spanner client instances, preventing global state side effects. The request and requestStream methods, as well as the interceptor logic, have been updated to reference this instance property. I have no feedback to provide.
Summary of ChangesThis pull request refactors the metrics configuration logic in the Spanner client to eliminate reliance on global state. By moving the metrics-enabled status to an instance-specific property, the changes prevent configuration leakage between multiple Spanner clients and ensure that metrics are consistently disabled when required by client options, environment variables, or insecure credentials. Highlights
Activity
|
Default MetricsTracerFactory.enabled to false so tracer creation stays disabled until metrics configuration explicitly enables the singleton factory.
This reverts commit 8bc203e.
Move MetricsTracerFactory.enabled assignment outside the metrics setup branch so explicitly disabled or insecure clients update the singleton guard before any request path can create metrics tracers.
Summary
SpannerinstanceMetricsTracerFactory.enabledwith the instance's computed metrics state duringconfigureMetrics_()MetricsTracerand metric interceptor creation when built-in metrics are disabled via client option, env var, or insecure credentialsWhy
When
disableBuiltInMetricswas true, metrics export setup was skipped, butMetricsTracerFactory.enabledcould still remain true from its default value or prior state. IfprojectId_was set, requests could still createMetricsTracerinstances even though built-in metrics were disabled.This change computes metrics enablement during client setup and uses the instance-level state to guard tracer/
interceptor creation.