health

package
v0.0.0-...-364fed7 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2021 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package health implements a node health checker which can emit events when a node goes unhealthy.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Checker

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

Checker is a node health checker. Checker is given a full set of nodes to actively perform checks against.

func NewChecker

func NewChecker(cfg Config, p *connpool.Pool, w Watcher) *Checker

NewChecker creates a new health checker. The pool will be used for retrieving gRPC clients. Health change events will be sent to the given Watcher.

Checker will run in the background until Close is called.

func (*Checker) CheckNodes

func (c *Checker) CheckNodes(ds []api.Descriptor) error

CheckNodes will update the set of nodes being checked for health. Subsequent calls to CheckNodes will stop checking nodes that have been removed from ds in between calls.

Fails if the checker is closed.

func (*Checker) Close

func (c *Checker) Close() error

Close stops the Checker. Fails if the Checker is already closed.

func (*Checker) SetHealth

func (c *Checker) SetHealth(ds api.Descriptor, h api.Health) error

SetHealth explicitly sets the health of a node and fires off the HealthChanged event. This is useful when communicating with a node fails and you wish to immediately mark it as suspicious.

type Config

type Config struct {
	// Frequency to check each node.
	CheckFrequency time.Duration
	// Timeout for each check.
	CheckTimeout time.Duration
	// Maximum number of times a check can fail before the next failure marks as
	// dead. 0 = dead at the first failure.
	MaxFailures int

	Log        log.Logger
	Registerer prometheus.Registerer
}

Config configures how the checker performs.

type Watcher

type Watcher interface {
	// HealthChanged will be invoked whenever the status of a node changes.
	// Unealthy indicates that the node is suspect and shouldn't be routed
	// to for messages.
	//
	// HealthChanged may be called concurrently.
	HealthChanged(d api.Descriptor, health api.Health)
}

Watcher is an interface used by Checker to send updates about the health of a node as it changes.

Jump to

Keyboard shortcuts

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