Add offline store-and-forward buffer for unsent build metrics - #5
Open
joeldickson wants to merge 1 commit into
Open
Add offline store-and-forward buffer for unsent build metrics#5joeldickson wants to merge 1 commit into
joeldickson wants to merge 1 commit into
Conversation
Metrics were lost whenever the endpoint was unreachable — exactly the offline and flaky-connection builds we still want to capture. A failed POST now parks the payload under the Gradle user home and the next build that sends successfully flushes it. MetricsPublisher distinguishes three send outcomes: accepted, unreachable (worth retrying), and refused by a reachable endpoint (retrying will not help, so the payload is dropped). Flushing drains oldest first and stops as soon as the endpoint goes unreachable again, so a flaky connection cannot turn into a burst of doomed requests. UnsentMetricsBuffer caps the store at 200 payloads and seven days, and swallows every I/O error. All of it stays off the build's critical path: post() still returns immediately, and the returned future exists only so tests can await the send without sleeping. Closes #4 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4.
Build metrics were lost whenever the endpoint was unreachable — offline, VPN down, DNS failure, endpoint outage — which are exactly the builds we'd still like to capture once connectivity returns. A failed POST now parks the payload on disk, and the next build that sends successfully flushes it.
What changed
MetricsPublishernow distinguishes three send outcomes instead of swallowing everything:SUCCEEDEDUNREACHABLEIOException/ timeout anywhere in the cause chainREJECTEDFlushing drains oldest first and stops as soon as the endpoint goes unreachable again, so a flaky connection can't turn into a burst of doomed requests. A buffered payload refused by a reachable endpoint is deleted rather than retried forever.
UnsentMetricsBufferis a plain class — no interface, no abstraction — over a directory:save/list/read/delete/prune. One file per payload, named by the payloadid(sanitized so it can't escape the directory). It's capped at 200 payloads and seven days; entries beyond either cap are dropped oldest-first. Writes go through a temp file and rename. Every operation swallows its own errors.Wiring:
BuildMetricsService.Parametersgains abufferDirectory, set by the plugin to<gradle user home>/kotlin-local-metrics/unsent-build-metrics.Non-blocking
post()still returns immediately andclose()still ignores the result — all buffer I/O and flushing happens on the existing daemon HTTP thread pool.post()now returns aCompletableFuturepurely so tests can await a send instead of sleeping; nothing on the build's critical path waits on it.Tests
15 new tests, all deterministic — no sleeps, no retries, no wall-clock dependence.
UnsentMetricsBufferTest(9): naming by id, overwrite, path-separator sanitization, oldest-first listing, delete, count cap viaprune, age cap viaprune, count cap enforced throughsave, and a missing directory. Cap tests pass a fixednowMillisand setlastModifiedexplicitly.MetricsPublisherTest(6): buffers on an unreachable endpoint (a loopback port bound then released, so the connect refusal is immediate); keeps earlier entries buffered while still unreachable; flushes and deletes all buffered payloads once a send succeeds; neither buffers nor flushes when a reachable endpoint returns 500; sends fine with no buffer configured; and never throws on a malformed endpoint../gradlew buildis green, including the existing configuration-cache functional test, which exercises the new service parameter.Open questions from the issue
🤖 Generated with Claude Code