Documentation
¶
Overview ¶
Package events fans containerd events out to subscribers (ADR-0007): one containerd subscription per environment, any number of in-process subscribers (WebSocket streams, later the scheduler and notifications).
The hub reconnects with backoff when containerd restarts. Events missed during an outage cannot be replayed, so the hub emits synthetic "nerdui" events: "disconnected" when the subscription breaks and "connected" when it is (re-)established — clients refetch their data on "connected".
Index ¶
Constants ¶
const ( KindNerdui = "nerdui" ActionConnected = "connected" ActionDisconnected = "disconnected" TopicConnected = "/nerdui/connected" TopicDisconnected = "/nerdui/disconnected" )
Synthetic events.
const ( DefaultRetention = 7 * 24 * time.Hour DefaultMaxEvents = 100_000 )
Recorder defaults (ADR-0021).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Filter ¶
type Filter struct {
// Namespace limits events to one containerd namespace; empty means all namespaces.
Namespace string
// Topics are topic prefixes such as "/containers/" or "/tasks/exit"; empty means all.
Topics []string
}
Filter selects events for a subscriber. Synthetic nerdui events always pass.
type Hub ¶
type Hub struct {
// Backoff between reconnect attempts.
MinBackoff, MaxBackoff time.Duration
// contains filtered or unexported fields
}
Hub distributes the events of one environment.
func NewHub ¶
func NewHub(source runtime.EventSource, logger *slog.Logger) *Hub
NewHub returns a hub for source. Call Run to start it.
func (*Hub) Connected ¶
Connected reports whether the containerd subscription is currently established.
type Recorder ¶
type Recorder struct {
Environment string
Hub *Hub
Store *store.Store
Names NameFunc
Retention time.Duration
MaxEvents int
Logger *slog.Logger
// contains filtered or unexported fields
}
Recorder stores the events of one environment for the event feed (#65, ADR-0021). It subscribes to the environment's hub, writes events in batches with the container name at the time of the event, and deletes events older than Retention or beyond MaxEvents.
type Subscription ¶
Subscription receives matching events on C. When the subscriber falls behind by more than its buffer, C is closed and Overflowed reports true: the subscriber must resync.
func (*Subscription) Close ¶
func (s *Subscription) Close()
Close unsubscribes. It is safe to call more than once.
func (*Subscription) Overflowed ¶
func (s *Subscription) Overflowed() bool
Overflowed reports whether the subscription was dropped because it fell behind.