fix: retry transient errors on api autocomplete status GET#115
Open
vtushar06 wants to merge 1 commit into
Open
fix: retry transient errors on api autocomplete status GET#115vtushar06 wants to merge 1 commit into
vtushar06 wants to merge 1 commit into
Conversation
Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR hardens the OpenCost API client path used by the autocomplete probe/validation by ensuring /allocation/.../autocomplete status GETs go through the same retry-capable HTTP client path as other API calls, and adds deterministic unit coverage for the retry behavior.
Changes:
- Route
GetAutocompleteStatusthrough a newhttpGetWithRetryhelper instead ofhttp.Get. - Add
httpGetWithRetryto retry GET transport errors with the existingMAX_RETRIESand a configurable backoff (test-shortenable). - Add deterministic unit tests for retry success and retry exhaustion via an injected
RoundTripper.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/api/api.go | Adds httpGetWithRetry and a configurable retry backoff used by the autocomplete status path. |
| pkg/api/autocomplete.go | Switches GetAutocompleteStatus from raw http.Get to the retrying helper using sharedHTTPClient. |
| pkg/api/retry_test.go | Adds deterministic unit tests covering retry success and retry exhaustion for httpGetWithRetry. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+127
to
+145
| // httpGetWithRetry performs an HTTP GET, retrying transient transport errors | ||
| // (such as "connection reset by peer" from the shared demo backend) that | ||
| // otherwise fail integration runs spuriously. Each retry is logged so it is | ||
| // visible in the run output. These GETs are idempotent, so retrying is safe. | ||
| func httpGetWithRetry(client *http.Client, url string) (*http.Response, error) { | ||
| var lastErr error | ||
| for try := 0; try < MAX_RETRIES; try++ { | ||
| resp, err := client.Get(url) | ||
| if err == nil { | ||
| return resp, nil | ||
| } | ||
| lastErr = err | ||
| if try < MAX_RETRIES-1 { | ||
| log.Warnf("error getting %s: %v, retrying... (%d/%d)", url, err, try+1, MAX_RETRIES) | ||
| time.Sleep(httpGetRetryBackoff) | ||
| } | ||
| } | ||
| return nil, lastErr | ||
| } |
ameijer
approved these changes
Jul 1, 2026
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.
Description
Follow-up to #106 (thanks @ameijer for catching that the retries weren't firing). The connection resets in that run were on the OpenCost API client path, not the Prometheus client I hardened in #106.
API.GETalready retries transport errors, butGetAutocompleteStatus(used by the autocomplete probe and validation tests) used a rawhttp.Getthat bypassed that retry, so a connection reset there failed the run with no retry and no log, e.g.:This routes that GET through a small
httpGetWithRetryhelper that retries transient transport errors with the sameMAX_RETRIESand backoff asAPI.GET, and logs each retry so they show up in the run output. As a bonus it now uses the shared client's timeout instead of the barehttp.Get.Related
Follow-up to #106.
Testing
pkg/api/retry_test.go(deterministic, injectedRoundTripper): retries transient errors then succeeds, and returns the error afterMAX_RETRIES.go build ./...,go vet ./pkg/api/, and thepkg/apitests pass locally.One thing out of scope: the other failure in that run (
TestAllocationAutocompletePrometheusGroundTruth, 74.2% coverage) is a data-coverage assertion, not a network issue, so it's not addressed here.cc @ameijer