Repository navigation
Add WithRetry: retries with backoff for requests that are safe to repeat - #50
Open
DzmitryHumianiuk wants to merge 1 commit into
Open
DzmitryHumianiuk wants to merge 1 commit into
DzmitryHumianiuk wants to merge 1 commit into
Conversation
WithRetry(RetryPolicy) repeats requests that failed with a network error, 5xx (except 501) or 429, with exponential backoff and jitter. A Retry-After header is honored up to MaxWait, other 4xx are never retried, retries stop with the context. The hand-written methods use Resty's retry API with the policy's own conditions and delays; the generated client gets a copy of the HTTP client with a retrying transport. GET, PUT and DELETE are retried. Launch and item starts are retried because they carry a client UUID, which the client now generates when the request has none. Rerun starts, raw starts without a uuid and logs are sent once. Part of #27 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Member
Author
|
Local ReportPortal 6.0.0 check (same build as demo), covering the two "Not verified" items:
|
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.
Summary
Part of #27 (slice L4). Stacked on L1 (
feat/client-options), which providesOption. Does not depend on #36; it merges with #36 with the resolution described in the L1 PR (trial merge built and passed all tests).WithRetry(RetryPolicy)makes a client repeat requests that failed for a reason that may pass. It is off by default, and the CLI does not use it yet.Changes
pkg/gorp/retry.go(new):RetryPolicy{MaxRetries, MinWait, MaxWait}andWithRetry. Defaults:MinWait500 ms,MaxWait10 s.MaxRetries <= 0means no retries.MinWait * 2^(attempt-1)capped atMaxWait, the actual pause is random between a half and the whole of that. ARetry-Afterheader (seconds or HTTP date) is used instead when present, capped atMaxWait.ReportingClient, launch and filter helpers ofClient): Resty's retry API with the policy's own condition, delay strategy and a hook that capsRetry-After. Each attempt is a separatehttp.Client.Do.http.ClientwithretryTransport(http.RoundTripper). The shared client is not wrapped, otherwise Resty calls would retry twice over.pkg/gorp/reporting_client.go: launch and item starts opt in to retries per request, see below.Which requests are retried
StartLaunch,StartTest,StartChildTestStart*Raw"uuid"rerunSaveLog,SaveLogs,SaveLogMultipartMergeLaunches, every POST/PATCH of the generated clientBehaviour change
Only with
WithRetry:id. WithoutWithRetrythe request goes out as before.Retry-Afteris the case retries exist for, and the server analysis recommends it. ReportPortal itself never sends 429 orRetry-After, a proxy may.RetryLogsfield after reading Resty: before a retry it rewinds multipart readers and fails withErrReaderNotSeekablefor one that can't seek (multipart.go:73-79), replacing the real error (request.go:1563), and it closes closable field readers after every attempt (client.go:2491-2497). The log batcher of L3 is the place to decide about re-sending logs.http.Client.Timeout(30 s by default,pkg/gorp/client.go) covers all attempts and pauses together, because the retries happen inside oneDo. For the Resty-based methods every attempt has its own timeout.Retry-Afteris rounded up to a whole second (the header only has seconds).Verification
On
feat/http-retries(19b9ae1):go build ./... && go vet ./...: okgo test -race ./...: ok;go test -race -count=3 ./pkg/gorp/: okgo run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0 run ./...: 0 issueshttptest) that answers with a scripted list of statuses or closes the connection without a response.Tests (
pkg/gorp/retry_test.go), each for the Resty-based methods and the generated client where it applies:MaxRetries: 2gives exactly 3 requests on both clients, anderrors.Asstill yields*HTTPError/*openapi.GenericOpenAPIErrorwith the last body;WithRetryno UUID is added;context.Canceledat once with one request sent;Retry-After: 1is waited for (>= 1 s);Retry-After: 3600is capped byMaxWait(for 503, which Resty handles itself, and for 500);GetBody, and sends once what it cannot replay (POST, PATCH, a PUT with a one-shot body);Investigation log
go.mod:11:resty.dev/v3 v3.0.0-rc.4. Its API was read in the module cache, not from memory.request.go:1470-1620(Execute): retries only whenRetryCount > 0and the request is idempotent (:1490,:1534); idempotent means GET/HEAD/OPTIONS/PUT/DELETE/TRACE orSetRetryAllowNonIdempotent(true)on the request (:1895-1908). This fits: POSTs are sent once unless a request opts in.client.go:2507-2514: on a transport error the conditions get a non-nilResponsewith a nilRawResponse, so one condition can handle both errors and statuses.retry.go:104-125(isDoNotRetryError): the built-in condition retries only errors that reportTemporary(), which a refused or reset connection does not. So the default conditions are switched off and the policy's own are used.retry.go:153-173(NextWaitDuration): for 429 and 503 Resty returnsRetry-Afteras is, before it asks a custom delay strategy, and without a cap (:215-245). A retry hook runs before that (request.go:1568-1576), so the hook rewrites an excessive header to the policy's limit. For other statuses the policy's delay strategy reads the header.developat 017642e9, migrations at 956ef1ad:StartRQ.java:66-68hasuuid; v2 keeps a client UUID for launches (reporting/async/producer/LaunchStartProducer.java:58-63) and items (ItemStartProducer.java:54-58) and generates one only when it is blank.LaunchStartProducer.java:58-60.launch.uuidandtest_item.uuidareVARCHAR(36) NOT NULL UNIQUE(1_initialize_schema.up.sql:383,419).16_remove_unused_indexes.up.sqldrops extra indexes and the unique constraint oflog.uuidonly, so launches and items stay unique and logs don't.reporting/async/exception/ReportingErrorHandler.java:89-98). So a repeated start with the same UUID is accepted with 201 and then dropped by the unique constraint, and a repeated log is stored twice.Retry-After(server analysis in the plan; not re-checked line by line).Uuid stringwithoutomitempty(pkg/openapi/model_com_epam_reportportal_base_reporting_start_launch_rq.go:30), so an unset UUID already goes out as""today; the client UUID replaces that.Not verified
ReportingClientuses v2 only.🤖 Generated with Claude Code