From f12aff959aa40b1085dee5def507273538230d65 Mon Sep 17 00:00:00 2001 From: Anton Tolchanov Date: Mon, 19 Aug 2024 12:40:07 +0100 Subject: [PATCH] move tailscaled_health_messages to the health package --- cmd/tailscaled/tailscaled.go | 8 -------- health/health.go | 32 +++++++++++++++++--------------- 2 files changed, 17 insertions(+), 23 deletions(-) diff --git a/cmd/tailscaled/tailscaled.go b/cmd/tailscaled/tailscaled.go index 83633dfaf..6dbf6c982 100644 --- a/cmd/tailscaled/tailscaled.go +++ b/cmd/tailscaled/tailscaled.go @@ -35,7 +35,6 @@ "tailscale.com/control/controlclient" "tailscale.com/drive/driveimpl" "tailscale.com/envknob" - "tailscale.com/health" "tailscale.com/hostinfo" "tailscale.com/ipn" "tailscale.com/ipn/conffile" @@ -341,13 +340,6 @@ func run() (err error) { sys := new(tsd.System) - healthTracker := sys.HealthTracker() - health.MetricHealthMessage.Set(health.MetricHealthMessageLabel{ - Severity: "warning", - }, expvar.Func(func() any { - return healthTracker.OverallErrorCount() - })) - // Parse config, if specified, to fail early if it's invalid. var conf *conffile.Config if args.confFile != "" { diff --git a/health/health.go b/health/health.go index 80d8b6fa0..e8d6702ea 100644 --- a/health/health.go +++ b/health/health.go @@ -8,6 +8,7 @@ import ( "context" "errors" + "expvar" "fmt" "maps" "net/http" @@ -898,18 +899,6 @@ func (t *Tracker) OverallError() error { return t.multiErrLocked() } -// OverallErrorCount returns the number of errors currently known to the -// Tracker. -func (t *Tracker) OverallErrorCount() int64 { - if t.nil() { - return 0 - } - t.mu.Lock() - defer t.mu.Unlock() - t.updateBuiltinWarnablesLocked() - return int64(len(t.stringsLocked())) -} - // Strings() returns a string array containing the Text of all Warnings // currently known to the Tracker. These strings can be presented to the // user, although ideally you would use the Code property on each Warning @@ -1215,6 +1204,18 @@ func (t *Tracker) ReceiveFuncStats(which ReceiveFunc) *ReceiveFuncStats { } func (t *Tracker) doOnceInit() { + metricHealthMessage.Set(metricHealthMessageLabel{ + Type: "warning", + }, expvar.Func(func() any { + if t.nil() { + return 0 + } + t.mu.Lock() + defer t.mu.Unlock() + t.updateBuiltinWarnablesLocked() + return int64(len(t.stringsLocked())) + })) + for i := range t.MagicSockReceiveFuncs { f := &t.MagicSockReceiveFuncs[i] f.name = (ReceiveFunc(i)).String() @@ -1246,11 +1247,12 @@ func (t *Tracker) checkReceiveFuncsLocked() { } } -type MetricHealthMessageLabel struct { - Severity string +type metricHealthMessageLabel struct { + // TODO: break down by warnable.severity as well? + Type string } -var MetricHealthMessage = usermetric.NewMultiLabelMap[MetricHealthMessageLabel]( +var metricHealthMessage = usermetric.NewMultiLabelMap[metricHealthMessageLabel]( "tailscaled_health_messages", "gauge", "Number of health messages broken down by severity.",