control/controlclient: add metric for health messages

Updates tailscale/corp#22075

Signed-off-by: Kristoffer Dalby <kristoffer@tailscale.com>
This commit is contained in:
Kristoffer Dalby 2024-08-01 15:34:14 +02:00
parent 1952888785
commit 3db0af4e61
No known key found for this signature in database

View File

@ -7,6 +7,7 @@
"cmp"
"context"
"encoding/json"
"expvar"
"fmt"
"maps"
"net"
@ -22,6 +23,7 @@
xmaps "golang.org/x/exp/maps"
"tailscale.com/control/controlknobs"
"tailscale.com/envknob"
"tailscale.com/metrics"
"tailscale.com/tailcfg"
"tailscale.com/tstime"
"tailscale.com/types/key"
@ -344,6 +346,9 @@ 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
@ -353,6 +358,16 @@ func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) {
}
}
type healthMessageLabel struct {
Severity string
}
var metricHealthMessages = metrics.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")