queue

package
v0.15.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2020 License: Apache-2.0 Imports: 19 Imported by: 35

Documentation

Overview

Package queue provides components for the queue-proxy binary.

Index

Constants

View Source
const (
	// Name is the name of the component.
	Name = "queue"

	// RequestQueueDrainPath specifies the path to wait until the proxy
	// server is shut down. Any subsequent calls to this endpoint after
	// the server has finished shutting down it will return immediately.
	// Main usage is to delay the termination of user-container until all
	// accepted requests have been processed.
	RequestQueueDrainPath = "/wait-for-drain"
)

Variables

View Source
var (
	// ErrUpdateCapacity indicates that the capacity could not be updated as wished.
	ErrUpdateCapacity = errors.New("failed to add all capacity to the breaker")
	// ErrRelease indicates that release was called more often than acquire.
	ErrRelease = errors.New("semaphore release error: returned tokens must be <= acquired tokens")
	// ErrRequestQueueFull indicates the breaker queue depth was exceeded.
	ErrRequestQueueFull = errors.New("pending request queue full")
)

Functions

func ForwardedShimHandler added in v0.7.0

func ForwardedShimHandler(h http.Handler) http.Handler

ForwardedShimHandler attempts to shim a `forwarded` HTTP header from the information available in the `x-forwarded-*` headers. When available, each node in the `x-forwarded-for` header is combined with the `x-forwarded-proto` and `x-forwarded-host` fields to construct a `forwarded` header. The `x-forwarded-by` header is ignored entirely, since it cannot be reliably combined with `x-forwarded-for`. No-op if a `forwarded` header is already present.

func NewAppRequestMetricsHandler added in v0.13.0

func NewAppRequestMetricsHandler(next http.Handler, b *Breaker,
	ns, service, config, rev, pod string) (http.Handler, error)

NewAppRequestMetricsHandler creates an http.Handler that emits request metrics.

func NewRequestMetricsHandler added in v0.13.0

func NewRequestMetricsHandler(next http.Handler,
	ns, service, config, rev, pod string) (http.Handler, error)

NewRequestMetricsHandler creates an http.Handler that emits request metrics.

func ReportStats added in v0.15.0

func ReportStats(startedAt time.Time, reqCh chan network.ReqEvent, reportCh <-chan time.Time, report func(float64, float64, float64, float64))

ReportStats continually processes network events from reqCh and reports aggregated stats via the `report` function whenever reportCh ticks.

func TimeToFirstByteTimeoutHandler added in v0.3.0

func TimeToFirstByteTimeoutHandler(h http.Handler, dt time.Duration, msg string) http.Handler

TimeToFirstByteTimeoutHandler returns a Handler that runs `h` with the given time limit in which the first byte of the response must be written.

The new Handler calls h.ServeHTTP to handle each request, but if a call runs for longer than its time limit, the handler responds with a 504 Gateway Timeout error and the given message in its body. (If msg is empty, a suitable default message will be sent.) After such a timeout, writes by h to its ResponseWriter will return ErrHandlerTimeout.

A panic from the underlying handler is propagated as-is to be able to make use of custom panic behavior by HTTP handlers. See https://golang.org/pkg/net/http/#Handler.

The implementation is largely inspired by http.TimeoutHandler.

Types

type Breaker

type Breaker struct {
	// contains filtered or unexported fields
}

Breaker is a component that enforces a concurrency limit on the execution of a function. It also maintains a queue of function executions in excess of the concurrency limit. Function call attempts beyond the limit of the queue are failed immediately.

func NewBreaker

func NewBreaker(params BreakerParams) *Breaker

NewBreaker creates a Breaker with the desired queue depth, concurrency limit and initial capacity.

func (*Breaker) Capacity added in v0.4.0

func (b *Breaker) Capacity() int

Capacity returns the number of allowed in-flight requests on this breaker.

func (*Breaker) InFlight added in v0.9.0

func (b *Breaker) InFlight() int

InFlight returns the number of requests currently in flight in this breaker.

func (*Breaker) Maybe

func (b *Breaker) Maybe(ctx context.Context, thunk func()) error

Maybe conditionally executes thunk based on the Breaker concurrency and queue parameters. If the concurrency limit and queue capacity are already consumed, Maybe returns immediately without calling thunk. If the thunk was executed, Maybe returns true, else false.

func (*Breaker) Reserve added in v0.11.0

func (b *Breaker) Reserve(ctx context.Context) (func(), bool)

Reserve reserves an execution slot in the breaker, to permit richer semantics in the caller. The caller on success must execute the callback when done with work.

func (*Breaker) UpdateConcurrency added in v0.4.0

func (b *Breaker) UpdateConcurrency(size int) error

UpdateConcurrency updates the maximum number of in-flight requests.

type BreakerParams added in v0.4.0

type BreakerParams struct {
	QueueDepth      int
	MaxConcurrency  int
	InitialCapacity int
}

BreakerParams defines the parameters of the breaker.

type PrometheusStatsReporter added in v0.5.0

type PrometheusStatsReporter struct {
	// contains filtered or unexported fields
}

PrometheusStatsReporter structure represents a prometheus stats reporter.

func NewPrometheusStatsReporter added in v0.5.0

func NewPrometheusStatsReporter(namespace, config, revision, pod string, reportingPeriod time.Duration) (*PrometheusStatsReporter, error)

NewPrometheusStatsReporter creates a reporter that collects and reports queue metrics.

func (*PrometheusStatsReporter) Handler added in v0.5.0

func (r *PrometheusStatsReporter) Handler() http.Handler

Handler returns an uninstrumented http.Handler used to serve stats registered by this PrometheusStatsReporter.

func (*PrometheusStatsReporter) Report added in v0.5.0

func (r *PrometheusStatsReporter) Report(acr float64, apcr float64, rc float64, prc float64)

Report captures request metrics.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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