Documentation ¶
Overview ¶
Package queue provides components for the queue-proxy binary.
Index ¶
- Constants
- Variables
- func NewRequestMetricHandler(h http.Handler, r stats.StatsReporter) (http.Handler, error)
- func TimeToFirstByteTimeoutHandler(h http.Handler, dt time.Duration, msg string) http.Handler
- type Breaker
- type BreakerParams
- type Channels
- type PrometheusStatsReporter
- type ReqEvent
- type ReqEventType
- type Stats
Constants ¶
const ( // Name is the name of the component. Name = "queue" // RequestQueueHealthPath specifies the path for health checks for // queue-proxy. RequestQueueHealthPath = "/health" // 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" )
const ( // ReporterReportingPeriod is the interval of time between reporting stats by queue proxy. ReporterReportingPeriod = time.Second )
Variables ¶
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") )
Functions ¶
func NewRequestMetricHandler ¶ added in v0.5.0
NewRequestMetricHandler creates an http.Handler that emits request metrics.
func TimeToFirstByteTimeoutHandler ¶ added in v0.3.0
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 503 Service Unavailable 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
Capacity returns the number of allowed in-flight requests on this breaker.
func (*Breaker) Maybe ¶
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) UpdateConcurrency ¶ added in v0.4.0
UpdateConcurrency updates the maximum number of in-flight requests.
type BreakerParams ¶ added in v0.4.0
BreakerParams defines the parameters of the breaker.
type Channels ¶
type Channels struct { // Ticks with every request arrived/completed respectively ReqChan chan ReqEvent // Ticks with every stat report request ReportChan <-chan time.Time // Stat reporting channel StatChan chan *autoscaler.Stat }
Channels is a structure for holding the channels for driving Stats. It's just to make the NewStats signature easier to read.
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) (*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(stat *autoscaler.Stat) error
Report captures request metrics.
type ReqEvent ¶
type ReqEvent struct { Time time.Time EventType ReqEventType }
ReqEvent represents either an incoming or closed request.
type ReqEventType ¶ added in v0.2.0
type ReqEventType int
ReqEventType denotes the type (incoming/closed) of a ReqEvent.
const ( // ReqIn represents an incoming request ReqIn ReqEventType = iota // ReqOut represents a finished request ReqOut // ProxiedIn represents an incoming request through a proxy. ProxiedIn // ProxiedOut represents a finished proxied request. ProxiedOut )