Documentation ¶
Index ¶
Constants ¶
View Source
const (
// ValAllChecks is the value used for the check tags when tagging all tests
ValAllChecks = "all_checks"
)
Variables ¶
View Source
var ( // ViewCheckExecutionTime is the checks execution time aggregation tagged by check name ViewCheckExecutionTime = &view.View{ Measure: mCheckDuration, TagKeys: []tag.Key{keyCheck}, Aggregation: view.Distribution(0, 1, 2, 3, 4, 6, 8, 10, 13, 16, 20, 25, 30, 40, 50, 65, 80, 100, 120, 160, 200, 250, 300, 500), } // ViewCheckCountByNameAndStatus is the checks execution count aggregation grouped by check name, and check status ViewCheckCountByNameAndStatus = &view.View{ Name: "health/check_count_by_name_and_status", Measure: mCheckStatus, TagKeys: []tag.Key{keyCheck, keyCheckPassing}, Aggregation: view.Count(), } // ViewCheckStatusByName is the checks status aggregation tagged by check name ViewCheckStatusByName = &view.View{ Name: "health/check_status_by_name", Measure: mCheckStatus, TagKeys: []tag.Key{keyCheck}, Aggregation: view.LastValue(), } // DefaultHealthViews are the default health check views provided by this package. DefaultHealthViews = []*view.View{ ViewCheckCountByNameAndStatus, ViewCheckStatusByName, ViewCheckExecutionTime, } )
Functions ¶
This section is empty.
Types ¶
type CheckListener ¶
type CheckListener interface { // 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 Config ¶
type Config struct { // Check is the health Check to be scheduled for execution. Check checks.Check // CheckListener is the listener to result of check and will call after check execution. Listener CheckListener // ExecutionPeriod is the period between successive executions. ExecutionPeriod time.Duration // InitialDelay is the time to delay first execution; defaults to zero. InitialDelay time.Duration // InitiallyPassing indicates when true, the check will be treated as passing before the first run; defaults to false InitiallyPassing bool }
Config defines a health Check and it's scheduling timing requirements.
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(cfg *Config) 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 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.
Click to show internal directories.
Click to hide internal directories.