add health check for registry write and read (#906)

This commit is contained in:
Karol Wypchło 2021-06-28 11:38:22 +02:00 committed by GitHub
parent 9dc24a8621
commit cdb5157958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 26 additions and 1 deletions

View File

@ -1,7 +1,8 @@
const got = require("got"); const got = require("got");
const FormData = require("form-data"); const FormData = require("form-data");
const { isEqual } = require("lodash");
const { calculateElapsedTime, getResponseContent } = require("../utils"); const { calculateElapsedTime, getResponseContent } = require("../utils");
const { SkynetClient } = require("skynet-js"); const { SkynetClient, genKeyPairAndSeed } = require("skynet-js");
const skynetClient = new SkynetClient(process.env.SKYNET_PORTAL_API); const skynetClient = new SkynetClient(process.env.SKYNET_PORTAL_API);
const exampleSkylink = "AACogzrAimYPG42tDOKhS3lXZD8YvlF8Q8R17afe95iV2Q"; const exampleSkylink = "AACogzrAimYPG42tDOKhS3lXZD8YvlF8Q8R17afe95iV2Q";
@ -64,6 +65,29 @@ async function accountWebsiteCheck(done) {
return done(await genericAccessCheck("account_website", url)); return done(await genericAccessCheck("account_website", url));
} }
// registryWriteAndReadCheck writes to registry and immediately reads and compares the data
async function registryWriteAndReadCheck(done) {
const time = process.hrtime();
const data = { name: "registry_write_and_read", up: false };
const { privateKey, publicKey } = genKeyPairAndSeed();
const expected = { datakey: "foo-key", data: "foo-data", revision: BigInt(0) };
try {
await skynetClient.registry.setEntry(privateKey, expected);
const { entry } = await skynetClient.registry.getEntry(publicKey, expected.datakey);
if (isEqual(expected, entry)) {
data.up = true;
} else {
data.errors = [{ message: "Data mismatch in registry (read after write)", entry, expected }];
}
} catch (error) {
data.errors = [{ message: error.message }];
}
return done({ ...data, time: calculateElapsedTime(time) });
}
// directServerApiAccessCheck returns the basic server api check on direct server address // directServerApiAccessCheck returns the basic server api check on direct server address
async function directServerApiAccessCheck(done) { async function directServerApiAccessCheck(done) {
if (!process.env.SKYNET_SERVER_API) { if (!process.env.SKYNET_SERVER_API) {
@ -138,6 +162,7 @@ const checks = [
downloadCheck, downloadCheck,
skylinkSubdomainCheck, skylinkSubdomainCheck,
handshakeSubdomainCheck, handshakeSubdomainCheck,
registryWriteAndReadCheck,
directServerApiAccessCheck, directServerApiAccessCheck,
]; ];