Readings and last good nights are the owners' published packages: disk-load's diskreadings and restic's backupgood, taken by series (B5b Left 3; ADR 0634 §4; issue 1966)

Claude-Session: https://claude.ai/code/session_01NcbgfFSnn24M3GcqttoU7i
This commit is contained in:
2026-11-05 14:48:10 +01:00
parent c7ae96414f
commit e0eecbf3c8
43 changed files with 565 additions and 147 deletions
@@ -9,9 +9,10 @@ import (
)
type manifest struct {
Module string `json:"module"`
RunsAs string `json:"runs-as"`
Claims []struct {
Packages map[string]string `json:"packages"`
Module string `json:"module"`
RunsAs string `json:"runs-as"`
Claims []struct {
Name string `json:"name"`
Scope string `json:"scope"`
Serves []string `json:"serves"`
@@ -43,6 +44,12 @@ func readManifest(t *testing.T) manifest {
// itself a tool that starts it by hand (ADR 0564 §12).
func TestTheManifestSaysWhatTheCodeDoes(t *testing.T) {
m := readManifest(t)
// The readings' layouts are the owners' published packages, taken by their series (ADR 0634 §4).
for _, pk := range []string{"diskreadings", "backupgood"} {
if m.Packages[pk] != "0.1" {
t.Errorf("packages %v: want %s of series 0.1", m.Packages, pk)
}
}
if m.Module != Module || m.RunsAs != Module {
t.Errorf("module %q runs as %q", m.Module, m.RunsAs)
}
@@ -19,6 +19,8 @@ import (
"sync"
"time"
"git.novox.be/novox/mesh-catalog/modules/disk-load/diskreadings"
"git.novox.be/novox/mesh-catalog/modules/restic/backupgood"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/delivery"
"git.novox.be/novox/mesh-sdk/go/health"
@@ -26,8 +28,8 @@ import (
// The states D13 reads (declared under `reads`).
const (
ReadingsRead = health.ReadingsRead
GoodRead = health.GoodRead
ReadingsRead = diskreadings.ReadingsRead
GoodRead = backupgood.GoodRead
ModulesRead = delivery.IndexerModule + ".modules"
ManifestsRead = delivery.IndexerModule + ".manifests"
)
@@ -52,8 +54,8 @@ const (
// dataFacts is everything D13 judges: the readings, the last good nights, each module's manifest, and the machines whose
// backup holder was heard from.
type dataFacts struct {
readings []health.Reading
good map[string]time.Time // by health.GoodKey
readings []diskreadings.Reading
good map[string]time.Time // by backupgood.GoodKey
manifests map[string]catalogue.Manifest
// unmeasured are the machines that hold node-backup, are heard from, and have no reading of anything.
unmeasured []string
@@ -139,7 +141,7 @@ func (c *Checker) dataFacts(ctx context.Context) (dataFacts, error) {
}
byNode := map[string]int{}
for _, k := range slices.Sorted(maps.Keys(states[ReadingsRead])) {
r, err := health.DecodeReading(states[ReadingsRead][k])
r, err := diskreadings.DecodeReading(states[ReadingsRead][k])
if err != nil {
continue
}
@@ -147,8 +149,8 @@ func (c *Checker) dataFacts(ctx context.Context) (dataFacts, error) {
byNode[r.Node]++
}
for _, raw := range states[GoodRead] {
if g, derr := health.DecodeGoodRow(raw); derr == nil && !g.LastGood.IsZero() {
f.good[health.GoodKey(g.Node, g.Module, g.Item)] = g.LastGood
if g, derr := backupgood.DecodeGoodRow(raw); derr == nil && !g.LastGood.IsZero() {
f.good[backupgood.GoodKey(g.Node, g.Module, g.Item)] = g.LastGood
}
}
for name, raw := range states[ModulesRead] {
@@ -247,7 +249,7 @@ func sizeWords(size *int64) string {
// firstSeen is when an item was first measured on its node (the reading keeps it); for a reading written before it did,
// the oldest day its seven-day peak is made of, else its measurement: a lower bound on how long it has been declared.
func firstSeen(r health.Reading, now time.Time) time.Time {
func firstSeen(r diskreadings.Reading, now time.Time) time.Time {
if !r.FirstSeen.IsZero() {
return r.FirstSeen
}
@@ -270,22 +272,22 @@ func obs(kind string, id, machine string, sev health.Severity, summary, said str
// dataFindings is every condition the data on record raises now: a function of what is known, as the controller's was.
func dataFindings(f dataFacts) []Observation {
var out []Observation
arrays := map[string][]health.Reading{}
arrays := map[string][]diskreadings.Reading{}
type shrunk struct {
machine, dataset, class string
size, peak int64
items []string
}
shrunkDatasets := map[string]shrunk{}
byItem := map[string][]health.Reading{}
retiredCopies := map[string][]health.Reading{}
byItem := map[string][]diskreadings.Reading{}
retiredCopies := map[string][]diskreadings.Reading{}
for _, m := range f.unmeasured {
o := obs(kindDataUnmeasured, m, m, Warning, fmt.Sprintf("%s's backup holder did not say what it measured of the data "+
"declared there, so nothing about that data is known", m), "disk-load keeps no reading of this machine's data")
o.Confirm = true
out = append(out, o)
}
rs := append([]health.Reading(nil), f.readings...)
rs := append([]diskreadings.Reading(nil), f.readings...)
sort.Slice(rs, func(i, j int) bool {
return keyOfItem(rs[i].Node, rs[i].Module, rs[i].ID) < keyOfItem(rs[j].Node, rs[j].Module, rs[j].ID)
})
@@ -354,7 +356,7 @@ func dataFindings(f dataFacts) []Observation {
// plan, said only where the machine was measured — where a holder is there to take it.
if item.BackedUp() && (class == catalogue.ClassIrreplaceable || r.MeasuredAt != nil) {
within := item.BackupWithin()
last, has := f.good[health.GoodKey(r.Node, r.Module, r.ID)]
last, has := f.good[backupgood.GoodKey(r.Node, r.Module, r.ID)]
switch {
case !has && f.now.Sub(firstSeen(r, f.now)) > within:
out = append(out, obs(kindBackupStale, id, r.Node, severity,
@@ -9,6 +9,8 @@ import (
"testing"
"time"
"git.novox.be/novox/mesh-catalog/modules/disk-load/diskreadings"
"git.novox.be/novox/mesh-catalog/modules/restic/backupgood"
"git.novox.be/novox/mesh-sdk/go/buscompose"
"git.novox.be/novox/mesh-sdk/go/catalogue"
"git.novox.be/novox/mesh-sdk/go/delivery"
@@ -173,8 +175,8 @@ func TestTheBusProbes(t *testing.T) {
})},
{"D13 no good backup is counted from when the item was first measured", probeData, bus{},
[]string{"machine.ace.pg.data.backup-stale"}, "", dataMesh(func(r *dataRig) {
delete(r.good, health.ReadingKey("ace", "pg", "data"))
delete(r.good, health.ReadingKey("ace", "plex", "meta"))
delete(r.good, diskreadings.ReadingKey("ace", "pg", "data"))
delete(r.good, diskreadings.ReadingKey("ace", "plex", "meta"))
r.firstSeen("ace", "pg", "data", -100*time.Hour).firstSeen("ace", "plex", "meta", -time.Hour)
})},
{"D13 a machine with a backup holder and no reading", probeData, bus{}, []string{"machine.g14.data-unmeasured"}, "",
@@ -361,18 +363,20 @@ var dataNow = time.Date(2026, 10, 29, 12, 0, 0, 0, time.UTC)
// dataRig is the mesh D13 reads: a manifest per module with the items it declares, a reading per item, a last good night.
type dataRig struct {
s *memStore
readings map[string]*health.Reading
readings map[string]*diskreadings.Reading
good map[string]time.Time
}
func (r *dataRig) key(node, module, item string) string { return health.ReadingKey(node, module, item) }
func (r *dataRig) key(node, module, item string) string {
return diskreadings.ReadingKey(node, module, item)
}
func (r *dataRig) reading(node, module, item string) *health.Reading {
func (r *dataRig) reading(node, module, item string) *diskreadings.Reading {
k := r.key(node, module, item)
if r.readings[k] == nil {
at := dataNow
r.readings[k] = &health.Reading{V: health.ReadingVersion, Node: node, PlacedDataItem: catalogue.PlacedDataItem{Module: module,
ID: item, Class: catalogue.ClassValuable, Path: "/srv/" + module + "/" + item}, Measured: health.Measured{MeasuredAt: &at, Precision: "exact"}}
r.readings[k] = &diskreadings.Reading{V: diskreadings.ReadingVersion, Node: node, PlacedDataItem: catalogue.PlacedDataItem{Module: module,
ID: item, Class: catalogue.ClassValuable, Path: "/srv/" + module + "/" + item}, Measured: diskreadings.Measured{MeasuredAt: &at, Precision: "exact"}}
}
return r.readings[k]
}
@@ -400,7 +404,7 @@ func (r *dataRig) dataset(node, module, item, name string) *dataRig {
}
func (r *dataRig) array(node, module, item, kind, where string, healthy bool) *dataRig {
r.reading(node, module, item).Redundancy = &health.Redundancy{Kind: kind, Where: where, Healthy: &healthy, Said: "a member is missing"}
r.reading(node, module, item).Redundancy = &diskreadings.Redundancy{Kind: kind, Where: where, Healthy: &healthy, Said: "a member is missing"}
return r
}
@@ -436,7 +440,7 @@ func (r *dataRig) holder(node string) {
// declares movies (protected by redundancy), thumbs, meta and library (all valuable); every item is read as held, and what
// is given changes it.
func dataMesh(change func(*dataRig)) *memStore {
r := &dataRig{s: newStore(), readings: map[string]*health.Reading{}, good: map[string]time.Time{}}
r := &dataRig{s: newStore(), readings: map[string]*diskreadings.Reading{}, good: map[string]time.Time{}}
r.holder("ace")
declare := func(module string, items map[string]catalogue.DataItem) {
var man catalogue.Manifest
@@ -472,7 +476,7 @@ func dataMesh(change func(*dataRig)) *memStore {
for k, t := range r.good {
node, rest, _ := strings.Cut(k, ".")
module, item, _ := strings.Cut(rest, ".")
_ = r.s.Put(GoodRead, k, health.GoodRow{V: health.GoodVersion, Node: node, Module: module, Item: item, CoveredBy: "/x", LastGood: t})
_ = r.s.Put(GoodRead, k, backupgood.GoodRow{V: backupgood.GoodVersion, Node: node, Module: module, Item: item, CoveredBy: "/x", LastGood: t})
}
return r.s
}