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 ¶
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.
const ( StateNotConfigured = integrations.HeartbeatNotConfigured StateWaiting = "waiting" StateLive = "live" StateLost = "lost" )
The Heartbeat states of an Integration (C-07.FR-3).
const AlertName = "MusterHeartbeat"
AlertName is the alertname of the always-firing rule of the snippet.
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 ¶
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.
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 (*Service) Signal ¶
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.