Package queue provides components for the queue-proxy binary.
const ( Name = "queue" RequestQueueDrainPath = "/wait-for-drain" )View Source
var ( ErrUpdateCapacity = errors.New("failed to add all capacity to the breaker") ErrRelease = errors.New("semaphore release error: returned tokens must be <= acquired tokens") ErrRequestQueueFull = errors.New("pending request queue full") )func ForwardedShimHandler ¶ added in v0.7.0
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 NewRequestMetricsHandler ¶ added in v0.13.0NewRequestMetricsHandler creates an http.Handler that emits request metrics.
NewStats instantiates a new instance of Stats.
func TimeToFirstByteTimeoutHandler ¶ added in v0.3.0TimeToFirstByteTimeoutHandler 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.
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.
NewBreaker creates a Breaker with the desired queue depth, concurrency limit and initial capacity.
Capacity returns the number of allowed in-flight requests on this breaker.
InFlight returns the number of requests currently in flight in this breaker.
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.
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.
UpdateConcurrency updates the maximum number of in-flight requests.
type BreakerParams struct { QueueDepth int MaxConcurrency int InitialCapacity int }
BreakerParams defines the parameters of the breaker.
type PrometheusStatsReporter struct { }
PrometheusStatsReporter structure represents a prometheus stats reporter.
NewPrometheusStatsReporter creates a reporter that collects and reports queue metrics.
func (*PrometheusStatsReporter) Handler ¶ added in v0.5.0Handler returns an uninstrumented http.Handler used to serve stats registered by this PrometheusStatsReporter.
Report captures request metrics.
ReqEvent represents either an incoming or closed request.
ReqEventType denotes the type (incoming/closed) of a ReqEvent.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4