From d4d58e166be3669ceb2163de452b85974f789666 Mon Sep 17 00:00:00 2001 From: Sanket Sudake Date: Thu, 22 Jul 2021 16:19:39 +0530 Subject: [PATCH] Avoid dumping request headers in router (#2122) Signed-off-by: Sanket Sudake --- pkg/router/functionHandler.go | 10 +++++----- pkg/router/router.go | 8 ++++++-- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pkg/router/functionHandler.go b/pkg/router/functionHandler.go index e6f083d7..4210a9f9 100644 --- a/pkg/router/functionHandler.go +++ b/pkg/router/functionHandler.go @@ -705,16 +705,17 @@ func (fh functionHandler) getProxyErrorHandler(start time.Time, rrt *RetryingRou // Reference: https://httpstatuses.com/499 status = 499 msg = "client closes the connection" - fh.logger.Debug(msg, zap.Any("function", fh.function), zap.Any("request_header", req.Header)) + fh.logger.Debug(msg, zap.Any("function", fh.function), zap.String("status", "Client Closed Request")) case context.DeadlineExceeded: status = http.StatusGatewayTimeout - msg := "function not responses before the timeout" - fh.logger.Error(msg, zap.Any("function", fh.function), zap.Any("request_header", req.Header)) + msg := "no response from function before timeout" + fh.logger.Error(msg, zap.Any("function", fh.function), zap.String("status", http.StatusText(status))) default: code, _ := ferror.GetHTTPError(err) status = code msg = "error sending request to function" - fh.logger.Error(msg, zap.Error(err), zap.Any("function", fh.function), zap.Any("request_header", req.Header), zap.Any("code", code)) + fh.logger.Error(msg, zap.Error(err), zap.Any("function", fh.function), + zap.Any("status", http.StatusText(status)), zap.Int("code", code)) } go fh.collectFunctionMetric(start, rrt, req, &http.Response{ @@ -730,7 +731,6 @@ func (fh functionHandler) getProxyErrorHandler(start time.Time, rrt *RetryingRou "error writing HTTP response", zap.Error(err), zap.Any("function", fh.function), - zap.Any("request_header", req.Header), ) } } diff --git a/pkg/router/router.go b/pkg/router/router.go index fd3587d6..c248c615 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -43,6 +43,7 @@ import ( "context" "fmt" "net/http" + "net/http/httputil" "os" "strconv" "strings" @@ -93,8 +94,11 @@ func serve(ctx context.Context, logger *zap.Logger, port int, tracingSamplingRat } } if displayAccessLog { - logger.Info("path", zap.String("path", r.URL.Path), - zap.String("method", r.Method), zap.Any("header", r.Header)) + reqMsg, err := httputil.DumpRequest(r, false) + if err != nil { + logger.Error("error dumping request", zap.Error(err)) + } + logger.Info("request dump", zap.String("request", string(reqMsg))) } return trace.StartOptions{ Sampler: trace.ProbabilitySampler(tracingSamplingRate),