From 84282d4cc60164a97daddfe6f17b3b9d157aae68 Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Fri, 14 Aug 2020 11:46:38 -0400 Subject: [PATCH 01/16] Extend web portal health check to have basic and verbose checks --- health-check/{checks.js => basicChecks.js} | 9 +- health-check/endpointHealthCheck.js | 15 +- health-check/schedule.js | 22 +- health-check/verboseChecks.js | 283 +++++++++++++++++++++ 4 files changed, 321 insertions(+), 8 deletions(-) rename health-check/{checks.js => basicChecks.js} (75%) create mode 100644 health-check/verboseChecks.js diff --git a/health-check/checks.js b/health-check/basicChecks.js similarity index 75% rename from health-check/checks.js rename to health-check/basicChecks.js index 8372ac6f..71608125 100644 --- a/health-check/checks.js +++ b/health-check/basicChecks.js @@ -1,6 +1,7 @@ const superagent = require("superagent"); const HttpStatus = require("http-status-codes"); +// uploadCheck returns the result of uploading a sample file async function uploadCheck(done) { const time = process.hrtime(); @@ -15,10 +16,12 @@ async function uploadCheck(done) { up: statusCode === HttpStatus.OK, statusCode, time: catchRequestTime(time), + critical: true, }); }); } +// downloadCheck returns the result of downloading the hard coded link function downloadCheck(done) { const time = process.hrtime(); const skylink = "AACogzrAimYPG42tDOKhS3lXZD8YvlF8Q8R17afe95iV2Q"; @@ -31,14 +34,18 @@ function downloadCheck(done) { up: statusCode === HttpStatus.OK, statusCode, time: catchRequestTime(time), + critical: true, }); }); } +// catchRequestTime records the time it took to resolve the request in +// milliseconds function catchRequestTime(start) { const diff = process.hrtime(start); return Math.round((diff[0] * 1e9 + diff[1]) / 1e6); // msec } -module.exports.checks = [uploadCheck, downloadCheck]; +module.exports.basicChecks = [uploadCheck, downloadCheck]; +module.exports.catchRequestTime = catchRequestTime; diff --git a/health-check/endpointHealthCheck.js b/health-check/endpointHealthCheck.js index 9b14b9c6..1f48b1d7 100644 --- a/health-check/endpointHealthCheck.js +++ b/health-check/endpointHealthCheck.js @@ -2,31 +2,42 @@ const HttpStatus = require("http-status-codes"); const { sum, sumBy } = require("lodash"); const db = require("./db"); +// getStatus returns the server's current health check status function getStatus() { + // Grab entry element from DB const entry = db.get("entries").orderBy("date", "desc").head().value(); - if (entry && entry.checks.every(({ up }) => up)) { + // Check that every critical check entry is up + if (entry && entry.checks.every(({ up, critical }) => up && critical)) { return HttpStatus.OK; } + // At least one check failed return HttpStatus.SERVICE_UNAVAILABLE; } +// getTimeout returns the average time out from a sample of 10 health check +// entries. function getTimeout() { + // Check status of the Health Check if (getStatus() === HttpStatus.SERVICE_UNAVAILABLE) { return 0; } + // Grab 10 entries from the database as a sample to determine the average + // timeout for the server. const sample = db .get("entries") .orderBy("date", "desc") - .filter(({ checks }) => checks.every(({ up }) => up)) + .filter(({ checks }) => checks.every(({ up, critical }) => up && critical)) .take(10) .value(); + // Return average timeout return Math.round(sum(sample.map(({ checks }) => sumBy(checks, "time"))) / sample.size); } +// getEntriesSinceYesterday gets the health check entries since yesterday function getEntriesSinceYesterday() { const yesterday = new Date(); diff --git a/health-check/schedule.js b/health-check/schedule.js index 5ac0afc1..9c1ab837 100644 --- a/health-check/schedule.js +++ b/health-check/schedule.js @@ -1,16 +1,28 @@ const schedule = require("node-schedule"); const db = require("./db"); -const { checks } = require("./checks"); +const { basicChecks } = require("./basicChecks"); +const { verboseChecks } = require("./verboseChecks"); -// execute the health-check script every 5 mintues -const job = schedule.scheduleJob("*/5 * * * *", async () => { +// execute the basic health-check script every 5 minutes +const basicJob = schedule.scheduleJob("*/5 * * * *", async () => { const entry = { date: new Date().toISOString(), checks: [] }; - entry.checks = await Promise.all(checks.map((check) => new Promise(check))); + entry.checks = await Promise.all(basicChecks.map((check) => new Promise(check))); db.get("entries").push(entry).write(); }); +// execute the verbose health-check script once a day at 3am +const verboseJob = schedule.scheduleJob("* * 3 * * *", async () => { + const entry = { date: new Date().toISOString(), checks: [] }; + + entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check))); + + db.get("entries").push(entry).write(); +}); + +// Launch Health check jobs setTimeout(() => { - job.invoke(); + basicJob.invoke(); + verboseJob.invoke(); }, 60 * 1000); // delay for 60s to give other services time to start up diff --git a/health-check/verboseChecks.js b/health-check/verboseChecks.js new file mode 100644 index 00000000..523740c2 --- /dev/null +++ b/health-check/verboseChecks.js @@ -0,0 +1,283 @@ +const superagent = require("superagent"); +const HttpStatus = require("http-status-codes"); +const hash = require("object-hash"); +const checks = require("./basicChecks"); + +// audioExampleCheck returns the result of trying to download the skylink +// for the Example audio file on siasky.net +function audioExampleCheck(done) { + const linkInfo = { + description: "Audio Example", + skylink: "_A2zt5SKoqwnnZU4cBF8uBycSKULXMyeg1c5ZISBr2Q3dA", + metadataHash: "35e70208d0cf5f9ba254a2772039713be46a69d6", + bodyHash: "be335f5ad9bc357248f3d35c7e49df491afb6b12", + }; + + skylinkVerification(done, linkInfo); +} + +// dappExampleCheck returns the result of trying to download the skylink +// for the Example Dapp on siasky.net +function dappExampleCheck(done) { + const linkInfo = { + description: "Dapp Example (UniSwap)", + skylink: "EAC5HJr5Pu086EAZG4fP_r6Pnd7Ft366vt6t2AnjkoFb9Q/index.html", + metadataHash: "72ea3859b8d83b234b62e8f6e1931f969ec39402", + bodyHash: "d6ad2506590bb45b5acc6a8a964a3da4d657354f", + }; + + skylinkVerification(done, linkInfo); +} + +// developMomentumIndexFileCheck returns the result of trying to download the skylink +// for the Develop Momentum Application with a trailing /index.html +function developMomentumIndexFileCheck(done) { + const linkInfo = { + description: "Develop Momentum Index File", + skylink: "EAA1fG_ip4C1Vi1Ijvsr1oyr8jpH0Bo9HXya0T3kw-elGw/index.html", + metadataHash: "f0d06f934d28b420a77529acdb779a117a0d4cf5", + bodyHash: "53b44a9d3cfa9b3d66ce5c29976f4383725d3652", + }; + + skylinkVerification(done, linkInfo); +} + +// htmlExampleCheck returns the result of trying to download the skylink +// for the Example HTML file on siasky.net +function htmlExampleCheck(done) { + const linkInfo = { + description: "HTML Example", + skylink: "PAL0w4SdA5rFCDGEutgpeQ50Om-YkBabtXVOJAkmedslKw", + metadataHash: "eebdbfe406466ed8bbd190127a5d5a07ada68403", + bodyHash: "c932fd56f98b6db589e56be8018817f13bb29f72", + }; + + skylinkVerification(done, linkInfo); +} + +// imageExampleCheck returns the result of trying to download the skylink +// for the Example image on siasky.net +function imageExampleCheck(done) { + const linkInfo = { + description: "Image Example", + skylink: "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ", + metadataHash: "e77df549c8e5f41881e34c3844ec7e182a0db701", + bodyHash: "313207978d0a88bf2b961f098804e9ab0f82837f", + }; + + skylinkVerification(done, linkInfo); +} + +// jsonExampleCheck returns the result of trying to download the skylink +// for the Example JSON file on siasky.net +function jsonExampleCheck(done) { + const linkInfo = { + description: "JSON Example", + skylink: "AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ", + metadataHash: "0e6ee84c15ee3bc848058575337303ad9958ec64", + bodyHash: "198771c3d07d5c7302aadcc0697a7298e5e8ccc3", + }; + + skylinkVerification(done, linkInfo); +} + +// pdfExampleCheck returns the result of trying to download the skylink +// for the Example PDF file on siasky.net +function pdfExampleCheck(done) { + const linkInfo = { + description: "PDF Example", + skylink: "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg", + metadataHash: "7cb17f927c37a1c9a78221ed8b17f1af4a7299e8", + bodyHash: "9bd8162e1575569a9041972f7f62d65887063dc3", + }; + + skylinkVerification(done, linkInfo); +} + +// randomImageCheck returns the result of trying to download the skylink for +// a Random Image. +function randomImageCheck(done) { + const linkInfo = { + description: "Random Image", + skylink: "PAHx7JmsU9EFGbqm5q0LNKT2wKfoJ_mhPI8zWlNEXZ8uOQ/", + metadataHash: "1ce51445b63d7c658b02392ca7268ea90119abd7", + bodyHash: "4c73c5a0eddd5823be677d7f93bf80cc9338ee9f", + }; + + skylinkVerification(done, linkInfo); +} + +// randomImageRedirectCheck returns the result of trying to download the skylink for +// a Random Image with no trailing slash. +function randomImageRedirectCheck(done) { + const linkInfo = { + description: "Random Image Redirect", + skylink: "PAHx7JmsU9EFGbqm5q0LNKT2wKfoJ_mhPI8zWlNEXZ8uOQ", + metadataHash: "1ce51445b63d7c658b02392ca7268ea90119abd7", + bodyHash: "4c73c5a0eddd5823be677d7f93bf80cc9338ee9f", + }; + + skylinkVerification(done, linkInfo); +} + +// skyBayCheck returns the result of trying to download the skylink for the SkyBay Application. +function skyBayCheck(done) { + const linkInfo = { + description: "SkyBay", + skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA/", + metadataHash: "4b3e12932186ed6925d1c8ad2d71e0220bd957dd", + bodyHash: "25d63937c9734fb08d2749c6517d1b3de8ecb856", + }; + + skylinkVerification(done, linkInfo); +} + +// skyBayRedirectCheck returns the result of trying to download the skylink +// for the SkyBay Application with no trailing slash. +function skyBayRedirectCheck(done) { + const linkInfo = { + description: "SkyBay Redirect", + skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA", + metadataHash: "4b3e12932186ed6925d1c8ad2d71e0220bd957dd", + bodyHash: "25d63937c9734fb08d2749c6517d1b3de8ecb856", + }; + + skylinkVerification(done, linkInfo); +} + +// skyBinCheck returns the result of trying to download the skylink for the SkyBin Application. +function skyBinCheck(done) { + const linkInfo = { + description: "SkyBin", + skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA/", + metadataHash: "5c23ba16cd62d623bfb73e86a503d681d2ffcb24", + bodyHash: "767ec67c417e11b97c5db7dad9ea3b6b27cb0d39", + }; + + skylinkVerification(done, linkInfo); +} + +// skyBinRedirectCheck returns the result of trying to download the skylink +// for the SkyBin Application with no trailing slash. +function skyBinRedirectCheck(done) { + const linkInfo = { + description: "SkyBin Redirect", + skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA", + metadataHash: "5c23ba16cd62d623bfb73e86a503d681d2ffcb24", + bodyHash: "767ec67c417e11b97c5db7dad9ea3b6b27cb0d39", + }; + + skylinkVerification(done, linkInfo); +} + +// skyGalleryCheck returns the result of trying to download the skylink for the SkyGallery Application. +function skyGalleryCheck(done) { + const linkInfo = { + description: "SkyGallery", + skylink: "AADW6GsQcetwDBaDYnGCSTbYjSKY743NtY1A5VRx5sj3Dg/", + metadataHash: "b17a16a3522f2877b5b9ebdcdfd98956eade8721", + bodyHash: "077e54054748d278114f1870f8045a162eb73641", + }; + + skylinkVerification(done, linkInfo); +} + +// skyGalleryIndexFileCheck returns the result of trying to download the skylink +// for the SkyGallery Application with a trailing /index.html +function skyGalleryIndexFileCheck(done) { + const linkInfo = { + description: "SkyGallery Index File", + skylink: "AADW6GsQcetwDBaDYnGCSTbYjSKY743NtY1A5VRx5sj3Dg/index.html", + metadataHash: "203dcc63e6c3db7501822d9f0d38fab26f3dbceb", + bodyHash: "077e54054748d278114f1870f8045a162eb73641", + }; + + skylinkVerification(done, linkInfo); +} + +// skyGalleryRedirectCheck returns the result of trying to download the skylink +// for the SkyGallery Application with no trailing slash. +function skyGalleryRedirectCheck(done) { + const linkInfo = { + description: "SkyGallery Redirect", + skylink: "AADW6GsQcetwDBaDYnGCSTbYjSKY743NtY1A5VRx5sj3Dg", + metadataHash: "b17a16a3522f2877b5b9ebdcdfd98956eade8721", + bodyHash: "077e54054748d278114f1870f8045a162eb73641", + }; + + skylinkVerification(done, linkInfo); +} + +// uniswapIndexFileCheck returns the result of trying to download the skylink +// for the Uniswap Application with a trailing /index.html +function uniswapIndexFileCheck(done) { + const linkInfo = { + description: "Uniswap Skylink Index File", + skylink: "IAC6CkhNYuWZqMVr1gob1B6tPg4MrBGRzTaDvAIAeu9A9w/index.html", + metadataHash: "5baef23f7cc138a41d945727eb862fc2cd94ae45", + bodyHash: "3965f9a7def085b3a764ddc76a528eda38d72359", + }; + + skylinkVerification(done, linkInfo); +} + +// skylinkVerification verifies a skylink against known information provided in +// the linkInfo. +function skylinkVerification(done, linkInfo) { + const time = process.hrtime(); + + // Create the query for the skylink + let query = `http://${process.env.PORTAL_URL}/${linkInfo.skylink}?nocache=true`; + + // Get the Skylink + superagent + .get(query) + .responseType("blob") + .end((err, res) => { + // Record the statusCode + const statusCode = (res && res.statusCode) || (err && err.statusCode) || null; + + // Determine if the skylink is up. Start with checking if there was an + // error in the request. + let up = err === null; + if (up) { + // Check if the response body is valid by checking against the known + // hash + let validBody = hash(res.body) === linkInfo.bodyHash; + // Check if the metadata is valid by checking against the known + // hash + let validMetadata = hash(res.header["skynet-file-metadata"]) === linkInfo.metadataHash; + // Redetermine if the Skylink is up based on the results from the body + // and metadata hash checks + up = up && validBody && validMetadata; + } + + // Return the entry information + done({ + name: linkInfo.description, + up: up, + statusCode, + time: checks.catchRequestTime(time), + }); + }); +} + +module.exports.verboseChecks = [ + audioExampleCheck, + dappExampleCheck, + developMomentumIndexFileCheck, + htmlExampleCheck, + imageExampleCheck, + jsonExampleCheck, + pdfExampleCheck, + randomImageCheck, + randomImageRedirectCheck, + skyBayCheck, + skyBayRedirectCheck, + skyBinCheck, + skyBinRedirectCheck, + skyGalleryCheck, + skyGalleryIndexFileCheck, + skyGalleryRedirectCheck, + uniswapIndexFileCheck, +]; From 3f406f962c3b41280778786a90919982240c3d16 Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Tue, 25 Aug 2020 11:15:25 -0400 Subject: [PATCH 02/16] update cron schedule and const definitions --- package.json | 88 +++++++++++++++++++++- packages/health-check/src/schedule.js | 2 +- packages/health-check/src/verboseChecks.js | 6 +- 3 files changed, 88 insertions(+), 8 deletions(-) diff --git a/package.json b/package.json index 9f0acdba..03ee3453 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,86 @@ { - "private": true, - "workspaces": [ - "packages/*" - ] + "name": "skynet-webportal", + "description": "Sia Skynet", + "version": "1.0.0", + "author": "Nebulous", + "dependencies": { + "axios": "^0.19.2", + "bytes": "^3.1.0", + "classnames": "^2.2.6", + "gatsby": "^2.24.5", + "gatsby-image": "^2.4.13", + "gatsby-plugin-manifest": "^2.4.18", + "gatsby-plugin-matomo": "^0.8.3", + "gatsby-plugin-react-helmet": "^3.3.10", + "gatsby-plugin-remove-serviceworker": "^1.0.0", + "gatsby-plugin-robots-txt": "^1.5.1", + "gatsby-plugin-sass": "^2.3.12", + "gatsby-plugin-sharp": "^2.6.20", + "gatsby-source-filesystem": "^2.3.20", + "gatsby-transformer-sharp": "^2.5.11", + "http-status-codes": "^1.4.0", + "jsonp": "^0.2.1", + "node-sass": "^4.14.0", + "path-browserify": "^1.0.1", + "prop-types": "^15.7.2", + "react": "^16.13.1", + "react-countup": "^4.3.3", + "react-dom": "^16.13.1", + "react-dropzone": "^11.0.2", + "react-helmet": "^6.1.0", + "react-mailchimp-form": "^1.0.2", + "react-mailchimp-subscribe": "^2.1.0", + "react-reveal": "^1.2.2", + "react-syntax-highlighter": "^12.2.1", + "react-visibility-sensor": "^5.1.1", + "skynet-js": "0.0.8", + "typeface-metropolis": "^0.0.74" + }, + "devDependencies": { + "cypress": "^4.10.0", + "cypress-file-upload": "^4.0.7", + "eslint": "^7.5.0", + "eslint-config-prettier": "^6.11.0", + "eslint-plugin-cypress": "^2.11.1", + "eslint-plugin-react": "^7.20.3", + "husky": "^4.2.5", + "lint-staged": "^10.2.11", + "prettier": "^2.0.5" + }, + "keywords": [ + "sia", + "skynet", + "nebulous", + "blockchain", + "decentralized", + "cloud storage" + ], + "license": "MIT", + "scripts": { + "build": "gatsby build", + "start": "gatsby develop", + "serve": "gatsby serve", + "clean": "gatsby clean" + }, + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, + "lint-staged": { + "*.{js,jsx,ts,tsx}": [ + "eslint --fix", + "prettier --write" + ], + "*.{md,html,css,scss}": [ + "prettier --write" + ] + }, + "repository": { + "type": "git", + "url": "https://github.com/NebulousLabs/skynet-webportal" + }, + "bugs": { + "url": "https://github.com/NebulousLabs/skynet-webportal/issues" + } } diff --git a/packages/health-check/src/schedule.js b/packages/health-check/src/schedule.js index 9c1ab837..3a35353e 100644 --- a/packages/health-check/src/schedule.js +++ b/packages/health-check/src/schedule.js @@ -13,7 +13,7 @@ const basicJob = schedule.scheduleJob("*/5 * * * *", async () => { }); // execute the verbose health-check script once a day at 3am -const verboseJob = schedule.scheduleJob("* * 3 * * *", async () => { +const verboseJob = schedule.scheduleJob("* 3 * * *", async () => { const entry = { date: new Date().toISOString(), checks: [] }; entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check))); diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index 523740c2..4492f362 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -227,7 +227,7 @@ function skylinkVerification(done, linkInfo) { const time = process.hrtime(); // Create the query for the skylink - let query = `http://${process.env.PORTAL_URL}/${linkInfo.skylink}?nocache=true`; + const query = `http://${process.env.PORTAL_URL}/${linkInfo.skylink}?nocache=true`; // Get the Skylink superagent @@ -243,10 +243,10 @@ function skylinkVerification(done, linkInfo) { if (up) { // Check if the response body is valid by checking against the known // hash - let validBody = hash(res.body) === linkInfo.bodyHash; + const validBody = hash(res.body) === linkInfo.bodyHash; // Check if the metadata is valid by checking against the known // hash - let validMetadata = hash(res.header["skynet-file-metadata"]) === linkInfo.metadataHash; + const validMetadata = hash(res.header["skynet-file-metadata"]) === linkInfo.metadataHash; // Redetermine if the Skylink is up based on the results from the body // and metadata hash checks up = up && validBody && validMetadata; From 401c592e560da73be9cec6de75fef5cd69e54f08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Wypch=C5=82o?= Date: Wed, 26 Aug 2020 14:11:26 +0200 Subject: [PATCH 03/16] Update packages/health-check/src/schedule.js --- packages/health-check/src/schedule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/health-check/src/schedule.js b/packages/health-check/src/schedule.js index 3a35353e..b61aa439 100644 --- a/packages/health-check/src/schedule.js +++ b/packages/health-check/src/schedule.js @@ -13,7 +13,7 @@ const basicJob = schedule.scheduleJob("*/5 * * * *", async () => { }); // execute the verbose health-check script once a day at 3am -const verboseJob = schedule.scheduleJob("* 3 * * *", async () => { +const verboseJob = schedule.scheduleJob("0 3 * * *", async () => { const entry = { date: new Date().toISOString(), checks: [] }; entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check))); From cb8a521ba71b7386f697461b6a91beb6c89d0c93 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 15:56:12 +0200 Subject: [PATCH 04/16] missing object-hash dep --- packages/health-check/package.json | 1 + yarn.lock | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/packages/health-check/package.json b/packages/health-check/package.json index f0bcfc25..21e61125 100644 --- a/packages/health-check/package.json +++ b/packages/health-check/package.json @@ -10,6 +10,7 @@ "lodash": "^4.17.19", "lowdb": "^1.0.0", "node-schedule": "^1.3.2", + "object-hash": "^2.0.3", "superagent": "^6.0.0" }, "devDependencies": { diff --git a/yarn.lock b/yarn.lock index 2e836b2e..74ffb357 100644 --- a/yarn.lock +++ b/yarn.lock @@ -10529,6 +10529,11 @@ object-hash@^1.1.4: resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-1.3.1.tgz#fde452098a951cb145f039bb7d455449ddc126df" integrity sha512-OSuu/pU4ENM9kmREg0BdNrUDIl1heYa4mBZacJc+vVWz4GtAwu7jO8s4AIt2aGRUTqxykpWzI3Oqnsm13tTMDA== +object-hash@^2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/object-hash/-/object-hash-2.0.3.tgz#d12db044e03cd2ca3d77c0570d87225b02e1e6ea" + integrity sha512-JPKn0GMu+Fa3zt3Bmr66JhokJU5BaNBIh4ZeTlaCBzrBsOeXzwcKKAK1tbLiPKgvwmPXsDvvLHoWh5Bm7ofIYg== + object-inspect@^1.7.0: version "1.8.0" resolved "https://registry.yarnpkg.com/object-inspect/-/object-inspect-1.8.0.tgz#df807e5ecf53a609cc6bfe93eac3cc7be5b3a9d0" From 5ceba4e0cff5b8e5a8c72f4aef24c572adc99041 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 15:57:13 +0200 Subject: [PATCH 05/16] drop unnecessary dep --- packages/health-check/src/verboseChecks.js | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index 4492f362..4c9bdc2a 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -1,5 +1,4 @@ const superagent = require("superagent"); -const HttpStatus = require("http-status-codes"); const hash = require("object-hash"); const checks = require("./basicChecks"); From ec6b73c130abc3cdb1a40f02d7f3e23c38a13759 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 15:59:47 +0200 Subject: [PATCH 06/16] nginx depends on health-check to be up first --- docker-compose.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/docker-compose.yml b/docker-compose.yml index 97fabaac..e230d90b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -81,6 +81,7 @@ services: - 80 depends_on: - sia + - health-check - handshake-api webapp: From c248efb73b0d20d4f67d451718bb7fdcbfc8e42b Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 16:02:49 +0200 Subject: [PATCH 07/16] circular dependencies --- docker-compose.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index e230d90b..3c40ca50 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -150,6 +150,5 @@ services: expose: - 3100 depends_on: - - caddy - handshake - handshake-api From 7e90b6f4dd7c9075e097001f9d3648dff433ca6a Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 16:06:12 +0200 Subject: [PATCH 08/16] fix http-status-codes usage --- packages/health-check/src/basicChecks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/health-check/src/basicChecks.js b/packages/health-check/src/basicChecks.js index 3b7e7b9d..ace17475 100644 --- a/packages/health-check/src/basicChecks.js +++ b/packages/health-check/src/basicChecks.js @@ -31,7 +31,7 @@ function downloadCheck(done) { done({ name: "download_file", - up: statusCode === HttpStatus.OK, + up: statusCode === StatusCodes.OK, statusCode, time: catchRequestTime(time), critical: true, From 843fcfde978232a03dd942f48e027f55bcdde2a0 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 16:06:45 +0200 Subject: [PATCH 09/16] every 5 minutes for debugging --- packages/health-check/src/schedule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/health-check/src/schedule.js b/packages/health-check/src/schedule.js index b61aa439..37da470d 100644 --- a/packages/health-check/src/schedule.js +++ b/packages/health-check/src/schedule.js @@ -13,7 +13,7 @@ const basicJob = schedule.scheduleJob("*/5 * * * *", async () => { }); // execute the verbose health-check script once a day at 3am -const verboseJob = schedule.scheduleJob("0 3 * * *", async () => { +const verboseJob = schedule.scheduleJob("*/5 * * * *", async () => { const entry = { date: new Date().toISOString(), checks: [] }; entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check))); From f201f9c4b4ea6e170c9ba35bc026549b3c9a5159 Mon Sep 17 00:00:00 2001 From: Matthew Sevey Date: Wed, 26 Aug 2020 10:22:55 -0400 Subject: [PATCH 10/16] add info field and set verbose checks to critical --- packages/health-check/src/verboseChecks.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index 4c9bdc2a..124a8e13 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -251,12 +251,19 @@ function skylinkVerification(done, linkInfo) { up = up && validBody && validMetadata; } + let info = ""; + if (!up) { + info = "validBody: " + validBody + "\nvalidMetadata: " + validMetadata; + } + // Return the entry information done({ name: linkInfo.description, up: up, statusCode, time: checks.catchRequestTime(time), + info: info, + critical: true, }); }); } From 9ad39482ad3b1ffe52bddb79cfa9d97f5077a90e Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 16:45:25 +0200 Subject: [PATCH 11/16] info should be an object --- packages/health-check/src/verboseChecks.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index 124a8e13..b0c6551a 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -251,18 +251,15 @@ function skylinkVerification(done, linkInfo) { up = up && validBody && validMetadata; } - let info = ""; - if (!up) { - info = "validBody: " + validBody + "\nvalidMetadata: " + validMetadata; - } + const info = { validBody, validMetadata }; // Return the entry information done({ name: linkInfo.description, - up: up, + up, + info, statusCode, time: checks.catchRequestTime(time), - info: info, critical: true, }); }); From 53b3933bee8e65de8cada5b26eac9d0096c8ac3c Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 16:47:53 +0200 Subject: [PATCH 12/16] info should be an object --- packages/health-check/src/verboseChecks.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index b0c6551a..955484c2 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -235,6 +235,7 @@ function skylinkVerification(done, linkInfo) { .end((err, res) => { // Record the statusCode const statusCode = (res && res.statusCode) || (err && err.statusCode) || null; + let info = null; // Determine if the skylink is up. Start with checking if there was an // error in the request. @@ -249,9 +250,9 @@ function skylinkVerification(done, linkInfo) { // Redetermine if the Skylink is up based on the results from the body // and metadata hash checks up = up && validBody && validMetadata; - } - const info = { validBody, validMetadata }; + info = { validBody, validMetadata }; + } // Return the entry information done({ From 94154924a109d938c6400943931fe8f286c2aa53 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 16:52:23 +0200 Subject: [PATCH 13/16] log metadata --- packages/health-check/src/verboseChecks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index 955484c2..18b20aed 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -251,7 +251,7 @@ function skylinkVerification(done, linkInfo) { // and metadata hash checks up = up && validBody && validMetadata; - info = { validBody, validMetadata }; + info = { validBody, validMetadata, metadata: res.header["skynet-file-metadata"] }; } // Return the entry information From 913b2dbb1533260ddd9c9170483b61c7959629eb Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 17:08:52 +0200 Subject: [PATCH 14/16] compare metdata objects --- packages/health-check/package.json | 3 +- packages/health-check/src/verboseChecks.js | 315 +++++++++++++++++++-- yarn.lock | 7 +- 3 files changed, 304 insertions(+), 21 deletions(-) diff --git a/packages/health-check/package.json b/packages/health-check/package.json index 21e61125..40f1ce4c 100644 --- a/packages/health-check/package.json +++ b/packages/health-check/package.json @@ -5,9 +5,10 @@ "license": "MIT", "dependencies": { "body-parser": "^1.19.0", + "deep-object-diff": "^1.1.0", "express": "^4.17.1", "http-status-codes": "^2.1.2", - "lodash": "^4.17.19", + "lodash": "^4.17.20", "lowdb": "^1.0.0", "node-schedule": "^1.3.2", "object-hash": "^2.0.3", diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index 18b20aed..af19d573 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -1,5 +1,7 @@ const superagent = require("superagent"); const hash = require("object-hash"); +const { detailedDiff } = require("deep-object-diff"); +const { isEqual } = require("lodash"); const checks = require("./basicChecks"); // audioExampleCheck returns the result of trying to download the skylink @@ -8,8 +10,8 @@ function audioExampleCheck(done) { const linkInfo = { description: "Audio Example", skylink: "_A2zt5SKoqwnnZU4cBF8uBycSKULXMyeg1c5ZISBr2Q3dA", - metadataHash: "35e70208d0cf5f9ba254a2772039713be46a69d6", bodyHash: "be335f5ad9bc357248f3d35c7e49df491afb6b12", + metadata: { filename: "feel-good.mp3" }, }; skylinkVerification(done, linkInfo); @@ -21,8 +23,12 @@ function dappExampleCheck(done) { const linkInfo = { description: "Dapp Example (UniSwap)", skylink: "EAC5HJr5Pu086EAZG4fP_r6Pnd7Ft366vt6t2AnjkoFb9Q/index.html", - metadataHash: "72ea3859b8d83b234b62e8f6e1931f969ec39402", bodyHash: "d6ad2506590bb45b5acc6a8a964a3da4d657354f", + metadata: { + filename: "/index.html", + length: 4131, + subfiles: { "index.html": { filename: "index.html", contenttype: "text/html", len: 4131 } }, + }, }; skylinkVerification(done, linkInfo); @@ -34,8 +40,12 @@ function developMomentumIndexFileCheck(done) { const linkInfo = { description: "Develop Momentum Index File", skylink: "EAA1fG_ip4C1Vi1Ijvsr1oyr8jpH0Bo9HXya0T3kw-elGw/index.html", - metadataHash: "f0d06f934d28b420a77529acdb779a117a0d4cf5", bodyHash: "53b44a9d3cfa9b3d66ce5c29976f4383725d3652", + metadata: { + filename: "/index.html", + length: 4981, + subfiles: { "index.html": { filename: "index.html", contenttype: "text/html", len: 4981 } }, + }, }; skylinkVerification(done, linkInfo); @@ -47,8 +57,8 @@ function htmlExampleCheck(done) { const linkInfo = { description: "HTML Example", skylink: "PAL0w4SdA5rFCDGEutgpeQ50Om-YkBabtXVOJAkmedslKw", - metadataHash: "eebdbfe406466ed8bbd190127a5d5a07ada68403", bodyHash: "c932fd56f98b6db589e56be8018817f13bb29f72", + metadata: { filename: "introduction – Sia API Documentation.html" }, }; skylinkVerification(done, linkInfo); @@ -60,8 +70,8 @@ function imageExampleCheck(done) { const linkInfo = { description: "Image Example", skylink: "IADUs8d9CQjUO34LmdaaNPK_STuZo24rpKVfYW3wPPM2uQ", - metadataHash: "e77df549c8e5f41881e34c3844ec7e182a0db701", bodyHash: "313207978d0a88bf2b961f098804e9ab0f82837f", + metadata: { filename: "sia-lm.png" }, }; skylinkVerification(done, linkInfo); @@ -73,8 +83,8 @@ function jsonExampleCheck(done) { const linkInfo = { description: "JSON Example", skylink: "AAC0uO43g64ULpyrW0zO3bjEknSFbAhm8c-RFP21EQlmSQ", - metadataHash: "0e6ee84c15ee3bc848058575337303ad9958ec64", bodyHash: "198771c3d07d5c7302aadcc0697a7298e5e8ccc3", + metadata: { filename: "consensus.json" }, }; skylinkVerification(done, linkInfo); @@ -86,8 +96,8 @@ function pdfExampleCheck(done) { const linkInfo = { description: "PDF Example", skylink: "XABvi7JtJbQSMAcDwnUnmp2FKDPjg8_tTTFP4BwMSxVdEg", - metadataHash: "7cb17f927c37a1c9a78221ed8b17f1af4a7299e8", bodyHash: "9bd8162e1575569a9041972f7f62d65887063dc3", + metadata: { filename: "sia.pdf" }, }; skylinkVerification(done, linkInfo); @@ -99,8 +109,12 @@ function randomImageCheck(done) { const linkInfo = { description: "Random Image", skylink: "PAHx7JmsU9EFGbqm5q0LNKT2wKfoJ_mhPI8zWlNEXZ8uOQ/", - metadataHash: "1ce51445b63d7c658b02392ca7268ea90119abd7", bodyHash: "4c73c5a0eddd5823be677d7f93bf80cc9338ee9f", + metadata: { + filename: "30355444.png", + subfiles: { "30355444.png": { filename: "30355444.png", contenttype: "image/png", len: 350473 } }, + defaultpath: "/30355444.png", + }, }; skylinkVerification(done, linkInfo); @@ -112,8 +126,12 @@ function randomImageRedirectCheck(done) { const linkInfo = { description: "Random Image Redirect", skylink: "PAHx7JmsU9EFGbqm5q0LNKT2wKfoJ_mhPI8zWlNEXZ8uOQ", - metadataHash: "1ce51445b63d7c658b02392ca7268ea90119abd7", bodyHash: "4c73c5a0eddd5823be677d7f93bf80cc9338ee9f", + metadata: { + filename: "30355444.png", + subfiles: { "30355444.png": { filename: "30355444.png", contenttype: "image/png", len: 350473 } }, + defaultpath: "/30355444.png", + }, }; skylinkVerification(done, linkInfo); @@ -124,8 +142,11 @@ function skyBayCheck(done) { const linkInfo = { description: "SkyBay", skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA/", - metadataHash: "4b3e12932186ed6925d1c8ad2d71e0220bd957dd", bodyHash: "25d63937c9734fb08d2749c6517d1b3de8ecb856", + metadata: { + filename: "skybay.html", + subfiles: { "skybay.html": { filename: "skybay.html", contenttype: "text/html", len: 11655 } }, + }, }; skylinkVerification(done, linkInfo); @@ -137,8 +158,11 @@ function skyBayRedirectCheck(done) { const linkInfo = { description: "SkyBay Redirect", skylink: "EABkMjXzxJRpPz0eO0Or5fy2eo-rz3prdigGwRlyNd9mwA", - metadataHash: "4b3e12932186ed6925d1c8ad2d71e0220bd957dd", bodyHash: "25d63937c9734fb08d2749c6517d1b3de8ecb856", + metadata: { + filename: "skybay.html", + subfiles: { "skybay.html": { filename: "skybay.html", contenttype: "text/html", len: 11655 } }, + }, }; skylinkVerification(done, linkInfo); @@ -149,8 +173,8 @@ function skyBinCheck(done) { const linkInfo = { description: "SkyBin", skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA/", - metadataHash: "5c23ba16cd62d623bfb73e86a503d681d2ffcb24", bodyHash: "767ec67c417e11b97c5db7dad9ea3b6b27cb0d39", + metadata: { filename: "skybin.html" }, }; skylinkVerification(done, linkInfo); @@ -162,8 +186,8 @@ function skyBinRedirectCheck(done) { const linkInfo = { description: "SkyBin Redirect", skylink: "CAAVU14pB9GRIqCrejD7rlS27HltGGiiCLICzmrBV0wVtA", - metadataHash: "5c23ba16cd62d623bfb73e86a503d681d2ffcb24", bodyHash: "767ec67c417e11b97c5db7dad9ea3b6b27cb0d39", + metadata: { filename: "skybin.html" }, }; skylinkVerification(done, linkInfo); @@ -174,8 +198,129 @@ function skyGalleryCheck(done) { const linkInfo = { description: "SkyGallery", skylink: "AADW6GsQcetwDBaDYnGCSTbYjSKY743NtY1A5VRx5sj3Dg/", - metadataHash: "b17a16a3522f2877b5b9ebdcdfd98956eade8721", bodyHash: "077e54054748d278114f1870f8045a162eb73641", + metadata: { + filename: "skygallery-v0.1.1-76c4c115fcb526716b2564568850f433", + subfiles: { + "css/app.84a130ed.css": { filename: "css/app.84a130ed.css", contenttype: "text/css", len: 698 }, + "css/chunk-5ce44031.d4e78528.css": { + filename: "css/chunk-5ce44031.d4e78528.css", + contenttype: "text/css", + offset: 698, + len: 45, + }, + "css/chunk-6bef839b.593aa2be.css": { + filename: "css/chunk-6bef839b.593aa2be.css", + contenttype: "text/css", + offset: 743, + len: 5013, + }, + "css/chunk-8ed50a48.8ba8c09d.css": { + filename: "css/chunk-8ed50a48.8ba8c09d.css", + contenttype: "text/css", + offset: 5756, + len: 7204, + }, + "css/chunk-eb4c1efc.2a7e25ed.css": { + filename: "css/chunk-eb4c1efc.2a7e25ed.css", + contenttype: "text/css", + offset: 12960, + len: 45, + }, + "css/chunk-vendors.b4f58487.css": { + filename: "css/chunk-vendors.b4f58487.css", + contenttype: "text/css", + offset: 13005, + len: 382063, + }, + "img/skygallery_logo.2336197e.svg": { + filename: "img/skygallery_logo.2336197e.svg", + contenttype: "image/svg+xml", + offset: 395068, + len: 923, + }, + "img/skynet-logo-animated.4d24345c.svg": { + filename: "img/skynet-logo-animated.4d24345c.svg", + contenttype: "image/svg+xml", + offset: 395991, + len: 2600, + }, + "index.html": { filename: "index.html", contenttype: "text/html", offset: 398591, len: 2534 }, + "js/app.cff1e0a4.js": { + filename: "js/app.cff1e0a4.js", + contenttype: "application/javascript", + offset: 401125, + len: 15604, + }, + "js/app.cff1e0a4.js.map": { + filename: "js/app.cff1e0a4.js.map", + contenttype: "application/json", + offset: 416729, + len: 54424, + }, + "js/chunk-5ce44031.7fb55da9.js": { + filename: "js/chunk-5ce44031.7fb55da9.js", + contenttype: "application/javascript", + offset: 471153, + len: 3644, + }, + "js/chunk-5ce44031.7fb55da9.js.map": { + filename: "js/chunk-5ce44031.7fb55da9.js.map", + contenttype: "application/json", + offset: 474797, + len: 13494, + }, + "js/chunk-6bef839b.b543fe7d.js": { + filename: "js/chunk-6bef839b.b543fe7d.js", + contenttype: "application/javascript", + offset: 488291, + len: 13349, + }, + "js/chunk-6bef839b.b543fe7d.js.map": { + filename: "js/chunk-6bef839b.b543fe7d.js.map", + contenttype: "application/json", + offset: 501640, + len: 46690, + }, + "js/chunk-8ed50a48.35f8ef35.js": { + filename: "js/chunk-8ed50a48.35f8ef35.js", + contenttype: "application/javascript", + offset: 548330, + len: 130329, + }, + "js/chunk-8ed50a48.35f8ef35.js.map": { + filename: "js/chunk-8ed50a48.35f8ef35.js.map", + contenttype: "application/json", + offset: 678659, + len: 507145, + }, + "js/chunk-eb4c1efc.57b6e01c.js": { + filename: "js/chunk-eb4c1efc.57b6e01c.js", + contenttype: "application/javascript", + offset: 1185804, + len: 4407, + }, + "js/chunk-eb4c1efc.57b6e01c.js.map": { + filename: "js/chunk-eb4c1efc.57b6e01c.js.map", + contenttype: "application/json", + offset: 1190211, + len: 15355, + }, + "js/chunk-vendors.1fd55121.js": { + filename: "js/chunk-vendors.1fd55121.js", + contenttype: "application/javascript", + offset: 1205566, + len: 749829, + }, + "js/chunk-vendors.1fd55121.js.map": { + filename: "js/chunk-vendors.1fd55121.js.map", + contenttype: "application/json", + offset: 1955395, + len: 2793251, + }, + }, + defaultpath: "/index.html", + }, }; skylinkVerification(done, linkInfo); @@ -187,8 +332,12 @@ function skyGalleryIndexFileCheck(done) { const linkInfo = { description: "SkyGallery Index File", skylink: "AADW6GsQcetwDBaDYnGCSTbYjSKY743NtY1A5VRx5sj3Dg/index.html", - metadataHash: "203dcc63e6c3db7501822d9f0d38fab26f3dbceb", bodyHash: "077e54054748d278114f1870f8045a162eb73641", + metadata: { + filename: "/index.html", + length: 2534, + subfiles: { "index.html": { filename: "index.html", contenttype: "text/html", len: 2534 } }, + }, }; skylinkVerification(done, linkInfo); @@ -200,8 +349,129 @@ function skyGalleryRedirectCheck(done) { const linkInfo = { description: "SkyGallery Redirect", skylink: "AADW6GsQcetwDBaDYnGCSTbYjSKY743NtY1A5VRx5sj3Dg", - metadataHash: "b17a16a3522f2877b5b9ebdcdfd98956eade8721", bodyHash: "077e54054748d278114f1870f8045a162eb73641", + metadata: { + filename: "skygallery-v0.1.1-76c4c115fcb526716b2564568850f433", + subfiles: { + "css/app.84a130ed.css": { filename: "css/app.84a130ed.css", contenttype: "text/css", len: 698 }, + "css/chunk-5ce44031.d4e78528.css": { + filename: "css/chunk-5ce44031.d4e78528.css", + contenttype: "text/css", + offset: 698, + len: 45, + }, + "css/chunk-6bef839b.593aa2be.css": { + filename: "css/chunk-6bef839b.593aa2be.css", + contenttype: "text/css", + offset: 743, + len: 5013, + }, + "css/chunk-8ed50a48.8ba8c09d.css": { + filename: "css/chunk-8ed50a48.8ba8c09d.css", + contenttype: "text/css", + offset: 5756, + len: 7204, + }, + "css/chunk-eb4c1efc.2a7e25ed.css": { + filename: "css/chunk-eb4c1efc.2a7e25ed.css", + contenttype: "text/css", + offset: 12960, + len: 45, + }, + "css/chunk-vendors.b4f58487.css": { + filename: "css/chunk-vendors.b4f58487.css", + contenttype: "text/css", + offset: 13005, + len: 382063, + }, + "img/skygallery_logo.2336197e.svg": { + filename: "img/skygallery_logo.2336197e.svg", + contenttype: "image/svg+xml", + offset: 395068, + len: 923, + }, + "img/skynet-logo-animated.4d24345c.svg": { + filename: "img/skynet-logo-animated.4d24345c.svg", + contenttype: "image/svg+xml", + offset: 395991, + len: 2600, + }, + "index.html": { filename: "index.html", contenttype: "text/html", offset: 398591, len: 2534 }, + "js/app.cff1e0a4.js": { + filename: "js/app.cff1e0a4.js", + contenttype: "application/javascript", + offset: 401125, + len: 15604, + }, + "js/app.cff1e0a4.js.map": { + filename: "js/app.cff1e0a4.js.map", + contenttype: "application/json", + offset: 416729, + len: 54424, + }, + "js/chunk-5ce44031.7fb55da9.js": { + filename: "js/chunk-5ce44031.7fb55da9.js", + contenttype: "application/javascript", + offset: 471153, + len: 3644, + }, + "js/chunk-5ce44031.7fb55da9.js.map": { + filename: "js/chunk-5ce44031.7fb55da9.js.map", + contenttype: "application/json", + offset: 474797, + len: 13494, + }, + "js/chunk-6bef839b.b543fe7d.js": { + filename: "js/chunk-6bef839b.b543fe7d.js", + contenttype: "application/javascript", + offset: 488291, + len: 13349, + }, + "js/chunk-6bef839b.b543fe7d.js.map": { + filename: "js/chunk-6bef839b.b543fe7d.js.map", + contenttype: "application/json", + offset: 501640, + len: 46690, + }, + "js/chunk-8ed50a48.35f8ef35.js": { + filename: "js/chunk-8ed50a48.35f8ef35.js", + contenttype: "application/javascript", + offset: 548330, + len: 130329, + }, + "js/chunk-8ed50a48.35f8ef35.js.map": { + filename: "js/chunk-8ed50a48.35f8ef35.js.map", + contenttype: "application/json", + offset: 678659, + len: 507145, + }, + "js/chunk-eb4c1efc.57b6e01c.js": { + filename: "js/chunk-eb4c1efc.57b6e01c.js", + contenttype: "application/javascript", + offset: 1185804, + len: 4407, + }, + "js/chunk-eb4c1efc.57b6e01c.js.map": { + filename: "js/chunk-eb4c1efc.57b6e01c.js.map", + contenttype: "application/json", + offset: 1190211, + len: 15355, + }, + "js/chunk-vendors.1fd55121.js": { + filename: "js/chunk-vendors.1fd55121.js", + contenttype: "application/javascript", + offset: 1205566, + len: 749829, + }, + "js/chunk-vendors.1fd55121.js.map": { + filename: "js/chunk-vendors.1fd55121.js.map", + contenttype: "application/json", + offset: 1955395, + len: 2793251, + }, + }, + defaultpath: "/index.html", + }, }; skylinkVerification(done, linkInfo); @@ -213,8 +483,12 @@ function uniswapIndexFileCheck(done) { const linkInfo = { description: "Uniswap Skylink Index File", skylink: "IAC6CkhNYuWZqMVr1gob1B6tPg4MrBGRzTaDvAIAeu9A9w/index.html", - metadataHash: "5baef23f7cc138a41d945727eb862fc2cd94ae45", bodyHash: "3965f9a7def085b3a764ddc76a528eda38d72359", + metadata: { + filename: "/index.html", + length: 3268, + subfiles: { "index.html": { filename: "index.html", contenttype: "text/html", len: 3268 } }, + }, }; skylinkVerification(done, linkInfo); @@ -246,12 +520,15 @@ function skylinkVerification(done, linkInfo) { const validBody = hash(res.body) === linkInfo.bodyHash; // Check if the metadata is valid by checking against the known // hash - const validMetadata = hash(res.header["skynet-file-metadata"]) === linkInfo.metadataHash; + const validMetadata = isEqual(res.header["skynet-file-metadata"], linkInfo.metadata); // Redetermine if the Skylink is up based on the results from the body // and metadata hash checks up = up && validBody && validMetadata; - info = { validBody, validMetadata, metadata: res.header["skynet-file-metadata"] }; + info = { + body: { valid: validBody }, + metadata: { valid: validMetadata, diff: detailedDiff(res.header["skynet-file-metadata"], linkInfo.metadata) }, + }; } // Return the entry information diff --git a/yarn.lock b/yarn.lock index 74ffb357..5c958731 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4880,6 +4880,11 @@ deep-is@^0.1.3, deep-is@~0.1.3: resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" integrity sha1-s2nW+128E+7PUk+RsHD+7cNXzzQ= +deep-object-diff@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/deep-object-diff/-/deep-object-diff-1.1.0.tgz#d6fabf476c2ed1751fc94d5ca693d2ed8c18bc5a" + integrity sha512-b+QLs5vHgS+IoSNcUE4n9HP2NwcHj7aqnJWsjPtuG75Rh5TOaGt0OjAYInh77d5T16V5cRDC+Pw/6ZZZiETBGw== + deepmerge@^2.1.1: version "2.2.1" resolved "https://registry.yarnpkg.com/deepmerge/-/deepmerge-2.2.1.tgz#5d3ff22a01c00f645405a2fbc17d0778a1801170" @@ -9473,7 +9478,7 @@ lodash.uniq@4.5.0, lodash.uniq@^4.5.0: resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773" integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M= -lodash@4, lodash@^4.0.0, lodash@^4.11.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0, lodash@~4.17.10: +lodash@4, lodash@^4.0.0, lodash@^4.11.1, lodash@^4.17.10, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.4, lodash@^4.17.5, lodash@^4.3.0, lodash@~4.17.10: version "4.17.20" resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.20.tgz#b44a9b6297bcb698f1c51a3545a2b3b368d59c52" integrity sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA== From 4eec29503558d7a25d82d982135b747cca83e806 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 17:14:23 +0200 Subject: [PATCH 15/16] parse --- packages/health-check/src/verboseChecks.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/health-check/src/verboseChecks.js b/packages/health-check/src/verboseChecks.js index af19d573..05de4048 100644 --- a/packages/health-check/src/verboseChecks.js +++ b/packages/health-check/src/verboseChecks.js @@ -518,16 +518,16 @@ function skylinkVerification(done, linkInfo) { // Check if the response body is valid by checking against the known // hash const validBody = hash(res.body) === linkInfo.bodyHash; - // Check if the metadata is valid by checking against the known - // hash - const validMetadata = isEqual(res.header["skynet-file-metadata"], linkInfo.metadata); + // Check if the metadata is valid + const metadata = res.header["skynet-file-metadata"] ? JSON.parse(res.header["skynet-file-metadata"]) : null; + const validMetadata = isEqual(metadata, linkInfo.metadata); // Redetermine if the Skylink is up based on the results from the body // and metadata hash checks up = up && validBody && validMetadata; info = { body: { valid: validBody }, - metadata: { valid: validMetadata, diff: detailedDiff(res.header["skynet-file-metadata"], linkInfo.metadata) }, + metadata: { valid: validMetadata, diff: detailedDiff(metadata, linkInfo.metadata) }, }; } From 062cc12a7d2cbfd3e70d211a2523dc9201872447 Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 26 Aug 2020 17:17:33 +0200 Subject: [PATCH 16/16] make it once per hour --- packages/health-check/src/schedule.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/health-check/src/schedule.js b/packages/health-check/src/schedule.js index 37da470d..252f2518 100644 --- a/packages/health-check/src/schedule.js +++ b/packages/health-check/src/schedule.js @@ -12,8 +12,8 @@ const basicJob = schedule.scheduleJob("*/5 * * * *", async () => { db.get("entries").push(entry).write(); }); -// execute the verbose health-check script once a day at 3am -const verboseJob = schedule.scheduleJob("*/5 * * * *", async () => { +// execute the verbose health-check script once per hour +const verboseJob = schedule.scheduleJob("0 * * * *", async () => { const entry = { date: new Date().toISOString(), checks: [] }; entry.checks = await Promise.all(verboseChecks.map((check) => new Promise(check)));