diff --git a/drift-common b/drift-common index c251089..79d7d2f 160000 --- a/drift-common +++ b/drift-common @@ -1 +1 @@ -Subproject commit c251089a1a4f10ad21814358290dab2541a6eb66 +Subproject commit 79d7d2f2fb10b4c211d1c2ac58484a43cf54404b diff --git a/src/core/metrics.ts b/src/core/metrics.ts index 3e1acb8..bd6b883 100644 --- a/src/core/metrics.ts +++ b/src/core/metrics.ts @@ -181,9 +181,7 @@ export const setHealthStatus = (status: HEALTH_STATUS): void => { * We may be hit by multiple sources performing health checks on us, so this middleware will latch * to its health state and only update every `healthCheckInterval`. * - * A grace period is also used to only report unhealthy if we have been unhealthy for a certain - * amount of time. This prevents reporting unhealthy even if we are just in the middle of a - * bulk account load. + * A grace period is also used to report unhealthy only if we have been unhealthy beyond the grace period. */ const handleHealthCheck = ( healthCheckGracePeriod: number, @@ -191,6 +189,7 @@ const handleHealthCheck = ( ) => { return async (_req, res, _next) => { if (healthStatus === HEALTH_STATUS.Restart) { + logger.error(`Health status: Restart`); res.writeHead(500); res.end(`NOK`); return; @@ -227,14 +226,14 @@ const handleHealthCheck = ( lastHealthCheckPerformed = Date.now(); if (!lastHealthCheckState && !inGracePeriod) { - healthStatus = HEALTH_STATUS.UnhealthySlotSubscriber; + setHealthStatus(HEALTH_STATUS.UnhealthySlotSubscriber); res.writeHead(500); res.end(`NOK`); return; } - healthStatus = HEALTH_STATUS.Ok; + setHealthStatus(HEALTH_STATUS.Ok); res.writeHead(200); res.end('OK'); }; diff --git a/src/dlob-subscriber/DLOBSubscriberIO.ts b/src/dlob-subscriber/DLOBSubscriberIO.ts index 7d8a4aa..0a603f9 100644 --- a/src/dlob-subscriber/DLOBSubscriberIO.ts +++ b/src/dlob-subscriber/DLOBSubscriberIO.ts @@ -221,10 +221,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber { !skipSlotCheck && !isPerpMarketAndPrelaunchMarket ) { - console.log(`Unhealthy process due to slot diffs for market ${marketName}: - dlobProvider slot: ${slot} - oracle slot: ${l2Formatted['oracleData']['slot']} - `); + console.log( + `Unhealthy process due to slot diffs for market ${marketName}. dlobProviderSlot: ${slot}, oracleSlot: ${l2Formatted['oracleData']['slot']}` + ); setHealthStatus(HEALTH_STATUS.Restart); } @@ -239,16 +238,15 @@ export class DLOBSubscriberIO extends DLOBSubscriber { Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD && !skipSlotCheck ) { - console.log(`Unhealthy process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms: - dlobProvider slot: ${slot} - market slot: ${l2Formatted['marketSlot']} - `); + logger.warn( + `Unhealthy process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms. dlobProviderSlot: ${slot}, marketSlot: ${l2Formatted['marketSlot']}` + ); setHealthStatus(HEALTH_STATUS.Restart); } else if ( lastMarketSlotAndTime && l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot ) { - console.log( + logger.warn( `Updating market slot for ${marketArgs.marketName} with slot ${l2Formatted['marketSlot']}` ); this.lastMarketSlotMap diff --git a/src/index.ts b/src/index.ts index 4214c4b..950daef 100644 --- a/src/index.ts +++ b/src/index.ts @@ -69,7 +69,9 @@ const clients = process.env.REDIS_CLIENT?.trim() clients?.forEach((client) => envClients.push(RedisClientPrefix[client])); -const REDIS_CLIENTS = envClients.length ? envClients : [RedisClientPrefix.DLOB, RedisClientPrefix.DLOB_HELIUS]; +const REDIS_CLIENTS = envClients.length + ? envClients + : [RedisClientPrefix.DLOB, RedisClientPrefix.DLOB_HELIUS]; console.log('Redis Clients:', REDIS_CLIENTS); const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; diff --git a/src/publishers/dlobPublisher.ts b/src/publishers/dlobPublisher.ts index b79af54..c5f5037 100644 --- a/src/publishers/dlobPublisher.ts +++ b/src/publishers/dlobPublisher.ts @@ -455,10 +455,10 @@ const main = async () => { app.get( '/health', - handleHealthCheck(2 * WS_FALLBACK_FETCH_INTERVAL, dlobProvider) + handleHealthCheck(WS_FALLBACK_FETCH_INTERVAL, dlobProvider) ); app.get('/startup', handleStartup); - app.get('/', handleHealthCheck(2 * WS_FALLBACK_FETCH_INTERVAL, dlobProvider)); + app.get('/', handleHealthCheck(WS_FALLBACK_FETCH_INTERVAL, dlobProvider)); const server = app.listen(8080); // Default keepalive is 5s, since the AWS ALB timeout is 60 seconds, clients diff --git a/src/serverLite.ts b/src/serverLite.ts index d2e4024..f79044c 100644 --- a/src/serverLite.ts +++ b/src/serverLite.ts @@ -45,7 +45,9 @@ const clients = process.env.REDIS_CLIENT?.trim() clients?.forEach((client) => envClients.push(RedisClientPrefix[client])); -const REDIS_CLIENTS = envClients.length ? envClients : [RedisClientPrefix.DLOB, RedisClientPrefix.DLOB_HELIUS]; +const REDIS_CLIENTS = envClients.length + ? envClients + : [RedisClientPrefix.DLOB, RedisClientPrefix.DLOB_HELIUS]; console.log('Redis Clients:', REDIS_CLIENTS); const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;