mirror of
https://github.com/tailscale/tailscale.git
synced 2025-07-29 23:33:45 +00:00
health: show DisplayMessage actions in 'tailscale status'
Updates tailscale/corp#27759 Signed-off-by: James Sanderson <jsanderson@tailscale.com>
This commit is contained in:
parent
5fde183754
commit
13ee285675
@ -1054,13 +1054,18 @@ func (t *Tracker) stringsLocked() []string {
|
|||||||
|
|
||||||
warnLen := len(result)
|
warnLen := len(result)
|
||||||
for _, c := range t.controlMessages {
|
for _, c := range t.controlMessages {
|
||||||
|
var msg string
|
||||||
if c.Title != "" && c.Text != "" {
|
if c.Title != "" && c.Text != "" {
|
||||||
result = append(result, c.Title+": "+c.Text)
|
msg = c.Title + ": " + c.Text
|
||||||
} else if c.Title != "" {
|
} else if c.Title != "" {
|
||||||
result = append(result, c.Title)
|
msg = c.Title + "."
|
||||||
} else if c.Text != "" {
|
} 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:])
|
sort.Strings(result[warnLen:])
|
||||||
|
|
||||||
|
@ -467,15 +467,24 @@ func TestControlHealth(t *testing.T) {
|
|||||||
baseWarns := ht.CurrentState().Warnings
|
baseWarns := ht.CurrentState().Warnings
|
||||||
baseStrs := ht.Strings()
|
baseStrs := ht.Strings()
|
||||||
|
|
||||||
ht.SetControlHealth(map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage{
|
msgs := map[tailcfg.DisplayMessageID]tailcfg.DisplayMessage{
|
||||||
"control-health-test": {
|
"control-health-test": {
|
||||||
Title: "Control health message",
|
Title: "Control health message",
|
||||||
Text: "Extra help",
|
Text: "Extra help.",
|
||||||
},
|
},
|
||||||
"control-health-title": {
|
"control-health-title": {
|
||||||
Title: "Control health title only",
|
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) {
|
t.Run("Warnings", func(t *testing.T) {
|
||||||
wantWarns := map[WarnableCode]UnhealthyState{
|
wantWarns := map[WarnableCode]UnhealthyState{
|
||||||
@ -483,13 +492,23 @@ func TestControlHealth(t *testing.T) {
|
|||||||
WarnableCode: "control-health-test",
|
WarnableCode: "control-health-test",
|
||||||
Severity: SeverityMedium,
|
Severity: SeverityMedium,
|
||||||
Title: "Control health message",
|
Title: "Control health message",
|
||||||
Text: "Extra help",
|
Text: "Extra help.",
|
||||||
},
|
},
|
||||||
"control-health-title": {
|
"control-health-title": {
|
||||||
WarnableCode: "control-health-title",
|
WarnableCode: "control-health-title",
|
||||||
Severity: SeverityMedium,
|
Severity: SeverityMedium,
|
||||||
Title: "Control health title only",
|
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()
|
state := ht.CurrentState()
|
||||||
gotWarns := maps.Clone(state.Warnings)
|
gotWarns := maps.Clone(state.Warnings)
|
||||||
@ -505,8 +524,9 @@ func TestControlHealth(t *testing.T) {
|
|||||||
|
|
||||||
t.Run("Strings()", func(t *testing.T) {
|
t.Run("Strings()", func(t *testing.T) {
|
||||||
wantStrs := []string{
|
wantStrs := []string{
|
||||||
"Control health message: Extra help",
|
"Control health message: Extra help.",
|
||||||
"Control health title only",
|
"Control health message: Extra help. Learn more: http://www.example.com",
|
||||||
|
"Control health title only.",
|
||||||
}
|
}
|
||||||
var gotStrs []string
|
var gotStrs []string
|
||||||
for _, s := range ht.Strings() {
|
for _, s := range ht.Strings() {
|
||||||
@ -527,8 +547,7 @@ func TestControlHealth(t *testing.T) {
|
|||||||
Type: MetricLabelWarning,
|
Type: MetricLabelWarning,
|
||||||
}).String()
|
}).String()
|
||||||
want := strconv.Itoa(
|
want := strconv.Itoa(
|
||||||
2 + // from SetControlHealth
|
len(msgs) + len(baseStrs),
|
||||||
len(baseStrs),
|
|
||||||
)
|
)
|
||||||
if got != want {
|
if got != want {
|
||||||
t.Errorf("metricsHealthMessage.Get(warning) = %q, want %q", got, want)
|
t.Errorf("metricsHealthMessage.Get(warning) = %q, want %q", got, want)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user