Documentation ¶
Index ¶
- func NewRoundRobinUpstream(opts ...RROption) (*roundRobinUpstream, error)
- type Cache
- type Event
- type PinKeyFunc
- type RROption
- func BurstFailGrace(t time.Duration) RROption
- func EventCallback(f func(Event)) RROption
- func HealthCheck(interval time.Duration, checkfunc func(*url.URL) error) (option RROption, startfunc func(context.Context) error)
- func MaxFails(m int) RROption
- func PinRequestsWith(cache Cache, ttl time.Duration, f PinKeyFunc) RROption
- func Quarantine(d time.Duration) RROption
- func Targets(urls ...*url.URL) RROption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewRoundRobinUpstream ¶
NewRoundRobinUpstream returns a Round Robin VirtualUpstream configured with the provided options.
Types ¶
type Cache ¶
type Cache interface { Set(key string, value int, ttl time.Duration) // Get must return the value set, or negative if not found Get(key string) (value int) Delete(key string) }
Cache is the interface needed to allow the RR upstream to remember where to send successful request for a period of time, (based on a cache key) to avoid moving requests too much around between backend servers.
type Event ¶
Event reports named event with the upstream pool via a callback function. Currently named events: "quarantine", "retrying"
type PinKeyFunc ¶
PinKeyFunc is a function which, based on a request, returns a string as a routing key for the request, to allow the Round Robin upstream to cache the picked server for requests with that routing key.
type RROption ¶
type RROption func(*roundRobinUpstream)
RROption is an option function configuring a Round Robin VirtualUpstream
func BurstFailGrace ¶
BurstFailGrace sets a duration for counting multiple errors as one. This prevents backend servers which in case of an isolated incidence will kill multiple HTTP request from reaching the MaxFails limit immediately. Fails not counted due to BurstFailGrace do not count as successes though.
func EventCallback ¶
EventCallback can be set to notify the application about changes to the upstream pool. This can be used for logging when a server is quarantined.
func HealthCheck ¶
func HealthCheck(interval time.Duration, checkfunc func(*url.URL) error) (option RROption, startfunc func(context.Context) error)
HealthCheck configures a periodic health check callback. The provided checkfunc will be called with the URL of the backend target to check. checkfunc can perform any activity it wish and returning anything but a nil error, will mark the backend as down. The simple check would be to adjust the target URL to add a Request-URI and perform an HTTP request to verify it's up. If this check fails it will keep the target from being picked by the Round Robin algorithm until the next health check. The health check will run when startfunc is called until the context is canceled. This option will return nil if interval is zero.
func MaxFails ¶
MaxFails configures how many times a backend server is allowed to fail before being put into quarantine. As fails are recorded for a backend it's picked less often with a chance proportional to MaxFails. A MaxFail of zero (default), means don't quarantine backend targets and don't weigh targets with fails lower when selecting next target.
func PinRequestsWith ¶
func PinRequestsWith(cache Cache, ttl time.Duration, f PinKeyFunc) RROption
PinRequestsWith will - if provided a cache implementation - allow the Round Robin upstream to remember where it send requests with a similar routing key and keep sending them to that server. This prevents picking a new server for every single related request. The provided PinkeyFunc is called on requests to determine the routing key.
func Quarantine ¶
Quarantine configures the quarantine period for failed servers.