Move longrunning predicate into Config instead of RE
... in order to be available for custom handler chains.
This commit is contained in:
@@ -158,11 +158,15 @@ type Config struct {
|
|||||||
|
|
||||||
// MaxRequestsInFlight is the maximum number of parallel non-long-running requests. Every further
|
// MaxRequestsInFlight is the maximum number of parallel non-long-running requests. Every further
|
||||||
// request has to wait.
|
// request has to wait.
|
||||||
MaxRequestsInFlight int
|
MaxRequestsInFlight int
|
||||||
LongRunningRequestRE string
|
|
||||||
|
// Predicate which is true for paths of long-running http requests
|
||||||
|
LongRunningFunc genericfilters.LongRunningRequestCheck
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig(options *options.ServerRunOptions) *Config {
|
func NewConfig(options *options.ServerRunOptions) *Config {
|
||||||
|
longRunningRE := regexp.MustCompile(options.LongRunningRequestRE)
|
||||||
|
|
||||||
var auditWriter io.Writer
|
var auditWriter io.Writer
|
||||||
if len(options.AuditLogPath) != 0 {
|
if len(options.AuditLogPath) != 0 {
|
||||||
auditWriter = &lumberjack.Logger{
|
auditWriter = &lumberjack.Logger{
|
||||||
@@ -201,8 +205,8 @@ func NewConfig(options *options.ServerRunOptions) *Config {
|
|||||||
Version: "unversioned",
|
Version: "unversioned",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
MaxRequestsInFlight: options.MaxRequestsInFlight,
|
MaxRequestsInFlight: options.MaxRequestsInFlight,
|
||||||
LongRunningRequestRE: options.LongRunningRequestRE,
|
LongRunningFunc: genericfilters.BasicLongRunningRequestCheck(longRunningRE, map[string]string{"watch": "true"}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -345,16 +349,13 @@ func (c Config) New() (*GenericAPIServer, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *GenericAPIServer) buildHandlerChains(c *Config, handler http.Handler) (secure http.Handler, insecure http.Handler) {
|
func (s *GenericAPIServer) buildHandlerChains(c *Config, handler http.Handler) (secure http.Handler, insecure http.Handler) {
|
||||||
longRunningRE := regexp.MustCompile(c.LongRunningRequestRE)
|
|
||||||
longRunningFunc := genericfilters.BasicLongRunningRequestCheck(longRunningRE, map[string]string{"watch": "true"})
|
|
||||||
|
|
||||||
// filters which insecure and secure have in common
|
// filters which insecure and secure have in common
|
||||||
handler = genericfilters.WithCORS(handler, c.CorsAllowedOriginList, nil, nil, "true")
|
handler = genericfilters.WithCORS(handler, c.CorsAllowedOriginList, nil, nil, "true")
|
||||||
|
|
||||||
// insecure filters
|
// insecure filters
|
||||||
insecure = handler
|
insecure = handler
|
||||||
insecure = genericfilters.WithPanicRecovery(insecure, s.NewRequestInfoResolver())
|
insecure = genericfilters.WithPanicRecovery(insecure, s.NewRequestInfoResolver())
|
||||||
insecure = genericfilters.WithTimeoutForNonLongRunningRequests(insecure, longRunningFunc)
|
insecure = genericfilters.WithTimeoutForNonLongRunningRequests(insecure, c.LongRunningFunc)
|
||||||
|
|
||||||
// secure filters
|
// secure filters
|
||||||
attributeGetter := apiserverfilters.NewRequestAttributeGetter(c.RequestContextMapper, s.NewRequestInfoResolver())
|
attributeGetter := apiserverfilters.NewRequestAttributeGetter(c.RequestContextMapper, s.NewRequestInfoResolver())
|
||||||
@@ -364,8 +365,8 @@ func (s *GenericAPIServer) buildHandlerChains(c *Config, handler http.Handler) (
|
|||||||
secure = apiserverfilters.WithAudit(secure, attributeGetter, c.AuditWriter) // before impersonation to read original user
|
secure = apiserverfilters.WithAudit(secure, attributeGetter, c.AuditWriter) // before impersonation to read original user
|
||||||
secure = authhandlers.WithAuthentication(secure, c.RequestContextMapper, c.Authenticator, authhandlers.Unauthorized(c.SupportsBasicAuth))
|
secure = authhandlers.WithAuthentication(secure, c.RequestContextMapper, c.Authenticator, authhandlers.Unauthorized(c.SupportsBasicAuth))
|
||||||
secure = genericfilters.WithPanicRecovery(secure, s.NewRequestInfoResolver())
|
secure = genericfilters.WithPanicRecovery(secure, s.NewRequestInfoResolver())
|
||||||
secure = genericfilters.WithTimeoutForNonLongRunningRequests(secure, longRunningFunc)
|
secure = genericfilters.WithTimeoutForNonLongRunningRequests(secure, c.LongRunningFunc)
|
||||||
secure = genericfilters.WithMaxInFlightLimit(secure, c.MaxRequestsInFlight, longRunningFunc)
|
secure = genericfilters.WithMaxInFlightLimit(secure, c.MaxRequestsInFlight, c.LongRunningFunc)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@@ -35,6 +35,9 @@ var errConnKilled = fmt.Errorf("kill connection/stream")
|
|||||||
|
|
||||||
// WithTimeoutForNonLongRunningRequests times out non-long-running requests after the time given by globalTimeout.
|
// WithTimeoutForNonLongRunningRequests times out non-long-running requests after the time given by globalTimeout.
|
||||||
func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning LongRunningRequestCheck) http.Handler {
|
func WithTimeoutForNonLongRunningRequests(handler http.Handler, longRunning LongRunningRequestCheck) http.Handler {
|
||||||
|
if longRunning == nil {
|
||||||
|
return handler
|
||||||
|
}
|
||||||
timeoutFunc := func(req *http.Request) (<-chan time.Time, string) {
|
timeoutFunc := func(req *http.Request) (<-chan time.Time, string) {
|
||||||
// TODO unify this with apiserver.MaxInFlightLimit
|
// TODO unify this with apiserver.MaxInFlightLimit
|
||||||
if longRunning(req) {
|
if longRunning(req) {
|
||||||
|
Reference in New Issue
Block a user