Files
mesh-catalog/modules/mesh-self-check/cmd/mesh-self-check/main.go
T
jschoubben bbd02004b8
mesh/delivery merged: source.main moved to novox/mesh-catalog@19714898986c
mesh/delivery-group group fix/l4-quick merged: every member is merged
mesh/check pass bbd02004b863 on 3d7830cfdc4f | unit 2729 run, 4570 kept, 16 skipped | integration 2975 run, 4493 kept, 25 skipped | over bound: unit, …
Let the health take-over's compare come out empty (issue 1952)
The self-check's D13 read every reading, good night, indexer module and
manifest one key at a time through the runtime and never finished
within its 30 s; it now keeps those states by watching them and judges
from memory, and reads the setting `probes` once a run. Findings name
their key's last part `ref`, since the runtime refuses a field named
`token`; the self-check, the healers and the keeper are pinned to the
mesh-sdk that reads it and lets a carried holder say its seat's events.
The controller's own bus.nats.upgrade-failed ends with its lease, as
the operator approved on 2026-10-31, so compare lists it apart.

Quick vs thorough: quick, these fixes for L4's take-over now; the
thorough fix (research 032 / ADR 0240's health view extension) is
decided later.

Claude-Session: https://claude.ai/code/session_01NcbgfJ9Gum47zkFKWRaovL
2026-10-31 21:35:59 +01:00

83 lines
2.6 KiB
Go

// mesh-self-check: the holder of the seat mesh-self-check (novox/hq ADR 0564 §6). A Go bundle served by a runtime of
// its own, on its own bus account (`runs-as`), so that its account alone writes its buckets: `findings` (what it finds
// wrong now, which the condition keeper raises and clears conditions from), `verdict` (the last run) and `verdicts`
// (every run, kept a week). It runs the probes every five minutes and says `checked` at the end of each run. stdout is
// the MCP channel; what this module says, it says on stderr.
package main
import (
"context"
"encoding/json"
"fmt"
"os"
"time"
stdio "git.novox.be/novox/mesh-sdk/go"
)
func logf(format string, a ...any) { fmt.Fprintf(os.Stderr, format+"\n", a...) }
// runtimeStore is the bus, through the runtime that launched this bundle.
type runtimeStore struct{}
func (runtimeStore) Get(state, key string) ([]byte, bool, error) {
e, err := stdio.State(state).Get(key)
if err != nil || e == nil {
return nil, false, err
}
return e.Value, true, nil
}
func (runtimeStore) Put(state, key string, value any) error {
_, err := stdio.State(state).Put(key, value)
return err
}
func (runtimeStore) Delete(state, key string) error { return stdio.State(state).Delete(key) }
func (runtimeStore) Keys(state string) ([]string, error) { return stdio.State(state).Keys() }
func (runtimeStore) Watch(state string, handle func(key string, value []byte, gone bool)) error {
return stdio.State(state).Watch("", func(ch stdio.StateChange) error {
handle(ch.Key, ch.Value, ch.Op != stdio.OpPut)
return nil
})
}
// NewChecker is the self-check over the runtime.
func NewChecker() *Checker {
return &Checker{Store: runtimeStore{}, Registry: Registry(), Now: time.Now, Logf: logf, Host: os.Getenv("MESH_NODE"),
Enabled: enabledProbes,
Ask: func(key string, body any) (json.RawMessage, error) { return stdio.Ask(key, body) },
Publish: stdio.SeatPublish}
}
func main() {
c := NewChecker()
go func() {
<-stdio.Served()
c.WatchKept(context.Background())
c.Keep(context.Background())
}()
if err := stdio.Serve("", Tools(c)); err != nil {
logf("%v", err)
os.Exit(1)
}
}
// enabledProbes is the setting `probes`, read once at each run so a change applies at the next; with it unreadable, the
// default list.
func enabledProbes() []string {
raw, err := stdio.Config("probes")
if err != nil {
logf("the setting probes cannot be read (%v); the default list runs", err)
return DefaultProbes
}
var list []string
if json.Unmarshal(raw, &list) != nil {
logf("the setting probes is not a list of probe ids (%s); the default list runs", raw)
return DefaultProbes
}
return list
}