From c0cdca6d0668ac22911c9db12b0524d5efd50a4e Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 1 Mar 2021 22:09:43 -0800 Subject: [PATCH] cmd/tailscaled, logtail: share link monitor from wgengine to logtail Part of overall effort to clean up, unify, use link monitoring more, and make Tailscale quieter when all networks are down. This is especially bad on macOS where we can get killed for not being polite it seems. (But we should be polite in any case) Signed-off-by: Brad Fitzpatrick --- cmd/tailscaled/tailscaled.go | 10 +++++++++- logtail/logtail.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index d96bff392..f4a5f9b06 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -36,6 +36,7 @@ import ( "tailscale.com/version" "tailscale.com/wgengine" "tailscale.com/wgengine/magicsock" + "tailscale.com/wgengine/monitor" "tailscale.com/wgengine/netstack" "tailscale.com/wgengine/router" "tailscale.com/wgengine/tstun" @@ -195,6 +196,12 @@ func run() error { go runDebugServer(debugMux, args.debug) } + linkMon, err := monitor.New(logf) + if err != nil { + log.Fatalf("creating link monitor: %v", err) + } + pol.Logtail.SetLinkMonitor(linkMon) + var socksListener net.Listener if args.socksAddr != "" { var err error @@ -205,7 +212,8 @@ func run() error { } conf := wgengine.Config{ - ListenPort: args.port, + ListenPort: args.port, + LinkMonitor: linkMon, } if args.tunname == "userspace-networking" { conf.TUN = tstun.NewFakeTUN() diff --git a/logtail/logtail.go b/logtail/logtail.go index bad60d011..e0e9f93be 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -19,6 +19,7 @@ import ( "tailscale.com/logtail/backoff" tslogger "tailscale.com/types/logger" + "tailscale.com/wgengine/monitor" ) // DefaultHost is the default host name to upload logs to when @@ -106,6 +107,7 @@ type Logger struct { url string lowMem bool skipClientTime bool + linkMonitor *monitor.Mon buffer Buffer sent chan struct{} // signal to speed up drain drainLogs <-chan struct{} // if non-nil, external signal to attempt a drain @@ -128,6 +130,14 @@ func (l *Logger) SetVerbosityLevel(level int) { l.stderrLevel = level } +// SetLinkMonitor sets the optional the link monitor. +// +// It should not be changed concurrently with log writes and should +// only be set once. +func (l *Logger) SetLinkMonitor(lm *monitor.Mon) { + l.linkMonitor = lm +} + // Shutdown gracefully shuts down the logger while completing any // remaining uploads. //