backend

package
Version: v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2014 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package backend defines interfaces and structures controlling the proxy configuration and changes.

Index

Constants

View Source
const (
	HTTP  = "http"
	HTTPS = "https"
	TCP   = "tcp"
	UNIX  = "unix"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	Network string
	Address string
}

func NewAddress

func NewAddress(network, address string) (*Address, error)

func (*Address) Equals

func (a *Address) Equals(o Address) bool

type AlreadyExistsError

type AlreadyExistsError struct {
	Message string
}

func (*AlreadyExistsError) Error

func (n *AlreadyExistsError) Error() string

type Anomaly

type Anomaly struct {
	Code    int
	Message string
}

func (Anomaly) String

func (a Anomaly) String() string

type Backend

type Backend interface {
	GetHosts() ([]*Host, error)
	AddHost(*Host) (*Host, error)
	DeleteHost(name string) error
	UpdateHostKeyPair(hostname string, keyPair *KeyPair) (*Host, error)

	GetHost(name string) (*Host, error)

	AddHostListener(hostname string, listener *Listener) (*Listener, error)
	DeleteHostListener(hostname string, listenerId string) error

	AddLocation(*Location) (*Location, error)
	GetLocation(hostname, id string) (*Location, error)
	UpdateLocationUpstream(hostname, id string, upstream string) (*Location, error)
	UpdateLocationOptions(hostname, locationId string, o LocationOptions) (*Location, error)
	DeleteLocation(hostname, id string) error

	AddLocationMiddleware(hostname, locationId string, m *MiddlewareInstance) (*MiddlewareInstance, error)
	GetLocationMiddleware(hostname, locationId string, mType, id string) (*MiddlewareInstance, error)
	UpdateLocationMiddleware(hostname, locationId string, m *MiddlewareInstance) (*MiddlewareInstance, error)
	DeleteLocationMiddleware(hostname, locationId, mType, id string) error

	GetUpstreams() ([]*Upstream, error)
	AddUpstream(*Upstream) (*Upstream, error)
	UpdateUpstreamOptions(upId string, o UpstreamOptions) (*Upstream, error)
	GetUpstream(id string) (*Upstream, error)
	DeleteUpstream(id string) error

	AddEndpoint(*Endpoint) (*Endpoint, error)
	GetEndpoint(upstreamId, id string) (*Endpoint, error)
	DeleteEndpoint(upstreamId, id string) error

	// WatchChanges is an entry point for getting the configuration changes as well as the initial configuration.
	// It should be a blocking function generating events from change.go to the changes channel.
	WatchChanges(changes chan interface{}, cancel chan bool) error

	// GetRegistry returns registry with the supported plugins.
	GetRegistry() *plugin.Registry

	Close()
}

type Bracket

type Bracket struct {
	Quantile float64
	Value    time.Duration
}

func NewBrackets

func NewBrackets(h metrics.Histogram) []Bracket

type Counters

type Counters struct {
	Period      time.Duration
	NetErrors   int64
	Total       int64
	StatusCodes []StatusCode
}

type Endpoint

type Endpoint struct {
	Id         string
	Url        string
	UpstreamId string
	Stats      RoundTripStats
}

Endpoint is a final destination of the request

func EndpointFromJSON

func EndpointFromJSON(in []byte) (*Endpoint, error)

func NewEndpoint

func NewEndpoint(upstreamId, id, url string) (*Endpoint, error)

func (*Endpoint) GetId

func (e *Endpoint) GetId() string

func (*Endpoint) GetUniqueId

func (e *Endpoint) GetUniqueId() EndpointKey

func (*Endpoint) String

func (e *Endpoint) String() string

type EndpointAdded

type EndpointAdded struct {
	Upstream *Upstream
	Endpoint *Endpoint
}

type EndpointDeleted

type EndpointDeleted struct {
	Upstream   *Upstream
	EndpointId string
}

type EndpointKey

type EndpointKey struct {
	UpstreamId string
	Id         string
}

func MustParseEndpointKey

func MustParseEndpointKey(v string) EndpointKey

func ParseEndpointKey

func ParseEndpointKey(v string) (*EndpointKey, error)

func (EndpointKey) String

func (e EndpointKey) String() string

type EndpointUpdated

type EndpointUpdated struct {
	Upstream *Upstream
	Endpoint *Endpoint
}

type Host

type Host struct {
	Name      string
	Locations []*Location
	KeyPair   *KeyPair
	Listeners []*Listener
	Options   HostOptions
}

Incoming requests are matched by their hostname first. Hostname is defined by incoming 'Host' header. E.g. curl http://example.com/alice will be matched by the host example.com first.

func HostFromJSON

func HostFromJSON(in []byte, getter plugin.SpecGetter) (*Host, error)

func HostsFromJSON

func HostsFromJSON(in []byte, getter plugin.SpecGetter) ([]*Host, error)

func NewHost

func NewHost(name string) (*Host, error)

func (*Host) GetId

func (h *Host) GetId() string

func (*Host) String

func (h *Host) String() string

type HostAdded

type HostAdded struct {
	Host *Host
}

type HostDeleted

type HostDeleted struct {
	Name string
}

type HostKeyPairUpdated

type HostKeyPairUpdated struct {
	Host *Host
}

type HostListenerAdded

type HostListenerAdded struct {
	Host     *Host
	Listener *Listener
}

type HostListenerDeleted

type HostListenerDeleted struct {
	Host       *Host
	ListenerId string
}

type HostOptions

type HostOptions struct {
	Default bool
}

type KeyPair

type KeyPair struct {
	Key  []byte
	Cert []byte
}

func KeyPairFromJSON

func KeyPairFromJSON(in []byte) (*KeyPair, error)

func NewKeyPair

func NewKeyPair(cert, key []byte) (*KeyPair, error)

func (*KeyPair) Equals

func (c *KeyPair) Equals(o *KeyPair) bool

type LatencyBrackets

type LatencyBrackets []Bracket

func (LatencyBrackets) GetQuantile

func (l LatencyBrackets) GetQuantile(q float64) (*Bracket, error)

type Listener

type Listener struct {
	Id string
	// HTTP or HTTPS
	Protocol string
	// Adddress specifies network (tcp or unix) and address (ip:port or path to unix socket)
	Address Address
}

Listener specifies the listening point - the network and interface for each host. Host can have multiple interfaces.

func ListenerFromJSON

func ListenerFromJSON(in []byte) (*Listener, error)

func NewListener

func NewListener(id, protocol, network, address string) (*Listener, error)

func (*Listener) String

func (l *Listener) String() string

type Location

type Location struct {
	Hostname    string
	Path        string
	Id          string
	Upstream    *Upstream
	Middlewares []*MiddlewareInstance
	Options     LocationOptions
	// Combined stats from all endpoints in the location
	Stats RoundTripStats
}

Hosts contain one or several locations. Each location defines a path - simply a regular expression that will be matched against request's url. Location contains link to an upstream and vulcand will use the endpoints from this upstream to serve the request. E.g. location loc1 will serve the request curl http://example.com/alice because it matches the path /alice:

func LocationFromJSON

func LocationFromJSON(in []byte, getter plugin.SpecGetter) (*Location, error)

func LocationsFromJSON

func LocationsFromJSON(in []byte, getter plugin.SpecGetter) ([]*Location, error)

func NewLocation

func NewLocation(hostname, id, path, upstreamId string) (*Location, error)

func NewLocationWithOptions

func NewLocationWithOptions(hostname, id, path, upstreamId string, options LocationOptions) (*Location, error)

func (*Location) GetId

func (l *Location) GetId() string

func (*Location) GetOptions

func (l *Location) GetOptions() (*httploc.Options, error)

func (*Location) GetUniqueId

func (l *Location) GetUniqueId() LocationKey

func (*Location) String

func (l *Location) String() string

type LocationAdded

type LocationAdded struct {
	Host     *Host
	Location *Location
}

type LocationDeleted

type LocationDeleted struct {
	Host       *Host
	LocationId string
}

type LocationKey

type LocationKey struct {
	Hostname string
	Id       string
}

func (LocationKey) String

func (l LocationKey) String() string

type LocationLimits

type LocationLimits struct {
	MaxMemBodyBytes int64 // Maximum size to keep in memory before buffering to disk
	MaxBodyBytes    int64 // Maximum size of a request body in bytes
}

Limits contains various limits one can supply for a location.

type LocationMiddlewareAdded

type LocationMiddlewareAdded struct {
	Host       *Host
	Location   *Location
	Middleware *MiddlewareInstance
}

type LocationMiddlewareDeleted

type LocationMiddlewareDeleted struct {
	Host           *Host
	Location       *Location
	MiddlewareId   string
	MiddlewareType string
}

type LocationMiddlewareUpdated

type LocationMiddlewareUpdated struct {
	Host       *Host
	Location   *Location
	Middleware *MiddlewareInstance
}

type LocationOptions

type LocationOptions struct {
	// Limits contains various limits one can supply for a location.
	Limits LocationLimits
	// Predicate that defines when requests are allowed to failover
	FailoverPredicate string
	// Used in forwarding headers
	Hostname string
	// In this case appends new forward info to the existing header
	TrustForwardHeader bool
}

Additional options to control this location, such as timeouts

func LocationOptionsFromJSON

func LocationOptionsFromJSON(in []byte) (*LocationOptions, error)

type LocationOptionsUpdated

type LocationOptionsUpdated struct {
	Host     *Host
	Location *Location
}

type LocationPathUpdated

type LocationPathUpdated struct {
	Host     *Host
	Location *Location
	Path     string
}

type LocationUpstreamUpdated

type LocationUpstreamUpdated struct {
	Host     *Host
	Location *Location
}

type MiddlewareInstance

type MiddlewareInstance struct {
	Id         string
	Priority   int
	Type       string
	Middleware plugin.Middleware
}

Wrapper that contains information about this middleware backend-specific data used for serialization/deserialization

func MiddlewareFromJSON

func MiddlewareFromJSON(in []byte, getter plugin.SpecGetter) (*MiddlewareInstance, error)

type NewBackendFn

type NewBackendFn func() (Backend, error)

type NotFoundError

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error

func (n *NotFoundError) Error() string

type RoundTripStats

type RoundTripStats struct {
	Verdict         Verdict
	Counters        Counters
	LatencyBrackets LatencyBrackets
}

RoundTrip stats contain real time statistics about performance of Endpoint or Location such as latency, processed and failed requests.

func NewRoundTripStats

func NewRoundTripStats(m *metrics.RoundTripMetrics) (*RoundTripStats, error)

func (*RoundTripStats) AppErrorRatio

func (e *RoundTripStats) AppErrorRatio() float64

AppErrorRate calculates the ratio of 500 responses that designate internal server errors to success responses - 2xx, it specifically not counts 4xx or any other than 500 error to avoid noisy results.

func (*RoundTripStats) NetErrorRatio

func (e *RoundTripStats) NetErrorRatio() float64

NetErroRate calculates the amont of ntwork errors such as time outs and dropped connection that occured in the given time window

func (*RoundTripStats) RequestsPerSecond

func (e *RoundTripStats) RequestsPerSecond() float64

func (*RoundTripStats) ResponseCodeRatio

func (e *RoundTripStats) ResponseCodeRatio(startA, endA, startB, endB int) float64

ResponseCodeRatio calculates ratio of count(startA to endA) / count(startB to endB)

func (*RoundTripStats) String

func (e *RoundTripStats) String() string

type StatsProvider

type StatsProvider interface {
	GetLocationStats(l *Location) (*RoundTripStats, error)
	GetEndpointStats(e *Endpoint) (*RoundTripStats, error)
	GetUpstreamStats(u *Upstream) (*RoundTripStats, error)

	// GetTopLocations returns locations sorted by criteria (faulty, slow, most used)
	// if hostname or upstreamId is present, will filter out locations for that host or upstreamId
	GetTopLocations(hostname, upstreamId string) ([]*Location, error)

	// GetTopEndpoints returns endpoints sorted by criteria (faulty, slow, mos used)
	// if upsrtreamId is not empty, will filter out endpoints for that upstreamId
	GetTopEndpoints(upstreamId string) ([]*Endpoint, error)
}

StatsProvider provides realtime stats abount endpoints, upstreams and locations

type StatusCode

type StatusCode struct {
	Code  int
	Count int64
}

type Upstream

type Upstream struct {
	Id        string
	Endpoints []*Endpoint
	Options   UpstreamOptions
}

Upstream is a collection of endpoints. Each location is assigned an upstream. Changing assigned upstream of the location gracefully redirects the traffic to the new endpoints of the upstream.

func NewUpstream

func NewUpstream(id string) (*Upstream, error)

NewUpstream creates a new instance of the upstream object with default options applied

func NewUpstreamWithOptions

func NewUpstreamWithOptions(id string, o UpstreamOptions) (*Upstream, error)

NewUpstreamWithOptions creates a new instance of the upstream object

func UpstreamFromJSON

func UpstreamFromJSON(in []byte) (*Upstream, error)

func (*Upstream) GetId

func (u *Upstream) GetId() string

func (*Upstream) GetTransportOptions

func (u *Upstream) GetTransportOptions() (*httploc.TransportOptions, error)

func (*Upstream) GetUniqueId

func (u *Upstream) GetUniqueId() UpstreamKey

func (*Upstream) String

func (u *Upstream) String() string

type UpstreamAdded

type UpstreamAdded struct {
	Upstream *Upstream
}

type UpstreamDeleted

type UpstreamDeleted struct {
	UpstreamId string
}

type UpstreamKeepAlive

type UpstreamKeepAlive struct {
	// Keepalive period
	Period string
	// How many idle connections will be kept per host
	MaxIdleConnsPerHost int
}

type UpstreamKey

type UpstreamKey struct {
	Id string
}

func (UpstreamKey) String

func (u UpstreamKey) String() string

type UpstreamOptions

type UpstreamOptions struct {
	Timeouts UpstreamTimeouts
	// Controls KeepAlive settins for backend servers
	KeepAlive UpstreamKeepAlive
}

Additional options to control this location, such as timeouts

func UpstreamOptionsFromJSON

func UpstreamOptionsFromJSON(in []byte) (*UpstreamOptions, error)

func (*UpstreamOptions) Equals

func (u *UpstreamOptions) Equals(o UpstreamOptions) bool

type UpstreamOptionsUpdated

type UpstreamOptionsUpdated struct {
	Upstream *Upstream
}

type UpstreamTimeouts

type UpstreamTimeouts struct {
	// Socket read timeout (before we receive the first reply header)
	Read string
	// Socket connect timeout
	Dial string
	// TLS handshake timeout
	TlsHandshake string
}

type Verdict

type Verdict struct {
	IsBad     bool
	Anomalies []Anomaly
}

func (Verdict) String

func (v Verdict) String() string

Directories

Path Synopsis
Etcd implementation of the backend, where all vulcand properties are implemented as directories or keys.
Etcd implementation of the backend, where all vulcand properties are implemented as directories or keys.
Provides in memory backend implementation, mostly used for test purposes
Provides in memory backend implementation, mostly used for test purposes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL