Skip to content

Commit

Permalink
Merge pull request #184 from Cerebellum-Network/fix/health-error-repo…
Browse files Browse the repository at this point in the history
…rting

replace raw error with parsed response
  • Loading branch information
Raid5594 authored Jan 5, 2024
2 parents b61100e + 2f03649 commit 517a077
Showing 1 changed file with 36 additions and 17 deletions.
53 changes: 36 additions & 17 deletions api/src/services/healthService.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,20 +146,25 @@ async function checkBlockchainBlocksFinalization(req, res, next) {
let healthErrors = [];
await Promise.all(
networks.map(async network => {
const [best, finalized] = await Promise.all([
cereNetworkService.getFinalizedBlock(network),
cereNetworkService.getBestBlock(network)
]);
const bestBlockNumberDiff = best - finalized;
if (bestBlockNumberDiff > cereConfig.bestBlockNumberDiff) {
healthErrors.push(`${network} network best block finalization difference number ${bestBlockNumberDiff} below the ${cereConfig.bestBlockNumberDiff} threshold`);
try {
const [best, finalized] = await Promise.all([
cereNetworkService.getFinalizedBlock(network),
cereNetworkService.getBestBlock(network)
]);
const bestBlockNumberDiff = best - finalized;
if (bestBlockNumberDiff > cereConfig.bestBlockNumberDiff) {
healthErrors.push(`${network} network best block finalization difference number ${bestBlockNumberDiff} below the ${cereConfig.bestBlockNumberDiff} threshold`);
}
} catch (error) {
console.error(error);
healthErrors.push(`Unable to connect to ${network} network`);
}
})
);

res.status(200).json(
healthErrors.length
? { msg: 'Health check failed', errors: healthErrors }
? { msg: 'Health check failed', errors: healthErrors }
: { msg: `${networks.join(',')} best block finalization difference number is ok`}
);
} catch (err) {
Expand All @@ -184,14 +189,19 @@ async function checkBlockchainBlocksProducing(req, res, next) {
let healthErrors = [];
await Promise.all(
networks.map(async network => {
const { block } = await cereNetworkService.getLatestBlock(network);
const [previousTime, lastTime] = await Promise.all([
cereNetworkService.getBlockTime(network, block.header.number - 1),
cereNetworkService.getBlockTime(network, block.header.number),
]);
const timeDiff = lastTime - previousTime;
if (timeDiff > cereConfig.blockTimeDiffMs) {
healthErrors.push(`${network} network block production time difference ${timeDiff}ms below the ${cereConfig.blockTimeDiffMs}ms threshold`);
try {
const { block } = await cereNetworkService.getLatestBlock(network);
const [previousTime, lastTime] = await Promise.all([
cereNetworkService.getBlockTime(network, block.header.number - 1),
cereNetworkService.getBlockTime(network, block.header.number),
]);
const timeDiff = lastTime - previousTime;
if (timeDiff > cereConfig.blockTimeDiffMs) {
healthErrors.push(`${network} network block production time difference ${timeDiff}ms below the ${cereConfig.blockTimeDiffMs}ms threshold`);
}
} catch (error) {
console.error(error);
healthErrors.push(`Unable to connect to ${network} network`);
}
})
);
Expand Down Expand Up @@ -278,4 +288,13 @@ module.exports = {
checkBlockchainHealth,
checkBlockchainBlocksFinalization,
checkBlockchainBlocksProducing,
};
};

"pallet-chainbridge/try-runtime",
"pallet-ddc-clusters/try-runtime",
"pallet-ddc-customers/try-runtime",
"pallet-ddc-nodes/try-runtime",
"pallet-ddc-payouts/try-runtime",
"pallet-ddc-staking/try-runtime",
"pallet-erc20/try-runtime",
"pallet-erc721/try-runtime",

0 comments on commit 517a077

Please sign in to comment.