health

package
v0.0.2-0...-4ce78c8 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2021 License: Apache-2.0, Apache-2.0 Imports: 3 Imported by: 0

README

package health

The health package handles internal healthchecks for the agents, that allow to check every asynchronous component is running as intended.

For more information on the context, see the agent-healthcheck.md proposal.

How to add a component?

  • First, you need to register, by calling health.Register with a user-visible name. You will receive a *health.Handle to keep. As soon as Register is called, you need to start reading the channel to be considered healthy.

  • In your main goroutine, you need to read from the handle.C channel, at least every 15 seconds. This is accomplished by using a select statement in your main goroutine. If the channel is full (after two tries), your component will be considered unhealthy, which might result in the agent getting killed by the system.

  • If your component is stopping, it should call handle.Deregister() before stopping. It will then be removed from the healthcheck system.

Where should I tick?

It depends on your component lifecycle, but the check's purpose is to check that your component is able to process new input and act accordingly. For components that read input from a channel, you should read the channel from this logic.

This is usually hightly unprobable, but it's exactly the scope of this system: be able to detect if a component is frozen because of a bug / race condition. This is usually the only kind of issue that could be solved by the agent restarting.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Deregister

func Deregister(handle *Handle) error

Deregister a component from the healthcheck

Types

type Handle

type Handle struct {
	C <-chan struct{}
}

Handle holds the token and the channel for components to use

func RegisterLiveness

func RegisterLiveness(name string) *Handle

RegisterLiveness registers a component fore liveness check with the default 30 seconds timeout, returns a token

func RegisterReadiness

func RegisterReadiness(name string) *Handle

RegisterReadiness registers a component for readiness check with the default 30 seconds timeout, returns a token

func (*Handle) Deregister

func (h *Handle) Deregister() error

Deregister allows a component to easily deregister itself

type Status

type Status struct {
	Healthy   []string
	Unhealthy []string
}

Status represents the current status of registered components it is built and returned by GetStatus()

func GetLive

func GetLive() Status

GetLive returns health of all components registered for liveness

func GetLiveNonBlocking

func GetLiveNonBlocking() (Status, error)

GetLiveNonBlocking returns the health of all components registered for liveness with a 500ms timeout

func GetReady

func GetReady() (ret Status)

GetReady returns health of all components registered for both readiness and liveness

func GetReadyNonBlocking

func GetReadyNonBlocking() (Status, error)

GetReadyNonBlocking returns the health of all components registered for both readiness and liveness with a 500ms timeout

Jump to

Keyboard shortcuts

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