From 59e9b44f53788e20daf6c215f75625933985ef91 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Fri, 25 Jun 2021 10:10:26 -0400 Subject: [PATCH] wgengine/filter: add a debug flag for filter logs (#2241) This uses a debug envvar to optionally disable filter logging rate limits by setting the environment variable TS_DEBUG_FILTER_RATE_LIMIT_LOGS to "all", and if it matches, the code will effectively disable the limits on the log rate by setting the limit to 1 millisecond. This should make sure that all filter logs will be captured. Signed-off-by: Christine Dodrill --- wgengine/filter/filter.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/wgengine/filter/filter.go b/wgengine/filter/filter.go index 766d4c8a8..e502502c3 100644 --- a/wgengine/filter/filter.go +++ b/wgengine/filter/filter.go @@ -7,6 +7,7 @@ package filter import ( "fmt" + "os" "sync" "time" @@ -217,6 +218,19 @@ func maybeHexdump(flag RunFlags, b []byte) string { var acceptBucket = rate.NewLimiter(rate.Every(10*time.Second), 3) var dropBucket = rate.NewLimiter(rate.Every(5*time.Second), 10) +// NOTE(Xe): This func init is used to detect +// TS_DEBUG_FILTER_RATE_LIMIT_LOGS=all, and if it matches, to +// effectively disable the limits on the log rate by setting the limit +// to 1 millisecond. This should capture everything. +func init() { + if os.Getenv("TS_DEBUG_FILTER_RATE_LIMIT_LOGS") != "all" { + return + } + + acceptBucket = rate.NewLimiter(rate.Every(time.Millisecond), 10) + dropBucket = rate.NewLimiter(rate.Every(time.Millisecond), 10) +} + func (f *Filter) logRateLimit(runflags RunFlags, q *packet.Parsed, dir direction, r Response, why string) { if !f.loggingAllowed(q) { return