Documentation ¶
Overview ¶
Package roundrobin implements dynamic weighted round robin load balancer http handler
Index ¶
- Constants
- func SetDefaultWeight(weight int) error
- type CookieOptions
- type LBOption
- type Meter
- type NewMeterFn
- type Rebalancer
- func (rb *Rebalancer) RemoveServer(u *url.URL) error
- func (rb *Rebalancer) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (rb *Rebalancer) Servers() []*url.URL
- func (rb *Rebalancer) UpsertServer(u *url.URL, options ...ServerOption) error
- func (rb *Rebalancer) Wrap(next balancerHandler) error
- type RebalancerOption
- func RebalancerBackoff(d time.Duration) RebalancerOption
- func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption
- func RebalancerLogger(l *log.Logger) RebalancerOption
- func RebalancerMeter(newMeter NewMeterFn) RebalancerOption
- func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption
- func RebalancerStickySession(stickySession *StickySession) RebalancerOption
- type RequestRewriteListener
- type RoundRobin
- func (r *RoundRobin) Next() http.Handler
- func (r *RoundRobin) NextServer() (*url.URL, error)
- func (r *RoundRobin) RemoveServer(u *url.URL) error
- func (r *RoundRobin) ServeHTTP(w http.ResponseWriter, req *http.Request)
- func (r *RoundRobin) ServerWeight(u *url.URL) (int, bool)
- func (r *RoundRobin) Servers() []*url.URL
- func (r *RoundRobin) UpsertServer(u *url.URL, options ...ServerOption) error
- type ServerOption
- type StickySession
Constants ¶
const ( // FSMMaxWeight is the maximum weight that handler will set for the server. FSMMaxWeight = 4096 // FSMGrowFactor Multiplier for the server weight. FSMGrowFactor = 4 )
Variables ¶
This section is empty.
Functions ¶
func SetDefaultWeight ¶
SetDefaultWeight sets the default server weight.
Types ¶
type CookieOptions ¶
type CookieOptions struct { HTTPOnly bool Secure bool Path string Domain string Expires time.Time MaxAge int SameSite http.SameSite }
CookieOptions has all the options one would like to set on the affinity cookie.
type LBOption ¶
type LBOption func(*RoundRobin) error
LBOption provides options for load balancer.
func EnableStickySession ¶
func EnableStickySession(stickySession *StickySession) LBOption
EnableStickySession enable sticky session.
func ErrorHandler ¶
func ErrorHandler(h utils.ErrorHandler) LBOption
ErrorHandler is a functional argument that sets error handler of the server.
func Logger ¶ added in v1.4.0
Logger defines the logger the round robin load balancer will use.
It defaults to logrus.StandardLogger(), the global logger used by logrus.
func RoundRobinLogger ¶
RoundRobinLogger defines the logger the round robin load balancer will use.
It defaults to logrus.StandardLogger(), the global logger used by logrus. Deprecated: use Logger instead.
func RoundRobinRequestRewriteListener ¶
func RoundRobinRequestRewriteListener(rrl RequestRewriteListener) LBOption
RoundRobinRequestRewriteListener is a functional argument that sets error handler of the server.
type NewMeterFn ¶
NewMeterFn type of functions to create new Meter.
type Rebalancer ¶
type Rebalancer struct {
// contains filtered or unexported fields
}
Rebalancer increases weights on servers that perform better than others. It also rolls back to original weights if the servers have changed. It is designed as a wrapper on top of the roundrobin.
func NewRebalancer ¶
func NewRebalancer(handler balancerHandler, opts ...RebalancerOption) (*Rebalancer, error)
NewRebalancer creates a new Rebalancer.
func (*Rebalancer) RemoveServer ¶
func (rb *Rebalancer) RemoveServer(u *url.URL) error
RemoveServer remove a server.
func (*Rebalancer) ServeHTTP ¶
func (rb *Rebalancer) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*Rebalancer) UpsertServer ¶
func (rb *Rebalancer) UpsertServer(u *url.URL, options ...ServerOption) error
UpsertServer upsert a server.
func (*Rebalancer) Wrap ¶
func (rb *Rebalancer) Wrap(next balancerHandler) error
Wrap sets the next handler to be called by rebalancer handler.
type RebalancerOption ¶
type RebalancerOption func(*Rebalancer) error
RebalancerOption - functional option setter for rebalancer.
func RebalancerBackoff ¶
func RebalancerBackoff(d time.Duration) RebalancerOption
RebalancerBackoff sets a beck off duration.
func RebalancerErrorHandler ¶
func RebalancerErrorHandler(h utils.ErrorHandler) RebalancerOption
RebalancerErrorHandler is a functional argument that sets error handler of the server.
func RebalancerLogger ¶
func RebalancerLogger(l *log.Logger) RebalancerOption
RebalancerLogger defines the logger the rebalancer will use.
It defaults to logrus.StandardLogger(), the global logger used by logrus.
func RebalancerMeter ¶
func RebalancerMeter(newMeter NewMeterFn) RebalancerOption
RebalancerMeter sets a Meter builder function.
func RebalancerRequestRewriteListener ¶
func RebalancerRequestRewriteListener(rrl RequestRewriteListener) RebalancerOption
RebalancerRequestRewriteListener is a functional argument that sets error handler of the server.
func RebalancerStickySession ¶
func RebalancerStickySession(stickySession *StickySession) RebalancerOption
RebalancerStickySession sets a sticky session.
type RequestRewriteListener ¶
RequestRewriteListener function to rewrite request.
type RoundRobin ¶
type RoundRobin struct {
// contains filtered or unexported fields
}
RoundRobin implements dynamic weighted round robin load balancer http handler.
func New ¶
func New(next http.Handler, opts ...LBOption) (*RoundRobin, error)
New created a new RoundRobin.
func (*RoundRobin) NextServer ¶
func (r *RoundRobin) NextServer() (*url.URL, error)
NextServer gets the next server.
func (*RoundRobin) RemoveServer ¶
func (r *RoundRobin) RemoveServer(u *url.URL) error
RemoveServer remove a server.
func (*RoundRobin) ServeHTTP ¶
func (r *RoundRobin) ServeHTTP(w http.ResponseWriter, req *http.Request)
func (*RoundRobin) ServerWeight ¶
func (r *RoundRobin) ServerWeight(u *url.URL) (int, bool)
ServerWeight gets the server weight.
func (*RoundRobin) UpsertServer ¶
func (r *RoundRobin) UpsertServer(u *url.URL, options ...ServerOption) error
UpsertServer In case if server is already present in the load balancer, returns error.
type ServerOption ¶
type ServerOption func(*server) error
ServerOption provides various options for server, e.g. weight.
func Weight ¶
func Weight(w int) ServerOption
Weight is an optional functional argument that sets weight of the server.
type StickySession ¶
type StickySession struct {
// contains filtered or unexported fields
}
StickySession is a mixin for load balancers that implements layer 7 (http cookie) session affinity.
func NewStickySession ¶
func NewStickySession(cookieName string) *StickySession
NewStickySession creates a new StickySession.
func NewStickySessionWithOptions ¶
func NewStickySessionWithOptions(cookieName string, options CookieOptions) *StickySession
NewStickySessionWithOptions creates a new StickySession whilst allowing for options to shape its affinity cookie such as "httpOnly" or "secure".
func (*StickySession) GetBackend ¶
GetBackend returns the backend URL stored in the sticky cookie, iff the backend is still in the valid list of servers.
func (*StickySession) SetCookieValue ¶ added in v1.3.0
func (s *StickySession) SetCookieValue(value stickycookie.CookieValue) *StickySession
SetCookieValue set the CookieValue for the StickySession.
func (*StickySession) StickBackend ¶
func (s *StickySession) StickBackend(backend *url.URL, w http.ResponseWriter)
StickBackend creates and sets the cookie.