journalview

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 13, 2026 License: AGPL-3.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EventTypeWorkloadSpec is a workload desired-state copy: initial
	// assignment at epoch zero, or an orphan reassignment with the epoch
	// incremented. Payload: workload.Spec.
	EventTypeWorkloadSpec = "workload.spec"
	// EventTypeWorkloadUnhealthy is a signal-action sickness edge.
	// Payload: workload.Unhealthy.
	EventTypeWorkloadUnhealthy = "workload.unhealthy"
	// EventTypeWorkloadInstancePrefix prefixes per-instance lifecycle
	// events (workload.instance.running, workload.instance.stopped).
	// Payload: workload.Instance.
	EventTypeWorkloadInstancePrefix = "workload.instance."
	// EventTypeNodeStarted marks a daemon boot. Payload: NodeStarted.
	EventTypeNodeStarted = "node.started"
	// EventTypePeerSeen, EventTypePeerUpdated, EventTypePeerLost track
	// membership edges observed from memberlist. Payload: PeerEvent.
	EventTypePeerSeen    = "peer.seen"
	EventTypePeerUpdated = "peer.updated"
	EventTypePeerLost    = "peer.lost"
	// EventTypePeerKeyPinned pins a node's first-seen Noise identity.
	// Payload: KeyPin.
	EventTypePeerKeyPinned = "peer.keypinned"
)

Journal event types. Every type the fleet writes is named here; no producer or view may use a bare type string. Unknown types (a newer binary's events replayed on an older one) are always recordable and never interpretable: the journal keeps their bytes, typed views skip them. Validation is shape, not completeness: missing fields decode to zero values, so additive payload evolution never breaks old readers.

Variables

This section is empty.

Functions

func Known

func Known(eventType string) bool

Known reports whether the type is a catalogued event type. The workload instance family matches by prefix; everything else by exact type.

func RebuildViews

func RebuildViews(ctx context.Context, views []View) error

RebuildViews reconstructs each view from the journal using a fresh reader per view.

func RecordEvent

func RecordEvent(ctx context.Context, j journal.Journal, views []View, event journal.Event) error

RecordEvent appends an event to the journal and applies it to every configured view. Known-type payloads are shape-checked first so producer bugs fail loudly at write time instead of diverging views silently. Unknown types always record: the journal is a complete log regardless of reader version, and typed views skip what they do not know.

func RecordEventAndLog

func RecordEventAndLog(
	ctx context.Context,
	logger *zap.Logger,
	j journal.Journal,
	views []View,
	event journal.Event,
	message string,
	fields ...zap.Field,
) error

RecordEventAndLog appends an event, applies it to views, and logs the persisted event.

func RecordKeyPin

func RecordKeyPin(ctx context.Context, j journal.Journal, views []View, selfID uuid.UUID, pin KeyPin) error

RecordKeyPin appends a peer.keypinned event and applies it to views.

func RecordNodeStarted

func RecordNodeStarted(
	ctx context.Context,
	logger *zap.Logger,
	j journal.Journal,
	views []View,
	nodeID uuid.UUID,
	memberlistAddress netip.AddrPort,
) error

RecordNodeStarted creates a node.started event and persists it.

func ValidatePayload

func ValidatePayload(eventType string, payload json.RawMessage) error

ValidatePayload checks a payload against its type's shape by decoding into the payload struct. Unknown types always validate: recordability must never depend on the reader's version. Malformed JSON fails for every type, including unknown ones.

Types

type EventsByID

type EventsByID struct {
	// contains filtered or unexported fields
}

EventsByID maintains a view of journal events indexed by event ID in key-value storage.

func NewEventsByID

func NewEventsByID(kv *kvstore.KVStore) *EventsByID

NewEventsByID creates a new EventsByID view backed by the given KVStore.

func (*EventsByID) Apply

func (e *EventsByID) Apply(ctx context.Context, event journal.Event) error

Apply updates the view by storing the given journal event indexed by its ID.

func (*EventsByID) Get

func (e *EventsByID) Get(ctx context.Context, id uuid.UUID) (*journal.Event, error)

Get retrieves a single journal event by its unique ID.

func (*EventsByID) List

func (e *EventsByID) List(ctx context.Context) ([]journal.Event, error)

List retrieves all stored journal events from the view.

func (*EventsByID) Rebuild

func (e *EventsByID) Rebuild(ctx context.Context, jr journalreader.Reader) error

Rebuild reconstructs the EventsByID view by resetting the storage bucket and replaying all journal events.

type EventsByNode

type EventsByNode struct {
	// contains filtered or unexported fields
}

EventsByNode maintains a view of journal events indexed by node ID and event ID in key-value storage.

func NewEventsByNode

func NewEventsByNode(kv *kvstore.KVStore) *EventsByNode

NewEventsByNode creates a new EventsByNode view backed by the given KVStore.

func (*EventsByNode) Apply

func (e *EventsByNode) Apply(ctx context.Context, event journal.Event) error

Apply updates the view by storing the given journal event indexed by its NodeID and ID.

func (*EventsByNode) Get

func (e *EventsByNode) Get(ctx context.Context, nodeID, id uuid.UUID) (*journal.Event, error)

Get retrieves a single journal event for a specific node ID and event ID.

func (*EventsByNode) List

func (e *EventsByNode) List(ctx context.Context, nodeID uuid.UUID) ([]journal.Event, error)

List retrieves all stored journal events for a given node ID.

func (*EventsByNode) Rebuild

func (e *EventsByNode) Rebuild(ctx context.Context, jr journalreader.Reader) error

Rebuild reconstructs the EventsByNode view by resetting the storage bucket and replaying all journal events.

type EventsByNodeKey

type EventsByNodeKey struct {
	NodeID uuid.UUID `json:"node_id"`
	ID     uuid.UUID `json:"id"`
}

EventsByNodeKey represents the lookup key for an event associated with a node.

type EventsByType

type EventsByType struct {
	// contains filtered or unexported fields
}

EventsByType maintains a view of journal events indexed by event type and event ID in key-value storage.

func NewEventsByType

func NewEventsByType(kv *kvstore.KVStore) *EventsByType

NewEventsByType creates a new EventsByType view backed by the given KVStore.

func (*EventsByType) Apply

func (e *EventsByType) Apply(ctx context.Context, event journal.Event) error

Apply updates the view by storing the given journal event indexed by its Type and ID.

func (*EventsByType) Get

func (e *EventsByType) Get(ctx context.Context, eventType string, id uuid.UUID) (*journal.Event, error)

Get retrieves a single journal event matching the specified event type and ID.

func (*EventsByType) List

func (e *EventsByType) List(ctx context.Context, eventType string) ([]journal.Event, error)

List retrieves all stored journal events of a given event type.

func (*EventsByType) Rebuild

func (e *EventsByType) Rebuild(ctx context.Context, jr journalreader.Reader) error

Rebuild reconstructs the EventsByType view by resetting the storage bucket and replaying all journal events.

type EventsByTypeKey

type EventsByTypeKey struct {
	EventType string    `json:"event_type"`
	ID        uuid.UUID `json:"id"`
}

EventsByTypeKey represents the lookup key for an event associated with an event type.

type KeyPin

type KeyPin struct {
	NodeID     uuid.UUID `json:"node_id"`
	PublicKey  []byte    `json:"public_key"`
	Generation uint64    `json:"generation"`
}

KeyPin is one pinned Noise identity: the peer's node ID, static public key, and the rotation generation the key was seen at.

type NodeStarted

type NodeStarted struct {
	MemberlistAddress string `json:"memberlist_address"`
}

NodeStarted is the payload of a node.started event.

type PeerEvent

type PeerEvent struct {
	PeerID  uuid.UUID `json:"peer_id"`
	Address string    `json:"address"`
	State   string    `json:"state"`
}

PeerEvent is the payload of peer membership edge events. Address and State stay strings so producers convert once at the edge; the catalog never imports peer packages back.

type PinnedKeys

type PinnedKeys struct {
	// contains filtered or unexported fields
}

PinnedKeys maintains first-seen Noise identities keyed by node ID.

func NewPinnedKeys

func NewPinnedKeys(kv *kvstore.KVStore) *PinnedKeys

NewPinnedKeys creates a new PinnedKeys view backed by the given KVStore.

func (*PinnedKeys) Apply

func (v *PinnedKeys) Apply(ctx context.Context, event journal.Event) error

Apply records the pin carried by a peer.keypinned event, ignoring every other event type.

func (*PinnedKeys) Get

func (v *PinnedKeys) Get(ctx context.Context, id uuid.UUID) (*KeyPin, error)

Get returns the pin stored for a node ID, or nil when nothing is pinned.

func (*PinnedKeys) Rebuild

func (v *PinnedKeys) Rebuild(ctx context.Context, jr journalreader.Reader) error

Rebuild reconstructs the PinnedKeys view by resetting the storage bucket and replaying all peer.keypinned journal events in order.

type View

type View interface {
	// Apply processes a single event to keep the view up to date.
	Apply(ctx context.Context, event journal.Event) error

	// Rebuild reconstructs the entire view by replaying the journal from scratch.
	Rebuild(ctx context.Context, jr journalreader.Reader) error
}

View represents a read-optimised projection of journal events. Views are kept in sync by applying events as they are appended to the journal.

type Workloads

type Workloads struct {
	// contains filtered or unexported fields
}

Workloads maintains a view of workload specs derived from workload.spec journal events.

func NewWorkloads

func NewWorkloads(kv *kvstore.KVStore) *Workloads

NewWorkloads creates a new Workloads view backed by the given KVStore.

func (*Workloads) Apply

func (e *Workloads) Apply(ctx context.Context, event journal.Event) error

Apply updates the view if the event is a workload.spec event, storing or updating the workload spec.

func (*Workloads) Get

func (e *Workloads) Get(ctx context.Context, id uuid.UUID) (*workload.Spec, error)

Get retrieves a workload spec by its unique ID.

func (*Workloads) List

func (e *Workloads) List(ctx context.Context) ([]workload.Spec, error)

List retrieves all stored workload specs.

func (*Workloads) Rebuild

func (e *Workloads) Rebuild(ctx context.Context, jr journalreader.Reader) error

Rebuild reconstructs the Workloads view by resetting the storage bucket and replaying all workload.spec events.

Jump to

Keyboard shortcuts

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