From ec4eec718da53ed56f3df39fffd6df9eda69d950 Mon Sep 17 00:00:00 2001 From: Nidhi Nandwani Date: Thu, 19 Nov 2026 15:10:10 +0000 Subject: [PATCH 1/2] feat(storage): record gcp.storage.client.retries counter in Retrying [Generated-by: AI] --- .../OpenTelemetryBootstrappingUtils.java | 1 + .../com/google/cloud/storage/Retrying.java | 34 +++++----- .../cloud/storage/StorageClientMetrics.java | 29 +++++++++ .../cloud/storage/StorageMetricsContext.java | 11 ++++ .../cloud/storage/RetryingMetricsTest.java | 62 +++++++++++++++++++ .../storage/StorageClientMetricsTest.java | 56 +++++++++++++++++ 6 files changed, 179 insertions(+), 14 deletions(-) diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/OpenTelemetryBootstrappingUtils.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/OpenTelemetryBootstrappingUtils.java index 1a7ab2e5879e..2a8e4b5c60de 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/OpenTelemetryBootstrappingUtils.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/OpenTelemetryBootstrappingUtils.java @@ -349,6 +349,7 @@ static SdkMeterProvider createDefaultClientMeterProvider( ImmutableList.of( StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_OPERATIONS, StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_ATTEMPTS, + StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_RETRIES, StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_ERRORS, StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_REQUEST_ACTIVE, StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_SERVER_UNREACHED, diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java index 00d01d7511b3..ebc9a822f1c6 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java @@ -22,7 +22,6 @@ import com.google.api.gax.retrying.BasicResultRetryAlgorithm; import com.google.api.gax.retrying.ResultRetryAlgorithm; import com.google.api.gax.retrying.RetrySettings; -import com.google.cloud.BaseServiceException; import com.google.cloud.storage.Backoff.Jitterer; import com.google.cloud.storage.Conversions.Decoder; import com.google.cloud.storage.spi.v1.HttpRpcContext; @@ -265,21 +264,12 @@ public Model run( } return decoded; } catch (StorageException se) { - if (metricsContext != null) { - metricsContext.recordAttemptFailure(metrics, se); - } - ctx.recordError(se, () -> attemptAgain.set(true), failure::set); + handleAttemptError(ctx, metricsContext, se, se, attemptAgain, failure); } catch (IllegalArgumentException iae) { - if (metricsContext != null) { - metricsContext.recordAttemptFailure(metrics, iae); - } - ctx.recordError(iae, () -> attemptAgain.set(true), failure::set); + handleAttemptError(ctx, metricsContext, iae, iae, attemptAgain, failure); } catch (Exception e) { - if (metricsContext != null) { - metricsContext.recordAttemptFailure(metrics, e); - } - BaseServiceException coalesced = StorageException.coalesce(e); - ctx.recordError(coalesced, () -> attemptAgain.set(true), failure::set); + handleAttemptError( + ctx, metricsContext, e, StorageException.coalesce(e), attemptAgain, failure); } } while (attemptAgain.get()); @@ -302,6 +292,22 @@ public Model run( } } } + + private void handleAttemptError( + RetryContext ctx, + @Nullable StorageMetricsContext metricsContext, + Throwable rawError, + Exception retryError, + AtomicBoolean attemptAgain, + AtomicReference failure) { + if (metricsContext != null) { + metricsContext.recordAttemptFailure(metrics, rawError); + } + ctx.recordError(retryError, () -> attemptAgain.set(true), failure::set); + if (attemptAgain.get() && metricsContext != null) { + metricsContext.recordRetry(metrics, rawError); + } + } } static final class HttpRetrier implements Retrier { diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java index dff0b43ea78b..f13d02455684 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java @@ -79,6 +79,7 @@ final class StorageClientMetrics implements AutoCloseable { static final String METRIC_GCP_CLIENT_REQUEST_DURATION = "gcp.client.request.duration"; static final String METRIC_GCP_STORAGE_CLIENT_OPERATIONS = "gcp.storage.client.operations"; static final String METRIC_GCP_STORAGE_CLIENT_ATTEMPTS = "gcp.storage.client.attempts"; + static final String METRIC_GCP_STORAGE_CLIENT_RETRIES = "gcp.storage.client.retries"; static final String METRIC_GCP_STORAGE_CLIENT_ERRORS = "gcp.storage.client.errors"; static final String METRIC_GCP_STORAGE_CLIENT_TTFB = "gcp.storage.client.ttfb"; static final String METRIC_GCP_STORAGE_CLIENT_REQUEST_BODY_SIZE = @@ -185,6 +186,7 @@ static StorageClientMetrics create( @Nullable private final DoubleHistogram gcpClientRequestDuration; @Nullable private final LongCounter operations; @Nullable private final LongCounter attempts; + @Nullable private final LongCounter retries; @Nullable private final LongCounter errors; @Nullable private final DoubleHistogram ttfb; @Nullable private final LongHistogram requestBodySize; @@ -251,6 +253,14 @@ private StorageClientMetrics( + " including retries, resumable upload chunks and list pages.") .setUnit("{attempt}") .build(); + this.retries = + meter + .counterBuilder(METRIC_GCP_STORAGE_CLIENT_RETRIES) + .setDescription( + "Number of GCS client attempts that retried an earlier failed attempt of the same" + + " request.") + .setUnit("{attempt}") + .build(); this.errors = meter .counterBuilder(METRIC_GCP_STORAGE_CLIENT_ERRORS) @@ -295,6 +305,7 @@ private StorageClientMetrics( this.gcpClientRequestDuration = null; this.operations = null; this.attempts = null; + this.retries = null; this.errors = null; this.ttfb = null; this.requestBodySize = null; @@ -400,6 +411,10 @@ Attributes attachClientAttributes(@Nullable Attributes other) { return attempts; } + @Nullable LongCounter getRetries() { + return retries; + } + @Nullable LongCounter getErrors() { return errors; } @@ -501,6 +516,20 @@ void recordTtfb( ttfb.record(ttfbSeconds, attributes, otelContext); } + void recordRetry( + Context otelContext, String operationName, String networkPath, String errorType) { + if (retries == null) { + return; + } + Attributes attributes = + baseAttributes.toBuilder() + .put(KEY_GCP_STORAGE_OPERATION, operationName) + .put(KEY_NETWORK_PATH, networkPath) + .put(KEY_ERROR_TYPE, errorType) + .build(); + retries.add(1L, attributes, otelContext); + } + @Nullable static StorageMetricsContext createContext( @Nullable StorageClientMetrics metrics, String operationName) { diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageMetricsContext.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageMetricsContext.java index 142f75c5d846..50902753d1e6 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageMetricsContext.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageMetricsContext.java @@ -317,6 +317,17 @@ void recordAttemptFailure(@Nullable StorageClientMetrics metrics, Throwable e) { } } + void recordRetry(@Nullable StorageClientMetrics metrics, Throwable priorError) { + if (metrics == null) { + return; + } + metrics.recordRetry( + otelContext, + operationName, + resolveNetworkPath(), + StorageErrorTypeMapper.mapThrowable(priorError)); + } + void setNetworkPath(String networkPath) { this.networkPath = networkPath; } diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/RetryingMetricsTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/RetryingMetricsTest.java index 06fce76f2973..fe1583faf069 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/RetryingMetricsTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/RetryingMetricsTest.java @@ -25,6 +25,7 @@ import static com.google.cloud.storage.StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_ATTEMPTS; import static com.google.cloud.storage.StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_ERRORS; import static com.google.cloud.storage.StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_OPERATIONS; +import static com.google.cloud.storage.StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_RETRIES; import static com.google.cloud.storage.StorageErrorTypeMapper.STATUS_DEADLINE_EXCEEDED; import static com.google.cloud.storage.StorageErrorTypeMapper.STATUS_DNS_FAILURE; import static com.google.cloud.storage.StorageErrorTypeMapper.STATUS_NOT_FOUND; @@ -38,6 +39,7 @@ import com.google.api.core.NanoClock; import com.google.api.gax.grpc.GrpcCallContext; import com.google.api.gax.retrying.RetrySettings; +import com.google.cloud.NoCredentials; import com.google.cloud.storage.Conversions.Decoder; import com.google.cloud.storage.Retrying.DefaultRetrier; import com.google.cloud.storage.Retrying.Retrier; @@ -103,6 +105,7 @@ public void successfulCallOnFirstAttempt_recordsExpectedMetrics() { () -> "success", Decoder.identity(), StorageMetricsContext.create("GetObject")); assertThat(result).isEqualTo("success"); assertOutcomeMetrics(STATUS_OK, 1L, 0L); + assertThat(getCounterValue(collect(), METRIC_GCP_STORAGE_CLIENT_RETRIES)).isEqualTo(0L); assertThat(assertDuration(STATUS_OK).getAttributes().get(KEY_GCP_CLIENT_SERVICE)) .isEqualTo("storage"); } @@ -126,6 +129,7 @@ public void retriedCallSuccessOnThirdAttempt_recordsAttemptsAndErrors() { assertThat(attemptCounter.get()).isEqualTo(3); assertOutcomeMetrics(STATUS_OK, 3L, 2L); assertAttr(METRIC_GCP_STORAGE_CLIENT_ERRORS, KEY_ERROR_TYPE, STATUS_UNAVAILABLE, 2L); + assertAttr(METRIC_GCP_STORAGE_CLIENT_RETRIES, KEY_ERROR_TYPE, STATUS_UNAVAILABLE, 2L); assertDuration(STATUS_OK); } @@ -169,6 +173,7 @@ public void terminalFailureAllAttemptsFail_recordsExhaustedRetries() { assertThat(se.getCode()).isEqualTo(503); assertOutcomeMetrics(STATUS_UNAVAILABLE, 3L, 3L); assertAttr(METRIC_GCP_STORAGE_CLIENT_ERRORS, KEY_ERROR_TYPE, STATUS_UNAVAILABLE, 3L); + assertAttr(METRIC_GCP_STORAGE_CLIENT_RETRIES, KEY_ERROR_TYPE, STATUS_UNAVAILABLE, 2L); assertDuration(STATUS_UNAVAILABLE); } @@ -249,6 +254,7 @@ public void nonRetryableError_singleAttemptTerminalFailure_recordsErrorAndTermin assertThat(se.getCode()).isEqualTo(404); assertOutcomeMetrics(STATUS_NOT_FOUND, 1L, 1L); assertAttr(METRIC_GCP_STORAGE_CLIENT_ERRORS, KEY_ERROR_TYPE, STATUS_NOT_FOUND, 1L); + assertThat(getCounterValue(collect(), METRIC_GCP_STORAGE_CLIENT_RETRIES)).isEqualTo(0L); assertDuration(STATUS_NOT_FOUND); } @@ -279,6 +285,9 @@ public void recordAttemptError_specificExceptions_mappedToCanonicalTypes() { assertAttr(METRIC_GCP_STORAGE_CLIENT_ERRORS, KEY_ERROR_TYPE, STATUS_DEADLINE_EXCEEDED, 1L); assertAttr(METRIC_GCP_STORAGE_CLIENT_ERRORS, KEY_ERROR_TYPE, STATUS_TIMEOUT, 1L); assertAttr(METRIC_GCP_STORAGE_CLIENT_ERRORS, KEY_ERROR_TYPE, STATUS_DNS_FAILURE, 1L); + assertAttr(METRIC_GCP_STORAGE_CLIENT_RETRIES, KEY_ERROR_TYPE, STATUS_DEADLINE_EXCEEDED, 1L); + assertAttr(METRIC_GCP_STORAGE_CLIENT_RETRIES, KEY_ERROR_TYPE, STATUS_TIMEOUT, 1L); + assertAttr(METRIC_GCP_STORAGE_CLIENT_RETRIES, KEY_ERROR_TYPE, STATUS_DNS_FAILURE, 0L); } @Test @@ -528,6 +537,59 @@ public void withMetricsContext_withAlg_runTwoArgs_recordsAttemptsAndErrors() { assertDuration(STATUS_OK); } + @Test + public void retriedCall_viaStorageOptions_recordsExactRetryAttributes() { + GrpcStorageOptions options = + StorageOptions.grpc() + .setProjectId("test-project") + .setCredentials(NoCredentials.getInstance()) + .setRetrySettings(RETRY_SETTINGS) + .setEnableOtelMetrics(true) + .setMeterProvider(provider) + .build(); + StorageMetricsContext ctx = options.getStorageClientMetrics().createContext("GetObject"); + ctx.setNetworkPath(StorageClientMetrics.NETWORK_PATH_DIRECTPATH); + Retrier bound = options.createRetrier().withMetricsContext(ctx); + + AtomicInteger attempts = new AtomicInteger(0); + String result = + bound.run( + Retrying.alwaysRetry(), + () -> { + if (attempts.incrementAndGet() == 1) { + throw new StorageException(503, "Unavailable"); + } + return "ok"; + }, + Decoder.identity()); + assertThat(result).isEqualTo("ok"); + + MetricData retriesMetric = findMetric(collect(), METRIC_GCP_STORAGE_CLIENT_RETRIES); + assertThat(retriesMetric).isNotNull(); + assertThat(retriesMetric.getUnit()).isEqualTo("{attempt}"); + assertThat(retriesMetric.getLongSumData().getPoints()).hasSize(1); + LongPointData point = retriesMetric.getLongSumData().getPoints().iterator().next(); + assertThat(point.getValue()).isEqualTo(1L); + assertThat(point.getAttributes()) + .isEqualTo( + Attributes.builder() + .put( + StorageClientMetrics.KEY_GCP_CLIENT_SERVICE, + StorageClientMetrics.SERVICE_STORAGE) + .put(StorageClientMetrics.KEY_GCP_CLIENT_VERSION, StorageOptions.version()) + .put( + StorageClientMetrics.KEY_GCP_CLIENT_ARTIFACT, + StorageClientMetrics.ARTIFACT_STORAGE) + .put(StorageClientMetrics.KEY_RPC_SYSTEM_NAME, "grpc") + .put(StorageClientMetrics.KEY_SERVER_ADDRESS, "storage.googleapis.com") + .put(StorageClientMetrics.KEY_GCP_STORAGE_OPERATION, "GetObject") + .put( + StorageClientMetrics.KEY_NETWORK_PATH, + StorageClientMetrics.NETWORK_PATH_DIRECTPATH) + .put(StorageClientMetrics.KEY_ERROR_TYPE, STATUS_UNAVAILABLE) + .build()); + } + private void assertCreateRetrierWiresMetricsWhenEnabled(StorageOptions options) { assertThat(options.getStorageClientMetrics()).isNotNull(); Retrier retrier = options.createRetrier(); diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java index 505aab2280d2..17605557e4f5 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java @@ -18,9 +18,11 @@ import static com.google.common.truth.Truth.assertThat; +import com.google.cloud.NoCredentials; import com.google.common.collect.ImmutableList; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; +import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.metrics.Aggregation; import io.opentelemetry.sdk.metrics.InstrumentType; @@ -28,6 +30,7 @@ import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.HistogramPointData; +import io.opentelemetry.sdk.metrics.data.LongPointData; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.metrics.export.CollectionRegistration; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -50,6 +53,7 @@ public final class StorageClientMetricsTest { StorageClientMetrics::getGcpClientRequestDuration, StorageClientMetrics::getOperations, StorageClientMetrics::getAttempts, + StorageClientMetrics::getRetries, StorageClientMetrics::getErrors, StorageClientMetrics::getTtfb, StorageClientMetrics::getRequestBodySize, @@ -144,6 +148,7 @@ public void inMemoryMetricReader_verifiesViewsAndBoundaries() { metrics.getOperations().add(1); metrics.getAttempts().add(2); + metrics.getRetries().add(1); metrics.getErrors().add(1); metrics.getRequestActive().add(1); metrics.getServerUnreached().add(1); @@ -207,6 +212,10 @@ public void inMemoryMetricReader_verifiesViewsAndBoundaries() { assertThat(metricsMap).containsKey(attemptsName); assertThat(metricsMap.get(attemptsName).getUnit()).isEqualTo("{attempt}"); + String retriesName = StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_RETRIES.replace(".", "/"); + assertThat(metricsMap).containsKey(retriesName); + assertThat(metricsMap.get(retriesName).getUnit()).isEqualTo("{attempt}"); + String errorsName = StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_ERRORS.replace(".", "/"); assertThat(metricsMap).containsKey(errorsName); assertThat(metricsMap.get(errorsName).getUnit()).isEqualTo("{error}"); @@ -413,6 +422,53 @@ public void createContext_nullMetrics_returnsNull() { assertThat(StorageClientMetrics.createMultiStepContext(null, "WriteObject")).isNull(); } + @Test + public void recordRetry_recordsExactAttributes() { + SdkMeterProvider provider = SdkMeterProvider.builder().registerMetricReader(reader).build(); + StorageClientMetrics grpcMetrics = + StorageOptions.grpc() + .setProjectId("test-project") + .setCredentials(NoCredentials.getInstance()) + .setEnableOtelMetrics(true) + .setMeterProvider(provider) + .build() + .getStorageClientMetrics(); + + grpcMetrics.recordRetry( + Context.current(), + "ReadObject", + StorageClientMetrics.NETWORK_PATH_DIRECTPATH, + StorageErrorTypeMapper.STATUS_UNAVAILABLE); + + MetricData metricData = + reader.collectAllMetrics().stream() + .filter(m -> m.getName().equals(StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_RETRIES)) + .findFirst() + .orElseThrow(() -> new AssertionError("Missing retries metric")); + assertThat(metricData.getUnit()).isEqualTo("{attempt}"); + assertThat(metricData.getLongSumData().getPoints()).hasSize(1); + LongPointData point = metricData.getLongSumData().getPoints().iterator().next(); + assertThat(point.getValue()).isEqualTo(1L); + assertThat(point.getAttributes()) + .isEqualTo( + Attributes.builder() + .put( + StorageClientMetrics.KEY_GCP_CLIENT_SERVICE, + StorageClientMetrics.SERVICE_STORAGE) + .put(StorageClientMetrics.KEY_GCP_CLIENT_VERSION, StorageOptions.version()) + .put( + StorageClientMetrics.KEY_GCP_CLIENT_ARTIFACT, + StorageClientMetrics.ARTIFACT_STORAGE) + .put(StorageClientMetrics.KEY_RPC_SYSTEM_NAME, "grpc") + .put(StorageClientMetrics.KEY_SERVER_ADDRESS, "storage.googleapis.com") + .put(StorageClientMetrics.KEY_GCP_STORAGE_OPERATION, "ReadObject") + .put( + StorageClientMetrics.KEY_NETWORK_PATH, + StorageClientMetrics.NETWORK_PATH_DIRECTPATH) + .put(StorageClientMetrics.KEY_ERROR_TYPE, StorageErrorTypeMapper.STATUS_UNAVAILABLE) + .build()); + } + static final class TestMetricReader implements MetricReader { private final MetricReader delegate = InMemoryMetricReader.create(); final AtomicBoolean shutdownCalled = new AtomicBoolean(false); From a166bfbfc63eb18c3815895ad6f0cce54c8156cc Mon Sep 17 00:00:00 2001 From: Nidhi Nandwani Date: Thu, 26 Nov 2026 05:11:50 +0000 Subject: [PATCH 2/2] fix(storage): address review feedback on gcp.storage.client.retries core - Combine the StorageException and IllegalArgumentException catches in Retrying. - Shorten the retries counter description. - Drop StorageClientMetricsTest.recordRetry_recordsExactAttributes; the end-to-end RetryingMetricsTest covers the exact attribute set. [Generated-by: AI] --- .../com/google/cloud/storage/Retrying.java | 6 +-- .../cloud/storage/StorageClientMetrics.java | 4 +- .../storage/StorageClientMetricsTest.java | 50 ------------------- 3 files changed, 3 insertions(+), 57 deletions(-) diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java index ebc9a822f1c6..38c81a071abb 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/Retrying.java @@ -263,10 +263,8 @@ public Model run( metricsContext.recordAttemptSuccess(metrics); } return decoded; - } catch (StorageException se) { - handleAttemptError(ctx, metricsContext, se, se, attemptAgain, failure); - } catch (IllegalArgumentException iae) { - handleAttemptError(ctx, metricsContext, iae, iae, attemptAgain, failure); + } catch (StorageException | IllegalArgumentException e) { + handleAttemptError(ctx, metricsContext, e, e, attemptAgain, failure); } catch (Exception e) { handleAttemptError( ctx, metricsContext, e, StorageException.coalesce(e), attemptAgain, failure); diff --git a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java index f13d02455684..915aeef51ea0 100644 --- a/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java +++ b/java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageClientMetrics.java @@ -256,9 +256,7 @@ private StorageClientMetrics( this.retries = meter .counterBuilder(METRIC_GCP_STORAGE_CLIENT_RETRIES) - .setDescription( - "Number of GCS client attempts that retried an earlier failed attempt of the same" - + " request.") + .setDescription("Number of GCS client retry attempts") .setUnit("{attempt}") .build(); this.errors = diff --git a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java index 17605557e4f5..39adecefeaf6 100644 --- a/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java +++ b/java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageClientMetricsTest.java @@ -18,11 +18,9 @@ import static com.google.common.truth.Truth.assertThat; -import com.google.cloud.NoCredentials; import com.google.common.collect.ImmutableList; import io.opentelemetry.api.common.AttributeKey; import io.opentelemetry.api.common.Attributes; -import io.opentelemetry.context.Context; import io.opentelemetry.sdk.common.CompletableResultCode; import io.opentelemetry.sdk.metrics.Aggregation; import io.opentelemetry.sdk.metrics.InstrumentType; @@ -30,7 +28,6 @@ import io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder; import io.opentelemetry.sdk.metrics.data.AggregationTemporality; import io.opentelemetry.sdk.metrics.data.HistogramPointData; -import io.opentelemetry.sdk.metrics.data.LongPointData; import io.opentelemetry.sdk.metrics.data.MetricData; import io.opentelemetry.sdk.metrics.export.CollectionRegistration; import io.opentelemetry.sdk.metrics.export.MetricReader; @@ -422,53 +419,6 @@ public void createContext_nullMetrics_returnsNull() { assertThat(StorageClientMetrics.createMultiStepContext(null, "WriteObject")).isNull(); } - @Test - public void recordRetry_recordsExactAttributes() { - SdkMeterProvider provider = SdkMeterProvider.builder().registerMetricReader(reader).build(); - StorageClientMetrics grpcMetrics = - StorageOptions.grpc() - .setProjectId("test-project") - .setCredentials(NoCredentials.getInstance()) - .setEnableOtelMetrics(true) - .setMeterProvider(provider) - .build() - .getStorageClientMetrics(); - - grpcMetrics.recordRetry( - Context.current(), - "ReadObject", - StorageClientMetrics.NETWORK_PATH_DIRECTPATH, - StorageErrorTypeMapper.STATUS_UNAVAILABLE); - - MetricData metricData = - reader.collectAllMetrics().stream() - .filter(m -> m.getName().equals(StorageClientMetrics.METRIC_GCP_STORAGE_CLIENT_RETRIES)) - .findFirst() - .orElseThrow(() -> new AssertionError("Missing retries metric")); - assertThat(metricData.getUnit()).isEqualTo("{attempt}"); - assertThat(metricData.getLongSumData().getPoints()).hasSize(1); - LongPointData point = metricData.getLongSumData().getPoints().iterator().next(); - assertThat(point.getValue()).isEqualTo(1L); - assertThat(point.getAttributes()) - .isEqualTo( - Attributes.builder() - .put( - StorageClientMetrics.KEY_GCP_CLIENT_SERVICE, - StorageClientMetrics.SERVICE_STORAGE) - .put(StorageClientMetrics.KEY_GCP_CLIENT_VERSION, StorageOptions.version()) - .put( - StorageClientMetrics.KEY_GCP_CLIENT_ARTIFACT, - StorageClientMetrics.ARTIFACT_STORAGE) - .put(StorageClientMetrics.KEY_RPC_SYSTEM_NAME, "grpc") - .put(StorageClientMetrics.KEY_SERVER_ADDRESS, "storage.googleapis.com") - .put(StorageClientMetrics.KEY_GCP_STORAGE_OPERATION, "ReadObject") - .put( - StorageClientMetrics.KEY_NETWORK_PATH, - StorageClientMetrics.NETWORK_PATH_DIRECTPATH) - .put(StorageClientMetrics.KEY_ERROR_TYPE, StorageErrorTypeMapper.STATUS_UNAVAILABLE) - .build()); - } - static final class TestMetricReader implements MetricReader { private final MetricReader delegate = InMemoryMetricReader.create(); final AtomicBoolean shutdownCalled = new AtomicBoolean(false);