Merge pull request #286 from drift-labs/master

staging
This commit is contained in:
wphan
2024-11-27 11:47:29 -08:00
committed by GitHub
6 changed files with 20 additions and 19 deletions

View File

@@ -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 * 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`. * 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 * A grace period is also used to report unhealthy only if we have been unhealthy beyond the grace period.
* amount of time. This prevents reporting unhealthy even if we are just in the middle of a
* bulk account load.
*/ */
const handleHealthCheck = ( const handleHealthCheck = (
healthCheckGracePeriod: number, healthCheckGracePeriod: number,
@@ -191,6 +189,7 @@ const handleHealthCheck = (
) => { ) => {
return async (_req, res, _next) => { return async (_req, res, _next) => {
if (healthStatus === HEALTH_STATUS.Restart) { if (healthStatus === HEALTH_STATUS.Restart) {
logger.error(`Health status: Restart`);
res.writeHead(500); res.writeHead(500);
res.end(`NOK`); res.end(`NOK`);
return; return;
@@ -227,14 +226,14 @@ const handleHealthCheck = (
lastHealthCheckPerformed = Date.now(); lastHealthCheckPerformed = Date.now();
if (!lastHealthCheckState && !inGracePeriod) { if (!lastHealthCheckState && !inGracePeriod) {
healthStatus = HEALTH_STATUS.UnhealthySlotSubscriber; setHealthStatus(HEALTH_STATUS.UnhealthySlotSubscriber);
res.writeHead(500); res.writeHead(500);
res.end(`NOK`); res.end(`NOK`);
return; return;
} }
healthStatus = HEALTH_STATUS.Ok; setHealthStatus(HEALTH_STATUS.Ok);
res.writeHead(200); res.writeHead(200);
res.end('OK'); res.end('OK');
}; };

View File

@@ -221,10 +221,9 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
!skipSlotCheck && !skipSlotCheck &&
!isPerpMarketAndPrelaunchMarket !isPerpMarketAndPrelaunchMarket
) { ) {
console.log(`Unhealthy process due to slot diffs for market ${marketName}: console.log(
dlobProvider slot: ${slot} `Unhealthy process due to slot diffs for market ${marketName}. dlobProviderSlot: ${slot}, oracleSlot: ${l2Formatted['oracleData']['slot']}`
oracle slot: ${l2Formatted['oracleData']['slot']} );
`);
setHealthStatus(HEALTH_STATUS.Restart); setHealthStatus(HEALTH_STATUS.Restart);
} }
@@ -239,16 +238,15 @@ export class DLOBSubscriberIO extends DLOBSubscriber {
Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD && Date.now() - lastMarketSlotAndTime.ts > MAKRET_STALENESS_THRESHOLD &&
!skipSlotCheck !skipSlotCheck
) { ) {
console.log(`Unhealthy process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms: logger.warn(
dlobProvider slot: ${slot} `Unhealthy process due to same slot for market ${marketName} after > ${MAKRET_STALENESS_THRESHOLD}ms. dlobProviderSlot: ${slot}, marketSlot: ${l2Formatted['marketSlot']}`
market slot: ${l2Formatted['marketSlot']} );
`);
setHealthStatus(HEALTH_STATUS.Restart); setHealthStatus(HEALTH_STATUS.Restart);
} else if ( } else if (
lastMarketSlotAndTime && lastMarketSlotAndTime &&
l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot l2Formatted['marketSlot'] !== lastMarketSlotAndTime.slot
) { ) {
console.log( logger.warn(
`Updating market slot for ${marketArgs.marketName} with slot ${l2Formatted['marketSlot']}` `Updating market slot for ${marketArgs.marketName} with slot ${l2Formatted['marketSlot']}`
); );
this.lastMarketSlotMap this.lastMarketSlotMap

View File

@@ -69,7 +69,9 @@ const clients = process.env.REDIS_CLIENT?.trim()
clients?.forEach((client) => envClients.push(RedisClientPrefix[client])); 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); console.log('Redis Clients:', REDIS_CLIENTS);
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;

View File

@@ -455,10 +455,10 @@ const main = async () => {
app.get( app.get(
'/health', '/health',
handleHealthCheck(2 * WS_FALLBACK_FETCH_INTERVAL, dlobProvider) handleHealthCheck(WS_FALLBACK_FETCH_INTERVAL, dlobProvider)
); );
app.get('/startup', handleStartup); 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); const server = app.listen(8080);
// Default keepalive is 5s, since the AWS ALB timeout is 60 seconds, clients // Default keepalive is 5s, since the AWS ALB timeout is 60 seconds, clients

View File

@@ -45,7 +45,9 @@ const clients = process.env.REDIS_CLIENT?.trim()
clients?.forEach((client) => envClients.push(RedisClientPrefix[client])); 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); console.log('Redis Clients:', REDIS_CLIENTS);
const driftEnv = (process.env.ENV || 'devnet') as DriftEnv; const driftEnv = (process.env.ENV || 'devnet') as DriftEnv;