From cd7dac5b7e98586515d3d99f2288516135180a43 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Thu, 29 Apr 2021 13:43:40 +0200 Subject: [PATCH] verbose => extended --- packages/health-check/Dockerfile | 2 +- .../src/api/{verbose.js => extended.js} | 4 +-- .../src/checks/{verbose.js => extended.js} | 14 ++++----- packages/health-check/src/db.js | 2 +- packages/health-check/src/index.js | 2 +- packages/health-check/src/run.js | 2 +- setup-scripts/health-checker.py | 30 +++++++++---------- 7 files changed, 27 insertions(+), 29 deletions(-) rename packages/health-check/src/api/{verbose.js => extended.js} (81%) rename packages/health-check/src/checks/{verbose.js => extended.js} (98%) diff --git a/packages/health-check/Dockerfile b/packages/health-check/Dockerfile index 02c5f800..bc867419 100644 --- a/packages/health-check/Dockerfile +++ b/packages/health-check/Dockerfile @@ -8,7 +8,7 @@ COPY src src COPY cli cli RUN echo '*/5 * * * * /usr/app/cli/run critical' >> /etc/crontabs/root -RUN echo '0 * * * * /usr/app/cli/run verbose' >> /etc/crontabs/root +RUN echo '0 * * * * /usr/app/cli/run extended' >> /etc/crontabs/root EXPOSE 3100 ENV NODE_ENV production diff --git a/packages/health-check/src/api/verbose.js b/packages/health-check/src/api/extended.js similarity index 81% rename from packages/health-check/src/api/verbose.js rename to packages/health-check/src/api/extended.js index 12acaa97..ff23e704 100644 --- a/packages/health-check/src/api/verbose.js +++ b/packages/health-check/src/api/extended.js @@ -1,11 +1,11 @@ const db = require("../db"); const { getYesterdayISOString } = require("../utils"); -// returns all verbose health check entries +// returns all extended health check entries module.exports = (req, res) => { const yesterday = getYesterdayISOString(); const entries = db - .get("verbose") + .get("extended") .orderBy("date", "desc") .filter(({ date }) => date > yesterday) .value(); diff --git a/packages/health-check/src/checks/verbose.js b/packages/health-check/src/checks/extended.js similarity index 98% rename from packages/health-check/src/checks/verbose.js rename to packages/health-check/src/checks/extended.js index 882e3e81..8707d6bb 100644 --- a/packages/health-check/src/checks/verbose.js +++ b/packages/health-check/src/checks/extended.js @@ -558,7 +558,7 @@ function dappExampleCheck(done) { skylinkVerification(done, linkInfo); } -const developMomentumBodyHash = "53b44a9d3cfa9b3d66ce5c29976f4383725d3652"; +const developMomentumBodyHash = "08e96877dd6c99c3e1d98105f2fd9df377b53d65"; const developMomentumMetadata = require("../fixtures/developMomentumMetadata.json"); // developMomentumCheck returns the result of trying to download the skylink @@ -811,7 +811,7 @@ function skyBinRedirectCheck(done) { skylinkVerification(done, linkInfo); } -const skyGalleryBodyHash = "077e54054748d278114f1870f8045a162eb73641"; +const skyGalleryBodyHash = "cb5905023a29bdd60d58817f26503345c9a1bd09"; const skyGalleryMetadata = require("../fixtures/skygalleryMetadata.json"); // skyGalleryCheck returns the result of trying to download the skylink for the SkyGallery Application. @@ -1101,13 +1101,12 @@ function parseHeaderString(header) { // skylinkVerification verifies a skylink against provided information. async function skylinkVerification(done, expected, { followRedirect = true, method = "get" } = {}) { const time = process.hrtime(); - - // Create the query for the skylink - const query = `${process.env.PORTAL_URL}/${expected.skylink}`; + const details = { name: expected.name, skylink: expected.skylink }; try { + const query = `${process.env.PORTAL_URL}/${expected.skylink}`; const response = await got[method](query, { followRedirect, headers: { cookie: "nocache=true" } }); - const entry = { name: expected.name, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) }; + const entry = { ...details, up: true, statusCode: response.statusCode, time: calculateElapsedTime(time) }; const info = {}; if (expected.statusCode && expected.statusCode !== response.statusCode) { @@ -1119,7 +1118,6 @@ async function skylinkVerification(done, expected, { followRedirect = true, meth if (expected.bodyHash) { const currentBodyHash = hasha(response.rawBody, { algorithm: "sha1" }); if (currentBodyHash !== expected.bodyHash) { - console.log(expected.name, currentBodyHash); entry.up = false; info.bodyHash = { expected: expected.bodyHash, current: currentBodyHash }; } @@ -1145,7 +1143,7 @@ async function skylinkVerification(done, expected, { followRedirect = true, meth done(entry); // Return the entry information } catch (error) { done({ - name: expected.name, + ...details, up: false, statusCode: error?.response?.statusCode || error.statusCode || error.status, errorMessage: error.message, diff --git a/packages/health-check/src/db.js b/packages/health-check/src/db.js index 760c217e..6dca215c 100644 --- a/packages/health-check/src/db.js +++ b/packages/health-check/src/db.js @@ -7,6 +7,6 @@ if (!fs.existsSync(process.env.STATE_DIR)) fs.mkdirSync(process.env.STATE_DIR); const adapter = new FileSync(`${process.env.STATE_DIR}/state.json`); const db = low(adapter); -db.defaults({ disabled: false, critical: [], verbose: [] }).write(); +db.defaults({ disabled: false, critical: [], extended: [] }).write(); module.exports = db; diff --git a/packages/health-check/src/index.js b/packages/health-check/src/index.js index 151c53b3..45c49572 100644 --- a/packages/health-check/src/index.js +++ b/packages/health-check/src/index.js @@ -21,7 +21,7 @@ server.use((req, res, next) => { server.get("/health-check", require("./api/index")); server.get("/health-check/critical", require("./api/critical")); -server.get("/health-check/verbose", require("./api/verbose")); +server.get("/health-check/extended", require("./api/extended")); server.get("/health-check/disabled", require("./api/disabled")); server.listen(port, host, (error) => { diff --git a/packages/health-check/src/run.js b/packages/health-check/src/run.js index 95a7b5a1..577fdaf6 100644 --- a/packages/health-check/src/run.js +++ b/packages/health-check/src/run.js @@ -8,7 +8,7 @@ require("yargs/yargs")(process.argv.slice(2)).command( .positional("type", { describe: "Type of checks to run", type: "string", - choices: ["critical", "verbose"], + choices: ["critical", "extended"], }) .option("portal-url", { describe: "Skynet portal url", diff --git a/setup-scripts/health-checker.py b/setup-scripts/health-checker.py index 507a76fa..66ab4d9c 100755 --- a/setup-scripts/health-checker.py +++ b/setup-scripts/health-checker.py @@ -144,8 +144,8 @@ async def check_health(): json_critical = requests.get( "http://localhost/health-check/critical", verify=False ).json() - json_verbose = requests.get( - "http://localhost/health-check/verbose", verify=False + json_extended = requests.get( + "http://localhost/health-check/extended", verify=False ).json() except: trace = traceback.format_exc() @@ -157,8 +157,8 @@ async def check_health(): critical_checks_total = 0 critical_checks_failed = 0 - verbose_checks_total = 0 - verbose_checks_failed = 0 + extended_checks_total = 0 + extended_checks_failed = 0 failed_records = [] failed_records_file = None @@ -178,18 +178,18 @@ async def check_health(): if bad: failed_records.append(critical) - for verbose in json_verbose: - time = datetime.strptime(verbose["date"], "%Y-%m-%dT%H:%M:%S.%fZ") + for extended in json_extended: + time = datetime.strptime(extended["date"], "%Y-%m-%dT%H:%M:%S.%fZ") if time < time_limit: continue bad = False - for check in verbose["checks"]: - verbose_checks_total += 1 + for check in extended["checks"]: + extended_checks_total += 1 if check["up"] == False: - verbose_checks_failed += 1 + extended_checks_failed += 1 bad = True if bad: - failed_records.append(verbose) + failed_records.append(extended) ################################################################################ # create a message @@ -213,14 +213,14 @@ async def check_health(): message += "All {} critical checks passed. ".format( critical_checks_total) - if verbose_checks_failed: - message += "{}/{} verbose checks failed over the last {} hours! ".format( - verbose_checks_failed, verbose_checks_total, CHECK_HOURS + if extended_checks_failed: + message += "{}/{} extended checks failed over the last {} hours! ".format( + extended_checks_failed, extended_checks_total, CHECK_HOURS ) force_notify = True else: - message += "All {} verbose checks passed. ".format( - verbose_checks_total) + message += "All {} extended checks passed. ".format( + extended_checks_total) if len(failed_records): failed_records_file = json.dumps(failed_records, indent=2)