engine

package
v0.0.0-...-7b8bf0e Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2015 License: Apache-2.0 Imports: 13 Imported by: 13

Documentation

Overview

Package model defines interfaces and structures controlling the proxy configuration.

Index

Constants

View Source
const (
	HTTP  = "http"
	HTTPS = "https"
	TCP   = "tcp"
	UNIX  = "unix"
	NoTTL = 0
)
View Source
const DefaultLRUCapacity = 1024
View Source
const LRUCacheType = "LRU"

Variables

This section is empty.

Functions

func NewTLSConfig

func NewTLSConfig(s *TLSSettings) (*tls.Config, error)

NewTLSConfig validates the TLSSettings and returns the tls.Config with the converted parameters

func NewTLSSessionCache

func NewTLSSessionCache(s *TLSSessionCache) (tls.ClientSessionCache, error)

NewTLSSessionCache validates parameters and creates a new TLS session cache

func ParseCipherSuite

func ParseCipherSuite(cs string) (uint16, error)

func ParseTLSVersion

func ParseTLSVersion(version string) (uint16, error)

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 struct {
	Id       string
	Type     string
	Stats    *RoundTripStats `json:",omitempty"`
	Settings interface{}
}

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

func BackendFromJSON

func BackendFromJSON(in []byte, id ...string) (*Backend, error)

func BackendsFromJSON

func BackendsFromJSON(in []byte) ([]Backend, error)

func NewHTTPBackend

func NewHTTPBackend(id string, s HTTPBackendSettings) (*Backend, error)

NewBackend creates a new instance of the backend object

func (*Backend) GetId

func (b *Backend) GetId() string

func (*Backend) GetUniqueId

func (b *Backend) GetUniqueId() BackendKey

func (*Backend) HTTPSettings

func (b *Backend) HTTPSettings() HTTPBackendSettings

func (*Backend) String

func (b *Backend) String() string

func (*Backend) TransportSettings

func (b *Backend) TransportSettings() (*TransportSettings, error)

type BackendDeleted

type BackendDeleted struct {
	BackendKey BackendKey
}

func (*BackendDeleted) String

func (b *BackendDeleted) String() string

type BackendKey

type BackendKey struct {
	Id string
}

func (BackendKey) String

func (u BackendKey) String() string

type BackendUpserted

type BackendUpserted struct {
	Backend Backend
}

func (*BackendUpserted) String

func (b *BackendUpserted) String() string

type Bracket

type Bracket struct {
	Quantile float64
	Value    time.Duration
}

func NewBrackets

func NewBrackets(h *memmetrics.HDRHistogram) []Bracket

type Counters

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

type Engine

type Engine interface {
	// GetHosts returns list of hosts registered in the storage engine
	// Returns empty list in case if there are no hosts.
	GetHosts() ([]Host, error)
	// GetHost returns host by given key, or engine.NotFoundError if it's not found
	GetHost(HostKey) (*Host, error)
	// UpsertHost updates or inserts the host, make sure to supply valid hostname
	UpsertHost(Host) error
	// DeleteHost deletes host by given key or returns engine.NotFoundError if it's not found
	DeleteHost(HostKey) error

	// GetListeners returns list of listeners registered in the storage engine
	// Returns empty list in case if there are no listeners
	GetListeners() ([]Listener, error)
	// GetListener returns a listener by key or engine.NotFoundError if it's not found
	GetListener(ListenerKey) (*Listener, error)
	// Updates or inserts a new listener, Listener.Id should not be empty
	UpsertListener(Listener) error
	// DeleteListener deletes a listener by key, returns engine.NotFoundError if it's not found
	DeleteListener(ListenerKey) error

	// GetFrontends returns a list of frontends registered in Vulcand
	// Returns empty list in case if there are no frontends
	GetFrontends() ([]Frontend, error)
	// GetFrontend returns a frontend by given key, or engine.NotFoundError if it's not found
	GetFrontend(FrontendKey) (*Frontend, error)
	// UpsertFrontend updates or inserts the frontend. Frontend.Id should not be empty. The second field specifies TTL, will be set to 0
	// in case if the frontend should not expire.
	UpsertFrontend(Frontend, time.Duration) error
	// DeleteFrontend deletes a frontend by a given key, returns engine.NotFoundError if it's not found
	DeleteFrontend(FrontendKey) error

	// GetMiddlewares returns middlewares registered for a given frontend
	// Returns empty list if there are no registered middlewares
	GetMiddlewares(FrontendKey) ([]Middleware, error)
	// GetMiddleware returns middleware by a given key, returns engine.NotFoundError if it's not there
	GetMiddleware(MiddlewareKey) (*Middleware, error)
	// UpsertMiddleware updates or inserts a middleware for a frontend. FrontendKey.Id and Middleware.Id should not be empty
	UpsertMiddleware(FrontendKey, Middleware, time.Duration) error
	// Delete middleware by given key, returns engine.NotFoundError if it's not found
	DeleteMiddleware(MiddlewareKey) error

	// GetBackends returns list of registered backends. Returns empty list if there are no backends
	GetBackends() ([]Backend, error)
	// GetBackend returns backend by given key, returns engine.NotFoundError if its not found
	GetBackend(BackendKey) (*Backend, error)
	// UpsertBackend updates or inserts a new backend. Backend.Id should not be empty
	UpsertBackend(Backend) error
	// DeleteBackend deletes backend by it's key. BackendKey.Id should not be empty. In case if backend is being used by frontends
	// this method should fail to preserve integrity, otherwise it will leave frontends in broken state
	DeleteBackend(BackendKey) error

	// GetServers returns servers assigned to the backend. BackendKey.Id should not be empty
	// Returns empty list if there are not assigned servers. Returns engine.NotFoundError if Backend does not exist
	GetServers(BackendKey) ([]Server, error)
	// GetServer returns server by given key or engine.NotFoundError if server is not found
	GetServer(ServerKey) (*Server, error)
	// UpsertServer updates or inserts a server. BackendKey.Id and Server.Id should not be empty.
	// TTL provides time to expire, in case if it's 0 server is permanent.
	UpsertServer(BackendKey, Server, time.Duration) error
	// DeleteServer deletes a server by given key. ServerKey.Id should not be empty.
	// Returns engine.NotFoundError if server not found
	DeleteServer(ServerKey) error

	// Subscribe 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.
	// Each change should be an instance of the struct provided in events.go
	// In  case if cancel channel is closed, the subscribe events should no longer be generated.
	Subscribe(events chan interface{}, cancel chan bool) error

	// GetRegistry returns registry with the supported plugins. It should be stored by Engine instance.
	GetRegistry() *plugin.Registry

	// GetLogSeverity returns the current logging severity level
	GetLogSeverity() string
	// SetLogSeverity updates the logging severity level
	SetLogSeverity(string) error

	// Close should close all underlying resources such as connections, files, etc.
	Close()
}

Engine is an interface for storage and configuration engine, e.g. Etcd. Simple in memory implementation is available at engine/memng package Engines should pass the following acceptance suite to be compatible: engine/test/suite.go, see engine/etcdng/etcd_test.go and engine/memng/mem_test.go for details

type EngineApiHandlers

type EngineApiHandlers interface {
	AddApiHandlers(app *scroll.App)
}

type Frontend

type Frontend struct {
	Id        string
	Route     string
	Type      string
	BackendId string

	Stats    *RoundTripStats `json:",omitempty"`
	Settings interface{}     `json:",omitempty"`
}

Frontend is connected to a backend and vulcand will use the servers from this backend.

func FrontendFromJSON

func FrontendFromJSON(in []byte, id ...string) (*Frontend, error)

func FrontendsFromJSON

func FrontendsFromJSON(in []byte) ([]Frontend, error)

func NewHTTPFrontend

func NewHTTPFrontend(id, backendId string, routeExpr string, settings HTTPFrontendSettings) (*Frontend, error)

func (*Frontend) GetId

func (l *Frontend) GetId() string

func (*Frontend) GetKey

func (l *Frontend) GetKey() FrontendKey

func (*Frontend) HTTPSettings

func (f *Frontend) HTTPSettings() HTTPFrontendSettings

func (*Frontend) String

func (f *Frontend) String() string

type FrontendDeleted

type FrontendDeleted struct {
	FrontendKey FrontendKey
}

func (*FrontendDeleted) String

func (f *FrontendDeleted) String() string

type FrontendKey

type FrontendKey struct {
	Id string
}

func (FrontendKey) String

func (f FrontendKey) String() string

type FrontendUpserted

type FrontendUpserted struct {
	Frontend Frontend
}

func (*FrontendUpserted) String

func (f *FrontendUpserted) String() string

type HTTPBackendKeepAlive

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

type HTTPBackendSettings

type HTTPBackendSettings struct {
	// Timeouts provides timeout settings for backend servers
	Timeouts HTTPBackendTimeouts
	// KeepAlive controls keep-alive settings for backend servers
	KeepAlive HTTPBackendKeepAlive
	// TLS provides optional TLS settings for HTTP backend
	TLS *TLSSettings `json:",omitempty"`
}

func (*HTTPBackendSettings) Equals

type HTTPBackendTimeouts

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

type HTTPFrontendLimits

type HTTPFrontendLimits 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 HTTPFrontendSettings

type HTTPFrontendSettings struct {
	// Limits contains various limits one can supply for a location.
	Limits HTTPFrontendLimits
	// 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
	// Used when no servers are available
	NoServersHandler NoServersHandler
	// Should host header be forwarded as-is?
	PassHostHeader bool
}

Additional options to control this location, such as timeouts

func (HTTPFrontendSettings) Equals

type HTTPSListenerSettings

type HTTPSListenerSettings struct {
	TLS TLSSettings
}

type Host

type Host struct {
	Name     string
	Settings HostSettings
}

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, name ...string) (*Host, error)

func HostsFromJSON

func HostsFromJSON(in []byte) ([]Host, error)

func NewHost

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

func (*Host) GetId

func (h *Host) GetId() string

func (*Host) String

func (h *Host) String() string

type HostDeleted

type HostDeleted struct {
	HostKey HostKey
}

func (*HostDeleted) String

func (h *HostDeleted) String() string

type HostKey

type HostKey struct {
	Name string
}

func (HostKey) String

func (h HostKey) String() string

type HostSettings

type HostSettings struct {
	Default bool
	KeyPair *KeyPair
	OCSP    OCSPSettings
}

type HostUpserted

type HostUpserted struct {
	Host Host
}

func (*HostUpserted) String

func (h *HostUpserted) String() string

type InitMiddlewareEngine

type InitMiddlewareEngine interface {
	InitEngine(Engine)
}

interfaces for plugins which requires some additional data for initialization

type InitMiddlewareFrontend

type InitMiddlewareFrontend interface {
	OnUpsertToFrontend(Frontend)
}

type InvalidFormatError

type InvalidFormatError struct {
	Message string
}

func (*InvalidFormatError) Error

func (n *InvalidFormatError) Error() string

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 LRUSessionCacheSettings

type LRUSessionCacheSettings struct {
	// LRU Capacity default is 1024
	Capacity int
}

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
	// Scope is optional expression that limits the operational scope of this listener
	Scope string
	// Settings provides listener-type specific settings, e.g. TLS settings for HTTPS listener
	Settings *HTTPSListenerSettings `json:",omitempty"`
}

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

func ListenerFromJSON

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

func ListenersFromJSON

func ListenersFromJSON(in []byte) ([]Listener, error)

func NewListener

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

func (*Listener) SettingsEquals

func (l *Listener) SettingsEquals(o *Listener) bool

func (*Listener) String

func (l *Listener) String() string

func (*Listener) TLSConfig

func (l *Listener) TLSConfig() (*tls.Config, error)

type ListenerDeleted

type ListenerDeleted struct {
	ListenerKey ListenerKey
}

func (*ListenerDeleted) String

func (l *ListenerDeleted) String() string

type ListenerKey

type ListenerKey struct {
	Id string
}

func (ListenerKey) String

func (l ListenerKey) String() string

type ListenerUpserted

type ListenerUpserted struct {
	HostKey  HostKey
	Listener Listener
}

func (*ListenerUpserted) String

func (l *ListenerUpserted) String() string

type Middleware

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

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

func MiddlewareFromJSON

func MiddlewareFromJSON(in []byte, getter plugin.SpecGetter, id ...string) (*Middleware, error)

func MiddlewaresFromJSON

func MiddlewaresFromJSON(in []byte, getter plugin.SpecGetter) ([]Middleware, error)

type MiddlewareDeleted

type MiddlewareDeleted struct {
	MiddlewareKey MiddlewareKey
}

func (*MiddlewareDeleted) String

func (m *MiddlewareDeleted) String() string

type MiddlewareKey

type MiddlewareKey struct {
	FrontendKey FrontendKey
	Id          string
}

func (MiddlewareKey) String

func (m MiddlewareKey) String() string

type MiddlewareUpserted

type MiddlewareUpserted struct {
	FrontendKey FrontendKey
	Middleware  Middleware
}

func (*MiddlewareUpserted) String

func (m *MiddlewareUpserted) String() string

type NewEngineFn

type NewEngineFn func() (Engine, error)

type NoServersHandler

type NoServersHandler struct {
	StatusCode  int
	ContentType string
	Body        string
}

func (*NoServersHandler) ServeHTTP

func (e *NoServersHandler) ServeHTTP(w http.ResponseWriter, req *http.Request, err error)

type NotFoundError

type NotFoundError struct {
	Message string
}

func (*NotFoundError) Error

func (n *NotFoundError) Error() string

type OCSPSettings

type OCSPSettings struct {
	Enabled bool
	Period  string
	// Optional responders. Responder is the CA-operated HTTP server that responds with revocation status
	// If set, this field will override
	Responders         []string
	SkipSignatureCheck bool
}

Sets up OCSP stapling, see http://en.wikipedia.org/wiki/OCSP_stapling

func (*OCSPSettings) Equals

func (o *OCSPSettings) Equals(other *OCSPSettings) bool

func (*OCSPSettings) RefreshPeriod

func (o *OCSPSettings) RefreshPeriod() (time.Duration, error)

type RawMiddleware

type RawMiddleware struct {
	Id         string
	Type       string
	Priority   int
	Middleware json.RawMessage
}

type RoundTripStats

type RoundTripStats struct {
	Verdict         Verdict
	Counters        Counters
	LatencyBrackets LatencyBrackets
}

RoundTripStats contain real time statistics about performance of Server or Frontend such as latency, processed and failed requests.

func NewRoundTripStats

func NewRoundTripStats(m *memmetrics.RTMetrics) (*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 Server

type Server struct {
	Id    string
	URL   string
	Stats *RoundTripStats `json:",omitempty"`
}

Server is a final destination of the request

func NewServer

func NewServer(id, u string) (*Server, error)

func ServerFromJSON

func ServerFromJSON(in []byte, id ...string) (*Server, error)

func ServersFromJSON

func ServersFromJSON(in []byte) ([]Server, error)

func (*Server) GetId

func (e *Server) GetId() string

func (*Server) String

func (e *Server) String() string

type ServerDeleted

type ServerDeleted struct {
	ServerKey ServerKey
}

func (*ServerDeleted) String

func (s *ServerDeleted) String() string

type ServerKey

type ServerKey struct {
	BackendKey BackendKey
	Id         string
}

func MustParseServerKey

func MustParseServerKey(v string) ServerKey

func ParseServerKey

func ParseServerKey(v string) (*ServerKey, error)

func (ServerKey) String

func (e ServerKey) String() string

type ServerUpserted

type ServerUpserted struct {
	BackendKey BackendKey
	Server     Server
}

func (*ServerUpserted) String

func (s *ServerUpserted) String() string

type StatsProvider

type StatsProvider interface {
	FrontendStats(FrontendKey) (*RoundTripStats, error)
	ServerStats(ServerKey) (*RoundTripStats, error)
	BackendStats(BackendKey) (*RoundTripStats, error)

	// TopFrontends returns locations sorted by criteria (faulty, slow, most used)
	// if hostname or backendId is present, will filter out locations for that host or backendId
	TopFrontends(*BackendKey) ([]Frontend, error)

	// TopServers returns endpoints sorted by criteria (faulty, slow, mos used)
	// if backendId is not empty, will filter out endpoints for that backendId
	TopServers(*BackendKey) ([]Server, error)
}

StatsProvider provides realtime stats abount endpoints, backends and locations

type StatusCode

type StatusCode struct {
	Code  int
	Count int64
}

type TLSSessionCache

type TLSSessionCache struct {
	// Session cache implementation, default is 'LRU' with capacity 1024
	Type     string
	Settings *LRUSessionCacheSettings
}

TLSSessionCache sets up parameters for TLS session cache

func (*TLSSessionCache) Equals

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

type TLSSettings

type TLSSettings struct {
	// PreferServerCipherSuites controls whether the server selects the CipherSuites
	PreferServerCipherSuites bool

	// SkipVerify skips certificate check, very insecure
	InsecureSkipVerify bool

	// MinVersion is minimal TLS version "VersionTLS10" is default
	MinVersion string

	// MaxVersion is max supported TLS version, "VersionTLS12" is default
	MaxVersion string

	// SessionTicketsDisabled disables session ticket resumption support
	SessionTicketsDisabled bool

	// SessionCache specifies TLS session cache, default it 'LRU' with capacity 1024
	SessionCache TLSSessionCache

	// Preferred CipherSuites, default is:
	//
	// TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256
	// TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
	// TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA
	// TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA
	// TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA
	// TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA
	// TLS_RSA_WITH_AES_256_CBC_SHA
	// TLS_RSA_WITH_AES_128_CBC_SHA
	CipherSuites []string
}

TLSSettings is a JSON and API friendly version of some of the tls.Config parameters

func (*TLSSettings) Equals

func (s *TLSSettings) Equals(other *TLSSettings) bool

type TransportKeepAlive

type TransportKeepAlive struct {
	// Keepalive period
	Period time.Duration
	// How many idle connections will be kept per host
	MaxIdleConnsPerHost int
}

type TransportSettings

type TransportSettings struct {
	Timeouts  TransportTimeouts
	KeepAlive TransportKeepAlive
	TLS       *tls.Config
}

type TransportTimeouts

type TransportTimeouts struct {
	// Socket read timeout (before we receive the first reply header)
	Read time.Duration
	// Socket connect timeout
	Dial time.Duration
	// TLS handshake timeout
	TLSHandshake time.Duration
}

type Verdict

type Verdict struct {
	IsBad     bool
	Anomalies []Anomaly
}

func (Verdict) String

func (v Verdict) String() string

Directories

Path Synopsis
package etcdng contains the implementation of the Etcd-backed engine, where all vulcand properties are implemented as directories or keys.
package etcdng contains the implementation of the Etcd-backed engine, where all vulcand properties are implemented as directories or keys.
package memng provides in memory engine implementation, mostly used for test purposes
package memng provides in memory engine implementation, mostly used for test purposes
package TomlNgng provides in toml engine implementation
package TomlNgng provides in toml engine implementation

Jump to

Keyboard shortcuts

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