liveness

package
v0.33.37-atree-inlining Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2024 License: AGPL-3.0 Imports: 3 Imported by: 0

README

Liveness Checks Helper

For applications that need to perform liveness checks, this utility creates a simple object capable of checking in with multiple routines.

Usage

The suggested usage is to create a collector and then spawn checks from it to use in your application.

Each worker gets a single Check to work from, and the collector itself is registered as an HTTP handler to respond to liveness probes.

multiCheck := liveness.NewCheckCollector(time.Second)

http.Handle("/live", multiCheck)

go worker1(multiCheck.NewCheck())
go worker2(multiCheck.NewCheck())

check3 = multiCheck.NewCheck()

for {
    check3.CheckIn()
    // do work
    // ...
}

Documentation

Index

Constants

View Source
const (
	// DefaultTolerance is the default time (in seconds) allowed between heartbeats.
	DefaultTolerance = time.Second * 30

	// ToleranceHeader is the HTTP header name used to override a collector's configured tolerance.
	ToleranceHeader = "X-Liveness-Tolerance"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Check

type Check interface {
	CheckIn()
	IsLive(time.Duration) bool
}

Check is a heartbeat style liveness reporter.

It is not guaranteed to be safe to CheckIn across multiple goroutines. IsLive must be safe to be called concurrently with CheckIn.

type CheckCollector

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

CheckCollector produces multiple checks and returns live only if all decendant checks are live.

Each child check may only be used by one goroutine, the CheckCollector may be used by multiple routines at once to produce checks.

func NewCheckCollector

func NewCheckCollector(tolerance time.Duration) *CheckCollector

NewCheckCollector creates a threadsafe Collector.

func (*CheckCollector) IsLive

func (c *CheckCollector) IsLive(tolerance time.Duration) bool

IsLive checks if we are still live against the given the tolerace between hearbeats.

If tolerance is 0, the default tolerance is used.

func (*CheckCollector) NewCheck

func (c *CheckCollector) NewCheck() Check

NewCheck returns a Check which is safe for use on a single routine.

func (*CheckCollector) Register

func (c *CheckCollector) Register(ck Check)

Register adds a check to a collector

func (*CheckCollector) ServeHTTP

func (c *CheckCollector) ServeHTTP(w http.ResponseWriter, r *http.Request)

Jump to

Keyboard shortcuts

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