Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotRunYet = newMarshalableError(errors.New("didn't run yet"))
)
Functions ¶
This section is empty.
Types ¶
type Check ¶ added in v0.4.0
type Check interface { // Name is the name of the check. // Check names must be metric compatible. Name() string // Execute runs a single time check, and returns an error when the check fails, and an optional details object. // The function is expected to exit as soon as the provided Context is Done. Execute(ctx context.Context) (details interface{}, err error) }
Check is the API for defining health checks. A valid check has a non empty Name() and a check (Execute()) function.
type CheckListener ¶ added in v0.1.0
type CheckListener interface { // OnCheckRegistered is called when the check with the specified name has registered. // Result argument is for reporting the first run state of the check OnCheckRegistered(name string, result Result) // OnCheckStarted is called when a check with the specified name has started OnCheckStarted(name string) // OnCheckCompleted is called when the check with the specified name has completed it's execution. // The results are passed as an argument OnCheckCompleted(name string, result Result) }
CheckListener can be used to gain check stats or log check transitions. Implementations of this interface **must not block!** If an implementation blocks, it may result in delayed execution of other health checks down the line. It's OK to log in the implementation and it's OK to add metrics, but it's not OK to run anything that takes long time to complete such as network IO etc.
type CheckListeners ¶ added in v0.3.0
type CheckListeners []CheckListener
CheckListeners is a slice of check listeners
func (CheckListeners) OnCheckCompleted ¶ added in v0.3.0
func (c CheckListeners) OnCheckCompleted(name string, result Result)
OnCheckCompleted is called when the check with the specified name has completed it's execution. The results are passed as an argument
func (CheckListeners) OnCheckRegistered ¶ added in v0.3.0
func (c CheckListeners) OnCheckRegistered(name string, result Result)
OnCheckRegistered is called when the check with the specified name has registered. Result argument is for reporting the first run state of the check
func (CheckListeners) OnCheckStarted ¶ added in v0.3.0
func (c CheckListeners) OnCheckStarted(name string)
OnCheckStarted is called when a check with the specified name has started
type CheckOption ¶ added in v0.4.0
type CheckOption interface {
// contains filtered or unexported methods
}
CheckOption configures a health check using the functional options paradigm popularized by Rob Pike and Dave Cheney. If you're unfamiliar with this style, see: - https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html - https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis. - https://sagikazarmark.hu/blog/functional-options-on-steroids/
func ExecutionTimeout ¶ added in v0.4.0
func ExecutionTimeout(d time.Duration) CheckOption
ExecutionTimeout sets the timeout of the check. It is up to the check to respect the timeout, which is provided via the Context argument of `Check.Execute` method. Defaults to no timeout
type Health ¶
type Health interface { // RegisterCheck registers a health check according to the given configuration. // Once RegisterCheck() is called, the check is scheduled to run in it's own goroutine. // Callers must make sure the checks complete at a reasonable time frame, or the next execution will delay. RegisterCheck(check Check, opts ...CheckOption) error // Deregister removes a health check from this instance, and stops it's next executions. // If the check is running while Deregister() is called, the check may complete it's current execution. // Once a check is removed, it's results are no longer returned. Deregister(name string) // Results returns a snapshot of the health checks execution results at the time of calling, and the current health. // A system is considered healthy iff all checks are passing Results() (results map[string]Result, healthy bool) // IsHealthy returns the current health of the system. // A system is considered healthy iff all checks are passing. IsHealthy() bool // DeregisterAll Deregister removes all health checks from this instance, and stops their next executions. // It is equivalent of calling Deregister() for each currently registered check. DeregisterAll() }
Health is the API for registering / deregistering health checks, and for fetching the health checks results.
type HealthListener ¶ added in v0.3.0
type HealthListeners ¶ added in v0.3.0
type HealthListeners []HealthListener
func (HealthListeners) OnResultsUpdated ¶ added in v0.3.0
func (h HealthListeners) OnResultsUpdated(results map[string]Result)
type HealthOption ¶ added in v0.4.0
type HealthOption interface {
// contains filtered or unexported methods
}
HealthOption configures a health checker using the functional options paradigm popularized by Rob Pike and Dave Cheney. If you're unfamiliar with this style, see: - https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html - https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis. - https://sagikazarmark.hu/blog/functional-options-on-steroids/
func WithCheckListeners ¶ added in v0.3.0
func WithCheckListeners(listener ...CheckListener) HealthOption
WithCheckListeners allows you to listen to check start/end events
func WithDefaults ¶ added in v0.3.0
func WithDefaults() HealthOption
WithDefaults sets all the Health object settings. It's not required to use this as no options is always default This is a simple placeholder for any future defaults
func WithHealthListeners ¶ added in v0.3.0
func WithHealthListeners(listener ...HealthListener) HealthOption
WithHealthListeners allows you to listen to overall results change
type Option ¶ added in v0.3.0
type Option interface { HealthOption CheckOption }
Option configures a health checker or a health check using the functional options paradigm popularized by Rob Pike and Dave Cheney. If you're unfamiliar with this style, see: - https://commandcenter.blogspot.com/2014/01/self-referential-functions-and-design.html - https://dave.cheney.net/2014/10/17/functional-options-for-friendly-apis. - https://sagikazarmark.hu/blog/functional-options-on-steroids/
func ExecutionPeriod ¶ added in v0.4.0
ExecutionPeriod is the period between successive executions.
func InitialDelay ¶ added in v0.4.0
InitialDelay is the time to delay first execution; defaults to zero.
func InitiallyPassing ¶ added in v0.4.0
InitiallyPassing indicates when true, the check will be treated as passing before the first run; defaults to false
type Result ¶
type Result struct { // the details of task Result - may be nil Details interface{} `json:"message,omitempty"` // the error returned from a failed health check - nil when successful Error error `json:"error,omitempty"` // the time of the last health check Timestamp time.Time `json:"timestamp"` // the execution duration of the last check Duration time.Duration `json:"duration,omitempty"` // the number of failures that occurred in a row ContiguousFailures int64 `json:"contiguousFailures"` // the time of the initial transitional failure TimeOfFirstFailure *time.Time `json:"timeOfFirstFailure"` }
Result represents the output of a health check execution.