Skip to content

feat(storage): record gRPC stall.duration and Watchdog TIMEOUT classification - #15231

Open
nidhiii-27 wants to merge 6 commits into
feat/storage-network-io-metricfrom
feat/storage-grpc-stall-duration-metric
Open

nidhiii-27 wants to merge 6 commits into
feat/storage-network-io-metricfrom
feat/storage-grpc-stall-duration-metric

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

Summary

Stacked on #15230.

Adds Debug-tier gcp.storage.client.stall.duration (DoubleHistogram, unit s) on gRPC streaming reads and introduces a zero-race GAX Watchdog timeout feedback hook between StorageGrpcMetricsInterceptor and GapicUnbufferedReadableByteChannel, resolving #14743#discussion_r4596591825.

Changes

  • StorageClientMetrics: add recordStallDuration(Context, double durationSeconds, String operationName, String rpcMethod, String networkPath) emitting exact 8-key attributes (gcp.client.service, gcp.client.version, gcp.client.artifact, rpc.system.name, server.address, gcp.storage.operation, rpc.method, network.path).
  • StorageMetricsContext: add enterWatchdogScope(Runnable) and notifyWatchdogTimeout() thread-local callback scope so WatchdogTimeoutException signals synchronously before the reader thread unblocks.
  • GapicUnbufferedReadableByteChannel.ReadObjectObserver.onErrorImpl: invoke StorageMetricsContext.notifyWatchdogTimeout() synchronously when t instanceof WatchdogTimeoutException before completing open or enqueueing t.
  • StorageGrpcMetricsInterceptor: track lastActivityNanos on the listener and, when onClose receives Status.Code.CANCELLED, wrap super.onClose in StorageMetricsContext.enterWatchdogScope(...) so real GAX Watchdog aborts synchronously tag rpc.client.call.duration with error.type = "TIMEOUT", record stall.duration since the last received message, and prevent false server.unreached increments (non-cancelled closes continue recording before super.onClose).
  • Unit tests in StorageClientMetricsTest, StorageMetricsContextTest, GapicUnbufferedReadableByteChannelTest, and StorageGrpcMetricsInterceptorTest (including real GAX Watchdog.createDuration(...) tests).

[Generated-by: AI]

…fication

Add Debug-tier gcp.storage.client.stall.duration (unit "s", exact 8-key
attributes) and a zero-race Watchdog timeout callback scope between
StorageGrpcMetricsInterceptor and GapicUnbufferedReadableByteChannel so
GAX Watchdog aborts synchronously tag rpc.client.call.duration with
error.type=TIMEOUT, record stall duration since the last received
message, and avoid false server.unreached counts.

[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 watchdog timeout tracking and stall duration metrics for Google Cloud Storage. It updates the gRPC metrics interceptor to track the last activity time and record stall duration metrics when a watchdog timeout occurs, supported by new thread-local scope management in StorageMetricsContext. The review feedback highlights two concurrency-related improvements in StorageGrpcMetricsInterceptor.java: declaring lastActivityNanos as volatile to ensure proper memory visibility across threads, and replacing a raw boolean[] array with AtomicBoolean to guarantee thread-safe execution of the onClose metrics recording.

…stall-duration-metric

Keep the shared releaseActive() exactly-once request.active decrement in the restructured
recordOnCloseMetrics finally block.

[Generated-by: AI]
interceptCall_watchdogTimeout_recordsStallDurationAndTimeoutErrorType already asserts the
exact attribute set, unit, and debug-tier gating end to end.

[Generated-by: AI]
@nidhiii-27
nidhiii-27 marked this pull request as ready for review November 26, 2026 06:05
@nidhiii-27
nidhiii-27 requested review from a team as code owners November 26, 2026 06:05
@nidhiii-27
nidhiii-27 requested review from Dhriti07 and cpriti-os and removed request for a team November 26, 2026 06:05

@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

@Override
public void onMessage(@Nullable RespT message) {
long now = clock.nanoTime();
lastActivityNanos = now;

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.

Should we update lastActivityNanos after super.onMessage(message) returns so time spent blocked in ReadObjectObserver's queue isn't counted as server stall duration?

}

@Test
public void interceptCall_watchdogTimeout_recordsStallDurationAndTimeoutErrorType()

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.

Nit: Can we split these scenarios into separate @Test methods (so they don't share metric state) and add a debug-enabled case where Watchdog fires before the first onMessage?

}

@Test
public void read_watchdogTimeout_notifiesWatchdogScopeSynchronously() throws IOException {

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.

Nit: Could we also test a non-watchdog CancellationException inside enterWatchdogScope to verify the callback isn't triggered for normal cancellations?

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