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
50 lines
2.1 KiB
Go
50 lines
2.1 KiB
Go
package versions
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"sort"
|
|
"strings"
|
|
"time"
|
|
|
|
"git.novox.be/novox/mesh-sdk/go/health"
|
|
"git.novox.be/novox/mesh-sdk/go/process"
|
|
)
|
|
|
|
// BuilderHealth is builder_health's answer at now (design 47 H2 §794, H-A-435, H-A-462): healthy when 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, read through consumers); otherwise unhealthy, naming
|
|
// each consumer behind and how long. The judgement is the module's shared code, so the builder's whole test proves it.
|
|
func BuilderHealth(consumers Reader, now time.Time, behindAfter time.Duration) 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))
|
|
}
|