history

package
v0.20.0 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewHistoryMetrics added in v0.14.2

func NewHistoryMetrics(store Store) prometheus.Collector

NewHistoryMetrics returns a Prometheus collector that tracks the size of the history store.

Types

type BackendType added in v0.14.1

type BackendType string
var BackendTypeRingStore BackendType = "ring"

type Event

type Event struct {
	Timestamp   time.Time       `json:"timestamp"`         // when it happened
	Type        EventType       `json:"type"`              // what kind of event
	HeartbeatID string          `json:"heartbeat_id"`      // which heartbeat it belongs to
	Version     int             `json:"version"`           // payload schema version
	RawPayload  json.RawMessage `json:"payload,omitempty"` // optional payload
}

Event is a generic record of something that happened.

func ListByType added in v0.20.0

func ListByType(store Store, t EventType) []Event

ListByType returns events matching the given type.

func ListRecent added in v0.20.0

func ListRecent(store Store, limit int) []Event

ListRecent returns events sorted newest-first. If limit <= 0, returns all.

func MustNewEvent added in v0.14.1

func MustNewEvent(t EventType, id string, payload any) Event

MustNewEvent creates a new Event or panics if payload marshalling fails.

func NewEvent added in v0.14.1

func NewEvent(t EventType, id string, payload any) (Event, error)

NewEvent creates a new Event with optional payload.

func (*Event) ToJSON added in v0.14.1

func (e *Event) ToJSON() string

ToJSON returns the raw payload as a JSON string.

type EventType

type EventType string

EventType categorizes what happened.

const (
	EventTypeHeartbeatReceived  EventType = "HeartbeatReceived"  // a ping from a client
	EventTypeHeartbeatFailed    EventType = "HeartbeatFailed"    // a manual failure
	EventTypeStateChanged       EventType = "StateChanged"       // state transition of an actor
	EventTypeNotificationSent   EventType = "NotificationSent"   // a notification was sent
	EventTypeNotificationFailed EventType = "NotificationFailed" // a notification failed
)

func (EventType) String

func (h EventType) String() string

String returns the EventType as string.

type MockStore added in v0.14.1

type MockStore struct {
	RecordEventFunc   func(context.Context, Event) error
	GetEventsFunc     func() []Event
	GetEventsByIDFunc func(string) []Event
	ByteSizeFunc      func() int
}

func (*MockStore) Append added in v0.15.1

func (m *MockStore) Append(ctx context.Context, e Event) error

func (*MockStore) ByteSize added in v0.14.2

func (m *MockStore) ByteSize() int

func (*MockStore) List added in v0.15.1

func (m *MockStore) List() []Event

func (*MockStore) ListByID added in v0.15.1

func (m *MockStore) ListByID(id string) []Event

type NotificationPayload added in v0.14.1

type NotificationPayload struct {
	Receiver string `json:"receiver"`        // receiver ID
	Type     string `json:"type"`            // notifier type (e.g., slack, msteams)
	Target   string `json:"target"`          // target destination
	Error    string `json:"error,omitempty"` // optional error message
}

NotificationPayload is used for NotificationSent and NotificationFailed events.

type RequestMetadataPayload added in v0.14.1

type RequestMetadataPayload struct {
	Source    string `json:"source"`     // remote IP address
	Method    string `json:"method"`     // HTTP method
	UserAgent string `json:"user_agent"` // user-agent header
}

RequestMetadataPayload is used for HeartbeatReceived and HeartbeatFailed events.

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) Append added in v0.15.1

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

Append appends a new event into the ring.

func (*RingStore) ByteSize added in v0.14.2

func (r *RingStore) ByteSize() int

ByteSize returns an estimated size of the ring buffer in bytes.

func (*RingStore) List added in v0.15.1

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

List 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) ListByID added in v0.15.1

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

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

type StateChangePayload added in v0.14.1

type StateChangePayload struct {
	From string `json:"from"` // previous state
	To   string `json:"to"`   // new state
}

StateChangePayload is used for StateChanged events.

type Store

type Store interface {
	Append(ctx context.Context, e Event) error // Append appends a new event to history.
	List() []Event                             // List returns a snapshot of all recorded events.
	ListByID(id string) []Event                // ListByID returns all events recorded for the specified heartbeat ID.
	ByteSize() int                             // ByteSize returns the current size of the history store in bytes.
}

Store records and exposes all system events.

func InitializeHistory added in v0.14.1

func InitializeHistory(size int) (Store, error)

InitializeHistory initializes a new history store.

Jump to

Keyboard shortcuts

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