Repository navigation
feat(storage): promote server.unreached to Standard tier with gRPC and HTTP heuristics #15229
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
5
commits into
feat/storage-server-duration-metric
Choose a base branch
from
feat/storage-server-unreached-metric
base: feat/storage-server-duration-metric
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+486
−38
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bb06e80
feat(storage): promote server.unreached to Standard tier with gRPC an…
nidhiii-27 7545612
Merge branch 'feat/storage-server-duration-metric' into feat/storage-…
nidhiii-27 8217629
Merge branch 'feat/storage-server-duration-metric' into feat/storage-…
nidhiii-27 24a3854
fix(storage): shorten the server.unreached counter description
nidhiii-27 01e1da7
Merge branch 'feat/storage-server-duration-metric' into feat/storage-…
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
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 |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
| import com.google.api.client.http.HttpIOExceptionHandler; | ||
| import com.google.api.client.http.HttpRequest; | ||
| import com.google.api.client.http.HttpRequestInitializer; | ||
| import com.google.api.client.http.HttpResponse; | ||
| import com.google.api.client.http.HttpResponseInterceptor; | ||
| import com.google.api.client.http.HttpUnsuccessfulResponseHandler; | ||
| import com.google.api.core.ApiClock; | ||
|
|
@@ -55,6 +56,9 @@ | |
| @NullMarked | ||
| final class StorageHttpMetricsInterceptor implements HttpRequestInitializer { | ||
|
|
||
| static final String HEADER_UPLOADER_UPLOAD_ID = "X-GUploader-UploadID"; | ||
| static final String HEADER_GFE_SERVICE_TIME = "X-Goog-Gfe-Service-Time"; | ||
|
|
||
| private static final ImmutableSet<String> OBJECT_SUB_RESOURCES = | ||
| ImmutableSet.of("acl", "compose", "restore"); | ||
|
|
||
|
|
@@ -180,7 +184,7 @@ public void initialize(HttpRequest request) throws IOException { | |
| && recorded.compareAndSet(false, true)) { | ||
| metrics.recordRequestActive( | ||
| activeOtelContext.get(), activeOperationName.get(), -1L); | ||
| recordResponse(req, startTimeNanos.get(), endNanos, response.getStatusCode()); | ||
| recordResponse(req, response, startTimeNanos.get(), endNanos); | ||
| } | ||
| } | ||
| if (handled | ||
|
|
@@ -203,7 +207,7 @@ public void initialize(HttpRequest request) throws IOException { | |
| } finally { | ||
| if (response.getRequest() == request && recorded.compareAndSet(false, true)) { | ||
| metrics.recordRequestActive(activeOtelContext.get(), activeOperationName.get(), -1L); | ||
| recordResponse(request, startTimeNanos.get(), endNanos, response.getStatusCode()); | ||
| recordResponse(request, response, startTimeNanos.get(), endNanos); | ||
| } | ||
| } | ||
| }); | ||
|
|
@@ -216,11 +220,18 @@ public void initialize(HttpRequest request) throws IOException { | |
| if (recorded.compareAndSet(false, true)) { | ||
| metrics.recordRequestActive(activeOtelContext.get(), activeOperationName.get(), -1L); | ||
| double durationSeconds = (clock.nanoTime() - startTimeNanos.get()) / 1_000_000_000.0; | ||
| String urlTemplate = extractUrlTemplate(req.getUrl()); | ||
| recordDuration( | ||
| req, | ||
| durationSeconds, | ||
| 0L, | ||
| extractUrlTemplate(req.getUrl()), | ||
| urlTemplate, | ||
| StorageErrorTypeMapper.STATUS_CONNECTION_ERROR); | ||
| StorageMetricsContext ctx = StorageMetricsContext.current(); | ||
| metrics.recordServerUnreached( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| ctx != null ? ctx.getOtelContext() : Context.current(), | ||
| resolveOperationName(req, urlTemplate), | ||
| StorageClientMetrics.NETWORK_PATH_CLOUDPATH, | ||
| StorageErrorTypeMapper.STATUS_CONNECTION_ERROR); | ||
| } | ||
| boolean handled = | ||
|
|
@@ -252,7 +263,9 @@ private void recordInternalRetry(HttpRequest request, int priorStatusCode) { | |
| errorType); | ||
| } | ||
|
|
||
| private void recordResponse(HttpRequest request, long startNanos, long endNanos, int statusCode) { | ||
| private void recordResponse( | ||
| HttpRequest request, HttpResponse response, long startNanos, long endNanos) { | ||
| int statusCode = response.getStatusCode(); | ||
| double durationSeconds = (endNanos - startNanos) / 1_000_000_000.0; | ||
| String urlTemplate = extractUrlTemplate(request.getUrl()); | ||
| String errorType = | ||
|
|
@@ -265,11 +278,16 @@ private void recordResponse(HttpRequest request, long startNanos, long endNanos, | |
| // may append query parameters (e.g. alt=media, uploadType) after buildRequest(). | ||
| StorageMetricsContext ctx = StorageMetricsContext.current(); | ||
| Context otelContext = ctx != null ? ctx.getOtelContext() : Context.current(); | ||
| String operationName = resolveOperationName(request, urlTemplate); | ||
| metrics.recordTtfb( | ||
| otelContext, | ||
| resolveOperationName(request, urlTemplate), | ||
| durationSeconds, | ||
| StorageClientMetrics.NETWORK_PATH_CLOUDPATH); | ||
| otelContext, operationName, durationSeconds, StorageClientMetrics.NETWORK_PATH_CLOUDPATH); | ||
| boolean reached = | ||
| hasNonEmptyHeader(response, HEADER_UPLOADER_UPLOAD_ID) | ||
| || hasNonEmptyHeader(response, HEADER_GFE_SERVICE_TIME); | ||
| if (!reached) { | ||
| metrics.recordServerUnreached( | ||
| otelContext, operationName, StorageClientMetrics.NETWORK_PATH_CLOUDPATH, errorType); | ||
| } | ||
|
nidhiii-27 marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| private void recordDuration( | ||
|
|
@@ -423,4 +441,9 @@ private static String extractObjectUrlTemplate(String[] segments) { | |
| } | ||
| return "/storage/v1/b/{bucket}/o/{object}"; | ||
| } | ||
|
|
||
| private static boolean hasNonEmptyHeader(HttpResponse response, String headerName) { | ||
| String value = response.getHeaders().getFirstHeaderStringValue(headerName); | ||
| return value != null && !value.isEmpty(); | ||
| } | ||
| } | ||
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
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.