fix circular references
This commit is contained in:
@@ -7,13 +7,6 @@ import {
|
|||||||
MeterProvider,
|
MeterProvider,
|
||||||
View,
|
View,
|
||||||
} from '@opentelemetry/sdk-metrics-base';
|
} from '@opentelemetry/sdk-metrics-base';
|
||||||
import {
|
|
||||||
ORDERBOOK_UPDATE_INTERVAL,
|
|
||||||
commitHash,
|
|
||||||
driftEnv,
|
|
||||||
endpoint,
|
|
||||||
wsEndpoint,
|
|
||||||
} from '..';
|
|
||||||
import { SlotSource } from '@drift-labs/sdk';
|
import { SlotSource } from '@drift-labs/sdk';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -93,15 +86,6 @@ const runtimeSpecsGauge = meter.createObservableGauge(
|
|||||||
description: 'Runtime sepcification of this program',
|
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;
|
let healthStatus: HEALTH_STATUS = HEALTH_STATUS.Ok;
|
||||||
const healthStatusGauge = meter.createObservableGauge(
|
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 lastHealthCheckSlot = -1;
|
||||||
let lastHealthCheckState = true; // true = healthy, false = unhealthy
|
let lastHealthCheckState = true; // true = healthy, false = unhealthy
|
||||||
let lastHealthCheckPerformed = Date.now() - healthCheckInterval;
|
let lastHealthCheckPerformed = Date.now() - healthCheckInterval;
|
||||||
@@ -245,4 +229,5 @@ export {
|
|||||||
setLastReceivedWsMsgTs,
|
setLastReceivedWsMsgTs,
|
||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
cacheHitCounter,
|
cacheHitCounter,
|
||||||
|
runtimeSpecsGauge,
|
||||||
};
|
};
|
||||||
|
|||||||
12
src/index.ts
12
src/index.ts
@@ -39,6 +39,7 @@ import {
|
|||||||
accountUpdatesCounter,
|
accountUpdatesCounter,
|
||||||
cacheHitCounter,
|
cacheHitCounter,
|
||||||
setLastReceivedWsMsgTs,
|
setLastReceivedWsMsgTs,
|
||||||
|
runtimeSpecsGauge,
|
||||||
} from './core/metrics';
|
} from './core/metrics';
|
||||||
import { handleResponseTime } from './core/middleware';
|
import { handleResponseTime } from './core/middleware';
|
||||||
import {
|
import {
|
||||||
@@ -125,6 +126,17 @@ app.use((req, _res, next) => {
|
|||||||
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);
|
app.use(errorHandler);
|
||||||
const server = http.createServer(app);
|
const server = http.createServer(app);
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,11 @@ import { Commitment, Connection } from '@solana/web3.js';
|
|||||||
import { logger, setLogLevel } from './utils/logger';
|
import { logger, setLogLevel } from './utils/logger';
|
||||||
|
|
||||||
import * as http from 'http';
|
import * as http from 'http';
|
||||||
import { handleHealthCheck, cacheHitCounter } from './core/metrics';
|
import {
|
||||||
|
handleHealthCheck,
|
||||||
|
cacheHitCounter,
|
||||||
|
runtimeSpecsGauge,
|
||||||
|
} from './core/metrics';
|
||||||
import { handleResponseTime } from './core/middleware';
|
import { handleResponseTime } from './core/middleware';
|
||||||
import { errorHandler, normalizeBatchQueryParams, sleep } from './utils/utils';
|
import { errorHandler, normalizeBatchQueryParams, sleep } from './utils/utils';
|
||||||
import { RedisClient } from './utils/redisClient';
|
import { RedisClient } from './utils/redisClient';
|
||||||
@@ -21,6 +25,7 @@ import {
|
|||||||
SlotSubscriber,
|
SlotSubscriber,
|
||||||
SpotMarkets,
|
SpotMarkets,
|
||||||
isVariant,
|
isVariant,
|
||||||
|
initialize,
|
||||||
} from '@drift-labs/sdk';
|
} from '@drift-labs/sdk';
|
||||||
|
|
||||||
require('dotenv').config();
|
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
|
// strip off /dlob, if the request comes from exchange history server LB
|
||||||
app.use((req, _res, next) => {
|
app.use((req, _res, next) => {
|
||||||
if (req.url.startsWith('/dlob')) {
|
if (req.url.startsWith('/dlob')) {
|
||||||
@@ -183,7 +199,7 @@ const main = async () => {
|
|||||||
if (redisL2) {
|
if (redisL2) {
|
||||||
slotDiff =
|
slotDiff =
|
||||||
slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot);
|
slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot);
|
||||||
if (slotDiff < 20) {
|
if (slotDiff < SLOT_STALENESS_TOLERANCE) {
|
||||||
l2Formatted = redisL2;
|
l2Formatted = redisL2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -211,7 +227,7 @@ const main = async () => {
|
|||||||
if (redisL2) {
|
if (redisL2) {
|
||||||
slotDiff =
|
slotDiff =
|
||||||
slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot);
|
slotSubscriber.getSlot() - parseInt(JSON.parse(redisL2).slot);
|
||||||
if (slotDiff < 20) {
|
if (slotDiff < SLOT_STALENESS_TOLERANCE) {
|
||||||
l2Formatted = redisL2;
|
l2Formatted = redisL2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,6 +244,9 @@ const main = async () => {
|
|||||||
if (slotDiff) {
|
if (slotDiff) {
|
||||||
res.writeHead(500);
|
res.writeHead(500);
|
||||||
res.end(`Slot too stale : ${slotDiff}`);
|
res.end(`Slot too stale : ${slotDiff}`);
|
||||||
|
} else {
|
||||||
|
res.writeHead(400);
|
||||||
|
res.end(`Bad Request: no cached L2 found`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user