From 7508115a3da9c5985dbc6afdee7ea49fcae54098 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 5 Mar 2021 12:33:16 +0100 Subject: [PATCH 1/2] avoid logging url params --- lib/configproxy.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/configproxy.js b/lib/configproxy.js index 7a98b730..4f8c891a 100644 --- a/lib/configproxy.js +++ b/lib/configproxy.js @@ -130,6 +130,11 @@ const loadStorage = (options) => { return new store.MemoryStore(options); }; +function _logUrl(url) { + // format a url for logging, e.g. strip url params + if (url) return url.split("?", 1)[0]; +} + class ConfigurableProxy extends EventEmitter { constructor(options) { super(); @@ -198,7 +203,7 @@ class ConfigurableProxy extends EventEmitter { var logErrors = (handler) => { return function (req, res) { function logError(e) { - that.log.error("Error in handler for " + req.method + " " + req.url + ": %s", e); + that.log.error("Error in handler for %s %s: %s", req.method, _logUrl(req.url), e); } try { let p = handler.apply(that, arguments); @@ -246,7 +251,7 @@ class ConfigurableProxy extends EventEmitter { logF = this.log.error; } var msg = res._logMsg || ""; - logF("%s %s %s %s", code, req.method.toUpperCase(), req.url, msg); + logF("%s %s %s %s", code, req.method.toUpperCase(), _logUrl(req.url), msg); } addRoute(path, data) { @@ -444,7 +449,7 @@ class ConfigurableProxy extends EventEmitter { errMsg = e; } } - this.log.error("%s %s %s %s", code, req.method, req.url, errMsg); + this.log.error("%s %s %s %s", code, req.method, _logUrl(req.url), errMsg); if (!res) { this.log.debug("Socket error, no response to send"); // socket-level error, no response to build @@ -541,7 +546,7 @@ class ConfigurableProxy extends EventEmitter { } var prefix = match.prefix; var target = match.target; - that.log.debug("PROXY %s %s to %s", kind.toUpperCase(), req.url, target); + that.log.debug("PROXY %s %s to %s", kind.toUpperCase(), _logUrl(req.url), target); if (!that.includePrefix) { req.url = req.url.slice(prefix.length); } From 7d7884b0a3549a5b505dc84e956340b128682314 Mon Sep 17 00:00:00 2001 From: Min RK Date: Fri, 5 Mar 2021 12:36:37 +0100 Subject: [PATCH 2/2] do not update activity for failed requests --- lib/configproxy.js | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/configproxy.js b/lib/configproxy.js index 4f8c891a..1e862bcc 100644 --- a/lib/configproxy.js +++ b/lib/configproxy.js @@ -580,8 +580,24 @@ class ConfigurableProxy extends EventEmitter { that.updateLastActivity(prefix); }); - // update last activity timestamp in routing table - return that.updateLastActivity(prefix); + if (kind === "web") { + // update last activity on completion of the request + // only consider 'successful' requests activity + // A flood of invalid requests such as 404s or 403s + // or 503s because the endpoint is down + // shouldn't make it look like the endpoint is 'active' + + // we no longer register activity at the *start* of the request + // because at that point we don't know if the endpoint is even available + res.on("finish", function () { + // (don't count redirects...but should we?) + if (res.statusCode < 300) { + that.updateLastActivity(prefix); + } else { + that.log.debug("Not recording activity for status %s on %s", res.statusCode, prefix); + } + }); + } }); }