Refactor client-go/util/flowcontrol/throttle.go RateLimiter

- Introduce PassiveRateLimiter which implements all methods of previous RateLimiter except Accept() and Wait()
- Change RateLimiter interface to extend PassiveRateLimiter by additionally implementing Accept() and Wait()
- Make client-go/tools/record use PassiveRateLimiter

Refactor EventSourceObjectSpamFilter, EventAggregator, EventCorrelator

- EventSourceObjectSpamFilter, EventAggregator, EventCorrelator use clock.PassiveClock now.
	- This won't be a breaking change because even if a clock.Clock is passed, it still implements the clock.PassiveClock interface.
- Extend clock.PassiveClock through Clock.
- Replace pacakge local implementation of realClock with clock.RealClock
- In flowcontrol/throttle.go split tokenBucketRateLimiters to use Clock and clock.PassiveClock.
- Migrate client-go/tools/record tests from using IntervalClock to using SimpleIntervalClock (honest implementation of clock.PassiveClock)

Signed-off-by: Madhav Jivrajani <madhav.jiv@gmail.com>

Kubernetes-commit: ac5c55f0bd853fcf883d9b8e1f5ef728a2fb5309
This commit is contained in:
Madhav Jivrajani
2021-08-25 21:56:26 +05:30
committed by Kubernetes Publisher
parent 191e5dc23b
commit b9fa896d5d
6 changed files with 89 additions and 51 deletions

View File

@@ -190,6 +190,10 @@ func (fc *fakeClock) Sleep(d time.Duration) {
fc.now = fc.now.Add(d)
}
func (fc *fakeClock) Since(ts time.Time) time.Duration {
return time.Since(ts)
}
func TestRatePrecisionBug(t *testing.T) {
// golang.org/x/time/rate used to have bugs around precision and this
// proves that they don't recur (at least in the form we know about). This