Merge pull request #72498 from dims/generate-stack-traces-for-bad-http-response

Generate Stack Traces for bad http responses
This commit is contained in:
Kubernetes Prow Robot 2019-01-03 17:36:20 -08:00 committed by GitHub
commit e89a3a7802
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -25,6 +25,17 @@ import (
"k8s.io/apiserver/pkg/server/httplog"
)
func badHTTPResponse() httplog.StacktracePred {
return func(status int) bool {
// http status code should not be zero
if status == 0 {
klog.Errorf("Bad HTTP Response - status is zero")
return true
}
return false
}
}
// WithPanicRecovery wraps an http Handler to recover and log panics.
func WithPanicRecovery(handler http.Handler) http.Handler {
return withPanicRecovery(handler, func(w http.ResponseWriter, req *http.Request, err interface{}) {
@ -39,7 +50,7 @@ func withPanicRecovery(handler http.Handler, crashHandler func(http.ResponseWrit
crashHandler(w, req, err)
})
logger := httplog.NewLogged(req, &w)
logger := httplog.NewLogged(req, &w).StacktraceWhen(badHTTPResponse())
defer logger.Log()
// Dispatch to the internal handler