Add blocker to health checks

This commit is contained in:
PJ 2022-01-17 12:18:03 +01:00
parent a04160976d
commit f0e2770f73
No known key found for this signature in database
GPG Key ID: F345964979FA8971
1 changed files with 26 additions and 0 deletions

View File

@ -169,6 +169,28 @@ async function accountHealthCheck(done) {
done({ name: "accounts", time: calculateElapsedTime(time), ...data });
}
// blockerHealthCheck returns the result of blocker container health endpoint
async function blockerHealthCheck(done) {
const time = process.hrtime();
const data = { up: false };
try {
const response = await got(`${process.env.BLOCKER_HOST}:${process.env.BLOCKER_PORT}/health`, { responseType: "json" });
data.statusCode = response.statusCode;
data.response = response.body;
data.up = response.body.dbAlive === true;
data.ip = response.ip;
} catch (error) {
data.statusCode = error?.response?.statusCode || error.statusCode || error.status;
data.errorMessage = error.message;
data.errorResponseContent = getResponseContent(error.response);
data.ip = error?.response?.ip ?? null;
}
done({ name: "blocker", time: calculateElapsedTime(time), ...data });
}
async function genericAccessCheck(name, url) {
const time = process.hrtime();
const data = { up: false, url };
@ -205,4 +227,8 @@ if (process.env.ACCOUNTS_ENABLED === "true") {
checks.push(accountHealthCheck, accountWebsiteCheck);
}
if (process.env.PORTAL_MODULES && process.env.PORTAL_MODULES.indexOf('b') !== -1) {
checks.push(blockerHealthCheck);
}
module.exports = checks;