From b75c3eeaa8e7ffca0ba3f37099dff0f79bc0a9ba Mon Sep 17 00:00:00 2001 From: Raj Singh Date: Tue, 25 Nov 2025 17:30:44 -0600 Subject: [PATCH] ipn/ipnlocal, health: add home DERP region usermetric Fixes #18061 Signed-off-by: Raj Singh --- health/health.go | 10 ++++++++++ ipn/ipnlocal/local.go | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/health/health.go b/health/health.go index f0f6a6ffb..1c0e2fbba 100644 --- a/health/health.go +++ b/health/health.go @@ -761,6 +761,16 @@ func (t *Tracker) SetMagicSockDERPHome(region int, homeless bool) { t.selfCheckLocked() } +// DERPHomeRegion returns the current home DERP region ID, or 0 if unknown. +func (t *Tracker) DERPHomeRegion() int { + if t.nil() { + return 0 + } + t.mu.Lock() + defer t.mu.Unlock() + return t.derpHomeRegion +} + // NoteMapRequestHeard notes whenever we successfully sent a map request // to control for which we received a 200 response. func (t *Tracker) NoteMapRequestHeard(mr *tailcfg.MapRequest) { diff --git a/ipn/ipnlocal/local.go b/ipn/ipnlocal/local.go index 3e7054896..eb2f73f11 100644 --- a/ipn/ipnlocal/local.go +++ b/ipn/ipnlocal/local.go @@ -439,6 +439,8 @@ type metrics struct { // approvedRoutes is a metric that reports the number of network routes served by the local node and approved // by the control server. approvedRoutes *usermetric.Gauge + + homeDERP *usermetric.Gauge } // clientGen is a func that creates a control plane client. @@ -490,6 +492,8 @@ func NewLocalBackend(logf logger.Logf, logID logid.PublicID, sys *tsd.System, lo "tailscaled_advertised_routes", "Number of advertised network routes (e.g. by a subnet router)"), approvedRoutes: sys.UserMetricsRegistry().NewGauge( "tailscaled_approved_routes", "Number of approved network routes (e.g. by a subnet router)"), + homeDERP: sys.UserMetricsRegistry().NewGauge( + "tailscaled_home_derp_region_id", "DERP region ID of this node's home relay server"), } b := &LocalBackend{ @@ -6153,6 +6157,8 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) { } } + b.metrics.homeDERP.Set(float64(b.health.DERPHomeRegion())) + if buildfeatures.HasDrive && nm != nil { if f, ok := hookSetNetMapLockedDrive.GetOk(); ok { f(b, nm)