From 72792d59f46f822cf360e797d886e582a6a2dc60 Mon Sep 17 00:00:00 2001 From: Davanum Srinivas Date: Thu, 3 Jan 2019 16:52:36 -0500 Subject: [PATCH] Generate Stack Traces for http response with status code zero When we spit out a http reponse with a `0` http status code we should log a trace back so we can easily find where things went wrong. Change-Id: Ic2aadec3a3de85fbdf64da66d6d12e3c631f409d --- .../src/k8s.io/apiserver/pkg/server/filters/wrap.go | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apiserver/pkg/server/filters/wrap.go b/staging/src/k8s.io/apiserver/pkg/server/filters/wrap.go index 0a75845611d..38ab585544f 100644 --- a/staging/src/k8s.io/apiserver/pkg/server/filters/wrap.go +++ b/staging/src/k8s.io/apiserver/pkg/server/filters/wrap.go @@ -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