Merge pull request 'Say an unhealthy resource's restart count as what it counts (issue 458)' (#84) from fix/458-restarts-say-what-they-count into main

This commit was merged in pull request #84.
This commit is contained in:
2026-10-12 09:03:47 +00:00
2 changed files with 29 additions and 2 deletions
+9 -2
View File
@@ -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)
}
+20
View File
@@ -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)
}
}