Merge pull request #112374 from Argh4k/no-stack-timeout

do not print status stack in case of timeout from timeout handler
This commit is contained in:
Kubernetes Prow Robot 2022-10-14 19:39:05 -07:00 committed by GitHub
commit 8fb8bb4e9a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 2 deletions

View File

@ -31,6 +31,7 @@ import (
"k8s.io/apiserver/pkg/endpoints/metrics"
apirequest "k8s.io/apiserver/pkg/endpoints/request"
"k8s.io/apiserver/pkg/endpoints/responsewriter"
"k8s.io/apiserver/pkg/server/httplog"
)
// WithTimeoutForNonLongRunningRequests times out non-long-running requests after the time given by timeout.
@ -141,7 +142,9 @@ func (t *timeoutHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
utilruntime.HandleError(err)
}()
}()
httplog.SetStacktracePredicate(r.Context(), func(status int) bool {
return false
})
defer postTimeoutFn()
tw.timeout(err)
}

View File

@ -59,7 +59,7 @@ type respLogger struct {
statusRecorded bool
status int
statusStack string
// mutex is used when accessing addedInfo and addedKeyValuePairs.
// mutex is used when accessing addedInfo, addedKeyValuePairs and logStacktracePred.
// They can be modified by other goroutine when logging happens (in case of request timeout)
mutex sync.Mutex
addedInfo strings.Builder
@ -181,6 +181,8 @@ func Unlogged(req *http.Request, w http.ResponseWriter) http.ResponseWriter {
// StacktraceWhen sets the stacktrace logging predicate, which decides when to log a stacktrace.
// There's a default, so you don't need to call this unless you don't like the default.
func (rl *respLogger) StacktraceWhen(pred StacktracePred) *respLogger {
rl.mutex.Lock()
defer rl.mutex.Unlock()
rl.logStacktracePred = pred
return rl
}
@ -316,6 +318,8 @@ func (rl *respLogger) Hijack() (net.Conn, *bufio.ReadWriter, error) {
}
func (rl *respLogger) recordStatus(status int) {
rl.mutex.Lock()
defer rl.mutex.Unlock()
rl.status = status
rl.statusRecorded = true
if rl.logStacktracePred(status) {