mirror of
https://github.com/tailscale/tailscale.git
synced 2025-12-08 22:12:21 +00:00
log rate limiting: reformat limiter messages, and use nonempty burst size.
- Reformat the warning about a message being rate limited to print the format string, rather than the formatted message. This helps give a clue what "type" of message is being limited. - Change the rate limit warning to be [RATE LIMITED] in all caps. This uses less space on each line, plus is more noticeable. - In tailscaled, change the frequency to be less often (once every 5 seconds per format string) but to allow bursts of up to 5 messages. This greatly reduces the number of messages that are rate limited during startup, but allows us to tighten the limit even further during normal runtime. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
This commit is contained in:
@@ -85,7 +85,10 @@ func RateLimitedFn(logf Logf, f time.Duration, burst int, maxCache int) Logf {
|
||||
if ok {
|
||||
msgCache.MoveToFront(rl.ele)
|
||||
} else {
|
||||
rl = &limitData{lim: rate.NewLimiter(r, burst), ele: msgCache.PushFront(format)}
|
||||
rl = &limitData{
|
||||
lim: rate.NewLimiter(r, burst),
|
||||
ele: msgCache.PushFront(format),
|
||||
}
|
||||
msgLim[format] = rl
|
||||
if msgCache.Len() > maxCache {
|
||||
delete(msgLim, msgCache.Back().Value.(string))
|
||||
@@ -108,8 +111,8 @@ func RateLimitedFn(logf Logf, f time.Duration, burst int, maxCache int) Logf {
|
||||
case allow:
|
||||
logf(format, args...)
|
||||
case warn:
|
||||
logf("Repeated messages were suppressed by rate limiting. Original message: %s",
|
||||
fmt.Sprintf(format, args...))
|
||||
// For the warning, log the specific format string
|
||||
logf("[RATE LIMITED] %s", format)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user