Repository navigation
feat(storage): OpenTelemetry client metrics configuration and options #14484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
nidhiii-27
wants to merge
6
commits into
feat/storage-client-metrics-infra
from
feat/storage-client-metrics-config
+969
−1
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9acfe44
feat(storage): add OpenTelemetry client metrics configuration and opt…
nidhiii-27 2bfbe39
fix(storage): preserve meterProvider equality across toBuilder and se…
nidhiii-27 1a0b1f0
fix(storage): add deserialization guard for metricInterval and update…
nidhiii-27 50e724f
fix(storage): address PR review comments for otel metrics config
nidhiii-27 bbc9922
style(storage): format StorageOptions classes with fmt-maven-plugin
nidhiii-27 9a3adbc
fix(storage): address review comments on otel metrics config
nidhiii-27 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
...age/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageMetricsConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /* | ||
| * Copyright 2026 Google LLC | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| package com.google.cloud.storage; | ||
|
|
||
| import com.google.common.annotations.VisibleForTesting; | ||
| import java.util.Locale; | ||
| import java.util.function.Function; | ||
| import java.util.logging.Logger; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| final class StorageMetricsConfig { | ||
| private static final Logger LOGGER = Logger.getLogger(StorageMetricsConfig.class.getName()); | ||
|
|
||
| static final String ENV_ENABLE_OTEL_METRICS_JAVA = "GCP_STORAGE_JAVA_ENABLE_OTEL_METRICS"; | ||
| static final String ENV_ENABLE_OTEL_DEBUG_METRICS = "GCP_STORAGE_JAVA_ENABLE_OTEL_DEBUG_METRICS"; | ||
|
|
||
| private static volatile Function<String, String> envResolver = System::getenv; | ||
|
|
||
| private StorageMetricsConfig() {} | ||
|
|
||
| static boolean isEnableOtelMetrics() { | ||
| return isEnableOtelMetrics(null); | ||
| } | ||
|
|
||
| static boolean isEnableOtelDebugMetrics() { | ||
| return isEnableOtelDebugMetrics(null); | ||
| } | ||
|
|
||
| static boolean isEnableOtelMetrics(@Nullable Boolean builderSetting) { | ||
| return isEnableOtelMetrics(envResolver, builderSetting); | ||
| } | ||
|
|
||
| static boolean isEnableOtelDebugMetrics(@Nullable Boolean builderSetting) { | ||
| return isEnableOtelDebugMetrics(envResolver, builderSetting); | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static boolean isEnableOtelMetrics( | ||
| Function<String, String> env, @Nullable Boolean builderSetting) { | ||
| if (builderSetting != null) { | ||
| return builderSetting; | ||
| } | ||
| String javaEnv = env.apply(ENV_ENABLE_OTEL_METRICS_JAVA); | ||
| Boolean parsed = parseBooleanValue(javaEnv, ENV_ENABLE_OTEL_METRICS_JAVA); | ||
| if (parsed != null) { | ||
| return parsed; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static boolean isEnableOtelDebugMetrics( | ||
| Function<String, String> env, @Nullable Boolean builderSetting) { | ||
| if (builderSetting != null) { | ||
| return builderSetting; | ||
| } | ||
| String javaEnv = env.apply(ENV_ENABLE_OTEL_DEBUG_METRICS); | ||
| Boolean parsed = parseBooleanValue(javaEnv, ENV_ENABLE_OTEL_DEBUG_METRICS); | ||
| if (parsed != null) { | ||
| return parsed; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| @Nullable | ||
| @VisibleForTesting | ||
| static Boolean parseBooleanValue(@Nullable String val, String varName) { | ||
| if (val == null) { | ||
| return null; | ||
| } | ||
| String normalized = val.trim().toLowerCase(Locale.ENGLISH); | ||
| switch (normalized) { | ||
| case "1": | ||
| case "t": | ||
| case "true": | ||
| return Boolean.TRUE; | ||
| case "0": | ||
| case "f": | ||
| case "false": | ||
| return Boolean.FALSE; | ||
| default: | ||
| LOGGER.warning( | ||
| "Unrecognized boolean value '" | ||
| + val | ||
| + "' for " | ||
| + varName | ||
| + "; ignoring and falling back to builder/default"); | ||
| return null; | ||
| } | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static void setEnvResolverForTesting(Function<String, String> testEnv) { | ||
| envResolver = testEnv != null ? testEnv : System::getenv; | ||
| } | ||
|
|
||
| @VisibleForTesting | ||
| static void resetResolversForTesting() { | ||
| envResolver = System::getenv; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.