Skip to content

feat(storage): record HTTP ReadObject stall.duration on SocketTimeoutException - #15232

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

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

Conversation

@nidhiii-27

Copy link
Copy Markdown
Contributor

Summary

Stacked on #15231.

Adds HTTP/JSON ReadObject stall detection for Debug-tier gcp.storage.client.stall.duration (DoubleHistogram, unit s) on SocketTimeoutException failures across both initial open attempts and mid-stream socket reads.

Changes

  • StorageErrorTypeMapper: add cycle-safe, depth-bounded hasSocketTimeoutCause(Throwable) helper.
  • StorageMetricsContext: track lastActivityNanos, add markActivity(), and add recordHttpReadStallIfTimeout(Throwable) emitting gcp.storage.client.stall.duration with exact 8-key attributes (gcp.storage.operation = "ReadObject", rpc.method = "google.storage.v2.Storage/ReadObject", network.path = "cloudpath") exclusively for HTTP ReadObject SocketTimeoutException failures.
  • ApiaryUnbufferedReadableByteChannel: call markMetricsActivity() immediately before sbc.read(...) (so inter-read application processing time does not inflate stall duration) and invoke recordHttpReadStall(t) in catch.
  • Unit tests in StorageErrorTypeMapperTest, StorageMetricsContextTest, and ApiaryUnbufferedReadableByteChannelTest.

[Generated-by: AI]

…Exception

Record Debug-tier gcp.storage.client.stall.duration (unit "s", exact
8-key attributes with rpc.method=google.storage.v2.Storage/ReadObject
and network.path=cloudpath) on HTTP ReadObject SocketTimeoutException
failures across initial open attempts and mid-stream socket reads while
excluding non-timeout errors, non-ReadObject operations, and inter-read
application processing time.

[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 and recording of HTTP read stall durations during ReadObject operations when a socket timeout occurs. It adds activity tracking to StorageMetricsContext and ApiaryUnbufferedReadableByteChannel to measure the time elapsed since the last progress. Feedback on the changes suggests addressing a potential double-recording of the stall duration during a terminal failure to open a stream by ensuring mid-stream stalls are only recorded when the channel is not null.

…age-http-stall-duration-metric [Generated-by: AI]
…age-http-stall-duration-metric

[Generated-by: AI]
…age-http-stall-duration-metric

[Generated-by: AI]
…age-http-stall-duration-metric

[Generated-by: AI]
recordAttemptFailure(String, long) passes no Throwable for google-http-client internal retries.

[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

String networkPath = resolveNetworkPath();
Attributes attemptBase = buildAttemptBaseAttributes(metrics);
recordErrorCounter(metrics, attemptBase, errorType, networkPath);
recordHttpReadStallIfTimeout(metrics, e);

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.

For StorageImpl.downloadTo and readAllBytes, lastActivityNanos isn't updated while bytes stream, so a mid-stream SocketTimeoutException will inflate stall.duration with prior transfer time; can we refresh activity as bytes are read and add a test?

|| !StorageErrorTypeMapper.hasSocketTimeoutCause(e)) {
return;
}
double stallSeconds = (clock.nanoTime() - lastActivityNanos.get()) / 1_000_000_000.0;

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: Read lastActivityNanos.get() before clock.nanoTime() and clamp to >= 0 so concurrent updates or clock skew can't record a negative duration.

}

void markActivity() {
lastActivityNanos.set(clock.nanoTime());

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 return early in markActivity() when metrics == null || metrics.getStallDuration() == null to skip clock.nanoTime() when debug metrics are off, and reuse it in incrementAttempts()?

storageClient,
SettableApiFuture.create(),
options.createRetrier().withMetricsContext(ctx),
new BasicResultRetryAlgorithm<Object>() {

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 reuse the existing retryIf helper below instead of an inline BasicResultRetryAlgorithm?

@Test
public void recordAttemptFailure_httpStallDuration_recordsOnlyHttpReadSocketTimeout() {
AtomicLong nanos = new AtomicLong(1_000_000_000L);
ApiClock fakeClock =

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 extract a small fakeClock helper to avoid duplicating this anonymous ApiClock from create_withApiClock_usesClockForStartAndElapsedTime?

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