From dd6b96ba6867205f1f5ad489d323a0309261a2ad Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Fri, 29 May 2020 12:30:43 -0700 Subject: [PATCH] types/logger: add TS_DEBUG_LOG_RATE knob to easily turn off rate limiting --- types/logger/logger.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/types/logger/logger.go b/types/logger/logger.go index d73c4e264..de7d124b1 100644 --- a/types/logger/logger.go +++ b/types/logger/logger.go @@ -14,6 +14,7 @@ "io" "io/ioutil" "log" + "os" "sync" "time" @@ -60,10 +61,15 @@ type limitData struct { ele *list.Element // list element used to access this string in the cache } +var disableRateLimit = os.Getenv("TS_DEBUG_LOG_RATE") == "all" + // RateLimitedFn returns a rate-limiting Logf wrapping the given logf. // Messages are allowed through at a maximum of one message every f (where f is a time.Duration), in // bursts of up to burst messages at a time. Up to maxCache strings will be held at a time. func RateLimitedFn(logf Logf, f time.Duration, burst int, maxCache int) Logf { + if disableRateLimit { + return logf + } r := rate.Every(f) var ( mu sync.Mutex