control/controlknobs,feature/*,ipn/ipnlocal,tailcfg: add runtimemetrics

Emit runtime metrics as clientmetrics when the
NodeAttrEmitRuntimeMetrics NodeCapability is present.

We start small with just 2 metrics: heap bytes and total process memory.

Updates tailscale/corp#39434

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited
2026-05-26 16:02:01 -07:00
committed by Jordan Whited
parent 2eb45c2457
commit e5a8cf3b18
10 changed files with 317 additions and 1 deletions
+16
View File
@@ -1286,6 +1286,14 @@ func (b *LocalBackend) Shutdown() {
if cc != nil {
cc.Shutdown()
}
if buildfeatures.HasRuntimeMetrics {
// We disable runtime metrics _after_ the control client is shutdown to
// ensure we don't leak the metrics polling goroutine in the case where
// netmap handling races [LocalBackend] shutdown.
if f, ok := HookSetRuntimeMetricsEnabled.GetOk(); ok {
f(false)
}
}
b.ctxCancel(errShutdown)
b.currentNode().shutdown(errShutdown)
b.extHost.Shutdown()
@@ -6892,6 +6900,11 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
b.MagicConn().SetSilentDisco(b.ControlKnobs().SilentDisco.Load())
b.MagicConn().SetProbeUDPLifetime(b.ControlKnobs().ProbeUDPLifetime.Load())
if buildfeatures.HasRuntimeMetrics {
if f, ok := HookSetRuntimeMetricsEnabled.GetOk(); ok {
f(b.ControlKnobs().EmitRuntimeMetrics.Load())
}
}
if buildfeatures.HasDebug {
b.setDebugLogsByCapabilityLocked(nm)
@@ -6970,6 +6983,9 @@ func (b *LocalBackend) setNetMapLocked(nm *netmap.NetworkMap) {
}
}
// HookSetRuntimeMetricsEnabled is an optional hook for the "runtimemetrics" feature.
var HookSetRuntimeMetricsEnabled feature.Hook[func(enabled bool)]
var hookSetNetMapLockedDrive feature.Hook[func(*LocalBackend, *netmap.NetworkMap)]
// roundTraffic rounds bytes. This is used to preserve user privacy within logs.