Documentation
¶
Overview ¶
Package healthz provides tools for service health checks
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrCheckFailed = errors.New("Check failed")
ErrCheckFailed is a generic error returned when a check fails
Functions ¶
Types ¶
type AlwaysFailureChecker ¶ added in v0.4.0
type AlwaysFailureChecker struct{}
AlwaysFailureChecker always returns failure as the check result
func (*AlwaysFailureChecker) Check ¶ added in v0.4.0
func (c *AlwaysFailureChecker) Check() error
Check implements the Checker interface
type AlwaysSuccessChecker ¶ added in v0.4.0
type AlwaysSuccessChecker struct{}
AlwaysSuccessChecker always returns success as the check result
func (*AlwaysSuccessChecker) Check ¶ added in v0.4.0
func (c *AlwaysSuccessChecker) Check() error
Check implements the Checker interface
type CheckFunc ¶ added in v0.4.0
type CheckFunc func() error
CheckFunc is a convenience type to create functions that implement the Checker interface
type Checker ¶ added in v0.4.0
type Checker interface {
// Returns nil if the check passes
Check() error
}
Checker is the interface for checking different resources
type Checkers ¶ added in v0.4.0
type Checkers struct {
// contains filtered or unexported fields
}
Checkers is a Checker collection responsible for executing a series of checks and decide if the resource is up or not
func NewCheckers ¶ added in v0.4.0
NewCheckers is a shortcut for easily creating a new Checker collection
type HTTPChecker ¶ added in v0.4.0
type HTTPChecker struct {
// contains filtered or unexported fields
}
HTTPChecker checks if an HTTP endpoint is available
func NewHTTPChecker ¶ added in v0.4.0
func NewHTTPChecker(url string) *HTTPChecker
NewHTTPChecker creates a new HTTPChecker with a URL
func (*HTTPChecker) Check ¶ added in v0.4.0
func (c *HTTPChecker) Check() error
Check implements the Checker interface and checks the HTTP endpoint status
type HealthService ¶
type HealthService struct {
// contains filtered or unexported fields
}
HealthService wraps two Checkers and exposes them as HTTP handlers
func NewHealthService ¶
func NewHealthService(livenessChecker Checker, readinessChecker Checker) *HealthService
NewHealthService creates a new HealthService from user configured Checkers
func (*HealthService) HealthStatus ¶
func (s *HealthService) HealthStatus(w http.ResponseWriter, r *http.Request)
HealthStatus checks if the application is healthy
func (*HealthService) ReadinessStatus ¶
func (s *HealthService) ReadinessStatus(w http.ResponseWriter, r *http.Request)
ReadinessStatus checks if the app is ready for accepting request (eg. database is available as well)
type PingChecker ¶ added in v0.5.0
type PingChecker struct {
// contains filtered or unexported fields
}
PingChecker checks if a database is available through builtin database/sql
func NewPingChecker ¶ added in v0.5.0
func NewPingChecker(pinger Pinger) *PingChecker
NewPingChecker creates a new PingChecker with a DB connection
func (*PingChecker) Check ¶ added in v0.5.0
func (c *PingChecker) Check() error
Check implements the Checker interface and checks the database status by pinging it
type Pinger ¶ added in v0.5.0
type Pinger interface {
Ping() error
}
Pinger is a commonly used interface to check if a connection is alive (used in sql.DB for example)
type StatusChecker ¶ added in v0.4.0
type StatusChecker struct {
// contains filtered or unexported fields
}
StatusChecker checks the status based on an internal state
func NewStatusChecker ¶ added in v0.4.0
func NewStatusChecker(status Status) *StatusChecker
NewStatusChecker creates a new StatusChecker with an initial state
func (*StatusChecker) Check ¶ added in v0.4.0
func (c *StatusChecker) Check() error
Check implements the Checker interface and checks the internal state Returns an error if the state is false
func (*StatusChecker) SetStatus ¶ added in v0.4.0
func (c *StatusChecker) SetStatus(status Status)
SetStatus sets the internal state