Documentation
¶
Index ¶
- Constants
- type Controller
- func (control *Controller) ActivateOutbound(inbound, outbound string) error
- func (control *Controller) AddInbound(inbound *Inbound) error
- func (control *Controller) AddOutbound(inbound, outbound, addr string) error
- func (control *Controller) Close()
- func (control *Controller) List() (result []*Inbound)
- func (control *Controller) ListInbound(inbound string) (*Inbound, error)
- func (control *Controller) RESTRoutes() rest.Routes
- func (control *Controller) ReadInboundStats(inbound string) (map[string]*Stats, error)
- func (control *Controller) ReadOutboundStats(inbound, outbound string) (*Stats, error)
- func (control *Controller) ReadStats() map[string]map[string]*Stats
- func (control *Controller) RemoveInbound(inbound string) error
- func (control *Controller) RemoveOutbound(inbound, outbound string) error
- func (control *Controller) Start()
- type Distribution
- type Event
- type Inbound
- func (inbound *Inbound) ActivateOutbound(outbound string) error
- func (inbound *Inbound) AddOutbound(outbound, addr string) error
- func (inbound *Inbound) Copy() *Inbound
- func (inbound *Inbound) Init()
- func (inbound *Inbound) MarshalJSON() ([]byte, error)
- func (inbound *Inbound) ReadOutboundStats(outbound string) (*Stats, error)
- func (inbound *Inbound) ReadStats() map[string]*Stats
- func (inbound *Inbound) RemoveOutbound(outbound string) error
- func (inbound *Inbound) ServeHTTP(writer http.ResponseWriter, httpReq *http.Request)
- func (inbound *Inbound) UnmarshalJSON(body []byte) (err error)
- func (inbound *Inbound) Validate() error
- type InboundServer
- func (server *InboundServer) ActivateOutbound(outbound string) error
- func (server *InboundServer) AddOutbound(outbound, addr string) error
- func (server *InboundServer) Close()
- func (server *InboundServer) List() *Inbound
- func (server *InboundServer) ReadOutboundStats(outbound string) (*Stats, error)
- func (server *InboundServer) ReadStats() map[string]*Stats
- func (server *InboundServer) RemoveOutbound(outbound string) error
- func (server *InboundServer) ServeHTTP(writer http.ResponseWriter, httpReq *http.Request)
- type Stats
- type StatsRecorder
Constants ¶
const DefaultDistributionSize = 1000
DefaultDistributionSize will be used as the default size for the Distribution.Items if not otherwise set.
const DefaultInboundTimeout = 1 * time.Second
DefaultInboundTimeout is used if no timeout is set for an inbound.
const DefaultSampleRate = 1 * time.Second
DefaultSampleRate is used if Rate is not set set in StatsRecorder.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Controller ¶
type Controller struct {
// Inbounds is the initial list of Inbounds.
Inbounds []*Inbound
// contains filtered or unexported fields
}
Controller manages a set of Inbound objects wrapped in InboundServer objects and defines a REST interface to do so.
func NewController ¶
func NewController(inbounds []*Inbound) *Controller
NewController returns a new Controller object initialized with the given inbounds.
func (*Controller) ActivateOutbound ¶
func (control *Controller) ActivateOutbound(inbound, outbound string) error
ActivateOutbound activates the given outbound for the given inbound.
func (*Controller) AddInbound ¶
func (control *Controller) AddInbound(inbound *Inbound) error
AddInbound creates a new InboundServer for the given inbound and launches it.
func (*Controller) AddOutbound ¶
func (control *Controller) AddOutbound(inbound, outbound, addr string) error
AddOutbound adds an outbound for the given inbound.
func (*Controller) Close ¶
func (control *Controller) Close()
Close closes the managed inbound servers.
func (*Controller) List ¶
func (control *Controller) List() (result []*Inbound)
List returns the Inbound object associated with each inbounds.
func (*Controller) ListInbound ¶
func (control *Controller) ListInbound(inbound string) (*Inbound, error)
ListInbound returns the Inbound object associated with the given inbound.
func (*Controller) RESTRoutes ¶
func (control *Controller) RESTRoutes() rest.Routes
RESTRoutes defines the REST inteface for a Controller.
func (*Controller) ReadInboundStats ¶
func (control *Controller) ReadInboundStats(inbound string) (map[string]*Stats, error)
ReadInboundStats returns the stats associated with the given inbound.
func (*Controller) ReadOutboundStats ¶
func (control *Controller) ReadOutboundStats(inbound, outbound string) (*Stats, error)
ReadOutboundStats returns the stats associated with the given inbound's outbound.
func (*Controller) ReadStats ¶
func (control *Controller) ReadStats() map[string]map[string]*Stats
ReadStats returns the stats associated with each inbounds.
func (*Controller) RemoveInbound ¶
func (control *Controller) RemoveInbound(inbound string) error
RemoveInbound kills and removes the given inbound.
func (*Controller) RemoveOutbound ¶
func (control *Controller) RemoveOutbound(inbound, outbound string) error
RemoveOutbound removes the given outbound for the given inbound.
func (*Controller) Start ¶
func (control *Controller) Start()
Start initializes and starts the server associated with the configured inbounds.
type Distribution ¶
type Distribution struct {
// Items holds the value whose sie determines the size of the reservoir.
Items []uint64
// Count is the number of elements sampled.
Count uint64
// Rand is the RNG used for sampling.
Rand *rand.Rand
// contains filtered or unexported fields
}
Distribution collects a set of outcomes to calculate various percentiles using reservoir sampling to avoid unbounded memory usage.
func (*Distribution) Percentiles ¶
func (dist *Distribution) Percentiles() (p50, p90, p99, max uint64)
Percentiles returns the approximated 99th, 90th and 50th percentile as well as the maximum value seen.
func (*Distribution) Sample ¶
func (dist *Distribution) Sample(value uint64)
Sample adds a new value to the distribution.
type Event ¶
type Event struct {
// Error indicates that an error occured.
Error bool
// Timeout indicates that the request timed out.
Timeout bool
// Response is the HTTP response code received.
Response int
// Latency mesures the latency of the request.
Latency time.Duration
}
Event contains the outcome of an HTTP request.
type Inbound ¶
type Inbound struct {
// Name is the name associated with this inbound.
Name string
// Listen defines which interface and port this inbound should listen on.
Listen string
// Outbound maps a set of outbound names to the address where HTTP requests
// should be redirected to. Addresses should be of the for
// <scheme>://<host>:<port>.
Outbound map[string]string
// Active defines the name of the outbound whose response will be forwarded
// back upstream. All other outbound responses are dropped.
Active string
// Timeout defines the timeout allowed for all outbounds. If the timeout
// expires for the active outbound, TimeoutCode is sent back upstream.
Timeout time.Duration
// TimeoutCode is HTTP status code sent back upstream if a timeout occurs on
// the active outbbound.
TimeoutCode int
// Client is the http.Client which will be used to forward HTTP requests to
// all outbounds.
Client *http.Client
// IdleConnections defines the maximum size of the connection pool which
// will be used by the http client for this inbound. Setting this will
// overwrite the transport of the Client if it is set.
IdleConnections int
// contains filtered or unexported fields
}
Inbound duplicates HTTP requests to a set of outbounds and only forwards the HTTP response of an active outbound. All other responses are dropped.
Stats are also gathered for each outbound and each outbounds can also be configured to timeout.
func (*Inbound) ActivateOutbound ¶
ActivateOutbound activates the given outbound.
func (*Inbound) AddOutbound ¶
AddOutbound adds a new outbound associated with the given address. If the outbound already exists, it is overridden.
func (*Inbound) Init ¶
func (inbound *Inbound) Init()
Init initializes the object. Inbounds are lazily initialized so calling this is optional.
func (*Inbound) MarshalJSON ¶
MarshalJSON defines a custom JSON format for the encoding/json package.
func (*Inbound) ReadOutboundStats ¶
ReadOutboundStats returns the stats associated with a given outbound.
func (*Inbound) RemoveOutbound ¶
RemoveOutbound removes the given outbound. An error is returned if the outbound doesn't exist.
func (*Inbound) ServeHTTP ¶
func (inbound *Inbound) ServeHTTP(writer http.ResponseWriter, httpReq *http.Request)
ServeHTTP forwards the given HTTP request to all the outbounds and forwards the response of the active outbound back upstream. All other responses are dropped.
func (*Inbound) UnmarshalJSON ¶
UnmarshalJSON defines a custom JSON format for the encoding/json package.
type InboundServer ¶
type InboundServer struct {
// contains filtered or unexported fields
}
InboundServer wraps an Inbound object into an HTTP server and allows the Inbound to be safely manipulated using a copy-on-write scheme.
InboundServer currently assumes that the various management functions are synchronized externally.
func NewInboundServer ¶
func NewInboundServer(inbound *Inbound) (*InboundServer, error)
NewInboundServer creates and starts a new HTTP server associated with the given Inbound.
func (*InboundServer) ActivateOutbound ¶
func (server *InboundServer) ActivateOutbound(outbound string) error
ActivateOutbound calls ActivateOutbound on the managed inbound.
func (*InboundServer) AddOutbound ¶
func (server *InboundServer) AddOutbound(outbound, addr string) error
AddOutbound calls AddOutbound on the managed inbound.
func (*InboundServer) Close ¶
func (server *InboundServer) Close()
Close closes the HTTP server releasing all associated resources.
func (*InboundServer) List ¶
func (server *InboundServer) List() *Inbound
List returns the managed inbound.
func (*InboundServer) ReadOutboundStats ¶
func (server *InboundServer) ReadOutboundStats(outbound string) (*Stats, error)
ReadOutboundStats calls ReadOutboundStats on the managed inbound.
func (*InboundServer) ReadStats ¶
func (server *InboundServer) ReadStats() map[string]*Stats
ReadStats calls ReadStats on the managed inbound.
func (*InboundServer) RemoveOutbound ¶
func (server *InboundServer) RemoveOutbound(outbound string) error
RemoveOutbound calls RemoveOutbound on the managed inbound.
func (*InboundServer) ServeHTTP ¶
func (server *InboundServer) ServeHTTP(writer http.ResponseWriter, httpReq *http.Request)
ServeHTTP forwards the given HTTP request to the managed inbound.
type Stats ¶
type Stats struct {
// Requests counts the number of requests made.
Requests uint64
// Errors counts the number of errors encountered.
Errors uint64
// Timeouts counts the number of timeouts encountered.
Timeouts uint64
// Latency is the latency distribution of all requests.
Latency Distribution
// Responses counts the number of responses received for an HTTP status
// code.
Responses map[int]uint64
}
Stats contains the stats of an outbound at a given point in time.
func (*Stats) MarshalJSON ¶
MarshalJSON defines a custom JSON format for encoding/json.
type StatsRecorder ¶
type StatsRecorder struct {
// Rate at which stats are updated.
Rate time.Duration
// Rand is the RNG used for stats sampling.
Rand *rand.Rand
// contains filtered or unexported fields
}
StatsRecorder records stats for a given outbound and updates them at a given rate.
func (*StatsRecorder) Close ¶
func (recorder *StatsRecorder) Close()
Close terminates the stats recorder.
func (*StatsRecorder) Read ¶
func (recorder *StatsRecorder) Read() (stats *Stats)
Read returns the last updated stats.
func (*StatsRecorder) Record ¶
func (recorder *StatsRecorder) Record(event Event)
Record records the given outcome.