apphealth

package
v1.10.7-rc.1 Latest Latest
Warning

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

Go to latest
Published: May 10, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// DefaultProbeInterval is the default interval for app health probes.
	DefaultProbeInterval = 5 * time.Second
	// DefaultProbeTimeout is the default value for probe timeouts.
	DefaultProbeTimeout = 500 * time.Millisecond
	// DefaultThreshold is the default threshold for determining failures in app health checks.
	DefaultThreshold = int32(3)
)
View Source
const (
	AppStatusUnhealthy uint8 = 0
	AppStatusHealthy   uint8 = 1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AppHealth

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

AppHealth manages the health checks for the app.

func NewAppHealth

func NewAppHealth(config *Config, probeFn ProbeFunction) *AppHealth

NewAppHealth creates a new AppHealth object.

func (*AppHealth) Enqueue

func (h *AppHealth) Enqueue()

Enqueue adds a new probe request to the queue

func (*AppHealth) GetStatus

func (h *AppHealth) GetStatus() uint8

GetStatus returns the status of the app's health

func (*AppHealth) OnHealthChange

func (h *AppHealth) OnHealthChange(cb ChangeCallback)

OnHealthChange sets the callback that is invoked when the health of the app changes (app becomes either healthy or unhealthy).

func (*AppHealth) ReportHealth

func (h *AppHealth) ReportHealth(status uint8)

ReportHealth is used by the runtime to report a health signal from the app.

func (*AppHealth) StartProbes

func (h *AppHealth) StartProbes(ctx context.Context)

StartProbes starts polling the app on the interval.

type ChangeCallback

type ChangeCallback func(status uint8)

ChangeCallback is the signature of the callback that is invoked when the app's health status changes.

type Config

type Config struct {
	ProbeInterval time.Duration
	ProbeTimeout  time.Duration
	ProbeOnly     bool
	Threshold     int32
}

Config is the configuration object for the app health probes.

type ProbeFunction

type ProbeFunction func(context.Context) (bool, error)

ProbeFunction is the signature of the function that performs health probes. Health probe functions return errors only in case of internal errors. Network errors are considered probe failures, and should return nil as errors.

Jump to

Keyboard shortcuts

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