From e3cb8cc88dfb27ec44dced6e03f682483c840ddb Mon Sep 17 00:00:00 2001 From: Mihai Parparita Date: Mon, 3 Apr 2023 14:16:53 -0700 Subject: [PATCH] ipn/ipnlocal: automatically upload sockstats logs when the period ends Avoids needing a separate c2n call to get the logs uploaded. Updates tailscale/corp#9230 Signed-off-by: Mihai Parparita --- ipn/ipnlocal/local.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index d5a105485..902a15458 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -400,7 +400,14 @@ func (b *LocalBackend) SetComponentDebugLogging(component string, until time.Tim setEnabled = mc.SetDebugLoggingEnabled case "sockstats": if b.sockstatLogger != nil { - setEnabled = b.sockstatLogger.SetLoggingEnabled + setEnabled = func(v bool) { + b.sockstatLogger.SetLoggingEnabled(v) + // Flush (and thus upload) logs when the enabled period ends, + // so that the logs are available for debugging. + if !v { + b.sockstatLogger.Flush() + } + } } } if setEnabled == nil || !slices.Contains(debuggableComponents, component) {