Documentation ¶
Index ¶
- type Backend
- type HealthCheck
- type IPBackend
- type LoadBalancer
- func (l *LoadBalancer) AddPool(pattern string, pool Pool) error
- func (l *LoadBalancer) GetPool(pattern string) (Pool, error)
- func (l *LoadBalancer) PoolHealth(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error)
- func (l *LoadBalancer) RemovePool(pattern string) error
- func (l *LoadBalancer) Serve(lis net.Listener) error
- func (l *LoadBalancer) ServeTLS(lis net.Listener, certFile, keyFile string) error
- type P2C
- type Pool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthCheck ¶
HealthCheck provides a health check for a backend. The state passed is the current state of the backend. If state is Healthy but fails the check, this will cause the backend to be removed from service . If state is Sick and passes the check, the backend will be returned to service.
func HealthMultiplexer ¶
func HealthMultiplexer(healthChecks ...HealthCheck) HealthCheck
HealthMultiplexer allows combining multiple HealthCheck(s) together.
func StatusCheck ¶
func StatusCheck(urlPath string, healthyValues []string) (HealthCheck, error)
StatusCheck returns a HealthCheck that checks the status
type IPBackend ¶
type IPBackend struct {
// contains filtered or unexported fields
}
IPBackend provides a backend to our proxy that will use ip:port as the backend. This gives us static backends that isolate us from DNS changes or failures.
type LoadBalancer ¶
type LoadBalancer struct {
// contains filtered or unexported fields
}
LoadBalancer is an HTTP reverse proxy load balancer.
func (*LoadBalancer) AddPool ¶
func (l *LoadBalancer) AddPool(pattern string, pool Pool) error
AddPool adds a pool of backends that serve the serveURL listed here. If a pattern is added more than once, this will panic.
func (*LoadBalancer) GetPool ¶
func (l *LoadBalancer) GetPool(pattern string) (Pool, error)
GetPool returns a pool by its pattern.
func (*LoadBalancer) PoolHealth ¶
func (l *LoadBalancer) PoolHealth(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error)
PoolHealth returns the health of a pool as defined in the req.
func (*LoadBalancer) RemovePool ¶
func (l *LoadBalancer) RemovePool(pattern string) error
RemovePool removes a pool of backends that serve a pattern. If the pattern does not exist, the error is still nil.
type P2C ¶
type P2C struct {
// contains filtered or unexported fields
}
P2C implements Pool using the Power of 2 choice selection method.
func NewP2C ¶
func NewP2C(hc HealthCheck, interval time.Duration) (*P2C, error)
NewP2C creates a new P2C instance. hc is the health check to perform on the backend to make sure its healthy and interval is how often to do the health check.
func (*P2C) Health ¶
func (s *P2C) Health(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error)
Health implements Pool.Health().
type Pool ¶
type Pool interface { // Add adds a new Backend to the pool. The Backend must be healthy. Add(ctx context.Context, b Backend) error // Remove removes a backend from the loadbalancer. Remove(ctx context.Context, b Backend) error // Health returns the health of a pool. Health(ctx context.Context, req *pb.PoolHealthReq) (*pb.PoolHealth, error) // Close closes the pool. It should not be used after this. Close() error // ServeHTTP implements http.Handler. ServeHTTP(w http.ResponseWriter, r *http.Request) }
Pool represents a set of backends that serve a URL.