history

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2025 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Event

type Event struct {
	Timestamp   time.Time // when it happened
	Type        EventType // what kind of event
	HeartbeatID string    // which heartbeat this belongs to
	Source      string    // e.g. remote address
	Method      string    // HTTP method, if relevant
	UserAgent   string    // user-agent, if relevant
	PrevState   string    // prior state (for state changes)
	NewState    string    // new state (for state changes)
	Payload     any       // payload for notification events
}

Event is a generic record of something that happened.

type EventType

type EventType string

EventType categorizes what happened.

const (
	EventTypeHeartbeatReceived  EventType = "HeartbeatReceived"  // EventTypeHeartbeatReceived is a ping from a client.
	EventTypeHeartbeatFailed    EventType = "HeartbeatFailed"    // EventTypeHeartbeatFailed is a manual failure.
	EventTypeStateChanged       EventType = "StateChanged"       // EventTypeStateChanged is when an Actor’s state changes.
	EventTypeNotificationSent   EventType = "NotificationSent"   // EventTypeNotificationSent is when a notification is dispatched.
	EventTypeNotificationFailed EventType = "NotificationFailed" // EventTypeNotificationFailed is when a notification fails to dispatch.
)

func (EventType) String

func (h EventType) String() string

String returns the EventType as string.

type RingStore

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

RingStore is a fixed-size circular buffer of history.Event. When full, new events overwrite the oldest one.

func NewRingStore

func NewRingStore(maxEvents int) *RingStore

NewRingStore returns a RingStore that holds at most maxEvents.

func (*RingStore) GetEvents

func (r *RingStore) GetEvents() []Event

GetEvents returns all events oldest-first. If the buffer has never wrapped, that's just buf[:next]. Once wrapped, we stitch buf[next:] before buf[:next].

func (*RingStore) GetEventsByID

func (r *RingStore) GetEventsByID(id string) []Event

GetEventsByID returns only those events for the given heartbeat ID, still in chronological (oldest-first) order.

func (*RingStore) RecordEvent

func (r *RingStore) RecordEvent(_ context.Context, e Event) error

RecordEvent appends a new event into the ring.

type Store

type Store interface {
	// RecordEvent appends a new event to history.
	RecordEvent(ctx context.Context, e Event) error
	// GetEvents returns a snapshot of all recorded events.
	GetEvents() []Event
	// GetEventsByID returns all events recorded for the specified heartbeat ID.
	GetEventsByID(id string) []Event
}

Store records and exposes all system events.

Jump to

Keyboard shortcuts

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