diff --git a/health/health.go b/health/health.go index 6dbbf782c..058870438 100644 --- a/health/health.go +++ b/health/health.go @@ -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:]) diff --git a/health/health_test.go b/health/health_test.go index f609cfb16..aa519e92c 100644 --- a/health/health_test.go +++ b/health/health_test.go @@ -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)