Repository navigation
feat(storage): record HTTP ReadObject stall.duration on SocketTimeoutException - #15232
nidhiii-27 wants to merge 6 commits into
Conversation
…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]
There was a problem hiding this comment.
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]
| String networkPath = resolveNetworkPath(); | ||
| Attributes attemptBase = buildAttemptBaseAttributes(metrics); | ||
| recordErrorCounter(metrics, attemptBase, errorType, networkPath); | ||
| recordHttpReadStallIfTimeout(metrics, e); |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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>() { |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
Nit: Can we extract a small fakeClock helper to avoid duplicating this anonymous ApiClock from create_withApiClock_usesClockForStartAndElapsedTime?
Summary
Stacked on #15231.
Adds HTTP/JSON
ReadObjectstall detection for Debug-tiergcp.storage.client.stall.duration(DoubleHistogram, units) onSocketTimeoutExceptionfailures across both initial open attempts and mid-stream socket reads.Changes
StorageErrorTypeMapper: add cycle-safe, depth-boundedhasSocketTimeoutCause(Throwable)helper.StorageMetricsContext: tracklastActivityNanos, addmarkActivity(), and addrecordHttpReadStallIfTimeout(Throwable)emittinggcp.storage.client.stall.durationwith exact 8-key attributes (gcp.storage.operation = "ReadObject",rpc.method = "google.storage.v2.Storage/ReadObject",network.path = "cloudpath") exclusively for HTTPReadObjectSocketTimeoutExceptionfailures.ApiaryUnbufferedReadableByteChannel: callmarkMetricsActivity()immediately beforesbc.read(...)(so inter-read application processing time does not inflate stall duration) and invokerecordHttpReadStall(t)incatch.StorageErrorTypeMapperTest,StorageMetricsContextTest, andApiaryUnbufferedReadableByteChannelTest.[Generated-by: AI]