lb

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoHealthyUpstreams = errors.New("no healthy upstreams")
View Source
var StateEnum = util.NewEnum(map[StateType]string{
	StateSticky: "sticky",
	StateNone:   "none",
})
View Source
var StrategyEnum = util.NewEnum(map[Strategy]string{
	StrategyLeastConn:  "least",
	StrategyRandom:     "random",
	StrategyHash:       "hash",
	StrategyRoundRobin: "round-robin",
})

Functions

This section is empty.

Types

type ErrorOptions

type ErrorOptions struct {
	Handle *vhttp.Subhandler `yaml:"handle,omitempty"` // The error handler.
	Limit  rate.Limit        `yaml:"limit,omitempty"`  // The rate limit.
}

type LoadBalancer

type LoadBalancer struct {
	Options `yaml:",inline"`
	// contains filtered or unexported fields
}

func (*LoadBalancer) AddUpstream

func (lb *LoadBalancer) AddUpstream(u *Upstream)

func (*LoadBalancer) ClearUpstreams

func (lb *LoadBalancer) ClearUpstreams()

func (*LoadBalancer) Healthy

func (lb *LoadBalancer) Healthy() bool

func (*LoadBalancer) Metrics

func (lb *LoadBalancer) Metrics() LoadBalancerMetrics

func (*LoadBalancer) NextUpstream

func (lb *LoadBalancer) NextUpstream(ctx *requestContext) (result *Upstream, err error)

func (*LoadBalancer) OnError

func (lb *LoadBalancer) OnError(ctx *requestContext, w http.ResponseWriter, r *http.Request, err error)

func (*LoadBalancer) OnErrorResponse

func (lb *LoadBalancer) OnErrorResponse(ctx *requestContext, r *http.Response) http.Handler

func (*LoadBalancer) PickUpstream

func (lb *LoadBalancer) PickUpstream(ctx *requestContext) (result *Upstream, err error)

func (*LoadBalancer) RemoveUpstream

func (lb *LoadBalancer) RemoveUpstream(u *Upstream)

func (*LoadBalancer) ServeHTTP

func (lb *LoadBalancer) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*LoadBalancer) SetLogger

func (lb *LoadBalancer) SetLogger(logger *xlog.Logger)

func (*LoadBalancer) Upstreams

func (lb *LoadBalancer) Upstreams() (us []*Upstream)

type LoadBalancerMetrics

type LoadBalancerMetrics struct {
	Upstreams []UpstreamMetrics `json:"upstreams,omitempty"`
}

type Options

type Options struct {
	Retry    retry.Policy  `yaml:",inline"`         // The retry policy.
	Strategy Strategy      `yaml:"strat,omitempty"` // The load balancing strategy.
	State    StateType     `yaml:"state,omitempty"` // The session kind.
	Error4xx *ErrorOptions `yaml:"4xx,omitempty"`   // The error handler for 4xx responses.
	Error5xx *ErrorOptions `yaml:"5xx,omitempty"`   // The error handler for 5xx responses.
	Error404 *ErrorOptions `yaml:"404,omitempty"`   // The error handler for 404 responses.
}

type StateType

type StateType uint8
const (
	StateSticky StateType = iota
	StateNone
)

func (StateType) MarshalText

func (e StateType) MarshalText() (text []byte, err error)

func (StateType) String

func (e StateType) String() string

func (*StateType) UnmarshalText

func (e *StateType) UnmarshalText(text []byte) error

type Strategy

type Strategy uint8
const (
	StrategyLeastConn Strategy = iota
	StrategyRandom
	StrategyHash
	StrategyRoundRobin
)

func (Strategy) MarshalText

func (e Strategy) MarshalText() (text []byte, err error)

func (Strategy) String

func (e Strategy) String() string

func (*Strategy) UnmarshalText

func (e *Strategy) UnmarshalText(text []byte) error

type SuppressedHttpError

type SuppressedHttpError struct {
	http.Handler
}

func (SuppressedHttpError) Error

func (err SuppressedHttpError) Error() string

type Upstream

type Upstream struct {
	Address      string
	Healthy      atomic.Bool
	LoadFactor   atomic.Int32
	ReverseProxy httputil.ReverseProxy

	// Metrics
	RequestCount     atomic.Uint32
	ErrorCount       atomic.Uint32
	ServerErrorCount atomic.Uint32
	ClientErrorCount atomic.Uint32
}

func NewHttpUpstream

func NewHttpUpstream(address string) (u *Upstream)

func NewHttpUpstreamTransport

func NewHttpUpstreamTransport(address string, director func(r *http.Request), transport http.RoundTripper) (u *Upstream)

func (*Upstream) Metrics

func (u *Upstream) Metrics() UpstreamMetrics

func (*Upstream) ServeHTTP

func (p *Upstream) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Upstream) SetHealthy

func (u *Upstream) SetHealthy(healthy bool)

func (*Upstream) String

func (u *Upstream) String() string

type UpstreamMetrics

type UpstreamMetrics struct {
	Address          string `json:"address,omitempty"`
	Healthy          bool   `json:"healthy,omitempty"`
	LoadFactor       int32  `json:"load_factor,omitempty"`
	RequestCount     uint32 `json:"request_count,omitempty"`
	ErrorCount       uint32 `json:"error_count,omitempty"`
	ServerErrorCount uint32 `json:"server_error_count,omitempty"`
	ClientErrorCount uint32 `json:"client_error_count,omitempty"`
}

Jump to

Keyboard shortcuts

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