Repository navigation
feat(storage): record gcp.storage.client.request.active metric #15227
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
base: feat/storage-retries-metric-streams-http
Are you sure you want to change the base?
Changes from all commits
9dd981b
c52cd3b
c053802
9853ac2
88ec8a8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,6 +132,7 @@ public class HttpStorageRpc implements StorageRpc { | |
|
|
||
| private final StorageOptions options; | ||
| private final Storage storage; | ||
| private final Storage batchPartStorage; | ||
| private final Tracer tracer = Tracing.getTracer(); | ||
| private final HttpRequestInitializer batchRequestInitializer; | ||
|
|
||
|
|
@@ -159,6 +160,7 @@ public HttpStorageRpc(StorageOptions options, JsonFactory jsonFactory) { | |
| CensusHttpModule censusHttpModule = new CensusHttpModule(tracer, IS_RECORD_EVENTS); | ||
| initializer = censusHttpModule.getHttpRequestInitializer(initializer); | ||
| initializer = new InvocationIdInitializer(initializer, applicationName, tm); | ||
| HttpRequestInitializer batchPartInitializer = initializer; | ||
| initializer = options.decorateWithMetrics(initializer); | ||
| batchRequestInitializer = | ||
| options.decorateWithMetrics(censusHttpModule.getHttpRequestInitializer(null)); | ||
|
|
@@ -186,6 +188,14 @@ public HttpStorageRpc(StorageOptions options, JsonFactory jsonFactory) { | |
| storageBuilder.setRootUrl(host); | ||
| } | ||
| storage = storageBuilder.build(); | ||
| // Batch parts skip decorateWithMetrics: they are serialized into the outer multipart request | ||
| // and never execute as their own HTTP exchange, so a metrics interceptor on them would | ||
| // increment gcp.storage.client.request.active without a matching response. The outer batch | ||
| // request (batchRequestInitializer) is instrumented instead. | ||
| batchPartStorage = | ||
|
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. Nit: Can we add a short comment on why
Contributor
Author
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. Done in 88ec8a8: added a comment. Batch parts are serialized into the outer multipart request and never run as their own HTTP exchange, so instrumenting them would increment Co-authored by AI Agent |
||
| initializer == batchPartInitializer | ||
| ? storage | ||
| : storageBuilder.setHttpRequestInitializer(batchPartInitializer).build(); | ||
| } | ||
|
|
||
| public Storage getStorage() { | ||
|
|
@@ -288,7 +298,7 @@ public void addDelete( | |
| batches.add(storage.batch(batchRequestInitializer)); | ||
| currentBatchSize = 0; | ||
| } | ||
| Delete call = deleteCall(storageObject, options); | ||
| Delete call = deleteCall(this.storage, storageObject, options); | ||
| addIdempotencyTokenToCall(call); | ||
| call.queue(batches.getLast(), toJsonCallback(callback)); | ||
| currentBatchSize++; | ||
|
|
@@ -307,7 +317,7 @@ public void addPatch( | |
| batches.add(storage.batch(batchRequestInitializer)); | ||
| currentBatchSize = 0; | ||
| } | ||
| Patch call = patchCall(storageObject, options); | ||
| Patch call = patchCall(this.storage, storageObject, options); | ||
| addIdempotencyTokenToCall(call); | ||
| call.queue(batches.getLast(), toJsonCallback(callback)); | ||
| currentBatchSize++; | ||
|
|
@@ -326,7 +336,7 @@ public void addGet( | |
| batches.add(storage.batch(batchRequestInitializer)); | ||
| currentBatchSize = 0; | ||
| } | ||
| Get call = getCall(storageObject, options); | ||
| Get call = getCall(this.storage, storageObject, options); | ||
| addIdempotencyTokenToCall(call); | ||
| call.queue(batches.getLast(), toJsonCallback(callback)); | ||
| currentBatchSize++; | ||
|
|
@@ -607,9 +617,9 @@ public Bucket get(Bucket bucket, Map<Option, ?> options) { | |
| } | ||
| } | ||
|
|
||
| private Storage.Objects.Get getCall(StorageObject object, Map<Option, ?> options) | ||
| private Storage.Objects.Get getCall(Storage client, StorageObject object, Map<Option, ?> options) | ||
| throws IOException { | ||
| Storage.Objects.Get get = storage.objects().get(object.getBucket(), object.getName()); | ||
| Storage.Objects.Get get = client.objects().get(object.getBucket(), object.getName()); | ||
| setEncryptionHeaders(get.getRequestHeaders(), ENCRYPTION_KEY_PREFIX, options); | ||
| setExtraHeaders(get, options); | ||
| return get.setGeneration(object.getGeneration()) | ||
|
|
@@ -628,7 +638,7 @@ public StorageObject get(StorageObject object, Map<Option, ?> options) { | |
| Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_GET_OBJECT); | ||
| Scope scope = tracer.withSpan(span); | ||
| try { | ||
| return getCall(object, options).execute(); | ||
| return getCall(storage, object, options).execute(); | ||
| } catch (IOException ex) { | ||
| span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); | ||
| StorageException serviceException = translate(ex); | ||
|
|
@@ -726,10 +736,10 @@ public Bucket patch(Bucket bucket, Map<Option, ?> options) { | |
| } | ||
| } | ||
|
|
||
| private Storage.Objects.Patch patchCall(StorageObject storageObject, Map<Option, ?> options) | ||
| throws IOException { | ||
| private Storage.Objects.Patch patchCall( | ||
| Storage client, StorageObject storageObject, Map<Option, ?> options) throws IOException { | ||
| Storage.Objects.Patch patch = | ||
| storage | ||
| client | ||
| .objects() | ||
| .patch(storageObject.getBucket(), storageObject.getName(), storageObject) | ||
| .setProjection(DEFAULT_PROJECTION) | ||
|
|
@@ -749,7 +759,7 @@ public StorageObject patch(StorageObject storageObject, Map<Option, ?> options) | |
| Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_PATCH_OBJECT); | ||
| Scope scope = tracer.withSpan(span); | ||
| try { | ||
| return patchCall(storageObject, options).execute(); | ||
| return patchCall(storage, storageObject, options).execute(); | ||
| } catch (IOException ex) { | ||
| span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); | ||
| throw translate(ex); | ||
|
|
@@ -787,10 +797,10 @@ public boolean delete(Bucket bucket, Map<Option, ?> options) { | |
| } | ||
| } | ||
|
|
||
| private Storage.Objects.Delete deleteCall(StorageObject blob, Map<Option, ?> options) | ||
| throws IOException { | ||
| private Storage.Objects.Delete deleteCall( | ||
| Storage client, StorageObject blob, Map<Option, ?> options) throws IOException { | ||
| Storage.Objects.Delete delete = | ||
| storage | ||
| client | ||
| .objects() | ||
| .delete(blob.getBucket(), blob.getName()) | ||
| .setGeneration(blob.getGeneration()) | ||
|
|
@@ -808,7 +818,7 @@ public boolean delete(StorageObject blob, Map<Option, ?> options) { | |
| Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_DELETE_OBJECT); | ||
| Scope scope = tracer.withSpan(span); | ||
| try { | ||
| deleteCall(blob, options).execute(); | ||
| deleteCall(storage, blob, options).execute(); | ||
| return true; | ||
| } catch (IOException ex) { | ||
| span.setStatus(Status.UNKNOWN.withDescription(ex.getMessage())); | ||
|
|
@@ -906,7 +916,7 @@ public RpcBatch createBatch() { | |
| Span span = startSpan(HttpStorageRpcSpans.SPAN_NAME_CREATE_BATCH); | ||
| Scope scope = tracer.withSpan(span); | ||
| try { | ||
| return new DefaultRpcBatch(storage); | ||
| return new DefaultRpcBatch(batchPartStorage); | ||
| } finally { | ||
| scope.close(); | ||
| span.end(HttpStorageRpcSpans.END_SPAN_OPTIONS); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.