events

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: AGPL-3.0 Imports: 9 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 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

View Source
const (
	KindNerdui         = "nerdui"
	ActionConnected    = "connected"
	ActionDisconnected = "disconnected"
	TopicConnected     = "/nerdui/connected"
	TopicDisconnected  = "/nerdui/disconnected"
)

Synthetic events.

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

func (Filter) Match

func (f Filter) Match(ev runtime.Event) bool

Match reports whether ev passes the filter.

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

func (h *Hub) Connected() bool

Connected reports whether the containerd subscription is currently established.

func (*Hub) Run

func (h *Hub) Run(ctx context.Context)

Run maintains the containerd subscription until ctx ends, then closes all subscriptions.

func (*Hub) Subscribe

func (h *Hub) Subscribe(f Filter, buffer int) *Subscription

Subscribe registers a subscriber with a buffer of size buffer (default 256). The first event delivered is the current connection state ("connected" or "disconnected").

type NameFunc

type NameFunc func(ctx context.Context, namespace, id string) string

NameFunc resolves the name of a container; "" when unknown.

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.

func (*Recorder) Run

func (r *Recorder) Run(ctx context.Context)

Run records until ctx ends.

type Subscription

type Subscription struct {
	C <-chan runtime.Event
	// contains filtered or unexported fields
}

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.

Jump to

Keyboard shortcuts

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