upstream

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2020 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package upstream provides utilities for choosing upstream backends based on score.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	HealthCheck(ctx context.Context) error
}

Backend is an interface which should be implemented for a Pick entry.

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()`.

func (*List) Down

func (list *List) Down(upstream Backend)

Down decreases backend score by fail score delta.

func (*List) Pick

func (list *List) Pick() (Backend, error)

Pick returns next backend to be used.

Default policy is to pick healthy (non-negative score) backend in round-robin fashion.

func (*List) Shutdown

func (list *List) Shutdown()

Shutdown stops healthchecks.

func (*List) Up

func (list *List) Up(upstream Backend)

Up increases backend score by success score delta.

type ListOption

type ListOption func(*List) error

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.

Jump to

Keyboard shortcuts

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