diff --git a/lib/configproxy.js b/lib/configproxy.js index 7a98b730..1e862bcc 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); } @@ -575,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); + } + }); + } }); }