health: show DisplayMessage actions in 'tailscale status'

Updates tailscale/corp#27759

Signed-off-by: James Sanderson <jsanderson@tailscale.com>
This commit is contained in:
James Sanderson 2025-06-04 12:10:15 +01:00 committed by James 'zofrex' Sanderson
parent 5fde183754
commit 13ee285675
2 changed files with 35 additions and 11 deletions

View File

@ -1054,13 +1054,18 @@ func (t *Tracker) stringsLocked() []string {
warnLen := len(result)
for _, c := range t.controlMessages {
var msg string
if c.Title != "" && c.Text != "" {
result = append(result, c.Title+": "+c.Text)
msg = c.Title + ": " + c.Text
} else if c.Title != "" {
result = append(result, c.Title)
msg = c.Title + "."
} else if c.Text != "" {
result = append(result, c.Text)
msg = c.Text
}
if c.PrimaryAction != nil {
msg = msg + " " + c.PrimaryAction.Label + ": " + c.PrimaryAction.URL
}
result = append(result, msg)
}
sort.Strings(result[warnLen:])

View File

@ -467,15 +467,24 @@ func TestControlHealth(t *testing.T) {
baseWarns := ht.CurrentState().Warnings
baseStrs := ht.Strings()
ht.SetControlHealth(map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage{
msgs := map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage{
"control-health-test": {
Title: "Control health message",
Text: "Extra help",
Text: "Extra help.",
},
"control-health-title": {
Title: "Control health title only",
},
})
"control-health-with-action": {
Title: "Control health message",
Text: "Extra help.",
PrimaryAction: &tailcfg.DisplayMessageAction{
URL: "http://www.example.com",
Label: "Learn more",
},
},
}
ht.SetControlHealth(msgs)
t.Run("Warnings", func(t *testing.T) {
wantWarns := map[WarnableCode]UnhealthyState{
@ -483,13 +492,23 @@ func TestControlHealth(t *testing.T) {
WarnableCode: "control-health-test",
Severity: SeverityMedium,
Title: "Control health message",
Text: "Extra help",
Text: "Extra help.",
},
"control-health-title": {
WarnableCode: "control-health-title",
Severity: SeverityMedium,
Title: "Control health title only",
},
"control-health-with-action": {
WarnableCode: "control-health-with-action",
Severity: SeverityMedium,
Title: "Control health message",
Text: "Extra help.",
PrimaryAction: &UnhealthyStateAction{
URL: "http://www.example.com",
Label: "Learn more",
},
},
}
state := ht.CurrentState()
gotWarns := maps.Clone(state.Warnings)
@ -505,8 +524,9 @@ func TestControlHealth(t *testing.T) {
t.Run("Strings()", func(t *testing.T) {
wantStrs := []string{
"Control health message: Extra help",
"Control health title only",
"Control health message: Extra help.",
"Control health message: Extra help. Learn more: http://www.example.com",
"Control health title only.",
}
var gotStrs []string
for _, s := range ht.Strings() {
@ -527,8 +547,7 @@ func TestControlHealth(t *testing.T) {
Type: MetricLabelWarning,
}).String()
want := strconv.Itoa(
2 + // from SetControlHealth
len(baseStrs),
len(msgs) + len(baseStrs),
)
if got != want {
t.Errorf("metricsHealthMessage.Get(warning) = %q, want %q", got, want)