@@ -24,30 +24,41 @@ async function checkNativeRpcHealth(): Promise<string | undefined> {
2424async function checkIndexerHealth (
2525 indexer : BlockchainIndexerHelper
2626) : Promise < string | undefined > {
27- try {
28- const ok = await indexer . getHealth ( )
29- if ( ! ok ) {
30- return 'health check failed'
27+ const msgs : string [ ] = [ ]
28+ for ( const [ i , client ] of indexer . verifier . clients . entries ( ) ) {
29+ const url = indexer . indexerWebServerUrls [ i ]
30+ try {
31+ const healthy = await indexer . getHealth ( client )
32+ if ( ! healthy ) {
33+ msgs . push ( `client ${ url } is unhealthy` )
34+ }
35+ } catch ( e : any ) {
36+ msgs . push ( `client ${ url } connection errored with ${ String ( e ?. message ) } ` )
3137 }
32- } catch ( e : any ) {
33- return String ( e ?. message )
38+ }
39+ if ( msgs . length > 0 ) {
40+ return msgs . join ( ', ' )
3441 }
3542}
3643
44+
3745async function checkDalHealth (
3846 fdc : FlareDataConnectorClientHelper
3947) : Promise < string | undefined > {
40- try {
41- const healthy = await fdc . getHealth ( )
42- const n = healthy . filter ( h => h ) . length
43- if ( n < fdc . dataAccessLayerClients . length ) {
44- const unhealthy = healthy . map ( ( h , i ) => h ? '' : fdc . dataAccessLayerUrls [ i ] ) . join ( ',' )
45- return `clients ${ unhealthy } are healthy`
46- } else if ( n == 0 ) {
47- return 'no clients available'
48+ const msgs : string [ ] = [ ]
49+ for ( const [ i , client ] of fdc . dataAccessLayerClients . entries ( ) ) {
50+ const url = fdc . dataAccessLayerUrls [ i ]
51+ try {
52+ const healthy = await fdc . getHealth ( client )
53+ if ( ! healthy ) {
54+ msgs . push ( `client ${ url } is unhealthy` )
55+ }
56+ } catch ( e : any ) {
57+ msgs . push ( `client ${ url } connection errored with ${ String ( e ?. message ) } ` )
4858 }
49- } catch ( e : any ) {
50- return String ( e ?. message )
59+ }
60+ if ( msgs . length > 0 ) {
61+ return msgs . join ( ', ' )
5162 }
5263}
5364
@@ -71,17 +82,20 @@ async function serviceHealthcheck(
7182 const errors : [ string , string ] [ ] = [ ]
7283 for ( const c of config . fAssets . values ( ) ) {
7384 const rpcHealth = await checkNativeRpcHealth ( )
74- const indexerHealth = await checkIndexerHealth ( c . blockchainIndexerClient )
75- // @ts -ignore flareDataConnector has the right implementation
76- const dalHealth = await checkDalHealth ( c . flareDataConnector )
77- const walletHealth = await checkUnderlyingWalletHealth ( c . wallet )
7885 if ( rpcHealth != null ) {
7986 errors . push ( [ 'Native RPC' , rpcHealth ] )
80- } else if ( indexerHealth != null ) {
87+ }
88+ const indexerHealth = await checkIndexerHealth ( c . blockchainIndexerClient )
89+ if ( indexerHealth != null ) {
8190 errors . push ( [ 'FDC verifier' , indexerHealth ] )
82- } else if ( dalHealth != null ) {
91+ }
92+ // @ts -ignore flareDataConnector implements FlareDataConnectorClientHelper
93+ const dalHealth = await checkDalHealth ( c . flareDataConnector )
94+ if ( dalHealth != null ) {
8395 errors . push ( [ 'DAL' , dalHealth ] )
84- } else if ( walletHealth != null ) {
96+ }
97+ const walletHealth = await checkUnderlyingWalletHealth ( c . wallet )
98+ if ( walletHealth != null ) {
8599 errors . push ( [ 'Underlying RPC' , walletHealth ] )
86100 }
87101 }
0 commit comments