live

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package live provides realtime dashboard event fan-out: every event this process publishes, plus, in a multi-replica deployment, the audit and usage rows its peers persist (see StartRemote).

Index

Constants

View Source
const (
	EventAuditStarted   = auditlog.LiveEventAuditStarted
	EventAuditUpdated   = auditlog.LiveEventAuditUpdated
	EventAuditStream    = auditlog.LiveEventAuditStream
	EventAuditCompleted = auditlog.LiveEventAuditCompleted
	EventAuditFailed    = auditlog.LiveEventAuditFailed
	EventAuditFlushed   = auditlog.LiveEventAuditFlushed
	EventAuditRemoved   = auditlog.LiveEventAuditRemoved
	EventUsageCompleted = usage.LiveEventUsageCompleted
	EventUsageFailed    = usage.LiveEventUsageFailed
	EventUsageFlushed   = usage.LiveEventUsageFlushed
	EventHeartbeat      = "heartbeat"
	EventReset          = "reset"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Broker

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

Broker stores a bounded replay window and fans live events out to subscribers.

func NewBroker

func NewBroker(cfg Config) *Broker

NewBroker creates a live event broker. A disabled broker is safe to use.

func (*Broker) Close

func (b *Broker) Close()

Close terminates all active subscribers and prevents future live events.

func (*Broker) Enabled

func (b *Broker) Enabled() bool

Enabled reports whether this broker should accept dashboard subscriptions.

func (*Broker) HasLiveSubscribers

func (b *Broker) HasLiveSubscribers() bool

HasLiveSubscribers reports whether any dashboard stream is currently connected. Publishers of high-frequency preview events use it to skip building payloads nobody would receive.

func (*Broker) Heartbeat

func (b *Broker) Heartbeat() time.Duration

Heartbeat returns the stream heartbeat interval.

func (*Broker) LatestSeq

func (b *Broker) LatestSeq() uint64

LatestSeq returns the newest assigned stream sequence.

func (*Broker) PublishAuditEvent

func (b *Broker) PublishAuditEvent(eventType string, entry *auditlog.LogEntry)

PublishAuditEvent publishes a compact audit log preview event. Connected subscribers receive the full preview, including any captured bodies; the copy retained for replay strips bodies (flagging them as captured so the dashboard hydrates them from the persisted entry) and is size-capped, so broker retention stays bounded regardless of request size.

The full preview is encoded only while someone is subscribed. Bodies are the bulk of the payload, and with no dashboard open (the common case) nobody would read them. A subscriber that connects between that check and the publish receives the retained copy, which is what replay gives it anyway.

func (*Broker) PublishRemoteAuditEntry added in v0.2.2

func (b *Broker) PublishRemoteAuditEntry(entry *auditlog.EntryPreview, writtenAt int64)

PublishRemoteAuditEntry publishes an audit entry another replica persisted, as the audit.flushed event that replica's own dashboards received, marked with its write stamp. The preview carries no bodies, only whether each was captured, so remote traffic costs the stream only the compact preview; the dashboard loads them from the stored entry.

func (*Broker) PublishRemoteUsageEntry added in v0.2.2

func (b *Broker) PublishRemoteUsageEntry(entry usage.UsageLogEntry, writtenAt int64)

PublishRemoteUsageEntry publishes a usage entry another replica persisted, as the usage.flushed event that replica's own dashboards received, marked with its write stamp.

func (*Broker) PublishUsageEvent

func (b *Broker) PublishUsageEvent(eventType string, entry *usage.UsageEntry)

PublishUsageEvent publishes a compact usage log event. Cached usage entries are broadcast like any other so the dashboard can choose to surface or hide them via the "Hide cached requests" toggle on the Usage page.

func (*Broker) StartRemote added in v0.2.2

func (b *Broker) StartRemote(cfg RemoteConfig)

StartRemote starts publishing the audit and usage entries other replicas persist, polling while at least one subscriber is connected. Close stops it. It does nothing on a disabled or closed broker, without a reader, or when already started.

func (*Broker) Subscribe

func (b *Broker) Subscribe(cursor uint64) *Subscription

Subscribe registers a client and returns replay events after cursor.

type Config

type Config struct {
	Enabled          bool
	BufferSize       int
	ReplayLimit      int
	SubscriberBuffer int
	Heartbeat        time.Duration
}

Config controls the in-process live event broker.

type Event

type Event struct {
	Seq       uint64          `json:"seq"`
	Type      string          `json:"type"`
	RequestID string          `json:"request_id,omitempty"`
	Timestamp time.Time       `json:"timestamp"`
	Data      json.RawMessage `json:"data,omitempty"`
}

Event is the stable envelope sent over the live dashboard stream.

type RemoteConfig added in v0.2.2

type RemoteConfig struct {
	// Writer is this process's writer id (storage.WriterID): entries it
	// stamped were already published live and are skipped.
	Writer string
	// Audit and Usage read the stamped entries. Either may be nil.
	Audit auditlog.RecentWriteReader
	Usage usage.RecentWriteReader
}

RemoteConfig names the persisted traffic StartRemote publishes.

type Subscription

type Subscription struct {
	Replay []Event
	Events <-chan Event
	Reset  bool
	// Latest is the newest sequence assigned when the subscription was
	// created, captured atomically with Replay: replay never goes past it,
	// and anything newer arrives on Events. Streams start their heartbeat
	// cursor from it — the broker-global counter read later can already
	// cover events still queued on Events, and advertising those would let
	// a reconnecting client skip them.
	Latest uint64
	// contains filtered or unexported fields
}

Subscription is one live stream consumer.

func (*Subscription) Close

func (s *Subscription) Close()

Close unregisters the subscription.

Jump to

Keyboard shortcuts

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