mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
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:
commit
8fb8bb4e9a
@ -31,6 +31,7 @@ import (
|
|||||||
"k8s.io/apiserver/pkg/endpoints/metrics"
|
"k8s.io/apiserver/pkg/endpoints/metrics"
|
||||||
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
apirequest "k8s.io/apiserver/pkg/endpoints/request"
|
||||||
"k8s.io/apiserver/pkg/endpoints/responsewriter"
|
"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.
|
// 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)
|
utilruntime.HandleError(err)
|
||||||
}()
|
}()
|
||||||
}()
|
}()
|
||||||
|
httplog.SetStacktracePredicate(r.Context(), func(status int) bool {
|
||||||
|
return false
|
||||||
|
})
|
||||||
defer postTimeoutFn()
|
defer postTimeoutFn()
|
||||||
tw.timeout(err)
|
tw.timeout(err)
|
||||||
}
|
}
|
||||||
|
@ -59,7 +59,7 @@ type respLogger struct {
|
|||||||
statusRecorded bool
|
statusRecorded bool
|
||||||
status int
|
status int
|
||||||
statusStack string
|
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)
|
// They can be modified by other goroutine when logging happens (in case of request timeout)
|
||||||
mutex sync.Mutex
|
mutex sync.Mutex
|
||||||
addedInfo strings.Builder
|
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.
|
// 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.
|
// 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 {
|
func (rl *respLogger) StacktraceWhen(pred StacktracePred) *respLogger {
|
||||||
|
rl.mutex.Lock()
|
||||||
|
defer rl.mutex.Unlock()
|
||||||
rl.logStacktracePred = pred
|
rl.logStacktracePred = pred
|
||||||
return rl
|
return rl
|
||||||
}
|
}
|
||||||
@ -316,6 +318,8 @@ func (rl *respLogger) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (rl *respLogger) recordStatus(status int) {
|
func (rl *respLogger) recordStatus(status int) {
|
||||||
|
rl.mutex.Lock()
|
||||||
|
defer rl.mutex.Unlock()
|
||||||
rl.status = status
|
rl.status = status
|
||||||
rl.statusRecorded = true
|
rl.statusRecorded = true
|
||||||
if rl.logStacktracePred(status) {
|
if rl.logStacktracePred(status) {
|
||||||
|
Loading…
Reference in New Issue
Block a user