Repository navigation
feat(storage): add MetricsRecordingCredentials decorator for credential_refresh.duration - #15233
Open
nidhiii-27 wants to merge 11 commits into
Open
nidhiii-27 wants to merge 11 commits into
nidhiii-27 wants to merge 11 commits into
Conversation
…al_refresh.duration Add Debug-tier StorageClientMetrics.recordCredentialRefreshDuration (exact 4-key clientAttributes + error.type, unit "s") and package-private MetricsRecordingCredentials extending GoogleCredentials to preserve PRIVACY_AND_INTEGRITY and QuotaProjectIdProvider, skip incompatible credential types (NoCredentials, non-GoogleCredentials, GdchCredentials, unscoped ServiceAccountCredentials, AppEngineCredentials), deduplicate concurrent coalesced refreshes with a backward-clobber-safe CAS loop, and handle Java serialization safely. [Generated-by: AI]
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces MetricsRecordingCredentials, a decorator for GoogleCredentials that records credential refresh durations, along with corresponding metric recording methods and unit tests. The review feedback highlights a correctness issue where getAccessToken() and refreshAccessToken() are not overridden, which could cause downstream components to receive stale or null tokens. Additionally, an optimization is suggested for maybeRecordTokenChange to reduce lock contention by avoiding redundant calls to delegate.getAccessToken() inside a loop.
…age-credential-refresh-wrapper [Generated-by: AI]
Construct real GdchCredentials and ServiceAccountCredentials instances via their builders in MetricsRecordingCredentialsTest instead of Mockito mocks. In google-auth-library 1.58.0, both classes carry JSpecify @NullMarked (whose @target includes ElementType.MODULE), which causes ByteBuddy's annotation inspection to throw ArrayStoreException on JDK 8. [Generated-by: AI]
…age-credential-refresh-wrapper [Generated-by: AI]
…t test MetricsRecordingCredentialsTest already asserts the exact four attribute keys (no server.address or rpc.system.name) and the unit end to end. [Generated-by: AI]
…age-credential-refresh-wrapper [Generated-by: AI]
…age-credential-refresh-wrapper [Generated-by: AI]
…age-credential-refresh-wrapper [Generated-by: AI]
nidhiii-27
marked this pull request as ready for review
November 26, 2026 06:05
nidhiii-27
requested review from
Dhriti07 and
cpriti-os
and removed request for
a team
November 26, 2026 06:05
cpriti-os
requested changes
Nov 26, 2026
…age-credential-refresh-wrapper
- Delegate equals/hashCode in MetricsRecordingCredentials to delegate - Move mapAuthErrorType into StorageErrorTypeMapper reusing MAX_CAUSE_DEPTH - Override createWithQuotaProject, createDelegated, createWithCustomRetryStrategy, and getCredentialInfo - Generalize runRecorded to <T> T runRecorded(IoSupplier<T>) shared across sync methods - Catch RuntimeException (including CancellationException, excluding non-cancellation IllegalStateException) in runRecorded and async getRequestMetadata - Add tests for scoped ServiceAccountCredentials, createScoped/factory rewrap paths, refreshIfExpired, equals/hashCode, CancellationException, and IllegalStateException
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Stacked on #15232.
Adds Debug-tier
gcp.storage.client.auth.credential_refresh.duration(DoubleHistogram, units) and the package-privateMetricsRecordingCredentialsdecorator to measure access token acquisition/refresh latency while omitting cached token hits.Changes
StorageClientMetrics: addrecordCredentialRefreshDuration(Context, double durationSeconds, String errorType)emitting exact 4-key attributes (gcp.client.service,gcp.client.version,gcp.client.artifact,error.type, omittingserver.addressandrpc.system.name).MetricsRecordingCredentials: package-private decorator extendingGoogleCredentials(preserving gRPCPRIVACY_AND_INTEGRITYandQuotaProjectIdProvidersemantics):NoCredentials, non-GoogleCredentials,GdchCredentials, unscopedServiceAccountCredentials, andAppEngineCredentials).getRequestMetadata, asynchronousgetRequestMetadata(URI, Executor, RequestMetadataCallback),refresh(), andrefreshIfExpired()using a backward-clobber-safe CAS loop so cached token hits and concurrent coalesced refreshes are not double-counted.StorageClientMetricsTestandMetricsRecordingCredentialsTest.[Generated-by: AI]