mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #77379 from tedyu/http-stat-map
Use map to check whether stack trace is needed
This commit is contained in:
commit
b7dc0124a0
@ -837,19 +837,19 @@ func isLongRunningRequest(path string) bool {
|
|||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
Block a user