views: count the events no handler takes as the module's finding

An event a module consumes that no handler takes was said in the journal
alone, so a part that never acted on it (the runner's placing at 17:34) was
seen only by reading the log. The event hub now tells a hook of each such
subject; the process reader, where it holds a findings writer, counts them
in one finding event-unhandled per module (the count since the start and
the last subject) and clears it at its start, since a new build may handle
the event. Without a findings writer the journal line stands alone.

Builds: design 47 H H-A-166, H-A-169
This commit is contained in:
2026-11-20 17:45:27 +01:00
parent 7aae152760
commit e568e6dc63
5 changed files with 106 additions and 2 deletions
+11
View File
@@ -23,6 +23,9 @@ const (
// EntryNotFoundKind is a part's finding of an entry by fingerprint the seat mesh-catalog's `entry` answered it does not hold
// (design 47 G §614, A-15, A-103): scope the part, id the fingerprint.
EntryNotFoundKind = "entry-not-found"
// EventUnhandledKind is a process's finding of the events its durable consumer delivered that no handler of the module
// took, one per module, counted since the process started (design 47 H, H-A-166, H-A-169).
EventUnhandledKind = "event-unhandled"
)
// viewFinding is what a views part says is wrong with a state it owns or follows, in plain fields: kind and id name it, summary
@@ -120,3 +123,11 @@ func WriteEntryNotFound(w WireWriter, fingerprint string, since, at time.Time) e
func ClearEntryNotFound(w WireWriter, fingerprint string) error {
return viewFinding{kind: EntryNotFoundKind, id: fingerprint}.drop(w)
}
// unhandledFinding is the module's one finding of the events no handler took since its process started (H-A-169): its id the
// module, its summary the count and the last subject.
func unhandledFinding(module string, count int, last string, since, at time.Time) viewFinding {
summary := fmt.Sprintf("%s took %d events by no handler since its process started at %s, the last on %s: what the module consumes it does not act on",
module, count, since.UTC().Format(time.RFC3339), last)
return viewFinding{kind: EventUnhandledKind, id: module, summary: summary, headline: fmt.Sprintf("%s hears events it does not handle", module), at: at.UTC()}
}
+54
View File
@@ -73,6 +73,10 @@ type ProcessReader struct {
asked bool
begun map[string]context.CancelFunc
status *process.AwaitedBucket
// unheard counts the events no handler of the module took since Start, the last of them on lastUnheard (H-A-169).
unheard int
lastUnheard string
startedAt time.Time
}
// adoptedHear is one adopted follower's handler of its seat event, by its picture's bucket.
@@ -395,6 +399,50 @@ func (r *ProcessReader) Hear(ctx context.Context) func(jetstream.Msg) {
}
r.logf("views: %s is no views event of an owner followed, acknowledged", m.Subject())
_ = m.Ack()
r.unhandled(m.Subject())
}
}
// now is the reader's clock.
func (r *ProcessReader) now() time.Time {
if r.Now != nil {
return r.Now()
}
return time.Now()
}
// unhandled counts an event no handler of the module took, said in the log already, in the module's finding
// `event-unhandled` (design 47 H, H-A-166, H-A-169); with no findings writer the log line stands alone.
func (r *ProcessReader) unhandled(subject string) {
if r.Findings == nil {
return
}
r.mu.Lock()
r.unheard++
r.lastUnheard = subject
count, since := r.unheard, r.startedAt
r.mu.Unlock()
w := r.Findings()
if w == nil {
return
}
if err := unhandledFinding(r.Module, count, subject, since, r.now()).put(w); err != nil {
r.logf("views: the finding %s of %s is not written: %v", EventUnhandledKind, r.Module, err)
}
}
// clearUnhandled clears the module's finding `event-unhandled` at the process's start: a new build may handle the event
// (H-A-169).
func (r *ProcessReader) clearUnhandled() {
if r.Findings == nil {
return
}
w := r.Findings()
if w == nil {
return
}
if err := (viewFinding{kind: EventUnhandledKind, id: r.Module}).drop(w); err != nil {
r.logf("views: the finding %s of %s is not cleared at its start: %v", EventUnhandledKind, r.Module, err)
}
}
@@ -847,7 +895,13 @@ func (r *ProcessReader) Start(ctx context.Context, js jetstream.JetStream, cred
})
hear := r.Hear(ctx)
err := hub.Handle(pattern, hear)
if r.Findings != nil {
// H-A-169: the events no handler of the module takes are its finding, cleared at each start
r.clearUnhandled()
hub.OnUnhandled(r.unhandled)
}
r.mu.Lock()
r.startedAt = r.now()
r.status = status
if !own {
// an event adopted after the start is handled on the module's hub (Adopt); the reader's own hub takes every one
+17 -2
View File
@@ -955,8 +955,23 @@ func subViews(t *testing.T) {
t.Fatal(err)
}
m := msg()
if pr.Hear(ctx)(m); len(pfs.m) != 0 || len(pr.Followers()) != 1 || len(*heard["pnext"]) != 1 || !m.acked {
t.Errorf("after the drop: findings %v, followers %d, heard %v, acked %v", pfs.m, len(pr.Followers()), *heard["pnext"], m.acked)
if pr.Hear(ctx)(m); len(pr.Followers()) != 1 || len(*heard["pnext"]) != 1 || !m.acked {
t.Errorf("after the drop: followers %d, heard %v, acked %v", len(pr.Followers()), *heard["pnext"], m.acked)
}
// H-A-166, H-A-169: the event no handler takes, the dropped view's here, is the module's one finding event-unhandled,
// counted since the start, and the next start clears it.
if fd := pfs.next(t); fd.Kind != EventUnhandledKind || fd.ID != "reader" || !strings.Contains(fd.Summary, "took 1 events") ||
!strings.Contains(fd.Summary, m.subject) || len(pfs.m) != 1 {
t.Errorf("after the drop: findings %v, the unhandled event's %+v", pfs.m, fd)
}
pr.Hear(ctx)(&seatMsg{subject: "mesh.seat.s.event.nobody"})
if fd := pfs.next(t); !strings.Contains(fd.Summary, "took 2 events") || !strings.Contains(fd.Summary, "mesh.seat.s.event.nobody") || len(pfs.m) != 1 {
t.Errorf("the second unhandled event: findings %v, %+v", pfs.m, fd)
}
again := &ProcessReader{Module: "reader", Findings: func() WireWriter { return pfs }, Now: now, Hub: process.NewEventHub(t.Logf)}
again.Start(ctx, nil, process.Account{}, nil)
if len(pfs.m) != 0 {
t.Errorf("the start left the finding %v", pfs.m)
}
})
// Design 47 G §717: a view found by its seat starts without a holder, waits naming the seat, follows the holder the