Documentation
¶
Overview ¶
Package eventbus is loom-server's in-memory observability fan-out. Every notable side-effect of the server (and the SPA, via POST /api/events/client) flows through here ; the DoctorPanel SSE stream at /api/events tails the bus so operators can watch what's happening end-to-end without grepping logs across processes.
Design : single Hub, slog.Handler-shaped Publish, lossy subscribers with a per-sub bounded ring buffer. A slow doctor browser doesn't hold the WS sync write path hostage ; if a subscriber falls behind past `slow` events the dropper increments a counter and the SSE emits a synthetic "<drop>" line so the operator knows they're missing context. Same shape as weft-doctor in the cluster — one less concept to learn when jumping between weft and weft-loom.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
type Event struct {
TS time.Time `json:"ts"`
Source string `json:"source"` // "server" or "client"
Component string `json:"component"`
Verb string `json:"verb"`
Level string `json:"level"` // "debug" | "info" | "warn" | "error"
Message string `json:"message,omitempty"`
Fields map[string]any `json:"fields,omitempty"`
// Project identifies the project the event relates to ; the
// doctor UI filters on this so two operators in different
// projects don't drown each other.
Project string `json:"project,omitempty"`
}
Event is the wire shape. Component + verb identify the producer + the action ; level matches slog ; Fields holds the structured payload (anything JSON-serialisable).
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub fans out events to N subscribers. Created at boot, retained for the loom-server's lifetime. Concurrent Publish + Subscribe + Unsubscribe safe.
func (*Hub) Close ¶
func (h *Hub) Close()
Close stops further publishes. Subscribers receive a final closed channel when they call their stop fn.
func (*Hub) Drops ¶
Drops returns the lifetime drop counter ; doctor UI surfaces this in the "Diagnostics" header so an operator sees buffer pressure before symptoms.
func (*Hub) Publish ¶
Publish fan-outs to every subscriber. Non-blocking : drops events when a subscriber buffer is full.
func (*Hub) PublishCtx ¶
PublishCtx is the same as Publish but tagged with the deadline origin ; the doctor UI surfaces request-scoped events as a thread.
func (*Hub) Subscribe ¶
Subscribe returns an unbuffered receive channel + an unregister fn. Caller MUST drain the channel ; once subBuffer events queue up the next publish drops the oldest and emits a "<drop>" sentinel via the overflow counter (visible to the SSE handler).
func (*Hub) SubscribeWithDrops ¶
SubscribeWithDrops returns the regular Event channel plus a drop-marker channel (capacity 1, drop-on-full) that publishes a single Event{Verb: "drop", Fields: {"drops": N}} sentinel whenever the regular channel overflows. Callers that want to surface buffer-pressure to operators (e.g. the doctor SSE stream) select on both ; everyone else uses Subscribe.