fix circular references

This commit is contained in:
Nour Alharithi
2023-12-14 16:04:24 -08:00
parent f506950dd6
commit 1760d6f0c4
3 changed files with 36 additions and 20 deletions

View File

@@ -7,13 +7,6 @@ import {
MeterProvider,
View,
} from '@opentelemetry/sdk-metrics-base';
import {
ORDERBOOK_UPDATE_INTERVAL,
commitHash,
driftEnv,
endpoint,
wsEndpoint,
} from '..';
import { SlotSource } from '@drift-labs/sdk';
/**
@@ -93,15 +86,6 @@ const runtimeSpecsGauge = meter.createObservableGauge(
description: 'Runtime sepcification of this program',
}
);
const bootTimeMs = Date.now();
runtimeSpecsGauge.addCallback((obs) => {
obs.observe(bootTimeMs, {
commit: commitHash,
driftEnv,
rpcEndpoint: endpoint,
wsEndpoint: wsEndpoint,
});
});
let healthStatus: HEALTH_STATUS = HEALTH_STATUS.Ok;
const healthStatusGauge = meter.createObservableGauge(
@@ -171,7 +155,7 @@ const responseStatusCounter = meter.createCounter(
}
);
const healthCheckInterval = 2 * (ORDERBOOK_UPDATE_INTERVAL ?? 1000); // ORDERBOOK_UPDATE_INTERVAL is NaN here for some reason ... hardcode to 1000.
const healthCheckInterval = 2000;
let lastHealthCheckSlot = -1;
let lastHealthCheckState = true; // true = healthy, false = unhealthy
let lastHealthCheckPerformed = Date.now() - healthCheckInterval;
@@ -245,4 +229,5 @@ export {
setLastReceivedWsMsgTs,
accountUpdatesCounter,
cacheHitCounter,
runtimeSpecsGauge,
};

View File

@@ -39,6 +39,7 @@ import {
accountUpdatesCounter,
cacheHitCounter,
setLastReceivedWsMsgTs,
runtimeSpecsGauge,
} from './core/metrics';
import { handleResponseTime } from './core/middleware';
import {
@@ -125,6 +126,17 @@ app.use((req, _res, next) => {
next();
});
// Metrics defined here
const bootTimeMs = Date.now();
runtimeSpecsGauge.addCallback((obs) => {
obs.observe(bootTimeMs, {
commit: commitHash,
driftEnv,
rpcEndpoint: endpoint,
wsEndpoint: wsEndpoint,
});
});
app.use(errorHandler);
const server = http.createServer(app);

View File

@@ -10,7 +10,11 @@ import { Commitment, Connection } from '@solana/web3.js';
import { logger, setLogLevel } from './utils/logger';
import * as http from 'http';
import { handleHealthCheck, cacheHitCounter } from './core/metrics';
import {
handleHealthCheck,
cacheHitCounter,
runtimeSpecsGauge,
} from './core/metrics';
import { handleResponseTime } from './core/middleware';
import { errorHandler, normalizeBatchQueryParams, sleep } from './utils/utils';
import { RedisClient } from './utils/redisClient';
@@ -21,6 +25,7 @@ import {
SlotSubscriber,
SpotMarkets,
isVariant,
initialize,
} from '@drift-labs/sdk';
require('dotenv').config();
@@ -72,6 +77,17 @@ app.use(
})
);
// Metrics defined here
const bootTimeMs = Date.now();
runtimeSpecsGauge.addCallback((obs) => {
obs.observe(bootTimeMs, {
commit: commitHash,
driftEnv,
rpcEndpoint: endpoint,
wsEndpoint: wsEndpoint,
});
});
// strip off /dlob, if the request comes from exchange history server LB
app.use((req, _res, next) => {
if (req.url.startsWith('/dlob')) {
@@ -183,7 +199,7 @@ const main = async () => {
if (redisL2) {
slotDiff =
slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot);
if (slotDiff < 20) {
if (slotDiff < SLOT_STALENESS_TOLERANCE) {
l2Formatted = redisL2;
}
}
@@ -211,7 +227,7 @@ const main = async () => {
if (redisL2) {
slotDiff =
slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot);
if (slotDiff < 20) {
if (slotDiff < SLOT_STALENESS_TOLERANCE) {
l2Formatted = redisL2;
}
}
@@ -228,6 +244,9 @@ const main = async () => {
if (slotDiff) {
res.writeHead(500);
res.end(`Slot too stale : ${slotDiff}`);
} else {
res.writeHead(400);
res.end(`Bad Request: no cached L2 found`);
}
}
} catch (err) {