Documentation ¶
Index ¶
- func CurrentHealthyTargets(count float64)
- func HealthyTargetsTotal(target string)
- func ReadyzProtocolRequestTotal(code, target string)
- func UnHealthyTargetsTotal(target string)
- type Listener
- type Metrics
- type Notifier
- type Prober
- func (sm *Prober) AddListener(listener Listener)
- func (sm *Prober) Enqueue()
- func (sm *Prober) Run(ctx context.Context)
- func (sm *Prober) Targets() ([]string, []string)
- func (sm *Prober) WithHealthyProbesThreshold(healthyProbesThreshold int) *Prober
- func (sm *Prober) WithMetrics(metrics *Metrics) *Prober
- func (sm *Prober) WithProbeInterval(probeInterval time.Duration) *Prober
- func (sm *Prober) WithProbeResponseTimeout(probeResponseTimeout time.Duration) *Prober
- func (sm *Prober) WithUnHealthyProbesThreshold(unhealthyProbesThreshold int) *Prober
- type StaticTargetProvider
- type TargetProvider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CurrentHealthyTargets ¶
func CurrentHealthyTargets(count float64)
CurrentHealthyTargets keeps track of the current number of healthy targets observed by the health monitor
func HealthyTargetsTotal ¶
func HealthyTargetsTotal(target string)
HealthyTargetsTotal increments the total number of healthy instances observed by the health monitor
func ReadyzProtocolRequestTotal ¶
func ReadyzProtocolRequestTotal(code, target string)
ReadyzProtocolRequestTotal increments the total number of requests issues by the health monitor that violate the "readyz" protocol
the "readyz" protocol defines the following HTTP status code:
HTTP 200 - when the server operates normally HTTP 500 - when the server is not ready, for example, is undergoing a shutdown
func UnHealthyTargetsTotal ¶
func UnHealthyTargetsTotal(target string)
UnHealthyTargetsTotal increments the total number of unhealthy instances observed by the health monitor
Types ¶
type Listener ¶
type Listener interface {
// Enqueue should be called when an input may have changed
Enqueue()
}
Listener is an interface to use to notify interested parties of a change.
type Metrics ¶
type Metrics struct { // HealthyTargetsTotal increments the total number of healthy instances observed by the health monitor HealthyTargetsTotal func(target string) // CurrentHealthyTargets keeps track of the current number of healthy targets observed by the health monitor CurrentHealthyTargets func(count float64) // UnHealthyTargetsTotal increments the total number of unhealthy instances observed by the health monitor UnHealthyTargetsTotal func(target string) // ReadyzProtocolRequestTotal increments the total number of requests issues by the health monitor that violate the "readyz" protocol // // the "readyz" protocol defines the following HTTP status code: // HTTP 200 - when the server operates normally // HTTP 500 - when the server is not ready, for example, is undergoing a shutdown ReadyzProtocolRequestTotal func(code, target string) }
Metrics specifies a set of methods that are used to register various metrics
func Register ¶
func Register(registerFn func(...compbasemetrics.Registerable)) *Metrics
Register is a way to register the health monitor related metrics in the provided store
type Notifier ¶
type Notifier interface { // AddListener is adds a listener to be notified of potential input changes AddListener(listener Listener) }
Notifier is a way to add listeners
type Prober ¶
type Prober struct {
// contains filtered or unexported fields
}
func New ¶
func New(targetProvider TargetProvider, restConfig *rest.Config) (*Prober, error)
New creates a health monitor that periodically sends requests to the provided targets to check their health.
The following methods allows you to configure behaviour of the monitor after creation.
WithUnHealthyProbesThreshold - that specifies consecutive failed health checks after which a target is considered unhealthy the default value is: 3 WithHealthyProbesThreshold - that specifies consecutive successful health checks after which a target is considered healthy the default value is: 5 WithProbeResponseTimeout - that specifies a time limit for requests made by the HTTP client for the health check the default value is: 1 second WithProbeInterval - that specifies a time interval at which health checks are send the default value is: 2 seconds WithMetrics - that specifies a set of methods that are used to register various metrics the default value is: no metrics
Additionally the monitor implements Listener and Notifier interfaces.
The health monitor automatically registers for notification if the target provided also implements the Notifier interface. It is implicit so that the provider can provide a static or a dynamic list of targets.
Interested parties can register a listener for notifications about healthy/unhealthy targets changes via AddListener. TODO: instead of restConfig we could accept transport so that it is reused instead of creating a new connection to targets
reusing the transport has the advantage of using the same connection as other clients
func (*Prober) AddListener ¶
AddListener adds a listener to be notified when the list of healthy targets changes
Note: this method is not thread safe and mustn't be called after calling StartMonitoring() method
func (*Prober) Enqueue ¶
func (sm *Prober) Enqueue()
Enqueue schedules refreshing the target list on the next probeInterval This method is used by the TargetProvider to notify that the list has changed
func (*Prober) Run ¶
Run starts monitoring the provided targets until stop channel is closed This method is blocking and it is meant to be launched in a separate goroutine
func (*Prober) WithHealthyProbesThreshold ¶
WithHealthyProbesThreshold specifies consecutive successful health checks after which a target is considered healthy
func (*Prober) WithMetrics ¶
WithMetrics specifies a set of methods that are used to register various metrics
func (*Prober) WithProbeInterval ¶
WithProbeInterval specifies a time interval at which health checks are send
func (*Prober) WithProbeResponseTimeout ¶
WithProbeResponseTimeout specifies a time limit for requests made by the HTTP client for the health check
func (*Prober) WithUnHealthyProbesThreshold ¶
WithUnHealthyProbesThreshold specifies consecutive failed health checks after which a target is considered unhealthy
type StaticTargetProvider ¶
type StaticTargetProvider []string
StaticTargetProvider implements TargetProvider and provides a static list of targets
func (StaticTargetProvider) CurrentTargetsList ¶
func (sp StaticTargetProvider) CurrentTargetsList() []string
type TargetProvider ¶
type TargetProvider interface { // CurrentTargetsList returns a precomputed list of targets CurrentTargetsList() []string }
TargetProviders is an interface to use to get a list of targets to monitor