mirror of
https://github.com/k3s-io/kubernetes.git
synced 2026-02-22 07:03:28 +00:00
Fix rudimentaryErrorBackoff to only be created once
This commit is contained in:
@@ -149,15 +149,10 @@ func logPanic(ctx context.Context, r interface{}) {
|
||||
// should be packaged up into a testable and reusable object.
|
||||
var ErrorHandlers = []ErrorHandler{
|
||||
logError,
|
||||
func(_ context.Context, _ error, _ string, _ ...interface{}) {
|
||||
(&rudimentaryErrorBackoff{
|
||||
lastErrorTime: time.Now(),
|
||||
// 1ms was the number folks were able to stomach as a global rate limit.
|
||||
// If you need to log errors more than 1000 times a second you
|
||||
// should probably consider fixing your code instead. :)
|
||||
minPeriod: time.Millisecond,
|
||||
}).OnError()
|
||||
},
|
||||
// 1ms was the number folks were able to stomach as a global rate limit.
|
||||
// If you need to log errors more than 1000 times a second, you
|
||||
// should probably consider fixing your code instead. :)
|
||||
backoffError(1 * time.Millisecond),
|
||||
}
|
||||
|
||||
type ErrorHandler func(ctx context.Context, err error, msg string, keysAndValues ...interface{})
|
||||
@@ -226,6 +221,18 @@ func logError(ctx context.Context, err error, msg string, keysAndValues ...inter
|
||||
logger.Error(err, msg, keysAndValues...) //nolint:logcheck // logcheck complains about unknown key/value pairs.
|
||||
}
|
||||
|
||||
// backoffError blocks if it is called more often than the minPeriod.
|
||||
func backoffError(minPeriod time.Duration) ErrorHandler {
|
||||
r := &rudimentaryErrorBackoff{
|
||||
lastErrorTime: time.Now(),
|
||||
minPeriod: minPeriod,
|
||||
}
|
||||
|
||||
return func(ctx context.Context, err error, msg string, keysAndValues ...interface{}) {
|
||||
r.OnError()
|
||||
}
|
||||
}
|
||||
|
||||
type rudimentaryErrorBackoff struct {
|
||||
minPeriod time.Duration // immutable
|
||||
// TODO(lavalamp): use the clock for testability. Need to move that
|
||||
|
||||
Reference in New Issue
Block a user