Repository navigation
feat(storage): record gcp.storage.client.request.active metric - #15227
nidhiii-27 wants to merge 5 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces tracking for active in-flight requests (request.active metric) across both gRPC and HTTP storage client interceptors, and refactors HttpStorageRpc to prevent double-counting of metrics during batch operations. The review feedback highlights two key improvements: first, enhancing encapsulation in StorageHttpMetricsInterceptor by removing an unnecessary public getter check for requestActive (as the record method already handles null checks); second, preventing a potential metric leak in StorageGrpcMetricsInterceptor by wrapping super.start in a try-catch block to ensure the active request count is decremented if starting the call throws an exception.
…nerated-by: AI] If the delegate ClientCall.start throws synchronously, gRPC never delivers onClose to the listener, so the request.active +1 recorded in start was never balanced. Decrement and rethrow in that case, and add a unit test.
…est [Generated-by: AI] Child interceptors may decorate CallOptions (e.g. stream tracers) before calling newCall, so stub newCall on the method only.
| } catch (RuntimeException | Error e) { | ||
| // Per the ClientCall contract, onClose is not delivered when start throws, so balance | ||
| // the +1 here. | ||
| metrics.recordRequestActive(otelContext, operationName, -1L); |
There was a problem hiding this comment.
Can we guard the -1 decrement with an AtomicBoolean so a synchronous onClose() throw inside super.start() can't decrement twice?
There was a problem hiding this comment.
Done in 88ec8a8: request.active is now released through a single per-call AtomicBoolean behind releaseActive(), shared by the start() catch and the onClose finally, so it can only be decremented once even if a downstream call closes the listener inline and then throws. This is different from the redundant onClose single-shot guard we avoided earlier: it dedups two distinct decrement sites (start-catch vs onClose), not repeated onClose calls. Added interceptCall_requestActive_releasesOnceWhenClosedInlineBeforeStartThrows; the guard is carried through the later onClose restructures in #15229 and #15231.
Co-authored by AI Agent
| throwingHandlerTransport | ||
| .createRequestFactory(debugInterceptor) | ||
| .buildGetRequest(new GenericUrl("https://storage.googleapis.com/storage/v1/b/my-b")); | ||
| assertThrows(IOException.class, failingReq::execute); |
There was a problem hiding this comment.
Can we assert the thrown message contains "refresh failed" (since HttpResponseException is also an IOException), check no retry was recorded, and add a throwing HttpResponseInterceptor case?
There was a problem hiding this comment.
Done in 88ec8a8: the test now checks the "refresh failed" message and that no retry was recorded, and adds a case where a delegate HttpResponseInterceptor throws (request.active still returns to 0).
Co-authored by AI Agent
| storageBuilder.setRootUrl(host); | ||
| } | ||
| storage = storageBuilder.build(); | ||
| batchPartStorage = |
There was a problem hiding this comment.
Nit: Can we add a short comment on why batchPartStorage intentionally skips decorateWithMetrics?
There was a problem hiding this comment.
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 request.active with no matching response; the outer batch request is instrumented instead.
Co-authored by AI Agent
| } | ||
| startTimeNanos.set(clock.nanoTime()); | ||
| recorded.set(false); | ||
| if (recorded.compareAndSet(true, false) && metrics.getRequestActive() != null) { |
There was a problem hiding this comment.
Nit: Can we pull boolean started = recorded.compareAndSet(true, false); onto its own line so the side effect isn't coupled to short-circuit order with metrics.getRequestActive() != null?
There was a problem hiding this comment.
Done in 9853ac2: boolean started = recorded.compareAndSet(true, false); is on its own line and stays unconditional (the response/IO handlers rely on it), before the getRequestActive() check.
Co-authored by AI Agent
| .build()); | ||
| } | ||
|
|
||
| @Test |
There was a problem hiding this comment.
Nit: Can we move the isMonotonic() == false check into inMemoryMetricReader_verifiesViewsAndBoundaries and drop this test, since StorageGrpcMetricsInterceptorTest already covers the exact 6 attributes and +1/-1 balance?
There was a problem hiding this comment.
Done in 9853ac2: moved the non-monotonic check into inMemoryMetricReader_verifiesViewsAndBoundaries and dropped recordRequestActive_recordsExactSixAttributes; the exact 6-key coverage stays in the gRPC/HTTP interceptor tests.
Co-authored by AI Agent
…rage-request-active-metric Resolve conflicts in StorageHttpMetricsInterceptor by dropping the isRetry plumbing in favor of the pending-retry hook, keeping the request.active +1/-1 lifecycle (with the start CAS on its own line), and drop the duplicated StorageClientMetricsTest exact-attribute tests. [Generated-by: AI]
…view feedback - StorageGrpcMetricsInterceptor releases request.active through a per-call releaseActive() guard shared by the start() catch and onClose, so a downstream call that closes the listener inline and then throws decrements only once. - Document why batch parts skip decorateWithMetrics in HttpStorageRpc. - Strengthen the request.active HTTP test (handler failure message, no retry, throwing delegate HttpResponseInterceptor) and move the non-monotonic check into inMemoryMetricReader_verifiesViewsAndBoundaries. [Generated-by: AI]
Summary
Stacked on #15226.
Adds Debug-tier
gcp.storage.client.request.active(LongUpDownCounter, unit{request}) across both gRPC and HTTP/JSON transports to track in-flight requests with balanced+1/-1accounting.Changes
StorageClientMetrics: addrecordRequestActive(Context, String operationName, long delta)emitting exact 6-key attributes (gcp.client.service,gcp.client.version,gcp.client.artifact,rpc.system.name,server.address,gcp.storage.operation).StorageGrpcMetricsInterceptor:+1instart(); the-1goes through a per-callreleaseActive()guard shared by thestart()catch (when start throws) andonClose, so it is recorded exactly once.StorageHttpMetricsInterceptor: reuse the singleAtomicBoolean recorded(start CAS unconditional) for balanced+1/-1with the operation captured at request start, normalize//batch/storage/v1paths, and keepresponse.getRequest() == reqguards.spi/v1/HttpStorageRpc: batch parts use a client without the metrics interceptor (batchPartStorage) so they never leakrequest.active; the outer batch request is instrumented.StorageClientMetricsTest,StorageGrpcMetricsInterceptorTest, andStorageHttpMetricsInterceptorTest.[Generated-by: AI]