Skip to content

feat(storage): record gcp.storage.client.request.active metric - #15227

Open
nidhiii-27 wants to merge 7 commits into
feat/storage-retries-metric-streams-httpfrom
feat/storage-request-active-metric
Open

nidhiii-27 wants to merge 7 commits into
feat/storage-retries-metric-streams-httpfrom
feat/storage-request-active-metric

Conversation

@nidhiii-27

@nidhiii-27 nidhiii-27 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

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/-1 accounting.

Changes

  • StorageClientMetrics: add recordRequestActive(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: +1 in start(); the -1 goes through a per-call releaseActive() guard shared by the start() catch (when start throws) and onClose, so it is recorded exactly once.
  • StorageHttpMetricsInterceptor: reuse the single AtomicBoolean recorded (start CAS unconditional) for balanced +1/-1 with the operation captured at request start, normalize //batch/storage/v1 paths, and keep response.getRequest() == req guards.
  • spi/v1/HttpStorageRpc: batch parts use a client without the metrics interceptor (batchPartStorage) so they never leak request.active; the outer batch request is instrumented.
  • Unit tests in StorageClientMetricsTest, StorageGrpcMetricsInterceptorTest, and StorageHttpMetricsInterceptorTest.

[Generated-by: AI]

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@nidhiii-27
nidhiii-27 marked this pull request as ready for review November 25, 2026 10:25
@nidhiii-27
nidhiii-27 requested review from a team as code owners November 25, 2026 10:25
…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.

@cpriti-os cpriti-os left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initial review

…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]
@nidhiii-27
nidhiii-27 requested a review from cpriti-os November 26, 2026 06:04
…est-active-metric

# Conflicts:
#	java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageHttpMetricsInterceptor.java
#	java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/spi/v1/HttpStorageRpc.java
#	java-storage/google-cloud-storage/src/test/java/com/google/cloud/storage/StorageGrpcMetricsInterceptorTest.java
…rage-request-active-metric

Pull in 37a28a2 (cdca421) from base PR #15226 to replace Mockito.mock(StreamController.class) with TestUtils.nullStreamController() in GrpcStorageImplTest for JDK 8 compatibility.

[Generated-by: AI]
nidhiii-27 added a commit that referenced this pull request Dec 4, 2026
…erver-duration-metric

Pull in ac485d5 (cdca421) from base PR #15227 to replace Mockito.mock(StreamController.class) with TestUtils.nullStreamController() in GrpcStorageImplTest for JDK 8 compatibility.

[Generated-by: AI]

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-generated Pull Request generated by AI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants