← Back to Pull requests

feat(inkless:storage): bound and shorten the GCS upload path #783

Closed
unknown closed this pull request without merging on Sep 08, 2026 09:07 UTC
View on GitHub
unknown unknown commented on Sep 03, 2026 10:33 UTC
Author

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 through FileCommitWaitTime. 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 - adds gcs.connect.timeout and gcs.read.timeout, defaulting to 2s and 1s; maps a timed out request to StorageBackendTimeoutException; 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 - uses storage.create for objects up to 1 MiB, keeps the resumable path above that, and adds an object-upload counter so per-request upload activity stays visible.

  • feat(inkless:storage): count GCS error responses by type - adds throttling-errors, server-errors, and other-errors under 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.timeout and s3.api.call.attempt.timeout knobs, 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:

  • The read value bounds each socket read, not a whole request. Connection setup falls under gcs.connect.timeout, request-body writes are not covered, and a response arriving in several reads can exceed it.

  • Whether it bounds the operation depends on the client's idempotency classification. A single-request upload and a resumable session initiate are non-idempotent, and the client's non-idempotent handler retries nothing, so their ceiling is ours to set: an object at or below 1 MiB ends its attempt on the first stalled read, making the upload budget produce.max.upload.attempts stalled 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.

  • Both values apply to every GCS role. SharedState builds four independent backends (fetch, lagging fetch, produce, background) from the same inkless.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 StorageBackendTimeoutException from upload, single-key delete, and a fetch's metadata request. A fetch's body is streamed from the channel fetch returns, so a stall mid-download reaches the caller as a plain IOException instead -- ReadableByteChannel.read cannot throw StorageBackendException. S3Storage classifies 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 gets KAFKA_STORAGE_ERROR. That is a RefreshRetriableException at 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-initiate and resumable-chunk-upload stop 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, as SlowDown is 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.bytes at 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 every produce.commit.interval.ms saves 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 FileUploadTime maxima 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.read reopens 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 inside file.cleaner.interval.ms. FileCleaner already 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 same false its 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. Driving Storage.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-delete counts confirmed deletions rather than attempted ones, so it can read lower than before on a bucket that is refusing deletes.

    Testing

    GcsStorageConfigTest covers the new defaults, that both values parse into Duration objects, and that a non-positive value is rejected. GcsStorageMetricsTest asserts the upload counters on both sides of the 1 MiB threshold. GcsStorageTest covers a delete spanning several batches, which the shared suite's ten-key case does not reach, and overrides testUploadOversizeStream, 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.

    GcsErrorHandlingTest uses WireMock for the failures fake-gcs-server cannot produce. A delayed response pins the timeout classification: an upload surfaces StorageBackendTimeoutException with SocketTimeoutException as 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-errors and io-errors are 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 an IOException, HttpIOExceptionHandler receives no exception, NetHttpTransport is 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 from FileUploadTime.

  • A stalled GCS object download is neither classified nor bounded. The body is streamed after fetch returns, so a stall reaches the caller as a plain IOException, 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, around ObjectFetcher.readToByteBuffer, which can throw StorageBackendException. Shared across backends, so it belongs in its own change.

  • Above 1 MiB an upload is retried twice over: by the client's idempotent handler on the resumable PUT and by FileUploadJob on 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, since SharedState builds all four backends from the same inkless.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 fast KAFKA_STORAGE_ERROR, and how often a stalled PUT recovers on a retry is the number that decides whether that trade is worth making.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: giuseppelillo Review duration: 7113m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%
    Repository