From 0b454f367374e8cb97927627dacd0f1b216fe5ad Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 13 May 2026 19:41:44 +0300 Subject: introduce Accumulator interface in statsengine to separate ingestion from snapshot-building MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Define statsengine.Accumulator (Ingest + Reset) to represent the event-accumulation responsibility separately from runtime.SnapshotSource (Snapshot), which handles the read side. This reduces the SRP violation in Engine: callers that only push events now hold an Accumulator; callers that only read statistics hold a SnapshotSource. - Add Accumulator interface and compile-time assertion in statsengine/engine.go - Add EventIngester type alias (= statsengine.Accumulator) in runtime/runtime.go with a compile-time assertion, so callers in the runtime layer can reference the ingestion contract without importing statsengine directly - Split tuiRuntime.engine field into accumulator + snapSource so the event-loop callback holds Accumulator and wireRuntimeBindings passes SnapshotSource to SetDashboardSnapshotSource — making each consumer's dependency explicit - Simplify resetDashboardSnapshotSource in tui.go to cast for interface{ Reset() } independently of Snapshot(), removing the combined ad-hoc interface check Co-Authored-By: Claude Sonnet 4.6 --- internal/statsengine/engine.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'internal/statsengine') diff --git a/internal/statsengine/engine.go b/internal/statsengine/engine.go index f9602a9..b7d93fa 100644 --- a/internal/statsengine/engine.go +++ b/internal/statsengine/engine.go @@ -23,6 +23,22 @@ const ( DefaultTopN = 64 ) +// Accumulator is the event-ingestion side of the stats engine. +// It accepts incoming event pairs (Ingest) and supports resetting all +// accumulated state back to zero (Reset). Snapshot building is a separate +// responsibility expressed by runtime.SnapshotSource; separating the two +// satisfies SRP — callers that only push events hold an Accumulator, while +// callers that only read statistics hold a SnapshotSource. +type Accumulator interface { + // Ingest records one event pair into the in-memory aggregates. + Ingest(pair *event.Pair) + // Reset clears all accumulated stats and restarts series baselines. + Reset() +} + +// compile-time assertion: *Engine must satisfy Accumulator. +var _ Accumulator = (*Engine)(nil) + // Engine aggregates streaming syscall data into immutable snapshots. type Engine struct { mu sync.Mutex -- cgit v1.2.3