healthcheck

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2024 License: MIT Imports: 5 Imported by: 0

README

The HealthCheck Module

The Problem

Modern software, particularly microservice based systems, often have multiple third party systems which they depend on, e.g. databases, message brokers, ip-geolocation APIs, etc... Our software must be able to validate whether these dependencies are available.

The Solution

HealthCheck provides both a framework for any arbitrary check as well as many pre-existing checks for common software. Upon system startup HealthCheck can be used to validate any and all dependencies, providing a guarantee that they are available. Whilst Enabling clean and reliable handling of cases where required dependencies aren't available.

Installation
go get github.com/LS6-Events/healthcheck
Example
aHealthManager, err = healthcheck.New(time.second, time.minute)
if err != nil {
    // handle error
}
defer aHealthManager.Cleanup()

aHttpCheck, err = checks.NewHttpCheck(
    "localhost", 80, 10*time.Second
)
if err != nil {
    // handle error
}

err = aHealthManager.Register(aHttpCheck)
if err != nil {
    // handle error
}

err = aHealthManager.Run()
if err != nil {
    // handle error
}
New Checks

If you require a check for an application, which we do not provide, and decide to
build the check yourself, please create a PR to add it to the checks package.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCheck = errors.New("cannot register invalid check")
View Source
var ErrInvalidConfig = errors.New("invalid health manager configuration")
View Source
var ErrTimeout = errors.New("health check timed out with checks failing")

Functions

This section is empty.

Types

type HealthManager

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

func New

func New(CheckFrequency, timeout time.Duration) (*HealthManager, error)

New returns a new HealthManager instance.

func (*HealthManager) Cleanup

func (hm *HealthManager) Cleanup()

Cleanup cleans up any resources required by the health manager and any registered checks.

func (*HealthManager) GetHealth

func (hm *HealthManager) GetHealth() bool

GetHealth returns the health manager's current healthy status.

func (*HealthManager) Register

func (hm *HealthManager) Register(c checks.CheckInterface) error

Register registers a new check with the health manager.

func (*HealthManager) Run

func (hm *HealthManager) Run() error

Run executes the registered checks until all return healthy or the timeout elapses. Runs all checks then sleeps until the check frequency elapses before re-running checks. New checks cannot be registerd whilst Run is ongoing.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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