lb

package
v0.0.0-...-c4ccf5f Latest Latest
Warning

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

Go to latest
Published: Jan 6, 2018 License: Apache-2.0 Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StateUnknown = iota
	StateHealthy
	StateUnhealthy
)
View Source
const DECAY = 0.1

tracks last 10 samples (very fast)

Variables

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

Functions

func NewK8sClient

func NewK8sClient(conf Config) (*kubernetes.Clientset, error)

func NewK8sStore

func NewK8sStore(conf Config) (*k8sStore, error)

func NewProxy

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

NewProxy will marry the given parameters into an able proxy.

func NullHandler

func NullHandler() http.Handler

Types

type Config

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

	// Kubernetes support
	Namespace     string `json:"k8s_namespace"`
	LabelSelector string `json:"k8s_label_selector"`
	TargetPort    int    `json:"target_port"`

	Transport *http.Transport
}

type DBStore

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

TODO put this somewhere better

func NewDB

func NewDB(conf Config) (DBStore, error)

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, db DBStore) (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