Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: more verbose healthcheck error log #246

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- more verbose healthcheck error log

### Fixed

- crash while fetching affected addresses for a block undergoing a rollback
Expand Down
29 changes: 15 additions & 14 deletions src/utils/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@ import { ALL_SEED } from '../scripts/performance/constants.js';
import { WebsocketClient } from './websocket-client.js';

export const healthCheck = async (url: string) => {
// Public key of the account that will be used to perform health check
// Account is already used on every network (mainnet, preprod, preview)
// One of the account testnet address: addr_test1qrx7xj9qf0j8cqty3eyntpentpgkuhzt9n7g06fa7l29sucle6svh9nacvm632nmcy6fnw9sq85tqkvhagfrhkj9tf6sa3ccwq
const ACCOUNT_PUB_KEY =
'140791584001446365f169c82241c7c214475000180dab39fa0588fc9c3d6d807f9f812d49816844b52e319857aa75961724ad1a146701679d02d7168622233d';
const c = new WebsocketClient(url, false);

await c.waitForConnection();

const serverInfo = await c.sendAndWait('GET_SERVER_INFO');

if (serverInfo.name !== 'Cardano') {
console.info('[HealthCheck] Received GET_SERVER_INFO', serverInfo);
c.close();
throw new Error('[HealthCheck] HealthCheck failed: serverInfo');
throw new Error('[HealthCheck] HealthCheck failed: GET_SERVER_INFO');
}

const xpub = ALL_SEED[1];
Expand All @@ -21,13 +27,10 @@ export const healthCheck = async (url: string) => {
pageSize: 25,
});

if (
basicAccountInfo.descriptor !==
'140791584001446365f169c82241c7c214475000180dab39fa0588fc9c3d6d807f9f812d49816844b52e319857aa75961724ad1a146701679d02d7168622233d' ||
basicAccountInfo.empty !== false
) {
if (basicAccountInfo.descriptor !== ACCOUNT_PUB_KEY || basicAccountInfo.empty !== false) {
c.close();
throw new Error('[HealthCheck] HealthCheck failed: basicAccountInfo');
console.info('[HealthCheck] Received GET_ACCOUNT_INFO (basic)', basicAccountInfo);
throw new Error('[HealthCheck] HealthCheck failed: GET_ACCOUNT_INFO (basic)');
}

const txsAccountInfo = await c.sendAndWait('GET_ACCOUNT_INFO', {
Expand All @@ -36,22 +39,20 @@ export const healthCheck = async (url: string) => {
pageSize: 25,
});

if (
txsAccountInfo.descriptor !==
'140791584001446365f169c82241c7c214475000180dab39fa0588fc9c3d6d807f9f812d49816844b52e319857aa75961724ad1a146701679d02d7168622233d' ||
txsAccountInfo.empty !== false
) {
if (txsAccountInfo.descriptor !== ACCOUNT_PUB_KEY || txsAccountInfo.empty !== false) {
console.info('[HealthCheck] Received GET_ACCOUNT_INFO (txs)', txsAccountInfo);
c.close();
throw new Error('[HealthCheck] HealthCheck failed: txsAccountInfo');
throw new Error('[HealthCheck] HealthCheck failed: GET_ACCOUNT_INFO (txs)');
}

const accountUtxo = await c.sendAndWait('GET_ACCOUNT_UTXO', {
descriptor: xpub,
});

if (!Array.isArray(accountUtxo)) {
console.info('[HealthCheck] Received GET_ACCOUNT_UTXO', accountUtxo);
c.close();
throw new Error('[HealthCheck] HealthCheck failed: accountUtxo');
throw new Error('[HealthCheck] HealthCheck failed: GET_ACCOUNT_UTXO');
}

c.close();
Expand Down
8 changes: 7 additions & 1 deletion src/utils/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ export class MetricsCollector {

private _collect = async () => {
logger.info('[HealthCheck] Running health check');
const t0 = Date.now();

try {
await healthCheck(`ws://localhost:${port}`);
this.healthy = true;
Expand All @@ -51,7 +53,11 @@ export class MetricsCollector {
this.healthCheckFailingSince = Date.now();
}
}
logger.info('[HealthCheck] Health check done');
const t1 = Date.now();

const durationSeconds = Math.floor(((t1 - t0) / 1000) * 100) / 100; // 2 decimals

logger.info(`[HealthCheck] Health check done in ${durationSeconds} seconds.`);
return {
is_healthy: this.healthy ? 1 : 0,
websocket_link_clients: this.wss.clients.size,
Expand Down
Loading