stream

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

type Event struct {
	TenantID  string
	MonitorID string
	Data      []byte
}

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

type HeartbeatSink struct {
	Hub    *Hub
	NodeID string
}

HeartbeatSink publishes every finished check of this node as a heartbeat event. It implements scheduler.Sink (internal/scheduler) and never blocks.

func (*HeartbeatSink) Record

func (s *HeartbeatSink) Record(_ context.Context, o scheduler.Outcome)

Record implements scheduler.Sink.

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

func NewHub(buffer int) *Hub

NewHub returns a hub whose subscriptions buffer up to buffer events (DefaultBuffer if buffer <= 0).

func (*Hub) Publish

func (h *Hub) Publish(e Event)

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

func (h *Hub) Subscribers() int

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL