Documentation ¶
Overview ¶
Package upstream provides utilities for choosing upstream backends based on score.
Index ¶
- type Backend
- type List
- type ListOption
- func WithHealthcheckInterval(interval time.Duration) ListOption
- func WithHealthcheckTimeout(timeout time.Duration) ListOption
- func WithInitialScore(initialScore float64) ListOption
- func WithLowHighScores(lowScore, highScore float64) ListOption
- func WithScoreDeltas(failScoreDelta, successScoreDelta float64) ListOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List struct {
// contains filtered or unexported fields
}
List of upstream Backends with healthchecks and different strategies to pick a node.
List keeps track of Backends with score. Score is updated on health checks, and via external interface (e.g. when actual connection fails).
Initial score is set via options (default is +1). Low and high scores defaults are (-3, +3). Backend score is limited by low and high scores. Each time healthcheck fails score is adjusted by fail delta score, and every successful check updates score by success score delta (defaults are -1/+1).
Backend might be used if its score is not negative.
func NewList ¶
func NewList(upstreams []Backend, options ...ListOption) (*List, error)
NewList initializes new list with upstream backends and options and starts health checks.
List should be stopped with `.Shutdown()`.
type ListOption ¶
ListOption allows to configure List.
func WithHealthcheckInterval ¶
func WithHealthcheckInterval(interval time.Duration) ListOption
WithHealthcheckInterval configures healthcheck interval.
func WithHealthcheckTimeout ¶
func WithHealthcheckTimeout(timeout time.Duration) ListOption
WithHealthcheckTimeout configures healthcheck timeout (for each backend).
func WithInitialScore ¶
func WithInitialScore(initialScore float64) ListOption
WithInitialScore configures initial backend score.
func WithLowHighScores ¶
func WithLowHighScores(lowScore, highScore float64) ListOption
WithLowHighScores configures low and high score.
func WithScoreDeltas ¶
func WithScoreDeltas(failScoreDelta, successScoreDelta float64) ListOption
WithScoreDeltas configures fail and success score delta.