Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not update activity on failed requests #292

Merged
merged 2 commits into from
Mar 5, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions lib/configproxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}
});
}
});
}

Expand Down