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
|
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.
|
// ServeHTTP responds to HTTP requests on the Kubelet.
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||||
defer httplog.NewLogged(req, &w).StacktraceWhen(
|
defer httplog.NewLogged(req, &w).StacktraceWhen(statusesNoTracePred).Log()
|
||||||
httplog.StatusIsNot(
|
|
||||||
http.StatusOK,
|
|
||||||
http.StatusFound,
|
|
||||||
http.StatusMovedPermanently,
|
|
||||||
http.StatusTemporaryRedirect,
|
|
||||||
http.StatusBadRequest,
|
|
||||||
http.StatusNotFound,
|
|
||||||
http.StatusSwitchingProtocols,
|
|
||||||
),
|
|
||||||
).Log()
|
|
||||||
|
|
||||||
// monitor http requests
|
// monitor http requests
|
||||||
var serverType string
|
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
|
// StatusIsNot returns a StacktracePred which will cause stacktraces to be logged
|
||||||
// for any status *not* in the given list.
|
// for any status *not* in the given list.
|
||||||
func StatusIsNot(statuses ...int) StacktracePred {
|
func StatusIsNot(statuses ...int) StacktracePred {
|
||||||
|
statusesNoTrace := map[int]bool{}
|
||||||
|
for _, s := range statuses {
|
||||||
|
statusesNoTrace[s] = true
|
||||||
|
}
|
||||||
return func(status int) bool {
|
return func(status int) bool {
|
||||||
for _, s := range statuses {
|
_, ok := statusesNoTrace[status]
|
||||||
if status == s {
|
return !ok
|
||||||
return false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue