heartbeat

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2025 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	ID          string        // unique heartbeat identifier
	Interval    time.Duration // expected interval between pings
	Description string        // human‐friendly description of this heartbeat
	Grace       time.Duration // grace period before triggering an alert
	Receivers   []string      // list of receiver IDs to notify upon alerts

	LastBump time.Time // timestamp of the last received heartbeat

	State common.HeartbeatState // current state (idle, active, grace, missing)
	// contains filtered or unexported fields
}

Actor handles a single heartbeat’s lifecycle.

func NewActor

func NewActor(
	ctx context.Context,
	id string,
	description string,
	interval, grace time.Duration,
	receivers []string,
	logger *slog.Logger,
	hist history.Store,
	dispatcher *notifier.Dispatcher,
) *Actor

NewActor constructs a new Actor, wiring in history recording and notification dispatch.

func (*Actor) Mailbox

func (a *Actor) Mailbox() chan<- common.EventType

Mailbox returns the channel on which this actor receives events.

func (*Actor) Run

func (a *Actor) Run(ctx context.Context)

Run starts the actor’s event loop, listening for pings, failures, and timer ticks.

type HeartbeatConfig

type HeartbeatConfig struct {
	ID          string        `json:"id"`
	Description string        `json:"description"`
	Interval    time.Duration `json:"interval"`
	Grace       time.Duration `json:"grace"`
	Receivers   []string      `json:"receivers"`
}

HeartbeatConfig contains heartbeat settings.

type HeartbeatConfigMap

type HeartbeatConfigMap map[string]HeartbeatConfig

HeartbeatConfigMap injects the map key as the ID field into each HeartbeatConfig during YAML unmarshalling.

func (*HeartbeatConfigMap) UnmarshalYAML

func (hcm *HeartbeatConfigMap) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML parses the map and assigns each key as the ID field of its HeartbeatConfig.

type Manager

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

Manager routes HTTP pings to Actors.

func NewManager

func NewManager(
	ctx context.Context,
	cfg map[string]HeartbeatConfig,
	dispatcher *notifier.Dispatcher,
	hist history.Store,
	logger *slog.Logger,
) *Manager

NewManager constructs and starts all Actors.

func (*Manager) Get

func (m *Manager) Get(id string) *Actor

Get returns one heartbeat’s info by ID.

func (*Manager) HandleFail

func (m *Manager) HandleFail(id string) error

HandleFail marks the Actor failed or logs unknown ID.

func (*Manager) HandleReceive

func (m *Manager) HandleReceive(id string) error

HandleReceive pings the Actor or logs unknown ID.

func (*Manager) List

func (m *Manager) List() map[string]*Actor

List returns all configured heartbeats.

Jump to

Keyboard shortcuts

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