Back to godoc.org
github.com/pace/bricks / maintenance / health / servicehealthcheck

Package servicehealthcheck

v0.1.73
Latest Go to latest

The latest major version is .

Published: today | License: MIT | Module: github.com/pace/bricks

Index

func HealthHandler

func HealthHandler() http.Handler

HealthHandler returns the health endpoint for transactional processing. This Handler only checks the required health checks and returns ERR and 503 or OK and 200.

func ReadableHealthHandler

func ReadableHealthHandler() http.Handler

ReadableHealthHandler returns the health endpoint with all details about service health. This handler checks all health checks. The response body contains two tables (for required and optional health checks) with the detailed results of the health checks.

func RegisterHealthCheck

func RegisterHealthCheck(name string, hc HealthCheck)

RegisterHealthCheck registers a required HealthCheck. The name must be unique. If the health check satisfies the Initializable interface, it is initialized before it is added. It is not possible to add a health check with the same name twice, even if one is required and one is optional

func RegisterHealthCheckFunc

func RegisterHealthCheckFunc(name string, f HealthCheckFunc)

RegisterHealthCheckFunc registers a required HealthCheck. The name must be unique. It is not possible to add a health check with the same name twice, even if one is required and one is optional

func RegisterOptionalHealthCheck

func RegisterOptionalHealthCheck(hc HealthCheck, name string)

RegisterOptionalHealthCheck registers a HealthCheck like RegisterHealthCheck(hc HealthCheck, name string) but the health check is only checked for /health/check and not for /health/

type ConnectionState

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

ConnectionState caches the result of health checks. It is concurrency-safe.

func (*ConnectionState) GetState

func (cs *ConnectionState) GetState() HealthCheckResult

GetState returns the current state. That is whether the check is healthy or the error occurred.

func (*ConnectionState) LastChecked

func (cs *ConnectionState) LastChecked() time.Time

LastChecked returns the time that the state was last updated or confirmed.

func (*ConnectionState) SetErrorState

func (cs *ConnectionState) SetErrorState(err error)

SetErrorState sets the state to not healthy.

func (*ConnectionState) SetHealthy

func (cs *ConnectionState) SetHealthy()

SetHealthy sets the state to healthy.

type HealthCheck

type HealthCheck interface {
	HealthCheck(ctx context.Context) HealthCheckResult
}

HealthCheck is a health check that is registered once and that is performed periodically and/or spontaneously.

type HealthCheckFunc

type HealthCheckFunc func(ctx context.Context) HealthCheckResult

func (HealthCheckFunc) HealthCheck

func (hcf HealthCheckFunc) HealthCheck(ctx context.Context) HealthCheckResult

type HealthCheckResult

type HealthCheckResult struct {
	State HealthState
	Msg   string
}

HealthCheckResult describes the result of a health check, contains the state of a service and a message that describes the state. If the state is Ok the description can be empty. The description should contain the error message if any error or warning occurred during the health check.

type HealthState

type HealthState string

HealthState describes if a any error or warning occurred during the health check of a service

const (
	// Err State of a service, if an error occurred during the health check of the service
	Err HealthState = "ERR"
	// Warn State of a service, if a warning occurred during the health check of the service
	Warn HealthState = "WARN"
	// Ok State of a service, if no warning or error occurred during the health check of the service
	Ok HealthState = "OK"
)

type Initializable

type Initializable interface {
	Init(ctx context.Context) error
}

Initializable is used to mark that a health check needs to be initialized

Package Files

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to identifier