8 consClient: {fuzzyPodName: string, portNo: number} 20const checkEthSyncLags = async ({ethStatusCfgs}: {ethStatusCfgs: EthStatusCfg[]}): Promise<SyncLagResult[]> => { 21 return await allPromCalls(ethStatusCfgs, async (cfg): Promise<SyncLagResult> => { 23 if (offlineReason) return {cfg, offline: offlineReason} 26 podHealth = await getPodHealthInfo({cluster_name: cfg.cluster_name, fuzzyPodName: cfg.consClient.fuzzyPodName}) 27 if (!podHealth.isRunning || !podHealth.podName) return {cfg, error: `${cfg.consClient.fuzzyPodName} ${podHealth.status}`} 29 cluster_name: cfg.cluster_name, podName: podHealth.podName, portNo: cfg.consClient.portNo, 30 checkerFn: getConsensusSyncStatus, 32 return {cfg, ...status.syncStatus} 34 return {cfg, error: fmtPodDownErr({podHealth, errMsg: (err as Error).message})} 39const formatLag = (r: SyncLagResult) => { 40 const name = `${r.cfg.cluster_name} ${r.cfg.consClient.fuzzyPodName}` 41 if (r.offline) return `${name}: ${chalkRed(`offline (${r.offline})`)}` 42 if (r.error) return `${name}: ${chalkRed(r.error)}` 43 if (r.isSynced) return `${name}: ${chalkGreen('synced')}` 44 return `${name}: ${chalkRed(`-${r.syncDistance} slots`)}` 47export const mkEthSyncMonitorJob = ({ethStatusCfgs, maxLagSlots = 64, intervalSec = 60 * 30}: { 48 ethStatusCfgs: EthStatusCfg[], maxLagSlots?: number, intervalSec?: number, 50 name: 'ethSyncMonitor', 53 const results = await checkEthSyncLags({ethStatusCfgs}) 54 const behind = results.filter((r: SyncLagResult) => r.syncDistance != null && r.syncDistance > maxLagSlots) 55 const down = results.filter((r: SyncLagResult) => r.error) 56 if (behind.length || down.length) { 57 throw new Error(`eth sync: ${[...down, ...behind].map(formatLag).join(', ')}`) 62export const mkSyncLagCheck = ({maxLagSlots = 64}: {maxLagSlots?: number} = {}) => { 63 return async ({ethStatusCfgs}: {ethStatusCfgs?: EthStatusCfg[]} = {}) => { 64 if (!ethStatusCfgs?.length) return 65 const results = await checkEthSyncLags({ethStatusCfgs}) 66 const hasIssues = results.some((r) => r.error || (r.syncDistance != null && r.syncDistance > maxLagSlots)) 67 const summary = results.map(formatLag).join('\n ')