nfork

package
v0.0.0-...-dcab4b5 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const DefaultDistributionSize = 1000

DefaultDistributionSize will be used as the default size for the Distribution.Items if not otherwise set.

View Source
const DefaultInboundTimeout = 1 * time.Second

DefaultInboundTimeout is used if no timeout is set for an inbound.

View Source
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

func (inbound *Inbound) ActivateOutbound(outbound string) error

ActivateOutbound activates the given outbound.

func (*Inbound) AddOutbound

func (inbound *Inbound) AddOutbound(outbound, addr string) error

AddOutbound adds a new outbound associated with the given address. If the outbound already exists, it is overridden.

func (*Inbound) Copy

func (inbound *Inbound) Copy() *Inbound

Copy returns a copy of the inbound object.

func (*Inbound) Init

func (inbound *Inbound) Init()

Init initializes the object. Inbounds are lazily initialized so calling this is optional.

func (*Inbound) MarshalJSON

func (inbound *Inbound) MarshalJSON() ([]byte, error)

MarshalJSON defines a custom JSON format for the encoding/json package.

func (*Inbound) ReadOutboundStats

func (inbound *Inbound) ReadOutboundStats(outbound string) (*Stats, error)

ReadOutboundStats returns the stats associated with a given outbound.

func (*Inbound) ReadStats

func (inbound *Inbound) ReadStats() map[string]*Stats

ReadStats returns the stats associated with each outbounds.

func (*Inbound) RemoveOutbound

func (inbound *Inbound) RemoveOutbound(outbound string) error

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

func (inbound *Inbound) UnmarshalJSON(body []byte) (err error)

UnmarshalJSON defines a custom JSON format for the encoding/json package.

func (*Inbound) Validate

func (inbound *Inbound) Validate() error

Validate returns an error if one of the Inbound invariants are not satisfied.

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

func (stats *Stats) MarshalJSON() ([]byte, error)

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) Init

func (recorder *StatsRecorder) Init()

Init initializes the object.

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.

Jump to

Keyboard shortcuts

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