Documentation ¶
Overview ¶
Package checker provides controllers that call health checks and manage the state associated with them.
It's built to be compatible with the check package, which provides the actual implementations of the health checks.
The controllers in this package are composable, with roughly the following usual pattern:
* `Periodic` - runs a health check periodically * `Stateful` - runs a health check periodically and keeps track of the state, this uses `Periodic` internally. * `StatefulMulti` - combines multiple stateful health checks, this uses `Stateful` internally. * `Server` - checks the health of a server's public interfaces, this uses `StatefulMulti` internally.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Check ¶
type Check[ResultType Result] interface { // Check runs the health check and returns the result. Check(ctx context.Context) ResultType // Config returns the configuration of the health check. Config() cfgmodel.HealthCheckConfig }
Check is a common interface for health checks.
type Result ¶
type Result interface { // Healthy returns true if the check is healthy. Healthy() bool }
Result is the result of a health check.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server checks the health of a server's public interfaces.
func NewServerChecker ¶
func NewServerChecker( cfgs []cfgmodel.HealthCheckConfig, serverWithStatus *resource.WithStatus[resource.Server], ) *Server
NewServerChecker creates a new server checker.
func (*Server) Start ¶
func (c *Server) Start(ctx context.Context, onUpdate chan<- ServerCheckUpdate)
Start periodic checks of the server's health, changing the server's status accordingly. This function blocks until the context is cancelled. The caller is responsible for closing the onUpdate channel.
type ServerCheckUpdate ¶
type ServerCheckUpdate struct { PreviousServerState resource.State ServerState resource.State ServerStateChanged bool // The server that was checked. Server *resource.Server // The result of the check. Result StatefulMultiUpdate[check.HTTPCheckResult] }
ServerCheckUpdate is an update to a server's health check.
func (ServerCheckUpdate) UnhealthyChecks ¶
func (u ServerCheckUpdate) UnhealthyChecks() []check.HTTPCheckResult
UnhealthyChecks returns the current unhealthy checks.
type State ¶
type State string
State is the state of a health check.
const ( // StateUnknown is the initial state of a health check. StateUnknown State = "unknown" // StateHealthy means past health checks indicate the service should be considered healthy. StateHealthy State = "healthy" // StateUnhealthy means past health checks indicate the service should be considered unhealthy. StateUnhealthy State = "unhealthy" )
Possible states of a health check.
type Stateful ¶
type Stateful[ResultType Result] struct { // contains filtered or unexported fields }
Stateful is a health checker that runs periodically and carries internal state between checks.
func (*Stateful[ResultType]) Start ¶
func (c *Stateful[ResultType]) Start(ctx context.Context, updateChan chan<- StatefulUpdate[ResultType])
Start the stateful health check. It will run the check every interval until the context is cancelled. The index can be used to identify this check in a multi-check setup (which is the most common use case for this). The caller is responsible for closing the update channel.
type StatefulMulti ¶
type StatefulMulti[ResultType Result] struct { // contains filtered or unexported fields }
StatefulMulti is a health checker that combines multiple stateful health checks. These checks can run in parallel, even at different intervals. The state of the multi check is the worst state of all the checks.
func NewStatefulMultiCheck ¶
func NewStatefulMultiCheck[ResultType Result]( checks []Check[ResultType], ) *StatefulMulti[ResultType]
NewStatefulMultiCheck creates a new stateful multi check.
func (*StatefulMulti[ResultType]) Start ¶
func (c *StatefulMulti[ResultType]) Start( ctx context.Context, updateChan chan<- StatefulMultiUpdate[ResultType], )
Start the stateful multi check. It will run the checks until the context is cancelled. It will send updates to the update channel on every individual check update.
type StatefulMultiUpdate ¶
type StatefulMultiUpdate[ResultType Result] struct { // HealthState is the current state of the multi check. // This will be the worst state of all the checks. HealthState State // contains filtered or unexported fields }
StatefulMultiUpdate is an update from a stateful multi check.
func (StatefulMultiUpdate[ResultType]) LastUpdate ¶
func (u StatefulMultiUpdate[ResultType]) LastUpdate() StatefulUpdate[ResultType]
LastUpdate returns the last update of the multi check.
func (StatefulMultiUpdate[ResultType]) UnhealthyChecks ¶
func (u StatefulMultiUpdate[ResultType]) UnhealthyChecks() []ResultType
UnhealthyChecks returns the current unhealthy checks.
type StatefulUpdate ¶
type StatefulUpdate[ResultType Result] struct { ResultType ResultType // Timestamp is the time when the check was started. Timestamp time.Time // Duration is the time it took to run the check. Duration time.Duration // State is the state of the health check. State State // ID is the check ID that the update is for. ID string // Rise is the number of consecutive health checks that were successful. Rise uint64 // Fall is the number of consecutive health checks that failed. Fall uint64 }
StatefulUpdate is an update from stateful health checker.