From 032121de27eff0bea9e472f3f0567621ddf63f9c Mon Sep 17 00:00:00 2001 From: wphan Date: Sat, 2 Dec 2023 14:13:02 -0800 Subject: [PATCH] health check logs --- src/core/metrics.ts | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/core/metrics.ts b/src/core/metrics.ts index 05b30f5..1bd288c 100644 --- a/src/core/metrics.ts +++ b/src/core/metrics.ts @@ -165,12 +165,16 @@ const handleHealthCheck = ( // healthy if slot has advanced since the last check const lastSlotReceived = slotSource.getSlot(); + const inGracePeriod = + Date.now() - lastTimeHealthy <= healthCheckGracePeriod; lastHealthCheckState = lastSlotReceived > lastHealthCheckSlot; if (!lastHealthCheckState) { logger.error( `Unhealthy: lastSlot: ${lastSlotReceived}, lastHealthCheckSlot: ${lastHealthCheckSlot}, timeSinceLastCheck: ${ Date.now() - lastHealthCheckPerformed - } ms` + } ms, sinceLastTimeHealthy: ${ + Date.now() - lastTimeHealthy + } ms, inGracePeriod: ${inGracePeriod}` ); } else { lastTimeHealthy = Date.now(); @@ -179,10 +183,7 @@ const handleHealthCheck = ( lastHealthCheckSlot = lastSlotReceived; lastHealthCheckPerformed = Date.now(); - if ( - !lastHealthCheckState && - Date.now() - lastTimeHealthy > healthCheckGracePeriod - ) { + if (!lastHealthCheckState && !inGracePeriod) { healthStatus = HEALTH_STATUS.UnhealthySlotSubscriber; res.writeHead(500);