fix: honor 429 rate limits from VngCloud API#7
Open
anngdinh wants to merge 2 commits into
Open
Conversation
When the API returns 429 the controller currently sees a generic error,
controller-runtime requeues with exponential backoff, and N reconciles
in flight independently keep hammering the bucket so it never refills.
Surface 429 as a typed domain.RateLimitError carrying the server's
X-Ratelimit-Reset / Retry-After hint, plumb it through every repository
call (sdkErr.GetError -> domain.SDKError), and convert it in
HandleReconcileError to ctrl.Result{RequeueAfter} with a 2s floor, 5m
ceiling, and up to 50% jitter so independent processes don't retry in
lockstep.
Co-Authored-By: Claude Opus 4.7 (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.
Summary
When the API returns 429 the controller currently sees a generic error, controller-runtime requeues with exponential backoff, and N reconciles in flight independently keep hammering the bucket so it never refills. This PR makes the controller honor the server's rate-limit signal.
domain.RateLimitErrorcarriesRetryAfterparsed fromX-Ratelimit-Reset(thenRetry-After).domain.SDKError(sdkErr)replaces 55 rawsdkErr.GetError()calls ininternal/repository/vngcloud_repo/so 429s propagate as the typed error.pkg/errs.HandleReconcileErrorconverts aRateLimitErrorintoctrl.Result{RequeueAfter}viadomain.RateLimitRequeueAfter(2s floor, 5m ceiling, +50% jitter) — workqueue items honor the server's wait hint, and independent processes/clusters desynchronize retries instead of re-colliding atreset+0s.IsRateLimitExceedednow useserrors.As(was a TODO stub).Cross-cluster note
One user can run this controller in many clusters; the rate limit applies per account, not per cluster. Reactive backoff alone covers this because the API server itself is the coordination point — every cluster sees the same 429 and jittered
RetryAfterkeeps them from re-colliding. Per-process bucket coordination is intentionally not included here; see follow-ups.Test plan
go build ./...go vet ./internal/domain/... ./pkg/errs/... ./internal/repository/vngcloud_repo/...go test ./internal/domain/... ./pkg/errs/...covers parser (status code,X-Ratelimit-Reset,Retry-Afterfallback, missing headers, nil),RateLimitRequeueAfter(floor/ceiling/jitter), and theHandleReconcileErrorrate-limit branch (direct + wrapped viafmt.Errorf("%w", ...)).statusCode 429lines to stop accumulating; expectrate limited by VngCloud API, requeue after Xswarnings instead.Follow-ups (not in this PR)
ListCertificatesand other hotList*calls. Likely the bigger win and attacks the cause, not the symptom.golang.org/x/time/rate.Limiter) so a cluster with many concurrent reconciles self-throttles before getting 429'd. Only worth doing if reactive backoff isn't enough.🤖 Generated with Claude Code