Add skylink health check
This commit is contained in:
parent
c1d07083fb
commit
e823e9f373
|
@ -1,6 +1,6 @@
|
||||||
FROM node:16.14.2-alpine
|
FROM node:16.14.2-alpine
|
||||||
|
|
||||||
RUN apk add --no-cache dnsmasq=2.86-r0
|
RUN apk add --no-cache dnsmasq=2.86-r1
|
||||||
|
|
||||||
WORKDIR /usr/app
|
WORKDIR /usr/app
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,7 @@ async function uploadCheck(done) {
|
||||||
form.append("file", payload, { filename: "time.txt", contentType: "text/plain" });
|
form.append("file", payload, { filename: "time.txt", contentType: "text/plain" });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// Upload file
|
||||||
const response = await got.post(`https://${process.env.PORTAL_DOMAIN}/skynet/skyfile`, {
|
const response = await got.post(`https://${process.env.PORTAL_DOMAIN}/skynet/skyfile`, {
|
||||||
body: form,
|
body: form,
|
||||||
headers: { cookie: authCookie },
|
headers: { cookie: authCookie },
|
||||||
|
@ -53,6 +54,18 @@ async function uploadCheck(done) {
|
||||||
data.statusCode = response.statusCode;
|
data.statusCode = response.statusCode;
|
||||||
data.up = true;
|
data.up = true;
|
||||||
data.ip = response.ip;
|
data.ip = response.ip;
|
||||||
|
|
||||||
|
// Check file health
|
||||||
|
const responseContent = getResponseContent(response);
|
||||||
|
const skylink = responseContent.skylink;
|
||||||
|
try {
|
||||||
|
await skylinkHealthCheck(skylink, 30, authCookie);
|
||||||
|
} catch (error) {
|
||||||
|
data.up = false;
|
||||||
|
data.statusCode = error.response?.statusCode || error.statusCode || error.status;
|
||||||
|
data.errorMessage = error.message || error;
|
||||||
|
data.errorResponseContent = getResponseContent(error.response) || error;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
data.statusCode = error.response?.statusCode || error.statusCode || error.status;
|
data.statusCode = error.response?.statusCode || error.statusCode || error.status;
|
||||||
data.errorMessage = error.message;
|
data.errorMessage = error.message;
|
||||||
|
@ -63,6 +76,25 @@ async function uploadCheck(done) {
|
||||||
done({ name: "upload_file", time: calculateElapsedTime(time), ...data });
|
done({ name: "upload_file", time: calculateElapsedTime(time), ...data });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// skylinkHealthCheck checks if the skylink has reached full redundancy
|
||||||
|
async function skylinkHealthCheck(skylink, numRetries, authCookie) {
|
||||||
|
try {
|
||||||
|
const response = await got(`https://${process.env.PORTAL_DOMAIN}/skynet/health/skylink/${skylink}`, {
|
||||||
|
headers: { cookie: authCookie },
|
||||||
|
});
|
||||||
|
const healthData = getResponseContent(response);
|
||||||
|
if (healthData.basesectorredundancy !== 10 && numRetries > 0) {
|
||||||
|
return skylinkHealthCheck(skylink, numRetries - 1);
|
||||||
|
}
|
||||||
|
if (healthData.basesectorredundancy !== 10 && numRetries === 0) {
|
||||||
|
throw "Skylink did not reach full redundancy";
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// websiteCheck checks whether the main website is working
|
// websiteCheck checks whether the main website is working
|
||||||
async function websiteCheck(done) {
|
async function websiteCheck(done) {
|
||||||
return done(await genericAccessCheck("website", `https://${process.env.PORTAL_DOMAIN}`));
|
return done(await genericAccessCheck("website", `https://${process.env.PORTAL_DOMAIN}`));
|
||||||
|
|
Reference in New Issue