Improve timeout handling in esplora api health monitoring & logs
This commit is contained in:
parent
b9d46003f8
commit
75578ac9fa
@ -1,5 +1,5 @@
|
|||||||
import config from '../../config';
|
import config from '../../config';
|
||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse, isAxiosError } from 'axios';
|
||||||
import http from 'http';
|
import http from 'http';
|
||||||
import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory';
|
import { AbstractBitcoinApi } from './bitcoin-api-abstract-factory';
|
||||||
import { IEsploraApi } from './esplora-api.interface';
|
import { IEsploraApi } from './esplora-api.interface';
|
||||||
@ -10,6 +10,7 @@ interface FailoverHost {
|
|||||||
host: string,
|
host: string,
|
||||||
rtts: number[],
|
rtts: number[],
|
||||||
rtt: number,
|
rtt: number,
|
||||||
|
timedOut?: boolean,
|
||||||
failures: number,
|
failures: number,
|
||||||
latestHeight?: number,
|
latestHeight?: number,
|
||||||
socket?: boolean,
|
socket?: boolean,
|
||||||
@ -108,11 +109,17 @@ class FailoverRouter {
|
|||||||
host.rtts = [];
|
host.rtts = [];
|
||||||
host.rtt = Infinity;
|
host.rtt = Infinity;
|
||||||
}
|
}
|
||||||
|
host.timedOut = false;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
host.outOfSync = true;
|
host.outOfSync = true;
|
||||||
host.unreachable = true;
|
host.unreachable = true;
|
||||||
host.rtts = [];
|
host.rtts = [];
|
||||||
host.rtt = Infinity;
|
host.rtt = Infinity;
|
||||||
|
if (isAxiosError(e) && (e.code === 'ECONNABORTED' || e.code === 'ETIMEDOUT')) {
|
||||||
|
host.timedOut = true;
|
||||||
|
} else {
|
||||||
|
host.timedOut = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
host.checked = true;
|
host.checked = true;
|
||||||
|
|
||||||
@ -143,7 +150,7 @@ class FailoverRouter {
|
|||||||
|
|
||||||
private formatRanking(index: number, host: FailoverHost, active: FailoverHost, maxHeight: number): string {
|
private formatRanking(index: number, host: FailoverHost, active: FailoverHost, maxHeight: number): string {
|
||||||
const heightStatus = !host.checked ? '⏳' : (host.outOfSync ? '🚫' : (host.latestHeight && host.latestHeight < maxHeight ? '🟧' : '✅'));
|
const heightStatus = !host.checked ? '⏳' : (host.outOfSync ? '🚫' : (host.latestHeight && host.latestHeight < maxHeight ? '🟧' : '✅'));
|
||||||
return `${host === active ? '⭐️' : ' '} ${host.rtt < Infinity ? Math.round(host.rtt).toString().padStart(5, ' ') + 'ms' : ' - '} ${!host.checked ? '⏳' : (host.unreachable ? '🔥' : '✅')} | block: ${host.latestHeight || '??????'} ${heightStatus} | ${host.host} ${host === active ? '⭐️' : ' '}`;
|
return `${host === active ? '⭐️' : ' '} ${host.rtt < Infinity ? Math.round(host.rtt).toString().padStart(5, ' ') + 'ms' : (host.timedOut ? ' ⌛️💥 ' : ' - ')} ${!host.checked ? '⏳' : (host.unreachable ? '🔥' : '✅')} | block: ${host.latestHeight || '??????'} ${heightStatus} | ${host.host} ${host === active ? '⭐️' : ' '}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateFallback(): FailoverHost[] {
|
private updateFallback(): FailoverHost[] {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user