Skip to content

Commit

Permalink
Merge pull request #117547 from wojtek-t/apf_dynamic_retry_after
Browse files Browse the repository at this point in the history
Return dynamic RetryAfter header from APF
  • Loading branch information
k8s-ci-robot committed May 15, 2023
2 parents 23ea699 + 23ac0fd commit 2a4bf45
Show file tree
Hide file tree
Showing 5 changed files with 641 additions and 213 deletions.
Expand Up @@ -34,7 +34,6 @@ import (

const (
// Constant for the retry-after interval on rate limiting.
// TODO: maybe make this dynamic? or user-adjustable?
retryAfter = "1"

// How often inflight usage metric should be updated. Because
Expand Down Expand Up @@ -210,7 +209,7 @@ func WithMaxInFlightLimit(
// We need to split this data between buckets used for throttling.
metrics.RecordDroppedRequest(r, requestInfo, metrics.APIServerComponent, isMutatingRequest)
metrics.RecordRequestTermination(r, requestInfo, metrics.APIServerComponent, http.StatusTooManyRequests)
tooManyRequests(r, w)
tooManyRequests(r, w, retryAfter)
}
}
})
Expand All @@ -221,9 +220,3 @@ func WithMaxInFlightLimit(
func StartMaxInFlightWatermarkMaintenance(stopCh <-chan struct{}) {
startWatermarkMaintenance(watermark, stopCh)
}

func tooManyRequests(req *http.Request, w http.ResponseWriter) {
// Return a 429 status indicating "Too Many Requests"
w.Header().Set("Retry-After", retryAfter)
http.Error(w, "Too many requests, please try again later.", http.StatusTooManyRequests)
}

0 comments on commit 2a4bf45

Please sign in to comment.