Documentation ¶
Index ¶
- Constants
- Variables
- func GetRetryFromContext(r *http.Request) int
- type Backend
- type BackendConfig
- type BackendConnection
- type BackendRouter
- type BackendRouterConfig
- type BackendSelectionMethod
- type Config
- type LBLight
- func (l *LBLight) AddBackendRouter(ber *BackendRouter) error
- func (l *LBLight) CheckHealthOfAllBackendRouters() error
- func (l *LBLight) GetBackendRouterByExactPathPrefix(path string) (*BackendRouter, error)
- func (l *LBLight) GetBackendRouterByHeader(headerName string, headerValue string) (*BackendRouter, error)
- func (l *LBLight) GetBackendRouterByPathPrefix(path string) (*BackendRouter, error)
- func (l *LBLight) GetBackendStats() error
- func (l *LBLight) ListenAndServeTraffic(certCRTPath string, certKeyPath string) error
Constants ¶
const ( RetryID int = 1 RetryAttempts int = 10 RetryDelayInMS time.Duration = 50 )
Variables ¶
var BackendSelectionMap = map[string]BackendSelectionMethod{ "roundrobin": BackendRoundRobin, "inuseconnection": BackendInuseConnections, "random": BackendRandom, }
Functions ¶
func GetRetryFromContext ¶
GetAttemptsFromContext returns the attempts for request
Types ¶
type Backend ¶
type Backend struct { Host string Port int BackendConnections []*BackendConnection MaxConnections int // Is this backend alive/dead Alive bool // contains filtered or unexported fields }
Backend is unique for a given host:port. This might be pointing to a single machine or possibly a LB/cluster. The Backend has a collection of BackendConnections. These BackendConnections are the REAL connections to the given target machine
func (*Backend) GetBackendConnection ¶
func (ber *Backend) GetBackendConnection() (*BackendConnection, error)
GetBackendConnection either retrieves BackendConnection from a pool OR adds new entry to pool (or errors out)
func (*Backend) LogStats ¶
LogStats... just a hack to get some data. Log stats (used connections etc).
func (*Backend) SetIsAlive ¶
type BackendConfig ¶
type BackendConnection ¶
type BackendConnection struct { InUse bool ReverseProxy *httputil.ReverseProxy // contains filtered or unexported fields }
BackendConnection has the ReverseProxy to the real backend server. There may be many BackendConnections going from the same Backend to the real host/IP. Each BackendConnection will be in it's own goroutine (probably).
func NewBackendConnection ¶
func NewBackendConnection(uri string) *BackendConnection
func (*BackendConnection) IsInUse ¶
func (b *BackendConnection) IsInUse() bool
func (*BackendConnection) SetInUse ¶
func (b *BackendConnection) SetInUse(inUse bool)
type BackendRouter ¶
type BackendRouter struct {
// contains filtered or unexported fields
}
BackendRouter is in control of a particular path (eg. /foo). The BackendRouter has a collection of Backends. Each Backend is a unique host/ip (could be single machine or another cluster/LB etc). The BackendRouter determines which Backend should receive the request, this could be based on random/round-robin/load-tracking/wild-guess etc.
func NewBackendRouter ¶
func NewBackendRouter(acceptedHeaders map[string]string, acceptedPaths map[string]bool, bes BackendSelectionMethod) *BackendRouter
func (*BackendRouter) AddBackend ¶
func (ber *BackendRouter) AddBackend(backend *Backend) error
AddBackend adds backend to router.
func (*BackendRouter) GetBackend ¶
func (ber *BackendRouter) GetBackend() (*Backend, error)
GetBackend either retrieves backend from a pool OR adds new entry to pool (or errors out) This needs to be based on random/load/wild-guess/spirits....
type BackendRouterConfig ¶
type BackendRouterConfig struct { SelectionMethod string `json:"SelectionMethod"` AcceptedPaths []string `json:"AcceptedPaths,omitempty"` AcceptedHeaders map[string]string `json:"AcceptedHeaders,omitempty"` BackendConfigs []BackendConfig `json:"BackendConfigs,omitempty"` }
type BackendSelectionMethod ¶
type BackendSelectionMethod int
const ( BackendRoundRobin BackendSelectionMethod = 1 BackendInuseConnections BackendSelectionMethod = 2 BackendRandom BackendSelectionMethod = 3 )
func ParseBackendSelectionString ¶
func ParseBackendSelectionString(bes string) BackendSelectionMethod
type Config ¶
type Config struct { HealthCheckTimerInSeconds int `json:"HealthCheckTimerInSeconds"` CertCrtPath string `json:"certcrtpath"` CertKeyPath string `json:"certkeypath"` Host string `json:"host"` Port int `json:"port"` TlsListener bool `json:"tlslistener"` BackendRouterConfigs []BackendRouterConfig `json:"BackendRouterConfigs"` }
func LoadConfig ¶
LoadConfig, loads configuation for LBLight. Primarily backend host, port, paths etc.
type LBLight ¶
type LBLight struct {
// contains filtered or unexported fields
}
LBLight is the core of the load balancer. Listens to port, parses both headers and request paths and determines (based on configuration) where the request should be forwarded on to. All WIP and learning.
func NewLBLight ¶
func (*LBLight) AddBackendRouter ¶
func (l *LBLight) AddBackendRouter(ber *BackendRouter) error
AddBackendRouter register a BackendRouter to both pathPrefix map and header maps for lookup at runtime. If we have multiple, then we'd definitely NOT know who the request really should go to. If any of the paths/headers fail for thie BER, then fail them all.
func (*LBLight) CheckHealthOfAllBackendRouters ¶
checkHealthOfAllBackendRouters loops through all BackendRouters, in turn each BackendRouter will check each backend and attempt a connection... to determine health.
func (*LBLight) GetBackendRouterByExactPathPrefix ¶
func (l *LBLight) GetBackendRouterByExactPathPrefix(path string) (*BackendRouter, error)
GetBackendRouterByExactPathPrefix returns the backend router which is registered for the exact match of "path". This is more for registration.
func (*LBLight) GetBackendRouterByHeader ¶
func (l *LBLight) GetBackendRouterByHeader(headerName string, headerValue string) (*BackendRouter, error)
func (*LBLight) GetBackendRouterByPathPrefix ¶
func (l *LBLight) GetBackendRouterByPathPrefix(path string) (*BackendRouter, error)
GetBackendRouterByPathPrefix Checks all routers that have been registered for path prefixes and searches each registered BackendRouter for a prefix match. This means it's NOT just a map lookup but iterating over all of them looking for prefix matches. May need to rethink this a bit.
func (*LBLight) GetBackendStats ¶
GetBackendStats just a hacky get stats/connection and logs it. will be replaced by prometheus/whatever metrics.