live

package
v0.1.61 Latest Latest
Warning

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

Go to latest
Published: Jul 26, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package live provides in-process realtime dashboard event fan-out.

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.

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) 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 Subscription

type Subscription struct {
	Replay []Event
	Events <-chan Event
	Reset  bool
	// 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