healthcheck

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// SupportedPolicies is the collection of policies registered
	SupportedPolicies = make(map[string]func() Policy)
)

Functions

func RegisterPolicy

func RegisterPolicy(name string, policy func() Policy)

RegisterPolicy adds a custom policy to the proxy.

Types

type HealthCheck

type HealthCheck struct {
	Hosts       HostPool
	Policy      Policy
	Spray       Policy
	FailTimeout time.Duration
	MaxFails    int32
	Path        string
	Port        string
	Interval    time.Duration
	// contains filtered or unexported fields
}

HealthCheck is used for performing healthcheck on a collection of upstream hosts and select one based on the policy.

func (*HealthCheck) Select

func (u *HealthCheck) Select() *UpstreamHost

Select selects an upstream host based on the policy and the healthcheck result.

func (*HealthCheck) Start

func (u *HealthCheck) Start()

Start starts the healthcheck

func (*HealthCheck) Stop

func (u *HealthCheck) Stop() error

Stop sends a signal to all goroutines started by this staticUpstream to exit and waits for them to finish before returning.

type HostPool

type HostPool []*UpstreamHost

HostPool is a collection of UpstreamHosts.

type LeastConn

type LeastConn struct{}

LeastConn is a policy that selects the host with the least connections.

func (*LeastConn) Select

func (r *LeastConn) Select(pool HostPool) *UpstreamHost

Select selects the up host with the least number of connections in the pool. If more than one host has the same least number of connections, one of the hosts is chosen at random.

type Policy

type Policy interface {
	Select(pool HostPool) *UpstreamHost
}

Policy decides how a host will be selected from a pool. When all hosts are unhealthy, it is assumed the healthchecking failed. In this case each policy will *randomly* return a host from the pool to prevent no traffic to go through at all.

type Random

type Random struct{}

Random is a policy that selects up hosts from a pool at random.

func (*Random) Select

func (r *Random) Select(pool HostPool) *UpstreamHost

Select selects an up host at random from the specified pool.

type RoundRobin

type RoundRobin struct {
	Robin uint32
}

RoundRobin is a policy that selects hosts based on round robin ordering.

func (*RoundRobin) Select

func (r *RoundRobin) Select(pool HostPool) *UpstreamHost

Select selects an up host from the pool using a round robin ordering scheme.

type Spray

type Spray struct{}

Spray is a policy that selects a host from a pool at random. This should be used as a last ditch attempt to get a host when all hosts are reporting unhealthy.

func (*Spray) Select

func (r *Spray) Select(pool HostPool) *UpstreamHost

Select selects an up host at random from the specified pool.

type UpstreamHost

type UpstreamHost struct {
	Conns       int64  // must be first field to be 64-bit aligned on 32-bit systems
	Name        string // IP address (and port) of this upstream host
	Fails       int32
	FailTimeout time.Duration
	CheckDown   UpstreamHostDownFunc
	CheckURL    string
	Checking    bool
	sync.Mutex
}

UpstreamHost represents a single proxy upstream

func (*UpstreamHost) Down

func (uh *UpstreamHost) Down() bool

Down checks whether the upstream host is down or not. Down will try to use uh.CheckDown first, and will fall back to some default criteria if necessary.

func (*UpstreamHost) HealthCheckURL

func (uh *UpstreamHost) HealthCheckURL()

HealthCheckURL performs the http.Get that implements healthcheck.

type UpstreamHostDownFunc

type UpstreamHostDownFunc func(*UpstreamHost) bool

UpstreamHostDownFunc can be used to customize how Down behaves.

Jump to

Keyboard shortcuts

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