This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add helper func to create a ratelimiter with different timings
This is the same approach as in https://github.com/kubernetes/client-go/blob/fb61a7c88cb9f599363919a34b7c54a605455ffc/util/workqueue/default_rate_limiters.go#L39 however it should react slower.
- Loading branch information
Mario Manno
committed
Dec 9, 2020
1 parent
ede27c7
commit f00172b
Showing
3 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package ratelimiter | ||
|
||
import ( | ||
"time" | ||
|
||
"golang.org/x/time/rate" | ||
|
||
"k8s.io/client-go/util/workqueue" | ||
) | ||
|
||
const ( | ||
baseDelay = 5 * time.Second | ||
maxDelay = 1000 * time.Second | ||
freq = 10 | ||
burst = 100 | ||
) | ||
|
||
// New is a no-arg constructor for a slow rate limiter for a workqueue. It has | ||
// both overall and per-item rate limiting. The overall is a token bucket and the per-item is exponential | ||
func New() workqueue.RateLimiter { | ||
return Custom(baseDelay, maxDelay, freq, burst) | ||
} | ||
|
||
// Custom allows to specify all args. | ||
func Custom( | ||
baseDelay time.Duration, | ||
maxDelay time.Duration, | ||
freq int, | ||
burst int, | ||
) workqueue.RateLimiter { | ||
return workqueue.NewMaxOfRateLimiter( | ||
workqueue.NewItemExponentialFailureRateLimiter(baseDelay, maxDelay), | ||
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(freq), burst)}, | ||
) | ||
} |