The keeper's one periodic read (ADR 0595 §6): every entry that refuses when full, by its fullest object; full raised at the raise mark (75 by default), cleared only below the clear mark (70), so an entry at the mark does not flap; an entry dropping its oldest is never read. HealthOf is the keeper's health for its tool: unhealthy when its pass is more than three minutes old, its first view has not answered (naming the indexer's verb), or verdicts wait on its consumer unanswered past the bound; it names the entries refused, waiting and full beside. Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
72 lines
2.5 KiB
Go
72 lines
2.5 KiB
Go
package keeper
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
)
|
|
|
|
// Bound is how long the keeper may go without its fill pass, or leave an accepted verdict unanswered, before it is
|
|
// unhealthy (design 25 § 12.2): three minutes, so the only guard against a store filling never stops without a sound.
|
|
const Bound = 3 * time.Minute
|
|
|
|
// Health is the keeper's health as its tool answers it: healthy or not, why, and what it names beside (the entries it
|
|
// could not create, the ones waiting, the ones past the raise mark). Another module's entry past the raise mark raises
|
|
// that module's condition and leaves the keeper healthy.
|
|
type Health struct {
|
|
Healthy bool `json:"healthy"`
|
|
Why string `json:"why"`
|
|
Pass string `json:"pass"`
|
|
Refused []string `json:"refused,omitempty"`
|
|
Waiting []string `json:"waiting,omitempty"`
|
|
Full []string `json:"full,omitempty"`
|
|
}
|
|
|
|
// HealthOf judges the keeper from its status, what it holds, and pending: how many accepted verdicts wait on its
|
|
// durable consumer unanswered (-1 when it could not be read). Pure.
|
|
func HealthOf(s Status, held map[string]Asked, pending int, now time.Time) Health {
|
|
h := Health{Healthy: true}
|
|
var why []string
|
|
switch {
|
|
case s.Pass.IsZero() && (s.Started.IsZero() || now.Sub(s.Started) > Bound):
|
|
why = append(why, "the keeper has made no fill pass since its start")
|
|
h.Pass = "none"
|
|
case !s.Pass.IsZero():
|
|
h.Pass = s.Pass.Format(time.RFC3339)
|
|
if now.Sub(s.Pass) > Bound {
|
|
why = append(why, fmt.Sprintf("its last fill pass is %s old, more than %s", now.Sub(s.Pass).Round(time.Second), Bound))
|
|
}
|
|
}
|
|
if s.FirstView.Answered.IsZero() {
|
|
w := fmt.Sprintf("its first view, %s.%s, has not answered", s.FirstView.Owner, s.FirstView.Verb)
|
|
if s.FirstView.Error != "" {
|
|
w += ": " + s.FirstView.Error
|
|
}
|
|
why = append(why, w)
|
|
}
|
|
if pending > 0 && (s.Heard.IsZero() || now.Sub(s.Heard) > Bound) {
|
|
why = append(why, fmt.Sprintf("%d accepted verdict(s) wait on its consumer unanswered for more than %s", pending, Bound))
|
|
}
|
|
for _, module := range sortedKeys(held) {
|
|
for _, local := range sortedKeys(held[module].Made) {
|
|
m := held[module].Made[local]
|
|
name := BusName(module, local)
|
|
switch {
|
|
case m.Refused != "":
|
|
h.Refused = append(h.Refused, name+": "+m.Refused)
|
|
case m.Waiting != "":
|
|
h.Waiting = append(h.Waiting, name+": "+m.Waiting)
|
|
}
|
|
if m.Full {
|
|
h.Full = append(h.Full, fmt.Sprintf("%s: %d%%", name, m.Fill))
|
|
}
|
|
}
|
|
}
|
|
if len(why) > 0 {
|
|
h.Healthy, h.Why = false, strings.Join(why, "; ")
|
|
} else {
|
|
h.Why = "its fill pass runs and its first view is held"
|
|
}
|
|
return h
|
|
}
|