cmd/tailscaled: count all health messages

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2024-08-14 16:45:40 +02:00
parent 0f0d54b5cc
commit 3e9eaa293a
No known key found for this signature in database
3 changed files with 30 additions and 15 deletions

View File

@ -63,6 +63,7 @@
"tailscale.com/util/clientmetric"
"tailscale.com/util/multierr"
"tailscale.com/util/osshare"
"tailscale.com/util/usermetric"
"tailscale.com/version"
"tailscale.com/version/distro"
"tailscale.com/wgengine"
@ -340,6 +341,13 @@ func run() (err error) {
sys := new(tsd.System)
health := sys.HealthTracker()
metricHealthMessages.Set(healthMessageLabel{
Severity: "warning",
}, expvar.Func(func() any {
return health.OverallErrorCount()
}))
// Parse config, if specified, to fail early if it's invalid.
var conf *conffile.Config
if args.confFile != "" {
@ -919,3 +927,13 @@ func applyIntegrationTestEnvKnob() {
}
}
}
type healthMessageLabel struct {
Severity string
}
var metricHealthMessages = usermetric.NewMultiLabelMap[healthMessageLabel](
"tailscaled_health_messages",
"gauge",
"A gauge of health messages from control, by severity",
)

View File

@ -7,7 +7,6 @@
"cmp"
"context"
"encoding/json"
"expvar"
"fmt"
"maps"
"net"
@ -33,7 +32,6 @@
"tailscale.com/util/clientmetric"
"tailscale.com/util/mak"
"tailscale.com/util/set"
"tailscale.com/util/usermetric"
"tailscale.com/wgengine/filter"
)
@ -346,9 +344,6 @@ func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) {
}
if resp.Health != nil {
ms.lastHealth = resp.Health
warnings := expvar.Int{}
warnings.Set(int64(len(resp.Health)))
metricHealthMessages.Set(healthMessageLabel{Severity: "warning"}, &warnings)
}
if resp.TKAInfo != nil {
ms.lastTKAInfo = resp.TKAInfo
@ -358,16 +353,6 @@ func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) {
}
}
type healthMessageLabel struct {
Severity string
}
var metricHealthMessages = usermetric.NewMultiLabelMap[healthMessageLabel](
"tailscaled_health_messages",
"gauge",
"A gauge of health messages from control, by severity",
)
var (
patchDERPRegion = clientmetric.NewCounter("controlclient_patch_derp")
patchEndpoints = clientmetric.NewCounter("controlclient_patch_endpoints")

View File

@ -897,6 +897,18 @@ 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