Implement rate limiting on log messages

Addresses issue #317, where logs can get spammed with the same message
nonstop. Created a rate limiting closure on logging functions, which
limits the number of messages being logged per second based on format
string.

Signed-off-by: Wendi Yu <wendi.yu@yahoo.ca>
This commit is contained in:
Wendi Yu
2020-05-06 17:27:32 -06:00
parent e3559d1c45
commit ca6675386b
5 changed files with 94 additions and 4 deletions

View File

@@ -21,6 +21,7 @@ import (
"tailscale.com/ipn/ipnserver"
"tailscale.com/logpolicy"
"tailscale.com/paths"
"tailscale.com/types/logger"
"tailscale.com/wgengine"
"tailscale.com/wgengine/magicsock"
)
@@ -50,7 +51,8 @@ func main() {
statepath := getopt.StringLong("state", 0, paths.DefaultTailscaledStateFile(), "Path of state file")
socketpath := getopt.StringLong("socket", 's', paths.DefaultTailscaledSocket(), "Path of the service unix socket")
logf := wgengine.RusagePrefixLog(log.Printf)
rlPrint := logger.RateLimitedFn(log.Printf, 1, 1)
logf := wgengine.RusagePrefixLog(rlPrint)
err := fixconsole.FixConsoleIfNeeded()
if err != nil {