Documentation ¶
Overview ¶
Package filters contains all the http handler chain filters which are not api related.
Index ¶
- func BasicLongRunningRequestCheck(longRunningVerbs, longRunningSubresources sets.String) apirequest.LongRunningRequestCheck
- func StartMaxInFlightWatermarkMaintenance(stopCh <-chan struct{})
- func StartPriorityAndFairnessWatermarkMaintenance(stopCh <-chan struct{})
- func WithCORS(handler http.Handler, allowedOriginPatterns []string, allowedMethods []string, ...) http.Handler
- func WithContentType(handler http.Handler, contentType string) http.Handler
- func WithHSTS(handler http.Handler, hstsDirectives []string) http.Handler
- func WithHTTPLogging(handler http.Handler) http.Handler
- func WithMaxInFlightLimit(handler http.Handler, nonMutatingLimit int, mutatingLimit int, ...) http.Handler
- func WithPanicRecovery(handler http.Handler, resolver request.RequestInfoResolver) http.Handler
- func WithPriorityAndFairness(handler http.Handler, ...) http.Handler
- func WithProbabilisticGoaway(inner http.Handler, chance float64) http.Handler
- func WithRetryAfter(handler http.Handler, shutdownDelayDurationElapsedCh <-chan struct{}) http.Handler
- func WithTimeout(h http.Handler, timeoutFunc timeoutFunc) http.Handler
- func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning apirequest.LongRunningRequestCheck) http.Handler
- func WithWaitGroup(handler http.Handler, longRunning apirequest.LongRunningRequestCheck, ...) http.Handler
- func WithWatchTerminationDuringShutdown(handler http.Handler, termination apirequest.ServerShutdownSignal, ...) http.Handler
- type GoawayDecider
- type PriorityAndFairnessClassification
- type RequestWaitGroup
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BasicLongRunningRequestCheck ¶
func BasicLongRunningRequestCheck(longRunningVerbs, longRunningSubresources sets.String) apirequest.LongRunningRequestCheck
BasicLongRunningRequestCheck returns true if the given request has one of the specified verbs or one of the specified subresources, or is a profiler request.
func StartMaxInFlightWatermarkMaintenance ¶ added in v0.19.5
func StartMaxInFlightWatermarkMaintenance(stopCh <-chan struct{})
StartMaxInFlightWatermarkMaintenance starts the goroutines to observe and maintain watermarks for max-in-flight requests.
func StartPriorityAndFairnessWatermarkMaintenance ¶ added in v0.19.5
func StartPriorityAndFairnessWatermarkMaintenance(stopCh <-chan struct{})
StartPriorityAndFairnessWatermarkMaintenance starts the goroutines to observe and maintain watermarks for priority-and-fairness requests.
func WithCORS ¶
func WithCORS(handler http.Handler, allowedOriginPatterns []string, allowedMethods []string, allowedHeaders []string, exposedHeaders []string, allowCredentials string) http.Handler
WithCORS is a simple CORS implementation that wraps an http Handler. Pass nil for allowedMethods and allowedHeaders to use the defaults. If allowedOriginPatterns is empty or nil, no CORS support is installed.
func WithContentType ¶
WithContentType sets both the Content-Type and the X-Content-Type-Options (nosniff) header
func WithHSTS ¶ added in v0.21.0
WithHSTS is a simple HSTS implementation that wraps an http Handler. If hstsDirectives is empty or nil, no HSTS support is installed.
func WithHTTPLogging ¶ added in v0.22.0
WithHTTPLogging enables logging of incoming requests.
func WithMaxInFlightLimit ¶
func WithMaxInFlightLimit( handler http.Handler, nonMutatingLimit int, mutatingLimit int, longRunningRequestCheck apirequest.LongRunningRequestCheck, ) http.Handler
WithMaxInFlightLimit limits the number of in-flight requests to buffer size of the passed in channel.
func WithPanicRecovery ¶
WithPanicRecovery wraps an http Handler to recover and log panics (except in the special case of http.ErrAbortHandler panics, which suppress logging).
func WithPriorityAndFairness ¶ added in v0.18.0
func WithPriorityAndFairness( handler http.Handler, longRunningRequestCheck apirequest.LongRunningRequestCheck, fcIfc utilflowcontrol.Interface, workEstimator flowcontrolrequest.WorkEstimatorFunc, defaultRequestWaitLimit time.Duration, ) http.Handler
WithPriorityAndFairness limits the number of in-flight requests in a fine-grained way.
func WithProbabilisticGoaway ¶ added in v0.18.0
WithProbabilisticGoaway returns an http.Handler that send GOAWAY probabilistically according to the given chance for HTTP2 requests. After client receive GOAWAY, the in-flight long-running requests will not be influenced, and the new requests will use a new TCP connection to re-balancing to another server behind the load balance.
func WithRetryAfter ¶ added in v0.23.0
func WithRetryAfter(handler http.Handler, shutdownDelayDurationElapsedCh <-chan struct{}) http.Handler
WithRetryAfter rejects any incoming new request(s) with a 429 if the specified shutdownDelayDurationElapsedFn channel is closed
It includes new request(s) on a new or an existing TCP connection Any new request(s) arriving after shutdownDelayDurationElapsedFn is closed are replied with a 429 and the following response headers:
- 'Retry-After: N` (so client can retry after N seconds, hopefully on a new apiserver instance)
- 'Connection: close': tear down the TCP connection
TODO: is there a way to merge WithWaitGroup and this filter?
func WithTimeout ¶
WithTimeout returns an http.Handler that runs h with a timeout determined by timeoutFunc. The new http.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 message provided. (If msg is empty, a suitable default message will be sent.) After the handler times out, writes by h to its http.ResponseWriter will return http.ErrHandlerTimeout. If timeoutFunc returns a nil timeout channel, no timeout will be enforced. recordFn is a function that will be invoked whenever a timeout happens.
func WithTimeoutForNonLongRunningRequests ¶
func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning apirequest.LongRunningRequestCheck) http.Handler
WithTimeoutForNonLongRunningRequests times out non-long-running requests after the time given by timeout.
func WithWaitGroup ¶
func WithWaitGroup(handler http.Handler, longRunning apirequest.LongRunningRequestCheck, wg RequestWaitGroup) http.Handler
WithWaitGroup adds all non long-running requests to wait group, which is used for graceful shutdown.
func WithWatchTerminationDuringShutdown ¶ added in v0.27.0
func WithWatchTerminationDuringShutdown(handler http.Handler, termination apirequest.ServerShutdownSignal, wg RequestWaitGroup) http.Handler
Types ¶
type GoawayDecider ¶ added in v0.18.0
GoawayDecider decides if server should send a GOAWAY
type PriorityAndFairnessClassification ¶ added in v0.18.0
type PriorityAndFairnessClassification struct { FlowSchemaName string FlowSchemaUID apitypes.UID PriorityLevelName string PriorityLevelUID apitypes.UID }
PriorityAndFairnessClassification identifies the results of classification for API Priority and Fairness
type RequestWaitGroup ¶ added in v0.27.0
type RequestWaitGroup interface { // Add adds delta, which may be negative, similar to sync.WaitGroup. // If Add with a positive delta happens after Wait, it will return error, // which prevent unsafe Add. Add(delta int) error // Done decrements the WaitGroup counter. Done() }
RequestWaitGroup helps with the accounting of request(s) that are in flight: the caller is expected to invoke Add(1) before executing the request handler and then invoke Done() when the handler finishes. NOTE: implementations must ensure that it is thread-safe when invoked from multiple goroutines.