diff --git a/cmd/mesh-host/main.go b/cmd/mesh-host/main.go index a3d69a0..86be16a 100644 --- a/cmd/mesh-host/main.go +++ b/cmd/mesh-host/main.go @@ -1604,8 +1604,7 @@ func judgeWhatRuns(ctx context.Context, j *liveness.Judge, queue *link.Queue, sa if changed { for _, r := range st.Resources { if r.State == liveness.Unhealthy { - say(fmt.Sprintf("%s (%s %s) is unhealthy: %s, %d restart(s) counted", r.ID, r.Kind, r.Target, - r.Reason, r.Restarts)) + say(unhealthyWords(r)) } } } @@ -2338,3 +2337,11 @@ func factsAsReported(f *store.Facts) map[string]any { } return out } + +// unhealthyWords is what the engine says of an unhealthy resource. Its restart count is the judge's own +// (kept.Counted): automatic restarts since it began watching the resource, kept across recreates and starts +// by hand, so it is said as that and never read as since the state began (novox/hq issue 458). +func unhealthyWords(r liveness.State) string { + return fmt.Sprintf("%s (%s %s) is unhealthy: %s, %d automatic restart(s) since this engine began watching it", + r.ID, r.Kind, r.Target, r.Reason, r.Restarts) +} diff --git a/cmd/mesh-host/restarts_words_test.go b/cmd/mesh-host/restarts_words_test.go new file mode 100644 index 0000000..cfa581e --- /dev/null +++ b/cmd/mesh-host/restarts_words_test.go @@ -0,0 +1,20 @@ +package main + +import ( + "strings" + "testing" + + "github.com/novox/mesh-host/internal/liveness" +) + +// The restart count the engine says is its own since it began watching the resource, never since the state +// began (novox/hq issue 458). +func TestAnUnhealthyResourceSaysWhatItsRestartCountCounts(t *testing.T) { + r := liveness.State{Resource: liveness.Resource{ID: "messenger.own-runtime", Kind: "process", + Target: "messenger-runtime.service"}, State: liveness.Unhealthy, Reason: liveness.ReasonRestarting, Restarts: 3890} + said := unhealthyWords(r) + if !strings.Contains(said, "3890 automatic restart(s) since this engine began watching it") || + strings.Contains(said, "counted") { + t.Fatalf("the restart count is not said as what it counts: %s", said) + } +}