From 1ce21041649fb9e1a5055e30517bc1a6c53616be Mon Sep 17 00:00:00 2001 From: Anuved Verma Date: Tue, 2 Jul 2024 14:29:56 -0700 Subject: [PATCH] add logging in preconnection hook --- .../lyft/data/proxyserver/ProxyHandler.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/proxyserver/src/main/java/com/lyft/data/proxyserver/ProxyHandler.java b/proxyserver/src/main/java/com/lyft/data/proxyserver/ProxyHandler.java index 0afd1c91..cb790383 100644 --- a/proxyserver/src/main/java/com/lyft/data/proxyserver/ProxyHandler.java +++ b/proxyserver/src/main/java/com/lyft/data/proxyserver/ProxyHandler.java @@ -35,6 +35,15 @@ protected String rewriteTarget(HttpServletRequest request) { */ public void preConnectionHook(HttpServletRequest request, Request proxyRequest) { // you may override it. + + // [sev-16337] with a 10% probably, log the request headers for debugging + if (Math.random() < 0.10) { + log.debug("(preConnectionHook) Request URL: {} , request URI {} , servlet path {} ," + + "toString {}, getContentLength {}, getRequestHeaderSize {}, requestHeaders {}", + request.getRequestURL(), request.getRequestURI(), request.getServletPath(), + request.toString(), request.getContentLength(), getRequestHeaderSize(request), + errorLogHeaders(request)); + } } /** @@ -60,12 +69,12 @@ protected void postConnectionHook( request.getRequestURL()); } response.getOutputStream().write(buffer, offset, length); - // [sev-16337] with a 1% probably, log the request and response headers + // [sev-16337] with a 10% probably, log the request and response headers // and size for debugging - if (Math.random() < 0.01) { - log.debug("Request URL: {} , request URI {} , servlet path {} ," - + "toString {}, getContentLength {}, getRequestHeaderSize {}, getResponseHeaderSize {}, - requestHeaders {}, responseHeaders {}", + if (Math.random() < 0.10) { + log.debug("(postConnectionHook - success) Request URL: {} , request URI {} , servlet path {} ," + + "toString {}, getContentLength {}, getRequestHeaderSize {}, getResponseHeaderSize {}, " + + "requestHeaders {}, responseHeaders {}", request.getRequestURL(), request.getRequestURI(), request.getServletPath(), request.toString(), request.getContentLength(), getRequestHeaderSize(request), getResponseHeaderSize(response), errorLogHeaders(request), @@ -74,9 +83,9 @@ protected void postConnectionHook( callback.succeeded(); } catch (Throwable var9) { - log.error("Exception occurred while processing request URL: {} , request URI {} ," - + " servlet path {} , toString {}, getContentLength {}, getRequestHeaderSize {}," - + "getResponseHeaderSize {}, requestHeaders {}, responseHeaders {}", + log.error("(postConnectionHook - failed) Exception occurred while processing request URL: {} , " + + "request URI {} , servlet path {} , toString {}, getContentLength {}, " + + "getRequestHeaderSize {}, getResponseHeaderSize {}, requestHeaders {}, responseHeaders {}", request.getRequestURL(), request.getRequestURI(), request.getServletPath(), request.toString(), request.getContentLength(), getRequestHeaderSize(request), getResponseHeaderSize(response), errorLogHeaders(request),