From 8487fd2ec26fae437392c4c6aa74047f6d9c5040 Mon Sep 17 00:00:00 2001 From: Andrew Dunham Date: Tue, 25 Jun 2024 22:28:37 -0400 Subject: [PATCH] wgengine/magicsock: add more DERP home clientmetrics Updates tailscale/corp#18095 Signed-off-by: Andrew Dunham Change-Id: I423adca2de0730092394bb5fd5796cd35557d352 --- wgengine/magicsock/derp.go | 3 +++ wgengine/magicsock/magicsock.go | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/wgengine/magicsock/derp.go b/wgengine/magicsock/derp.go index 1ef63112b..c1486bc80 100644 --- a/wgengine/magicsock/derp.go +++ b/wgengine/magicsock/derp.go @@ -135,6 +135,7 @@ func (c *Conn) pickDERPFallback() int { return pickDERPFallbackForTests() } + metricDERPHomeFallback.Add(1) return ids[rands.IntN(uint64(uintptr(unsafe.Pointer(c))), len(ids))] } @@ -173,6 +174,7 @@ func (c *Conn) maybeSetNearestDERP(report *netcheck.Report) (preferredDERP int) myDerp := c.myDerp c.mu.Unlock() if myDerp != 0 { + metricDERPHomeNoChangeNoControl.Add(1) return myDerp } @@ -948,6 +950,7 @@ func (c *Conn) cleanStaleDerp() { } if ad.lastWrite.Before(tooOld) { c.closeDerpLocked(i, "idle") + metricDERPStaleCleaned.Add(1) dirty = true } else { someNonHomeOpen = true diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index 87f6ca164..080b38b19 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -3028,6 +3028,17 @@ type discoInfo struct { // changed from non-zero to a different non-zero. metricDERPHomeChange = clientmetric.NewCounter("derp_home_change") + // metricDERPHomeNoChangeNoControl is how many times our DERP home + // region did not change because we didn't have an active connection to + // the control server. + metricDERPHomeNoChangeNoControl = clientmetric.NewCounter("derp_home_no_change_no_control") + + // metricDERPHomeFallback is how many times we picked a DERP fallback. + metricDERPHomeFallback = clientmetric.NewCounter("derp_home_fallback") + + // metricDERPStaleCleaned is how many times we closed a stale DERP connection. + metricDERPStaleCleaned = clientmetric.NewCounter("derp_stale_cleaned") + // Disco packets received bpf read path //lint:ignore U1000 used on Linux only metricRecvDiscoPacketIPv4 = clientmetric.NewCounter("magicsock_disco_recv_bpf_ipv4")