mirror of https://github.com/k3s-io/k3s
Use map to check whether stack trace is needed
Signed-off-by: Ted Yu <yute@vmware.com>k3s-v1.15.3
parent
16085784bc
commit
85fc089855
|
@ -835,19 +835,19 @@ func isLongRunningRequest(path string) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
var statusesNoTracePred = httplog.StatusIsNot(
|
||||
http.StatusOK,
|
||||
http.StatusFound,
|
||||
http.StatusMovedPermanently,
|
||||
http.StatusTemporaryRedirect,
|
||||
http.StatusBadRequest,
|
||||
http.StatusNotFound,
|
||||
http.StatusSwitchingProtocols,
|
||||
)
|
||||
|
||||
// ServeHTTP responds to HTTP requests on the Kubelet.
|
||||
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
defer httplog.NewLogged(req, &w).StacktraceWhen(
|
||||
httplog.StatusIsNot(
|
||||
http.StatusOK,
|
||||
http.StatusFound,
|
||||
http.StatusMovedPermanently,
|
||||
http.StatusTemporaryRedirect,
|
||||
http.StatusBadRequest,
|
||||
http.StatusNotFound,
|
||||
http.StatusSwitchingProtocols,
|
||||
),
|
||||
).Log()
|
||||
defer httplog.NewLogged(req, &w).StacktraceWhen(statusesNoTracePred).Log()
|
||||
|
||||
// monitor http requests
|
||||
var serverType string
|
||||
|
|
|
@ -125,13 +125,13 @@ func (rl *respLogger) StacktraceWhen(pred StacktracePred) *respLogger {
|
|||
// StatusIsNot returns a StacktracePred which will cause stacktraces to be logged
|
||||
// for any status *not* in the given list.
|
||||
func StatusIsNot(statuses ...int) StacktracePred {
|
||||
statusesNoTrace := map[int]bool{}
|
||||
for _, s := range statuses {
|
||||
statusesNoTrace[s] = true
|
||||
}
|
||||
return func(status int) bool {
|
||||
for _, s := range statuses {
|
||||
if status == s {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
_, ok := statusesNoTrace[status]
|
||||
return !ok
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue