lb

package
v0.0.0-...-2853c3c Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DECAY = 0.1

tracks last 10 samples (very fast)

Variables

View Source
var (
	ErrNoNodes = errors.New("no nodes available")
)

Functions

func NewProxy

func NewProxy(keyFunc KeyFunc, g Grouper, r Router, conf Config) http.Handler

NewProxy will marry the given parameters into an able proxy.

Types

type Config

type Config struct {
	DBurl                string          `json:"db_url"`
	Listen               string          `json:"port"`
	ZipkinURL            string          `json:"zipkin_url"`
	Nodes                []string        `json:"nodes"`
	HealthcheckInterval  int             `json:"healthcheck_interval"`
	HealthcheckEndpoint  string          `json:"healthcheck_endpoint"`
	HealthcheckUnhealthy int             `json:"healthcheck_unhealthy"`
	HealthcheckTimeout   int             `json:"healthcheck_timeout"`
	MinAPIVersion        *semver.Version `json:"min_api_version"`

	Transport *http.Transport
}

type DBStore

type DBStore interface {
	Add(string) error
	Delete(string) error
	List() ([]string, error)
}

TODO put this somewhere better

type Grouper

type Grouper interface {
	// List returns a set of hosts that may be used to route a request
	// for a given key.
	List(key string) ([]string, error)

	// Wrap allows adding middleware to the provided http.Handler.
	Wrap(http.Handler) http.Handler
}

func NewAllGrouper

func NewAllGrouper(conf Config) (Grouper, error)

NewAllGrouper returns a Grouper that will return the entire list of nodes that are being maintained, regardless of key. An 'AllGrouper' will health check servers at a specified interval, taking them in and out as they pass/fail and exposes endpoints for adding, removing and listing nodes.

type KeyFunc

type KeyFunc func(req *http.Request) (string, error)

KeyFunc maps a request to a shard key, it may return an error if there are issues locating the shard key.

type Router

type Router interface {

	// Route will pick a node from the given set of nodes.
	Route(nodes []string, key string) (string, error)

	// InterceptResponse allows a Router to extract information from proxied
	// requests so that it might do a better job next time. InterceptResponse
	// should not modify the Response as it has already been received nor the
	// Request, having already been sent.
	InterceptResponse(req *http.Request, resp *http.Response)

	// Wrap allows adding middleware to the provided http.Handler.
	Wrap(http.Handler) http.Handler
}

func NewConsistentRouter

func NewConsistentRouter(conf Config) Router

Jump to

Keyboard shortcuts

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