Repository navigation
feat(storage): record gcp.storage.client.retries for mid-stream and HTTP retries #15226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: feat/storage-retries-metric-core
Are you sure you want to change the base?
Changes from all commits
4940a70
6c86038
736b10f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ | |
| import com.google.api.services.storage.Storage.Objects; | ||
| import com.google.api.services.storage.Storage.Objects.Get; | ||
| import com.google.api.services.storage.model.StorageObject; | ||
| import com.google.cloud.BaseServiceException; | ||
| import com.google.cloud.storage.Conversions.Decoder; | ||
| import com.google.cloud.storage.Retrying.Retrier; | ||
| import com.google.cloud.storage.UnbufferedReadableByteChannelSession.UnbufferedReadableByteChannel; | ||
|
|
@@ -152,16 +153,21 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { | |
| if (resultRetryAlgorithm.shouldRetry(t, null)) { | ||
| // if our retry algorithm COULD allow a retry, continue the loop and allow trying to | ||
| // open the stream again. | ||
| recordMidStreamRetry(t); | ||
| sbc = null; | ||
| } else if (t instanceof IOException) { | ||
| IOException ioE = (IOException) t; | ||
| if (resultRetryAlgorithm.shouldRetry(StorageException.translate(ioE), null)) { | ||
| recordMidStreamRetry(ioE); | ||
| sbc = null; | ||
|
nidhiii-27 marked this conversation as resolved.
Resolved
|
||
| } else { | ||
| recordMidStreamError(ioE); | ||
| throw ioE; | ||
| } | ||
| } else { | ||
| throw new IOException(StorageException.coalesce(t)); | ||
| BaseServiceException coalesced = StorageException.coalesce(t); | ||
| recordMidStreamError(coalesced); | ||
| throw new IOException(coalesced); | ||
| } | ||
| } finally { | ||
| long totalRemainingAfter = Buffers.totalRemaining(dsts, offset, length); | ||
|
|
@@ -203,6 +209,21 @@ public void close() throws IOException { | |
| } | ||
| } | ||
|
|
||
| private void recordMidStreamRetry(Throwable error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 736b10f: both terminal branches ( Co-authored by AI Agent |
||
| StorageMetricsContext metricsContext = retrier.getMetricsContext(); | ||
| if (metricsContext != null) { | ||
| metricsContext.recordError(error); | ||
| metricsContext.recordRetry(error); | ||
| } | ||
| } | ||
|
|
||
| private void recordMidStreamError(Throwable error) { | ||
| StorageMetricsContext metricsContext = retrier.getMetricsContext(); | ||
| if (metricsContext != null) { | ||
| metricsContext.recordError(error); | ||
| } | ||
| } | ||
|
|
||
| private void setXGoogGeneration(long xGoogGeneration) { | ||
| this.xGoogGeneration = xGoogGeneration; | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -163,9 +163,11 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { | |
| if (take instanceof IOException) { | ||
| IOException ioe = (IOException) take; | ||
| if (alg.shouldRetry(ioe, null)) { | ||
| recordMidStreamRetry(StorageException.coalesce(ioe)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Can we add a test case that hits this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 736b10f: added Co-authored by AI Agent |
||
| cancelAndDrainCurrentObserver(); | ||
| continue; | ||
| } else { | ||
| recordMidStreamError(StorageException.coalesce(ioe)); | ||
| ioe.addSuppressed(new AsyncStorageTaskException()); | ||
| throw ioe; | ||
| } | ||
|
|
@@ -174,9 +176,11 @@ public long read(ByteBuffer[] dsts, int offset, int length) throws IOException { | |
| Throwable throwable = (Throwable) take; | ||
| BaseServiceException coalesce = StorageException.coalesce(throwable); | ||
| if (alg.shouldRetry(coalesce, null)) { | ||
| recordMidStreamRetry(coalesce); | ||
| cancelAndDrainCurrentObserver(); | ||
| continue; | ||
| } else { | ||
| recordMidStreamError(coalesce); | ||
| close(); | ||
| throw new IOException(coalesce); | ||
| } | ||
|
|
@@ -298,6 +302,21 @@ private void drainQueue() throws IOException { | |
| } | ||
| } | ||
|
|
||
| private void recordMidStreamRetry(Throwable error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here: should we call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done in 736b10f: same change on the gRPC path for both terminal branches, using the same Co-authored by AI Agent |
||
| StorageMetricsContext metricsContext = retrier.getMetricsContext(); | ||
| if (metricsContext != null) { | ||
| metricsContext.recordError(error); | ||
| metricsContext.recordRetry(error); | ||
| } | ||
| } | ||
|
|
||
| private void recordMidStreamError(Throwable error) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we also call |
||
| StorageMetricsContext metricsContext = retrier.getMetricsContext(); | ||
| if (metricsContext != null) { | ||
| metricsContext.recordError(error); | ||
| } | ||
| } | ||
|
|
||
| private void cancelAndDrainCurrentObserver() { | ||
| if (readObjectObserver != null) { | ||
| readObjectObserver.cancel(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can we add a test case that hits this retryable branch too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in 736b10f: added
midStreamIoException_directlyRetryable_recordsRetryAndErrorMetrics, where the algorithm accepts the raw exception so the first branch is taken.Co-authored by AI Agent