builder: the slow-event and events-behind-bound bounds are settings (F3)
The review found §794's two bounds fixed in code: the builder's 100 ms for saying a slow event's handling, and builder_health's five minutes for naming a consumer behind. Both become settings read at run time, slow-event (100ms) and events-behind-bound (5m), declared in the manifest's config with those defaults; a value that is no duration refuses the builder's start, and makes the health say it. Builds: design 47 H2 §794, H-A-461 (2)
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"time"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/health"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
@@ -11,20 +12,29 @@ import (
|
||||
const (
|
||||
// HealthTool is builder_health, the builder's health as its manifest's health asks it (design 47 H2 §794, H-A-435).
|
||||
HealthTool = "builder_health"
|
||||
// BehindAfter is how long a durable consumer's oldest unacknowledged message may wait before the health names it: an
|
||||
// events backlog, or a handler standing still on one message (§794).
|
||||
BehindAfter = 5 * time.Minute
|
||||
// eventsBehindBoundSetting is the setting events-behind-bound (§794; H-A-461 (2), P11): how long a durable consumer's
|
||||
// oldest unacknowledged message may wait before the health names it, an events backlog or a handler standing still on one
|
||||
// message; defaultEventsBehindBound when none is set.
|
||||
eventsBehindBoundSetting = "events-behind-bound"
|
||||
defaultEventsBehindBound = 5 * time.Minute
|
||||
)
|
||||
|
||||
// healthTool is builder_health: healthy when it answers, and each of the builder's durable consumers' oldest unacknowledged
|
||||
// message waits less than BehindAfter, as the consumers' facts the builder writes at every delivery and every acknowledgement
|
||||
// say them (its state consumers, the runner's runner_health form; H-A-435 and its addendum); otherwise unhealthy, naming each
|
||||
// consumer behind and how long.
|
||||
// message waits less than the setting events-behind-bound, as the consumers' facts the builder writes at every delivery and
|
||||
// every acknowledgement say them (its state consumers, the runner's runner_health form; H-A-435 and its addendum); otherwise
|
||||
// unhealthy, naming each consumer behind and how long. A setting that holds no duration is said as the health's answer.
|
||||
func healthTool(consumers versions.Reader, now func() time.Time) stdio.Tool {
|
||||
return stdio.Tool{Name: HealthTool,
|
||||
Description: "The builder's health: healthy when it answers and each of its durable consumers' oldest unacknowledged message waits less " +
|
||||
"than five minutes (no events backlog, no handler standing still on a message); otherwise it names each consumer behind and how long. " +
|
||||
"Read from the builder's state consumers, which it writes at every message delivered and acknowledged. Read-only.",
|
||||
"than the setting events-behind-bound (five minutes by default; no events backlog, no handler standing still on a message); otherwise it " +
|
||||
"names each consumer behind and how long. Read from the builder's state consumers, which it writes at every message delivered and " +
|
||||
"acknowledged. Read-only.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) { return versions.BuilderHealth(consumers, now(), BehindAfter), nil }}
|
||||
Run: func(map[string]any) (any, error) {
|
||||
bound, err := stdio.SettingDuration(eventsBehindBoundSetting, defaultEventsBehindBound)
|
||||
if err != nil {
|
||||
return health.Unhealthy("The builder's " + err.Error() + "."), nil
|
||||
}
|
||||
return versions.BuilderHealth(consumers, now(), bound), nil
|
||||
}}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import (
|
||||
"git.novox.be/novox/mesh-contracts/health-and-repair/go/clients/meshhandactsclient"
|
||||
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/seats/meshbuilds"
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/health"
|
||||
|
||||
"mesh-delivery-builder/internal/build"
|
||||
|
||||
@@ -58,13 +59,23 @@ func TestAStateIsReadInOnePage(t *testing.T) {
|
||||
"builder-kept": json.RawMessage(`{"stream":"K","name":"builder-kept","oldest-unacknowledged":"` + now.Add(-time.Minute).UTC().Format(time.RFC3339) + `"}`)}
|
||||
r := versions.Reader{Keys: func() ([]string, error) { return []string{"builder-kept", "builder-events"}, nil },
|
||||
Get: func(k string) (json.RawMessage, bool, error) { v, ok := facts[k]; return v, ok, nil }}
|
||||
a := versions.BuilderHealth(r, now, BehindAfter)
|
||||
a := versions.BuilderHealth(r, now, defaultEventsBehindBound)
|
||||
if a.Healthy || a.Why != "The builder's consumers behind by 5m0s or more: builder-events (its oldest unacknowledged message waits 6m0s, 40 more not yet given)." {
|
||||
t.Errorf("health = %+v, want unhealthy naming builder-events alone", a)
|
||||
}
|
||||
if a := versions.BuilderHealth(r, now.Add(-2*time.Minute), BehindAfter); !a.Healthy {
|
||||
if a := versions.BuilderHealth(r, now.Add(-2*time.Minute), defaultEventsBehindBound); !a.Healthy {
|
||||
t.Errorf("health four minutes in = %+v, want healthy", a)
|
||||
}
|
||||
// H-A-461 (2): the bound is the setting events-behind-bound, five minutes when none is set.
|
||||
tool := healthTool(r, func() time.Time { return now })
|
||||
for _, c := range []struct{ set, want string }{{"", "unhealthy"}, {"10m", "healthy"}, {"soon", "events-behind-bound"}} {
|
||||
t.Setenv(stdio.SettingWord(eventsBehindBoundSetting), c.set)
|
||||
got, _ := tool.Run(nil)
|
||||
a := got.(health.Answer)
|
||||
if (c.want == "healthy") != a.Healthy || (c.want == "events-behind-bound" && !strings.Contains(a.Why, c.want)) {
|
||||
t.Errorf("with events-behind-bound %q the health = %+v, want %s", c.set, a, c.want)
|
||||
}
|
||||
}
|
||||
})
|
||||
// Design 47 H2 §793, H-A-454: builder_publish_queue asks the seat mesh-builds' verb publish-queue, which the builder serves from
|
||||
// its own stream, and answers its counts, list and cap with the states beside them; builder_publish_drop and
|
||||
|
||||
Reference in New Issue
Block a user