From f2e2ffa423cd4373a3103b84ec8ea313454e1a45 Mon Sep 17 00:00:00 2001 From: Avery Pennarun Date: Thu, 12 Mar 2020 22:28:11 -0400 Subject: [PATCH] controlclient: log the entire netmap up to every 5 minutes. We log it once upon receiving the first copy of the map, then subsequently when a new one appears, but only if we haven't logged one less than 5 minutes ago. This avoids overly cluttering the log (as we did before, logging the netmap every time one appeared, which could be hundreds of lines every few seconds), but still gives the log enough context to help in diagnosing problems retroactively. --- control/controlclient/direct.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/control/controlclient/direct.go b/control/controlclient/direct.go index 7af66a64b..9e05719ca 100644 --- a/control/controlclient/direct.go +++ b/control/controlclient/direct.go @@ -76,6 +76,7 @@ type Direct struct { httpc *http.Client // HTTP client used to talk to tailcontrol serverURL string // URL of the tailcontrol server timeNow func() time.Time + lastPrintMap time.Time newDecompressor func() (Decompressor, error) keepAlive bool logf logger.Logf @@ -579,7 +580,17 @@ func (c *Direct) PollNetMap(ctx context.Context, maxPolls int, cb func(*NetworkM } else { nm.MachineStatus = tailcfg.MachineUnauthorized } - //c.logf("new network map[%d]:\n%s", i, nm.Concise()) + + // Printing the netmap can be extremely verbose, but is very + // handy for debugging. Let's limit how often we do it. + // Code elsewhere prints netmap diffs every time, so this + // occasional full dump, plus incremental diffs, should do + // the job. + now := c.timeNow() + if now.Sub(c.lastPrintMap) >= 5*time.Minute { + c.lastPrintMap = now + c.logf("new network map[%d]:\n%s", i, nm.Concise()) + } c.mu.Lock() c.expiry = &nm.Expiry