feat(inkless:storage): bound and shorten the GCS upload path #783
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #783"
general
weight: 0.35
giuseppelillo
GCS requests were bounded only by the google-cloud client defaults (20s connect, 20s read), neither of which was configurable, and every upload opened a resumable session and paid two round trips. Both costs land on the produce path: a stalled or slow upload holds an uploader thread, shows up as
FileUploadTime, and cascades into produce latency throughFileCommitWaitTime. This makes the timeouts configurable, bounds each response read by default, and drops one round trip for small objects. See the commit messages for the reasoning behind each step.Commits
feat(inkless:storage): bound each GCS request attempt by default- addsgcs.connect.timeoutandgcs.read.timeout, defaulting to 2s and 1s; maps a timed out request toStorageBackendTimeoutException; and reshapes the batch delete so it chunks its work, reports per-key failures, and no longer confirms a key the server refused to delete.feat(inkless:storage): upload GCS objects in a single request- usesstorage.createfor objects up to 1 MiB, keeps the resumable path above that, and adds anobject-uploadcounter so per-request upload activity stays visible.feat(inkless:storage): count GCS error responses by type- addsthrottling-errors,server-errors, andother-errorsunder the S3 backend's names, counted per request attempt from the response interceptor.Config changes
gcs.connect.timeout(new): connection establishment timeout in milliseconds. Default 2000.gcs.read.timeout(new): response read timeout in milliseconds. Default 1000.Both mirror the existing
s3.api.call.timeoutands3.api.call.attempt.timeoutknobs, except that these carry real defaults rather than deferring to the client's. An operator who wants the old behavior sets the client's values explicitly (20000 each); there is no null or sentinel, because a plain number already expresses it.Three properties of these bounds are worth knowing before tuning them:
gcs.connect.timeout, request-body writes are not covered, and a response arriving in several reads can exceed it.produce.max.upload.attemptsstalled reads, about 3s. A read and a resumable upload's chunk write are idempotent and run up to 6 client attempts under a 50s total timeout, so above 1 MiB an upload attempt is bounded by that budget rather than by this value, and lowering the read timeout changes how many attempts fit in the 50s rather than shortening it. Removing the client's retry on the produce path is left as a follow-up.SharedStatebuilds four independent backends (fetch, lagging fetch, produce, background) from the sameinkless.storage.config. Connect keeps the wider bound on purpose: it applies only on a connection-pool miss, so a generous ceiling costs nothing in steady state and leaves headroom for the connection churn that accompanies a slowdown, while the read bound applies to every stalled request and is the one worth keeping tight.A timed out request surfaces as
StorageBackendTimeoutExceptionfromupload, single-keydelete, and a fetch's metadata request. A fetch's body is streamed from the channelfetchreturns, so a stall mid-download reaches the caller as a plainIOExceptioninstead --ReadableByteChannel.readcannot throwStorageBackendException.S3Storageclassifies its whole fetch only because it materializes the response into a buffer. The batch delete stops the pass rather than classifying, as S3 does. When an upload exhausts its attempts the file fails, and every produce request in it getsKAFKA_STORAGE_ERROR. That is aRefreshRetriableExceptionat the client, so producers retry after a metadata refresh rather than losing data.Metric changes
object-upload-rate/object-upload-total(new): single-request object uploads.resumable-upload-initiateandresumable-chunk-uploadstop advancing for objects at or below the threshold, so dashboards that track upload activity through those two need this one added.throttling-errors,server-errors,other-errors(new, each-rate/-total): error responses per request attempt, under the S3 backend's names so one dashboard serves both. 429 and 503 are throttling, asSlowDownis on S3; other 5xx are server errors; other non-2xx, including the 404 for a missing key, are other errors. A request that fails without a response (a configured timeout, a connection reset) is not counted; see the follow-ups.Operator impact
Objects up to 1 MiB now issue one request instead of two. With
produce.buffer.max.bytesat 8 MiB, that is the small-file end of the distribution: a broker rotating full buffers under load keeps streaming, while a low-throughput topic flushing a few kilobytes everyproduce.commit.interval.mssaves a round trip, which is where the fixed cost dominates. The threshold sits below the measured break-even near 2 MiB, above which a single request costs more per megabyte than the round trip it saves.A GCS request that stalls beyond the new timeouts fails its attempt rather than holding a connection for 20s. For an object at or below 1 MiB, where nothing is retried inside the client, three upload attempts now complete in about 3s instead of a minute. Above the threshold the client's own 50s retry budget dominates and the read timeout does not shorten the upload, so expect
FileUploadTimemaxima to drop at the small end of the distribution and stay where they are at the large end.A stalled object download is a second place the client's budget wins.
ApiaryUnbufferedReadableByteChannel.readreopens the stream on a retryable failure and each reopen starts a fresh budget, so a shorter read timeout makes it reopen more often against a backend that is already slow rather than giving up sooner. Bounding a stalled fetch needs a deadline above the channel; see the follow-ups.Batch deletes change shape rather than budget. The client splits a delete into HTTP batches of at most 100 sub-requests and answers only after processing all of them, so the response wait scales with the batch, and a batch delete is not retried by the client.
GcsStorage.delete(Set)now deletes in chunks of half that maximum and returns the keys confirmed so far, so a slow batch costs one chunk instead of a whole cleaner pass. A default cycle of 20000 files becomes 400 round trips, well insidefile.cleaner.interval.ms.FileCleaneralready treats deletion as partial, so this matches the contract it expects and the S3 backend's shape.The same rewrite fixes a confirmation bug the previous shape had.
Storage.delete(Iterable)reports a failed sub-request as the samefalseits callback uses for an absent blob, and the old code ignored the result and confirmed every key in the batch, so a 403 or 5xx on one key still dereferenced its file in the control plane and left a permanent orphan. DrivingStorage.batch()directly keeps the three outcomes apart: deleted and already-absent are confirmed, a failure is not, and failures are now logged by response code the way the S3 backend logs them.object-deletecounts confirmed deletions rather than attempted ones, so it can read lower than before on a bucket that is refusing deletes.Testing
GcsStorageConfigTestcovers the new defaults, that both values parse intoDurationobjects, and that a non-positive value is rejected.GcsStorageMetricsTestasserts the upload counters on both sides of the 1 MiB threshold.GcsStorageTestcovers a delete spanning several batches, which the shared suite's ten-key case does not reach, and overridestestUploadOversizeStream, since a stream longer than its declared length is now reported by the trailing-byte probe rather than by the size check, matching the S3 backend.GcsErrorHandlingTestuses WireMock for the failures fake-gcs-server cannot produce. A delayed response pins the timeout classification: an upload surfacesStorageBackendTimeoutExceptionwithSocketTimeoutExceptionas its root cause, which exercises the cause-chain walk every classification site depends on. A hand-built multipart batch response pins the delete confirmation on both sides: with one deleted sub-response and two refused, only one key comes back confirmed, and with every sub-response a 404, both keys do. Each error sensor is asserted at exactly one count end to end: a 429 and a 500 on upload, a 404 on fetch, and a 503 on the batch endpoint, which the interceptor never sees and the caller reports.Follow-ups
configured-timeout-errorsandio-errorsare still missing on GCS, so nothing reports how often these timeouts fire per attempt. The AWS SDK publishes those itself; the GCS client has no once-per-attempt hook that carries the exception (the response interceptor never runs on anIOException,HttpIOExceptionHandlerreceives no exception,NetHttpTransportis final, and gax consults the retry strategy up to three times per attempt). Settling where that hook lives is its own change, and it is what would let these defaults be validated in production rather than inferred fromFileUploadTime.fetchreturns, so a stall reaches the caller as a plainIOException, and the client's read channel reopens the stream on each retryable failure with a fresh retry budget, so no number of read timeouts ends the fetch. Both need a wall-clock deadline above the channel, aroundObjectFetcher.readToByteBuffer, which can throwStorageBackendException. Shared across backends, so it belongs in its own change.FileUploadJobon top, while a fetch has only the client's retry. The fix is no client retry on the produce backend and the default on the fetch backend, which needs per-role storage config, sinceSharedStatebuilds all four backends from the sameinkless.storage.map.produce.upload.backoff.ms(10ms, unjittered) has to be re-sized in the same change: it is masked by the client's backoff today and becomes the only wait between attempts once that is gone. Both should follow the error counters, because removing the client's retry trades a slow success for a fastKAFKA_STORAGE_ERROR, and how often a stalled PUT recovers on a retry is the number that decides whether that trade is worth making.