verbose => extended

This commit is contained in:
Karol Wypchlo 2021-04-29 13:43:40 +02:00
parent 209a12ccad
commit cd7dac5b7e
7 changed files with 27 additions and 29 deletions

View File

@ -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

View File

@ -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();

View File

@ -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,

View File

@ -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;

View File

@ -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) => {

View File

@ -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",

View File

@ -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)