Documentation ¶
Overview ¶
Package queue provides components for the queue-proxy binary.
Index ¶
- Constants
- Variables
- func ConcurrencyStateHandler(logger *zap.SugaredLogger, h http.Handler, ...) http.HandlerFunc
- func ForwardedShimHandler(h http.Handler) http.Handler
- func GetRouteTagNameFromRequest(r *http.Request) string
- func NewAppRequestMetricsHandler(next http.Handler, b *Breaker, ns, service, config, rev, pod string) (http.Handler, error)
- func NewRequestMetricsHandler(next http.Handler, ns, service, config, rev, pod string) (http.Handler, error)
- func NewStatsHandler(prom, proto http.Handler) http.Handler
- func ProxyHandler(breaker *Breaker, stats *network.RequestStats, tracingEnabled bool, ...) http.HandlerFunc
- type Breaker
- type BreakerParams
- type ConcurrencyEndpoint
- func (c *ConcurrencyEndpoint) Endpoint() string
- func (c *ConcurrencyEndpoint) Pause(logger *zap.SugaredLogger)
- func (c *ConcurrencyEndpoint) RefreshToken() error
- func (c *ConcurrencyEndpoint) Request(action string) error
- func (c *ConcurrencyEndpoint) Resume(logger *zap.SugaredLogger)
- func (c *ConcurrencyEndpoint) Terminating(logger *zap.SugaredLogger)
- type PrometheusStatsReporter
- type ProtobufStatsReporter
Constants ¶
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" )
const MaxBreakerCapacity = math.MaxInt32
MaxBreakerCapacity is the largest valid value for the MaxConcurrency value of BreakerParams. This is limited by the maximum size of a chan struct{} in the current implementation.
Variables ¶
var ( // ErrRequestQueueFull indicates the breaker queue depth was exceeded. ErrRequestQueueFull = errors.New("pending request queue full") )
Functions ¶
func ConcurrencyStateHandler ¶ added in v0.30.2
func ConcurrencyStateHandler(logger *zap.SugaredLogger, h http.Handler, pause, resume func(*zap.SugaredLogger)) http.HandlerFunc
ConcurrencyStateHandler tracks the in flight requests for the pod. When the requests drop to zero, it runs the `pause` function, and when requests scale up from zero, it runs the `resume` function. If either of `pause` or `resume` are not passed, it runs the respective local function(s). The local functions are the expected behavior; the function parameters are enabled primarily for testing purposes.
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 GetRouteTagNameFromRequest ¶ added in v0.30.2
GetRouteTagNameFromRequest extracts the value of the tag header from http.Request
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 NewStatsHandler ¶ added in v0.30.2
NewStatsHandler returns a new StatHandler.
func ProxyHandler ¶ added in v0.30.2
func ProxyHandler(breaker *Breaker, stats *network.RequestStats, tracingEnabled bool, next http.Handler) http.HandlerFunc
ProxyHandler sends requests to the `next` handler at a rate controlled by the passed `breaker`, while recording stats to `stats`.
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) InFlight ¶ added in v0.9.0
InFlight returns the number of requests currently in flight in 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 nil, else error.
func (*Breaker) Reserve ¶ added in v0.11.0
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
UpdateConcurrency updates the maximum number of in-flight requests.
type BreakerParams ¶ added in v0.4.0
BreakerParams defines the parameters of the breaker.
type ConcurrencyEndpoint ¶ added in v0.30.2
type ConcurrencyEndpoint struct {
// contains filtered or unexported fields
}
func NewConcurrencyEndpoint ¶ added in v0.30.2
func NewConcurrencyEndpoint(e, m string) *ConcurrencyEndpoint
func (*ConcurrencyEndpoint) Endpoint ¶ added in v0.30.2
func (c *ConcurrencyEndpoint) Endpoint() string
func (*ConcurrencyEndpoint) Pause ¶ added in v0.30.2
func (c *ConcurrencyEndpoint) Pause(logger *zap.SugaredLogger)
Pause freezes a container, retrying until either successful or a timeout is reached, at which point the container is killed
func (*ConcurrencyEndpoint) RefreshToken ¶ added in v0.30.2
func (c *ConcurrencyEndpoint) RefreshToken() error
func (*ConcurrencyEndpoint) Request ¶ added in v0.30.2
func (c *ConcurrencyEndpoint) Request(action string) error
func (*ConcurrencyEndpoint) Resume ¶ added in v0.30.2
func (c *ConcurrencyEndpoint) Resume(logger *zap.SugaredLogger)
Resume thaws a container, retrying until either successful or a timeout is reached, at which point the container is killed
func (*ConcurrencyEndpoint) Terminating ¶ added in v0.30.2
func (c *ConcurrencyEndpoint) Terminating(logger *zap.SugaredLogger)
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) Report ¶ added in v0.5.0
func (r *PrometheusStatsReporter) Report(stats network.RequestStatsReport)
Report captures request metrics.
func (*PrometheusStatsReporter) ServeHTTP ¶ added in v0.30.2
func (r *PrometheusStatsReporter) ServeHTTP(w http.ResponseWriter, req *http.Request)
ServeHTTP serves the stats in prometheus format over HTTP.
type ProtobufStatsReporter ¶ added in v0.30.2
type ProtobufStatsReporter struct {
// contains filtered or unexported fields
}
ProtobufStatsReporter structure represents a protobuf stats reporter.
func NewProtobufStatsReporter ¶ added in v0.30.2
func NewProtobufStatsReporter(pod string, reportingPeriod time.Duration) *ProtobufStatsReporter
NewProtobufStatsReporter creates a reporter that collects and reports queue metrics.
func (*ProtobufStatsReporter) Report ¶ added in v0.30.2
func (r *ProtobufStatsReporter) Report(stats network.RequestStatsReport)
Report captures request metrics.
func (*ProtobufStatsReporter) ServeHTTP ¶ added in v0.30.2
func (r *ProtobufStatsReporter) ServeHTTP(w http.ResponseWriter, _ *http.Request)
ServeHTTP serves the stats in protobuf format over HTTP.