{"modulePath":"github.com/zcube/serving","version":"v0.14.2","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package queue\n\nPackage queue provides components for the queue-proxy binary.\n\n## Constants\n\n```go\nconst (\n\t// Name is the name of the component.\n\tName = \"queue\"\n\n\t// RequestQueueDrainPath specifies the path to wait until the proxy\n\t// server is shut down. Any subsequent calls to this endpoint after\n\t// the server has finished shutting down it will return immediately.\n\t// Main usage is to delay the termination of user-container until all\n\t// accepted requests have been processed.\n\tRequestQueueDrainPath = \"/wait-for-drain\"\n)\n```\n\n## Variables\n\n```go\nvar (\n\t// ErrUpdateCapacity indicates that the capacity could not be updated as wished.\n\tErrUpdateCapacity = errors.New(\"failed to add all capacity to the breaker\")\n\t// ErrRelease indicates that release was called more often than acquire.\n\tErrRelease = errors.New(\"semaphore release error: returned tokens must be \u003c= acquired tokens\")\n\t// ErrRequestQueueFull indicates the breaker queue depth was exceeded.\n\tErrRequestQueueFull = errors.New(\"pending request queue full\")\n)\n```\n\n## Functions\n\n```go\nfunc ForwardedShimHandler(h http.Handler) http.Handler\n```\nForwardedShimHandler 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.\n\n```go\nfunc NewAppRequestMetricsHandler(next http.Handler, b *Breaker,\n\tns, service, config, rev, pod string) (http.Handler, error)\n```\nNewAppRequestMetricsHandler creates an http.Handler that emits request metrics.\n\n```go\nfunc NewRequestMetricsHandler(next http.Handler,\n\tns, service, config, rev, pod string) (http.Handler, error)\n```\nNewRequestMetricsHandler creates an http.Handler that emits request metrics.\n\n```go\nfunc NewStats(startedAt time.Time, reqCh chan ReqEvent, reportCh \u003c-chan time.Time, report func(float64, float64, float64, float64))\n```\nNewStats instantiates a new instance of Stats.\n\n```go\nfunc TimeToFirstByteTimeoutHandler(h http.Handler, dt time.Duration, msg string) http.Handler\n```\nTimeToFirstByteTimeoutHandler returns a Handler that runs \\`h\\` with the given time limit in which the first byte of the response must be written.\n\nThe 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.\n\nA 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](https://golang.org/pkg/net/http/#Handler).\n\nThe implementation is largely inspired by http.TimeoutHandler.\n\n## Types\n\n```go\ntype Breaker struct {\n\t// contains filtered or unexported fields\n}\n```\nBreaker 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.\n\n```go\nfunc NewBreaker(params BreakerParams) *Breaker\n```\nNewBreaker creates a Breaker with the desired queue depth, concurrency limit and initial capacity.\n\n```go\nfunc (b *Breaker) Capacity() int\n```\nCapacity returns the number of allowed in-flight requests on this breaker.\n\n```go\nfunc (b *Breaker) InFlight() int\n```\nInFlight returns the number of requests currently in flight in this breaker.\n\n```go\nfunc (b *Breaker) Maybe(ctx context.Context, thunk func()) error\n```\nMaybe 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.\n\n```go\nfunc (b *Breaker) Reserve(ctx context.Context) (func(), bool)\n```\nReserve 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.\n\n```go\nfunc (b *Breaker) UpdateConcurrency(size int) error\n```\nUpdateConcurrency updates the maximum number of in-flight requests.\n\n```go\ntype BreakerParams struct {\n\tQueueDepth      int\n\tMaxConcurrency  int\n\tInitialCapacity int\n}\n```\nBreakerParams defines the parameters of the breaker.\n\n```go\ntype PrometheusStatsReporter struct {\n\t// contains filtered or unexported fields\n}\n```\nPrometheusStatsReporter structure represents a prometheus stats reporter.\n\n```go\nfunc NewPrometheusStatsReporter(namespace, config, revision, pod string, reportingPeriod time.Duration) (*PrometheusStatsReporter, error)\n```\nNewPrometheusStatsReporter creates a reporter that collects and reports queue metrics.\n\n```go\nfunc (r *PrometheusStatsReporter) Handler() http.Handler\n```\nHandler returns an uninstrumented http.Handler used to serve stats registered by this PrometheusStatsReporter.\n\n```go\nfunc (r *PrometheusStatsReporter) Report(acr float64, apcr float64, rc float64, prc float64)\n```\nReport captures request metrics.\n\n```go\ntype ReqEvent struct {\n\tTime      time.Time\n\tEventType ReqEventType\n}\n```\nReqEvent represents either an incoming or closed request.\n\n```go\ntype ReqEventType int\n```\nReqEventType denotes the type (incoming/closed) of a ReqEvent.\n\n```go\nconst (\n\t// ReqIn represents an incoming request\n\tReqIn ReqEventType = iota\n\t// ReqOut represents a finished request\n\tReqOut\n\t// ProxiedIn represents an incoming request through a proxy.\n\tProxiedIn\n\t// ProxiedOut represents a finished proxied request.\n\tProxiedOut\n)\n```\n\n","path":"github.com/zcube/serving/pkg/queue","name":"queue","synopsis":"Package queue provides components for the queue-proxy binary.","isRedistributable":true}
