Artifact 76989d922d5b6f63563551f803d0a0048f30946290bf8706d6a7382ab9efcf23:
- File
internal/obs/health_test.go
— part of check-in
[e2b74749b4]
at
2026-08-25 22:19:15
on branch fleet-census
— Analytics: say whether history is being kept, and stop keeping it for ever
The live panels read in-memory rings, so a forge whose store failed to open looked exactly like a healthy one. Sink.Err() existed and nothing asked it. The page now distinguishes three states: off, broken, and recording to a named path.
Retention was 'append for ever', which is a default nobody was asked about. --analytics-keep sets the window, 14d by default, 0 keeps everything. Pruned at startup and daily. (user: dmestas, size: 2013) [annotate] [blame] [check-ins using] [more...]
package obs import ( "errors" "testing" ) type failingSink struct{ err error } func (f failingSink) Render(Render) {} func (f failingSink) Subprocess(Subprocess) {} func (f failingSink) Err() error { return f.err } // Switched off and broken must not look the same. One is a choice the // operator made; the other is the forge failing to do what it was told, // and the live panels look identical either way because they are fed by // the rings. func TestHealthDistinguishesOffFromBroken(t *testing.T) { r := NewRecorder(8, nil) if h := r.Health(); h.Configured || h.Err != "" { t.Fatalf("a fresh recorder reports %+v, want unconfigured and healthy", h) } r.SetHealth(Health{Configured: true, Path: "/tmp/ops.duckdb", Kept: "14d"}) h := r.Health() if !h.Configured || h.Err != "" || h.Path != "/tmp/ops.duckdb" || h.Kept != "14d" { t.Fatalf("configured store reports %+v", h) } r.SetHealth(Health{Configured: true, Path: "/tmp/ops.duckdb", Err: "schema: at is reserved"}) if h := r.Health(); h.Err == "" { t.Fatal("a store that failed to open reports healthy") } } // A store that opened and then started failing its writes is the case // the open-time record cannot see, so Health has to ask the sink. func TestHealthFoldsInTheSinksWriteFailure(t *testing.T) { r := NewRecorder(8, nil) r.SetHealth(Health{Configured: true, Path: "/tmp/ops.duckdb"}) r.SetSink(failingSink{}) if h := r.Health(); h.Err != "" { t.Fatalf("healthy sink reported %q", h.Err) } r.SetSink(failingSink{err: errors.New("disk full")}) if h := r.Health(); h.Err != "disk full" { t.Fatalf("write failure reported as %q, want \"disk full\"", h.Err) } } // A sink that cannot fail must not be interrogated into looking broken: // the default nop sink has no Err at all. func TestHealthToleratesASinkWithoutErr(t *testing.T) { r := NewRecorder(8, nil) r.SetHealth(Health{Configured: true}) r.SetSink(nil) if h := r.Health(); h.Err != "" { t.Fatalf("nop sink reported %q", h.Err) } }