move tailscaled_health_messages to the health package

This commit is contained in:
Anton Tolchanov 2024-08-19 12:40:07 +01:00
parent 2b01273124
commit f12aff959a
2 changed files with 17 additions and 23 deletions

View File

@ -35,7 +35,6 @@
"tailscale.com/control/controlclient" "tailscale.com/control/controlclient"
"tailscale.com/drive/driveimpl" "tailscale.com/drive/driveimpl"
"tailscale.com/envknob" "tailscale.com/envknob"
"tailscale.com/health"
"tailscale.com/hostinfo" "tailscale.com/hostinfo"
"tailscale.com/ipn" "tailscale.com/ipn"
"tailscale.com/ipn/conffile" "tailscale.com/ipn/conffile"
@ -341,13 +340,6 @@ func run() (err error) {
sys := new(tsd.System) 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. // Parse config, if specified, to fail early if it's invalid.
var conf *conffile.Config var conf *conffile.Config
if args.confFile != "" { if args.confFile != "" {

View File

@ -8,6 +8,7 @@
import ( import (
"context" "context"
"errors" "errors"
"expvar"
"fmt" "fmt"
"maps" "maps"
"net/http" "net/http"
@ -898,18 +899,6 @@ func (t *Tracker) OverallError() error {
return t.multiErrLocked() 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 // Strings() returns a string array containing the Text of all Warnings
// currently known to the Tracker. These strings can be presented to the // currently known to the Tracker. These strings can be presented to the
// user, although ideally you would use the Code property on each Warning // 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() { 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 { for i := range t.MagicSockReceiveFuncs {
f := &t.MagicSockReceiveFuncs[i] f := &t.MagicSockReceiveFuncs[i]
f.name = (ReceiveFunc(i)).String() f.name = (ReceiveFunc(i)).String()
@ -1246,11 +1247,12 @@ func (t *Tracker) checkReceiveFuncsLocked() {
} }
} }
type MetricHealthMessageLabel struct { type metricHealthMessageLabel struct {
Severity string // TODO: break down by warnable.severity as well?
Type string
} }
var MetricHealthMessage = usermetric.NewMultiLabelMap[MetricHealthMessageLabel]( var metricHealthMessage = usermetric.NewMultiLabelMap[metricHealthMessageLabel](
"tailscaled_health_messages", "tailscaled_health_messages",
"gauge", "gauge",
"Number of health messages broken down by severity.", "Number of health messages broken down by severity.",