Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EnablePrometheus ¶
EnablePrometheus exposes the overall status and status of each component as Prometheus metrics using the default Prometheus registry.
The overall status is exposed as a gauge named "health_status" with a value of 0 for down, 1 for degraded, and 2 for up.
The status of each component is exposed as a gauge named "health_component_status" with a value of 0 for down, 1 for up.
Types ¶
type CheckFunc ¶
CheckFunc is a function type that checks/verifies the health of a component and or service. If an error is returned, the component/service is considered unhealthy and down.
type Component ¶
type Component struct { // Name or identifier of the component. Each component should have a unique // name. Otherwise, the response from ServeHTTP will be not be particularly // helpful in identifying which component is in a bad state. Name string // Determines if the component is critical to the overall health and // functionality of the system. If a component is marked as critical, and // it fails its check, the overall status of the system will be down. Critical bool // Timeout for the health check. If the health check takes longer than the // timeout, the check is considered to have failed. The default value is // 5 seconds. Timeout time.Duration // Interval between health checks. If the interval is set to zero, a default // interval of 15 seconds will be used. The Interval must be greater than // the Timeout. Interval time.Duration // The health check of the component. // // A nil Check will cause a panic. Check CheckFunc // contains filtered or unexported fields }
Component represents a single component that can be checked for health.
type ComponentStatus ¶
type ComponentStatus struct { Name string `json:"name"` Critical bool `json:"critical"` Status Status `json:"status"` }
ComponentStatus represents the status of a component.
type Components ¶
type Components []*Component
Components is a collection of components that can be checked for health.
Components implements http.Handler and can be used to serve as a readiness or liveness health check endpoint.
func (Components) ComponentStatus ¶
func (c Components) ComponentStatus(ctx context.Context) []ComponentStatus
ComponentStatus returns the status of each component.
func (Components) ServeHTTP ¶
func (c Components) ServeHTTP(w http.ResponseWriter, r *http.Request)
type Health ¶
type Health struct {
// contains filtered or unexported fields
}
Health monitors the health of services/components that an application depends on and tracks their status to determine the overall health of the application.
Health implements the http.Handler interface and can be used to expose the health status of the application via an HTTP endpoint.
func New ¶
New initializes a new Health instance with the provided components.
Additional components can be registered by calling the Register method on the Health instance.
func (*Health) HandlerFunc ¶
func (h *Health) HandlerFunc() http.HandlerFunc
HandlerFunc returns an http.HandlerFunc for the health endpoint which returns the overall health status of the application along with the status of each component. If the application overall status is Up or Degraded a 200 OK status code is returned. If the application overall status is Down a 503 Service Unavailable status code is returned.
func (*Health) Register ¶
Register adds a component to be monitored and considered in the overall health of the application.
Panics if the component does not have a non-nil check function.
func (*Health) ServeHTTP ¶
func (h *Health) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP is the HTTP handler for the health endpoint which returns the overall health status of the application along with the status of each component. If the application overall status is Up or Degraded a 200 OK status code is returned. If the application overall status is Down a 503 Service Unavailable status code is returned.
type Status ¶
type Status string
Status represents the status of the application.
const ( // StatusUp indicates the application is up and functioning as expected. StatusUp Status = "UP" // StatusDegraded indicates the application is up and functional but is // experiencing non-critical issues which is degrading the experience. StatusDegraded Status = "DEGRADED" // StatusDown indicates the application is not functional and for all intents // and purposes the application is down (not usable). StatusDown Status = "DOWN" )
func (Status) HttpStatusCode ¶
HttpStatusCode returns the HTTP status code for the given status.