builder: prove the tag at another commit and the six-minute backlog whole (F2)
The review found §794's backlog and §796's tag at another commit proven only by unit tests. Both become steps of the builder's whole test on the embedded bus: a reservation skips 0.2.0 whose tag stands at another commit, takes 0.2.1 with the finding version-tagged-elsewhere, the release writes modules/m4/v0.2.1 at the build's commit and the version-released heard from the bus clears the finding; a message the handler asks again is kept on its consumer's ledger in the state consumers on the bus, and the health held six minutes names it. The health judgement moves from the tools program's main into internal/versions (BuilderHealth), which the tools program calls, so the whole test can prove it. The test's comment no longer says the old state is dropped through the bus module (F1). Builds: design 47 H2 §794, §796, H-A-453 (3), H-A-435, H-A-462
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
stdio "git.novox.be/novox/mesh-sdk/go"
|
||||
"git.novox.be/novox/mesh-sdk/go/health"
|
||||
"git.novox.be/novox/mesh-sdk/go/process"
|
||||
|
||||
"mesh-delivery-builder/internal/versions"
|
||||
)
|
||||
@@ -32,39 +26,5 @@ func healthTool(consumers versions.Reader, now func() time.Time) stdio.Tool {
|
||||
"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.",
|
||||
Input: map[string]any{"type": "object", "properties": map[string]any{}},
|
||||
Run: func(map[string]any) (any, error) { return builderHealth(consumers, now()), nil }}
|
||||
}
|
||||
|
||||
// builderHealth is builder_health's answer at now.
|
||||
func builderHealth(consumers versions.Reader, now time.Time) health.Answer {
|
||||
keys, err := consumers.Keys()
|
||||
if err != nil {
|
||||
return health.Unhealthy(fmt.Sprintf("The ages of the builder's consumers cannot be read from its state %s (%v).", process.ConsumersState, err))
|
||||
}
|
||||
if len(keys) == 0 {
|
||||
return health.Healthy(fmt.Sprintf("The builder answers and has heard no event yet: its state %s holds no consumer.", process.ConsumersState))
|
||||
}
|
||||
sort.Strings(keys)
|
||||
var behind []string
|
||||
for _, k := range keys {
|
||||
raw, ok, err := consumers.Get(k)
|
||||
if err != nil {
|
||||
return health.Unhealthy(fmt.Sprintf("The age of the consumer %s cannot be read (%v).", k, err))
|
||||
}
|
||||
var f process.ConsumerFacts
|
||||
if ok {
|
||||
if err := json.Unmarshal(raw, &f); err != nil {
|
||||
return health.Unhealthy(fmt.Sprintf("The age of the consumer %s does not read (%v).", k, err))
|
||||
}
|
||||
}
|
||||
if !f.OldestUnacknowledged.IsZero() {
|
||||
if age := now.Sub(f.OldestUnacknowledged); age >= BehindAfter {
|
||||
behind = append(behind, fmt.Sprintf("%s (its oldest unacknowledged message waits %s, %d more not yet given)", k, age.Round(time.Second), f.Pending))
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(behind) > 0 {
|
||||
return health.Unhealthy(fmt.Sprintf("The builder's consumers behind by %s or more: %s.", BehindAfter, strings.Join(behind, ", ")))
|
||||
}
|
||||
return health.Healthy(fmt.Sprintf("The builder answers, and each of its %d consumers is less than %s behind.", len(keys), BehindAfter))
|
||||
Run: func(map[string]any) (any, error) { return versions.BuilderHealth(consumers, now(), BehindAfter), nil }}
|
||||
}
|
||||
|
||||
@@ -58,11 +58,11 @@ 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 := builderHealth(r, now)
|
||||
a := versions.BuilderHealth(r, now, BehindAfter)
|
||||
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 := builderHealth(r, now.Add(-2*time.Minute)); !a.Healthy {
|
||||
if a := versions.BuilderHealth(r, now.Add(-2*time.Minute), BehindAfter); !a.Healthy {
|
||||
t.Errorf("health four minutes in = %+v, want healthy", a)
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user