Documentation ¶
Index ¶
- Constants
- Variables
- func IsKnownHealthCheck(healthcheck string) bool
- func IsKnownLoadBalancerPolicy(policyName string) bool
- func KnownHealthChecks() string
- func MakeHealthCheck(lbEndpoint *LoadBalancerEndpoint, serverConfig config.ServerConfig, loop bool) func()
- func RegisterLoadBalancer(policyName string, factory LoadBalancerFactory) error
- func RegisteredLoadBalancers() string
- type BackendLoadBalancer
- type LoadBalancer
- type LoadBalancerEndpoint
- type LoadBalancerFactory
- type PreferLocalLoadBalancer
- type PreferLocalLoadBalancerFactory
- type RoundRobinLoadBalancer
- type RoundRobinLoadBalancerFactory
Constants ¶
const DefaultHealthCheckInterval = 30 * 1000 //30 seconds
DefaultHealthCheckInterval is the time between health checks if no value is specified by the configuration
const DefaultHealthCheckTimeout = 10 * 1000 //10 seconds
DefaultHealthCheckTimeout is the timeout for the health check if no value is specified by the configuration
Variables ¶
var ErrBackendNotFound = errors.New("Given backed end not found in active listener config")
Functions ¶
func IsKnownHealthCheck ¶
IsKnownHealthCheck returns true for the health check types supported by the toolkit
func IsKnownLoadBalancerPolicy ¶
IsKnownLoadBalancerPolicy returns true if the load balancer policy has been registered, false otherwise
func KnownHealthChecks ¶
func KnownHealthChecks() string
KnownHealthChecks returns the names of the health checks supported bt the toolkit
func MakeHealthCheck ¶
func MakeHealthCheck(lbEndpoint *LoadBalancerEndpoint, serverConfig config.ServerConfig, loop bool) func()
MakeHealthCheck returns a health check function based on the server configuration and load balancer endpoint. The loop arguement is meant to enable testability - normal health check functions run until the listener is shutdown, unit test health checks run once typically.
func RegisterLoadBalancer ¶
func RegisterLoadBalancer(policyName string, factory LoadBalancerFactory) error
RegisterLoadBalancer registers a load balancer factory with a given load balancer policy name. Once registered, the load balancer policy can be used in the configuration of a backend.
func RegisteredLoadBalancers ¶
func RegisteredLoadBalancers() string
RegisteredLoadBalancers returns a string listing all registered load balanacers
Types ¶
type BackendLoadBalancer ¶
type BackendLoadBalancer struct { LoadBalancer LoadBalancer BackendConfig *config.BackendConfig CertPool *x509.CertPool // contains filtered or unexported fields }
func NewBackendLoadBalancer ¶
func NewBackendLoadBalancer(backendName string) (*BackendLoadBalancer, error)
NewLoadBalancer instantiates a load balancer based on the named backend configuration. Backend names are scoped to routes, thus the route is given to ensure the correct backend is returned if multiple backend definitions with the same name are given.
func (*BackendLoadBalancer) DoWithLoadBalancer ¶
type LoadBalancer ¶
type LoadBalancer interface { GetConnectAddress() (string, error) MarkEndpointDown(string) error MarkEndpointUp(string) error GetEndpoints() (healthy []string, unhealthy []string) }
LoadBalancer has methods for handing out connection addressed and marking endpoints up or down.
type LoadBalancerEndpoint ¶
type LoadBalancerEndpoint struct { Address string PingURI string Up bool CACertPath string // contains filtered or unexported fields }
LoadBalancerEndpoint contains the information about an endpoint needed by the load balancer for handing connections to a consumer
func (*LoadBalancerEndpoint) IsUp ¶
func (lb *LoadBalancerEndpoint) IsUp() bool
IsUp reads the status of the endpoint. The function is safe for simultaneous use by multiple goroutines.
func (*LoadBalancerEndpoint) MarkLoadBalancerEndpointUp ¶
func (lb *LoadBalancerEndpoint) MarkLoadBalancerEndpointUp(isUp bool)
MarkLoadBalancerEndpointUp sets the status for this endpoind. The function is safe for simultaneous use by multiple goroutines.
type LoadBalancerFactory ¶
type LoadBalancerFactory interface {
NewLoadBalancer(name, caCertPath string, servers []config.ServerConfig) (LoadBalancer, error)
}
LoadBalancerFactory defines an interface for instantiating load balancers.
func ObtainFactoryForLoadBalancer ¶
func ObtainFactoryForLoadBalancer(policyName string) LoadBalancerFactory
ObtainFactoryForLoadBalancer returns the load balancer associated with the given policy.
type PreferLocalLoadBalancer ¶
type PreferLocalLoadBalancer struct { BackendName string LocalServers LoadBalancer RemoteServers LoadBalancer }
PreferLocalLoadBalancer is a load balancer that looks to route traffic locally before sending traffic remote. Local is defined as servers that have the same hostname as that the load balancer is deployed on. The load balancer keeps two server pools - a local pool and a remote pool. Local traffic is used and distributed via a round robin load balancer when a local server is available, other wise remote servers are used.
func (*PreferLocalLoadBalancer) GetConnectAddress ¶
func (pl *PreferLocalLoadBalancer) GetConnectAddress() (string, error)
GetConnectAddress returns the connect address for the PreferLocalLoadBalancer instance
func (*PreferLocalLoadBalancer) GetEndpoints ¶
func (pl *PreferLocalLoadBalancer) GetEndpoints() ([]string, []string)
GetEndpoints returns the endpoints associated with the load balancer, partitioning the set of endpoints into healthy and unhealthy endpoints
func (*PreferLocalLoadBalancer) MarkEndpointDown ¶
func (pl *PreferLocalLoadBalancer) MarkEndpointDown(endpoint string) error
MarkEndpointDown marks the given endpoint down for the PreferLocalLoadBalancer instance
func (*PreferLocalLoadBalancer) MarkEndpointUp ¶
func (pl *PreferLocalLoadBalancer) MarkEndpointUp(endpoint string) error
MarkEndpointUp marks the given endpoint down for the PreferLocalLoadBalancer instance
type PreferLocalLoadBalancerFactory ¶
type PreferLocalLoadBalancerFactory struct{}
PreferLocalLoadBalancerFactory is used to instantiate PreferLocalLoadBalancer instances.
func (*PreferLocalLoadBalancerFactory) NewLoadBalancer ¶
func (pl *PreferLocalLoadBalancerFactory) NewLoadBalancer(backendName, caCertPath string, servers []config.ServerConfig) (LoadBalancer, error)
NewLoadBalancer creates an instance of PreferLocalLoadBalancer
type RoundRobinLoadBalancer ¶
type RoundRobinLoadBalancer struct {
// contains filtered or unexported fields
}
RoundRobinLoadBalancer maintains the information needed to hand out connections one after another in order
func (*RoundRobinLoadBalancer) GetConnectAddress ¶
func (rr *RoundRobinLoadBalancer) GetConnectAddress() (string, error)
GetConnectAddress return the next connect address, then advances the ring to the next server address in the sequence.
func (*RoundRobinLoadBalancer) GetEndpoints ¶
func (rr *RoundRobinLoadBalancer) GetEndpoints() ([]string, []string)
GetEndpoints returns the endpoints associated with the load balancer, partitioning the set of endpoints into healthy and unhealthy endpoints
func (*RoundRobinLoadBalancer) MarkEndpointDown ¶
func (rr *RoundRobinLoadBalancer) MarkEndpointDown(connectAddress string) error
MarkEndpointDown marks the endpoint in the load balancer pool associated with the connect address as up.
func (*RoundRobinLoadBalancer) MarkEndpointUp ¶
func (rr *RoundRobinLoadBalancer) MarkEndpointUp(connectAddress string) error
MarkEndpointUp marks the endpoint in the load balancer pool associated with the connect address as up.
type RoundRobinLoadBalancerFactory ¶
type RoundRobinLoadBalancerFactory struct{}
RoundRobinLoadBalancerFactory is the method receiver for the round robin load balancer factory method
func (*RoundRobinLoadBalancerFactory) NewLoadBalancer ¶
func (rrf *RoundRobinLoadBalancerFactory) NewLoadBalancer(backendName, caCertPath string, servers []config.ServerConfig) (LoadBalancer, error)
NewLoadBalancer creates a new instance of a Round Robin load balancer