heartbeat

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package heartbeat holds the Heartbeat of C-07: the endpoint on the ingest listener that records the signals of an Integration's Alertmanager, the four Heartbeat states, the liveness clock that the signals advance, and the Leader's Heartbeat check that makes a silent Integration Heartbeat lost and raises MusterHeartbeatLost. The Heartbeat settings themselves are part of the Integration (internal/integrations); the Stale scan, which counts only the time the liveness clock covers, is processing's (internal/ingest).

Index

Constants

View Source
const (
	RouteHeader = integrations.HeartbeatPath
	RoutePath   = integrations.HeartbeatPath + "/{ingest_token}"
)

The routes of the Heartbeat endpoint, as log lines name them: never the path, which may carry the token.

View Source
const (
	StateNotConfigured = integrations.HeartbeatNotConfigured
	StateWaiting       = "waiting"
	StateLive          = "live"
	StateLost          = "lost"
)

The Heartbeat states of an Integration (C-07.FR-3).

View Source
const AlertName = "MusterHeartbeat"

AlertName is the alertname of the always-firing rule of the snippet.

View Source
const RepeatInterval = time.Minute

RepeatInterval is snippet.heartbeat_repeat_interval: the repeat_interval of the Heartbeat route, so that Alertmanager sends the always-firing alert about once a minute.

Variables

This section is empty.

Functions

func NewHandler

func NewHandler(cfg HandlerConfig) http.Handler

NewHandler is the Heartbeat endpoint of the ingest listener (C-07.FR-1): GET and POST on /api/v1/heartbeat with the token as Authorization: Bearer, and on /api/v1/heartbeat/{ingest_token} with the token in the path; HEAD is served as GET, as net/http does. Any other request under it answers 404, as the API answers a path or a method it has no operation for.

func Snippet

func Snippet(integrationName, heartbeatURL, token string) string

Snippet is the Heartbeat configuration of an Integration token (C-07.FR-6): a Prometheus rule MusterHeartbeat that always fires, with the note that kube-prometheus-stack's Watchdog serves instead; an Alertmanager child route for it with continue, group_wait 0s, group_interval 1m and snippet.heartbeat_repeat_interval; and a receiver whose webhook sends it, without resolves, to the Heartbeat URL with the token as a bearer token.

Types

type Authenticator

type Authenticator interface {
	Authenticate(ctx context.Context, value string) (integrations.Caller, error)
}

Authenticator finds the Integration of a signal by its token: internal/integrations.

type Checker

type Checker struct {
	Store Store
	// Business is the business clock, which the signals are recorded on.
	Business clock.Clock
	Log      *logging.Logger
	// RunbookBase is MUSTER_RUNBOOK_BASE_URL.
	RunbookBase string
	// contains filtered or unexported fields
}

Checker is the Leader's Heartbeat check (C-07.FR-4, C-07.FR-8): a live Integration whose last signal is older than its timeout becomes Heartbeat lost and raises MusterHeartbeatLost, and muster_heartbeat_lost follows the states. The check is safe to run twice and beside another Leader's: each change locks the Integration and checks again.

func (*Checker) Check

func (c *Checker) Check(ctx context.Context, orgs []int64) error

Check runs the Heartbeat check in every Organization of orgs at the same now. A failed Organization does not stop the others.

type Config

type Config struct {
	OrgID int64
	Store Store
	// Business is the business clock: the times of the signals and the timeouts follow it, and so the development
	// clock.
	Business clock.Clock
	Log      *logging.Logger
	// RunbookBase is MUSTER_RUNBOOK_BASE_URL, the base of the runbook_url of MusterHeartbeatLost.
	RunbookBase string
}

Config is what a Service needs.

type HandlerConfig

type HandlerConfig struct {
	Auth    Authenticator
	Signals Signaler
	Log     *logging.Logger
	// TrustedProxies are MUSTER_TRUSTED_PROXIES, for the client address of a refused request.
	TrustedProxies []netip.Prefix
	// BodyLimit is ingest.body_limit, how much of a body is read and discarded; zero takes ingest.BodyLimit.
	BodyLimit int64
}

HandlerConfig is what the Heartbeat handler serves with.

type Queries

type Queries interface {
	LockHeartbeat(ctx context.Context, arg dbgen.LockHeartbeatParams) (dbgen.LockHeartbeatRow, error)
	RecordSignal(ctx context.Context, arg dbgen.RecordSignalParams) error
	MarkLost(ctx context.Context, arg dbgen.MarkLostParams) error
	ListOverdue(ctx context.Context, arg dbgen.ListOverdueParams) ([]int64, error)
	ListHeartbeats(ctx context.Context, orgID int64) ([]dbgen.ListHeartbeatsRow, error)
	GetLeaderStart(ctx context.Context) (dbgen.GetLeaderStartRow, error)
	internalalerts.Store
	Notify(ctx context.Context, h db.Hint) error
}

Queries are the queries of the package, with those that raise and resolve Internal alerts and the live hint.

type Service

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

Service records the Heartbeat signals of the Integrations of an Organization.

func New

func New(cfg Config) *Service

New returns the Service of the Organization in cfg.

func (*Service) Signal

func (s *Service) Signal(ctx context.Context, integrationID int64) error

Signal records a Heartbeat signal of the Integration integrationID, which its token named (C-07.FR-1), in one short transaction that locks the Integration. An Integration whose Heartbeat is off records nothing, so that turning the Heartbeat on later starts from waiting; a deleted one, or the built-in one, records nothing either. A signal that makes the Heartbeat live sends the live hint integration and is logged, and one that ends a loss resolves MusterHeartbeatLost in the same transaction.

type Signaler

type Signaler interface {
	Signal(ctx context.Context, integrationID int64) error
}

Signaler records a signal of an Integration: the Service.

type Store

type Store interface {
	Queries
	InTx(ctx context.Context, f func(Queries) error) error
}

Store runs the queries alone or in one transaction.

func NewStore

func NewStore(pool *pgxpool.Pool) Store

NewStore is the Store over the main pool.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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