Documentation
¶
Overview ¶
Package stream fans out live events (heartbeats, status changes, incidents) to the WebSocket clients of this node (FA-API-04). Every event belongs to exactly one tenant, and a subscription only ever receives events of the tenant it was opened for (FA-TEN-05).
Index ¶
Constants ¶
const DefaultBuffer = 256
DefaultBuffer is the number of events a subscriber may lag behind before it is dropped.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Event ¶
Event is one message for the clients of a tenant. Data is the encoded JSON message; it is shared between subscribers and must not be modified.
type HeartbeatSink ¶
HeartbeatSink publishes every finished check of this node as a heartbeat event. It implements scheduler.Sink (internal/scheduler) and never blocks.
type Hub ¶
type Hub struct {
// contains filtered or unexported fields
}
Hub distributes events to subscriptions. Publish never blocks: a subscriber that cannot keep up is closed, and its client reconnects and reloads.
func NewHub ¶
NewHub returns a hub whose subscriptions buffer up to buffer events (DefaultBuffer if buffer <= 0).
func (*Hub) Publish ¶
Publish delivers e to the subscriptions of e.TenantID. Events without a tenant are dropped.
func (*Hub) Subscribe ¶
func (h *Hub) Subscribe(tenantID string) *Subscription
Subscribe opens a subscription for tenantID. The tenant must come from the authenticated principal, never from the client. An empty tenant ID yields a subscription that is already closed.
func (*Hub) Subscribers ¶
Subscribers returns the number of open subscriptions (for metrics and tests).
type IncidentReader ¶
type IncidentReader interface {
GetIncident(ctx context.Context, tenantID, id string) (store.Incident, error)
ListIncidents(ctx context.Context, tenantID string, q store.IncidentQuery) (store.IncidentPage, error)
}
IncidentReader reads incidents of a tenant (store.State satisfies it).
type StateBridge ¶
type StateBridge struct {
// contains filtered or unexported fields
}
StateBridge turns committed status changes (cluster.StateEvent) into state and incident events. Handle is called from the Raft FSM and must not block: it only queues; Run does the store reads and publishing.
func NewStateBridge ¶
func NewStateBridge(hub *Hub, incidents IncidentReader, log *slog.Logger) *StateBridge
NewStateBridge returns a bridge that publishes to hub. Call Run to start it.
func (*StateBridge) Handle ¶
func (b *StateBridge) Handle(ev cluster.StateEvent)
Handle queues ev for Run. It never blocks: when the queue is full, ev is dropped and counted. It does no logging or I/O, so it is safe to call from the FSM.
func (*StateBridge) Run ¶
func (b *StateBridge) Run(ctx context.Context)
Run publishes queued state changes until ctx is done.
type Subscription ¶
type Subscription struct {
// contains filtered or unexported fields
}
Subscription receives the events of one tenant.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close ends the subscription. It is safe to call more than once.
func (*Subscription) Done ¶
func (s *Subscription) Done() <-chan struct{}
Done is closed when the subscription ended (Close or overflow).
func (*Subscription) Events ¶
func (s *Subscription) Events() <-chan []byte
Events returns the channel of encoded messages. It is closed together with Done, after which buffered messages may still be read.
func (*Subscription) Overflowed ¶
func (s *Subscription) Overflowed() bool
Overflowed reports whether the subscription was closed because the client could not keep up.
func (*Subscription) SetMonitors ¶
func (s *Subscription) SetMonitors(ids []string)
SetMonitors limits the subscription to the given monitors of its tenant; an empty list means all monitors. IDs of other tenants never match because events are filtered by tenant first.