health

package
v0.0.0-...-3dd6856 Latest Latest
Warning

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

Go to latest
Published: May 20, 2019 License: 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 Register

func Register(name string) *Handle

Register a component 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 GetStatus

func GetStatus() Status

GetStatus allows to query the health status of the agent

func GetStatusNonBlocking

func GetStatusNonBlocking() (Status, error)

GetStatusNonBlocking allows to query the health status of the agent and is guaranteed to return under 500ms.

Jump to

Keyboard shortcuts

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