Skip to content

fix(storage): propagate credentials and universe domain to Cloud Monitoring exporter - #15177

Draft
lqiu96 wants to merge 2 commits into
googleapis:mainfrom
lqiu96:fix/storage-metrics-universe-domain
Draft

lqiu96 wants to merge 2 commits into
googleapis:mainfrom
lqiu96:fix/storage-metrics-universe-domain

Conversation

@lqiu96

@lqiu96 lqiu96 commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Updates OpenTelemetryBootstrappingUtils, GrpcStorageOptions, and StorageClientMetrics to forward client credentials and the resolved universe domain (including GOOGLE_CLOUD_UNIVERSE_DOMAIN fallback) to Cloud Monitoring via MetricServiceSettings.

  • Validates the client credentials universe domain against the resolved universe domain before enabling Cloud Monitoring export, and sets the resolved endpoint explicitly on MetricServiceSettings (clearing the mTLS endpoint outside googleapis.com).
  • Skips automatic Cloud Monitoring export for unsupported or unauthenticated credentials (null, NoCredentials, GdchCredentials, ApiKeyCredentials, and static OAuth2Credentials/GoogleCredentials without a token) and for plaintext http:// or loopback endpoints.
  • Normalizes universe domain values and resolves monitoring.<universeDomain>, private.<universeDomain>, and restricted.<universeDomain> from the exact parsed hostname.
  • Declares com.google.cloud:google-cloud-monitoring directly in java-storage/google-cloud-storage/pom.xml, updates ITGrpcMetricsTest, and adds unit tests in OpenTelemetryBootstrappingUtilsTest.

…toring exporter

Updates OpenTelemetryBootstrappingUtils, GrpcStorageOptions, and
StorageClientMetrics to forward client credentials and the resolved
universe domain (including GOOGLE_CLOUD_UNIVERSE_DOMAIN fallback) to
Cloud Monitoring via MetricServiceSettings.

@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 updates the OpenTelemetry metrics bootstrapping logic to support authenticated exports to Cloud Monitoring by utilizing MetricServiceSettings configured with client credentials and the resolved universe domain. It also introduces safeguards to skip metrics configuration when credentials are missing or when running in an unconfigured custom universe. The feedback suggests catching generic Exceptions instead of only IOExceptions during the initialization of MetricServiceSettings to prevent potential runtime exceptions from propagating and crashing the main storage client.

Comment on lines +156 to +166
try {
metricServiceSettings =
buildMetricServiceSettings(metricServiceEndpoint, resolvedUniverseDomain, credentials);
} catch (IOException e) {
log.log(
Level.WARNING,
"Failed to configure Cloud Monitoring settings for gRPC client metrics: "
+ e.getMessage(),
e);
return fallback;
}

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.

medium

Since metrics collection is a non-critical background task, any initialization failures should be gracefully handled to prevent crashing the main storage client. buildMetricServiceSettings or the underlying GAX builder could throw runtime exceptions (such as IllegalArgumentException or dependency-related exceptions) which would bypass the IOException catch block and propagate. Consider catching Exception instead of IOException to ensure all initialization errors are safely suppressed and logged.

Suggested change
try {
metricServiceSettings =
buildMetricServiceSettings(metricServiceEndpoint, resolvedUniverseDomain, credentials);
} catch (IOException e) {
log.log(
Level.WARNING,
"Failed to configure Cloud Monitoring settings for gRPC client metrics: "
+ e.getMessage(),
e);
return fallback;
}
try {
metricServiceSettings =
buildMetricServiceSettings(metricServiceEndpoint, resolvedUniverseDomain, credentials);
} catch (Exception e) {
log.log(
Level.WARNING,
"Failed to configure Cloud Monitoring settings for gRPC client metrics: "
+ e.getMessage(),
e);
return fallback;
}

… setup

- Validate credentials universe domain directly against the resolved universe domain before starting Cloud Monitoring export.
- Set explicit endpoint on MetricServiceSettings and clear mTLS endpoint outside googleapis.com.
- Skip automatic metrics export for unsupported credentials (GdchCredentials, ApiKeyCredentials, and static OAuth2Credentials/GoogleCredentials without a token) and plaintext http:// or loopback endpoints.
- Normalize universe domain values and harden endpoint host parsing.
- Expand OpenTelemetryBootstrappingUtilsTest coverage and close SdkMeterProvider in ITGrpcMetricsTest.

This branch has not been deployed

No deployments
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.

1 participant