Documentation ¶
Index ¶
- Constants
- func ComputeStatusCode(info bool, s Summary) int
- func WrapServeMux(mux *http.ServeMux, appname string, provided DependencySet, ...)
- type BasicDependencySet
- type Component
- type Components
- type DependencySet
- type Health
- type HealthChecker
- type HealthMonitor
- type HealthStatus
- type HealthTracker
- type Info
- type InfoResult
- type Message
- type Monitor
- func NewMonitor(name, description, docURL string, urgency Urgency, check HealthChecker, ...) *Monitor
- func NewMonitorWithOptions(name, description, docURL string, urgency Urgency, check HealthChecker, ...) *Monitor
- func TransitiveMonitor(url, name, description, wikipage string, urgency Urgency, ...) *Monitor
- func (m *Monitor) Check(ctx context.Context) Health
- func (m *Monitor) Description() string
- func (m *Monitor) Documentation() string
- func (m *Monitor) Failed() int
- func (m *Monitor) LastOk() time.Time
- func (m *Monitor) Name() string
- func (m *Monitor) Period() time.Duration
- func (m *Monitor) Timeout() time.Duration
- func (m *Monitor) Urgency() Urgency
- type MonitorOption
- type Private
- type PrivateResult
- type Result
- type Status
- type Summary
- type Urgency
Constants ¶
const ( InfoHealthCheck = `/info/healthcheck` InfoHealthCheckLive = `/info/healthcheck/live` )
Paths to info healthchecks.
const ( PrivateHealthCheck = `/private/healthcheck` PrivateHealthCheckLive = `/private/healthcheck/live` )
The exposed endpoints for private healthchecks.
Variables ¶
This section is empty.
Functions ¶
func ComputeStatusCode ¶
ComputeStatusCode returns the HTTP status code representative of the status. The public info endpoints return HTTP 500 internal server error if the component is in outage. Otherwise, any lessor status returns HTTP 200 ok. The private endpoints conversely return a HTTP 200 ok if and only if the overall state is ok. Any unhealthy state will return an HTTP 500 internal server error.
func WrapServeMux ¶
func WrapServeMux( mux *http.ServeMux, appname string, provided DependencySet, additional ...HealthMonitor, )
WrapServeMux will wrap mux with Handlers for
- /private/healthcheck
- /private/healthcheck/live
- /info/healthcheck
- /info/healthcheck/live
Types ¶
type BasicDependencySet ¶
type BasicDependencySet struct {
// contains filtered or unexported fields
}
BasicDependencySet is the standard implementation of DependancySet that behaves the way you would expect. HealthMonitors are registered to a DependencySet instance, and then you can call Live() or Background() on that instance. Live() will cause all of the HealthMonitors to call their Check() methods, whereas Background() will retrieve the cached Health of that health check.
func NewBasicDependencySet ¶
func NewBasicDependencySet(monitors ...HealthMonitor) *BasicDependencySet
NewBasicDependencySet will create a new BasicDependencySet instance and register all of the provided HealthMonitor instances.
func NewBasicDependencySetWithContext ¶
func NewBasicDependencySetWithContext(ctx context.Context, monitors ...HealthMonitor) *BasicDependencySet
NewBasicDependencySet will create a new BasicDependencySet instance using a specific context and register all of the provided HealthMonitor instances.
func (*BasicDependencySet) Background ¶
func (d *BasicDependencySet) Background() Summary
Background will retrieve the cached Health for each of the registered HealthChecker instances.
func (*BasicDependencySet) Live ¶
func (d *BasicDependencySet) Live() Summary
Live will force all of the HealthChecker instances to execute their Check methods, and will update all cached Health as well.
func (*BasicDependencySet) Register ¶
func (d *BasicDependencySet) Register(monitors ...HealthMonitor)
Register will register all of the provided HealthMonitor instances. HealthMonitors which have a 0 value Timeout will NOT be executed on Register(). They will only be executed on calls to Live(). This is important, because it means such a checker will be set to OUTAGE if only Background() is ever called.
type Component ¶
type Component struct { Timestamp int64 `json:"timestamp"` DocURL string `json:"documentationUrl"` Urgency string `json:"urgency"` Description string `json:"description"` State string `json:"status"` Message string `json:"errorMessage"` Duration int64 `json:"duration"` LastGood int64 `json:"lastKnownGoodTimestamp"` Period int64 `json:"period"` ID string `json:"id"` Date string `json:"date"` }
A Component is the healthcheck status of one component in a /private/healthcheck result.
type Components ¶
type Components struct { Outage []Component `json:"OUTAGE,omitempty"` Major []Component `json:"MAJOR,omitempty"` Minor []Component `json:"MINOR,omitempty"` Ok []Component `json:"OK,omitempty"` }
Components of a particular Status. We list them explicitly so that during json encoding they are ordered.
type DependencySet ¶
type DependencySet interface { Register(monitors ...HealthMonitor) Background() Summary Live() Summary }
DependencySet is an interface which can be used to represent a set of HealthChecker instances. These HealthChecker instances are used to determine the healthiness of a service.
type Health ¶
Health is a representation of the health of a service at a moment in time. It is composed of a Status, an Urgency, a Time, and a Message. Once created it should not be modified.
type HealthChecker ¶
HealthChecker is a func that you provide which checks the status of something's health.
type HealthMonitor ¶
type HealthMonitor interface { // Name provides a unique name for the healthcheck. Name() string // Check is the function representing the work of a health check. Check(ctx context.Context) Health // Timeout is how long Check gets to run before defaulting to OUTAGE. Timeout() time.Duration // Period is how often Check should run. Period() time.Duration // Description is an informative string about what the healthcheck does. Description() string // Documentation is a url link that documents additional information about the healthcheck. Documentation() string // Urgency is how important this service. Urgency() Urgency // LastOk is the time when this healthcheck was last OK. LastOk() time.Time // Failed is the number of consecutive healthcheck failures. Returns zero when the healthcheck is OK. Failed() int }
HealthMonitor is an interface that should be implemented for every custom type of health check you need. These can then be added to a DependencySet and used in Live and Background version of Info and Private healthchecks.
type HealthStatus ¶
type HealthStatus struct { Monitor HealthMonitor Prev Status Next Health }
type HealthTracker ¶
type HealthTracker interface { DependencySet() DependencySet // implemented by your app RegisterDependencies(DependencySet) // implemented by libhealth }
HealthTracker is the interface a framework that takes care of managing a HealthServer should satisfy so that it can register dependencies defined by the thing the framework is running.
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info is an http.Handler for
/info/healthcheck /info/healthcheck/live.
func NewInfo ¶
func NewInfo(d DependencySet) *Info
NewInfo will create a new Info handler for a given DependencySet set.
type InfoResult ¶
type InfoResult struct { Condition string `json:"condition"` Hostname string `json:"hostname"` Duration int64 `json:"duration"` }
InfoResult represents the body of an info healthcheck.
type Message ¶
type Message string
Message is a string with some useful information regarding a Health.
type Monitor ¶
type Monitor struct {
// contains filtered or unexported fields
}
Monitor is the standard implementation of HealthChecker.
func NewMonitor ¶
func NewMonitor( name, description, docURL string, urgency Urgency, check HealthChecker, statusChan chan HealthStatus, ) *Monitor
NewMonitor will create a new monitor and set some defaults. If desired, pass in a channel and it will be published to when the health state of the monitor changes.
func NewMonitorWithOptions ¶
func NewMonitorWithOptions( name, description, docURL string, urgency Urgency, check HealthChecker, options ...MonitorOption, ) *Monitor
NewMonitorWithOptions constructs a new monitor from the provided components and configures optional ones (such as a status channel, timeout, and interval) based on the provided in options.
func TransitiveMonitor ¶
func TransitiveMonitor( url, name, description, wikipage string, urgency Urgency, statusChan chan HealthStatus, ) *Monitor
TransitiveMonitor creates a Monitor that is a dependency on another service that responds to a healthcheck
func (*Monitor) Description ¶
func (*Monitor) Documentation ¶
type MonitorOption ¶
type MonitorOption func(monitor *Monitor)
func WithPeriod ¶
func WithPeriod(period time.Duration) MonitorOption
WithPeriod configures an optional interval for the montor to be run on. If not provided, the default is used.
func WithStatusChan ¶
func WithStatusChan(statusChan chan HealthStatus) MonitorOption
WithStatusChan configures the optional subscription channel to notify consumers of health changes.
func WithTimeout ¶
func WithTimeout(timeout time.Duration) MonitorOption
WithTimeout configures an optional timeout for the monitor. If not provided, the default is used.
type Private ¶
type Private struct {
// contains filtered or unexported fields
}
Private is an http.Handler for
/private/healthcheck /private/healthcheck/live
func NewPrivate ¶
func NewPrivate(appName string, set DependencySet) *Private
NewPrivate creates a new Private so that service appName can be register its DependencySet.
type PrivateResult ¶
type PrivateResult struct { AppName string `json:"appName"` Condition string `json:"condition"` Duration int64 `json:"duration"` Hostname string `json:"hostname"` Environment map[string]string `json:"environment"` CWD string `json:"cwd"` AppStartDateSystem string `json:"appStartDateSystem"` AppStartDateUTC string `json:"appStartDateUTC"` AppStartUnixTimestamp string `json:"appStartUnixTimestamp"` AppUpTimeReadable string `json:"appUpTimeReadable"` AppUpTimeSeconds string `json:"appUpTimeSeconds"` LeastRecentlyExecutedDate string `json:"leastRecentlyExecutedDate"` LeastRecentlyExecutedTime int64 `json:"leastRecentlyExecutedTimestamp"` Results Components `json:"results"` }
A PrivateResult is the struct (and JSON) definition of what the response to a private healthcheck endpoint should be composed of.
type Result ¶
type Result struct { Health // contains filtered or unexported fields }
Result represents the final result of a HealthChecker. It contains all the information needed before being consumed by a robot.
type Status ¶
type Status int
Status is a representation of the health of the component.
func ParseStatus ¶
ParseStatus parses the given string into a Status. If the string is malformed, OUTAGE is returned.
func WorstState ¶
WorstState returns the less positive of two states.
func (Status) BetterThan ¶
BetterThan compares a Status to another Status.
func (Status) SameOrBetterThan ¶
SameOrBetterThan compares a Status to another Status.
func (Status) SameOrWorseThan ¶
SameOrWorseThan compares a Status to another Status.
type Summary ¶
type Summary struct {
// contains filtered or unexported fields
}
Summary is for representing the result of running multiple Checker instances such as the ones kept by a Dependencies. This object is intended to be used by a Dependencies for generating specified JSON output.
func NewSummary ¶
NewSummary will create a new Summary for a list of Health responses.
func (Summary) Duration ¶
Duration is a method provided to determine the total length of time it took to compute a Summary - that is how long it took to run a set of Checkers and produce results.
func (Summary) Executed ¶
Executed returns the time at which s was generated by initiating the checks it represents.
func (Summary) Overall ¶
Overall will return the combined downgraded Status of all of the Health instances. This state depends on both the check status and the urgency of each of the Health instances.
func (Summary) Status ¶
Status will return the combined downgraded Status of all of the Health instances identified by name The state does NOT depend on the urgency of each of the Health instances
func (Summary) StatusWithUrgency ¶
StatusWithUrgency will return the combined downgraded Status of all of the Health instances identified by name This status depends on both the check status and the urgency of each of the Health instances.
type Urgency ¶
type Urgency int
Urgency is a level of requirement for a service to be operational. A REQUIRED service would cause major service disruption if it is not healthy. Likewise a WEAK service can fail without major issues.
func ParseUrgency ¶
ParseUrgency converts the given string into an Urgency. If the string is malformed, UNKNOWN is returned.
func (Urgency) DowngradeWith ¶
DowngradeWith returns the downgraded Outage state according to HCv3 math.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package count enables tracking accumulating values.
|
Package count enables tracking accumulating values. |
internal/data
Package data provides time series buckets of accumulated values.
|
Package data provides time series buckets of accumulated values. |
Package gauge provides mechanisms for gauging values.
|
Package gauge provides mechanisms for gauging values. |