healthz

package module
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2017 License: MIT Imports: 3 Imported by: 1

README

Healthz

Build Status Go Report Card GoDoc

Tools for providing service health checks.

Documentation

Development

You need Glide to install dependencies.

$ make install

Run tests and linters:

$ make check

License

The MIT License (MIT). Please see License File for more information.

Documentation

Overview

Package healthz provides tools for service health checks

Index

Constants

This section is empty.

Variables

View Source
var ErrCheckFailed = errors.New("Check failed")

ErrCheckFailed is a generic error returned when a check fails

Functions

func NewHealthServiceHandler added in v0.4.0

func NewHealthServiceHandler(livenessChecker Checker, readinessChecker Checker) http.Handler

NewHealthServiceHandler creates an http.Handler from user configured Checkerss The handler is a standard http.ServeMux

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

func (CheckFunc) Check added in v0.4.0

func (f CheckFunc) Check() error

Check implements the Checker interface and allows any func() error signatured method to be passed as a Checker

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

func NewCheckers(checkers ...Checker) *Checkers

NewCheckers is a shortcut for easily creating a new Checker collection

func (*Checkers) Check added in v0.4.0

func (c *Checkers) Check() error

Check implements the Checker interface and executes the underlying checks Note that since we have no information about what may become a Checker, this cannot be called concurrently

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 Status added in v0.4.0

type Status int

Status is an enum type representing health status

const (
	Healthy Status = iota
	Unhealthy
)

Possibly values are Health and Unhealthy

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL