healthz

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Feb 9, 2017 License: MIT Imports: 4 Imported by: 1

README

Healthz

Build Status Go Report Card GoDoc

Tools for checking service health.

Documentation

Development

You need Glide to install dependencies.

$ make install

Run tests:

$ make test

License

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

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrHealthCheckFailed = errors.New("Health check failed")

ErrHealthCheckFailed is a generic error returned when a check fails

Functions

This section is empty.

Types

type DbHealthChecker added in v0.2.0

type DbHealthChecker struct {
	// contains filtered or unexported fields
}

DbHealthChecker checks if a database is available through builtin database/sql

func NewDbHealthChecker added in v0.2.0

func NewDbHealthChecker(db *sql.DB) *DbHealthChecker

NewDbHealthChecker creates a new DB health checker with a connection

func (*DbHealthChecker) Ping added in v0.2.0

func (c *DbHealthChecker) Ping() error

Ping checks the database status by pinging it

func (*DbHealthChecker) Type added in v0.2.0

func (c *DbHealthChecker) Type() string

Type returns the name of the database checker

type HTTPHealthChecker added in v0.2.0

type HTTPHealthChecker struct {
	// contains filtered or unexported fields
}

HTTPHealthChecker checks if an HTTP service is available

func NewHTTPHealthChecker added in v0.2.0

func NewHTTPHealthChecker(url string) *HTTPHealthChecker

NewHTTPHealthChecker creates a new HTTP health checker with an URL

func (*HTTPHealthChecker) Ping added in v0.2.0

func (c *HTTPHealthChecker) Ping() error

Ping checks the database status by pinging it

func (*HTTPHealthChecker) Type added in v0.2.0

func (c *HTTPHealthChecker) Type() string

Type returns the name of the database checker

type HealthChecker

type HealthChecker interface {
	Type() string
	Ping() error
}

HealthChecker is responsible for checking certain resources

type HealthService

type HealthService struct {
	LivenessProbe  *Probe
	ReadinessProbe *Probe
}

HealthService is the HTTP handler implementation which wraps the Probe and Checker logic

func NewHealthService

func NewHealthService(livenessProbe *Probe, readinessProbe *Probe) *HealthService

NewHealthService creates a new HealthService from user configured Probes

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)

func (*HealthService) RegisterMux added in v0.2.0

func (s *HealthService) RegisterMux(mux *http.ServeMux)

RegisterMux registers HTTP Endpoints in a Mux

type Probe

type Probe struct {
	// contains filtered or unexported fields
}

Probe is responsible for executing a series of checks and decide if the service is up or not

func NewProbe

func NewProbe(checkers ...HealthChecker) *Probe

NewProbe is a shortcut for easily creating a new Probe

func (*Probe) Check

func (p *Probe) Check() error

Check executes the underlying health checks

type StatusHealthChecker

type StatusHealthChecker struct {
	// contains filtered or unexported fields
}

StatusHealthChecker checks the status based on an internal state

func NewStatusHealthChecker added in v0.2.0

func NewStatusHealthChecker(status bool) *StatusHealthChecker

NewStatusHealthChecker creates a new status health checker with an initial status

func (*StatusHealthChecker) Ping

func (c *StatusHealthChecker) Ping() error

Ping checks the internal status and returns an error if it is false

func (*StatusHealthChecker) SetStatus added in v0.2.0

func (c *StatusHealthChecker) SetStatus(status bool)

SetStatus sets the internal status

func (*StatusHealthChecker) Type

func (c *StatusHealthChecker) Type() string

Type returns the name of the status checker

Jump to

Keyboard shortcuts

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