count response codes, remove health checks
This commit is contained in:
35
src/index.ts
35
src/index.ts
@@ -1,7 +1,7 @@
|
|||||||
import { program } from 'commander';
|
import { program } from 'commander';
|
||||||
|
|
||||||
import responseTime = require('response-time');
|
import responseTime = require('response-time');
|
||||||
import express from 'express';
|
import express, { Request, Response } from 'express';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import compression from 'compression';
|
import compression from 'compression';
|
||||||
import morgan from 'morgan';
|
import morgan from 'morgan';
|
||||||
@@ -147,6 +147,7 @@ const createHistogramBuckets = (
|
|||||||
enum METRIC_TYPES {
|
enum METRIC_TYPES {
|
||||||
runtime_specs = 'runtime_specs',
|
runtime_specs = 'runtime_specs',
|
||||||
endpoint_response_times_histogram = 'endpoint_response_times_histogram',
|
endpoint_response_times_histogram = 'endpoint_response_times_histogram',
|
||||||
|
endpoint_response_status = 'endpoint_response_status',
|
||||||
health_status = 'health_status',
|
health_status = 'health_status',
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,6 +221,13 @@ const endpointResponseTimeHistogram = meter.createHistogram(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const responseStatusCounter = meter.createCounter(
|
||||||
|
METRIC_TYPES.endpoint_response_status,
|
||||||
|
{
|
||||||
|
description: 'Count of endpoint responses by status code',
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
const getPhoenixSubscriber = (
|
const getPhoenixSubscriber = (
|
||||||
driftClient: DriftClient,
|
driftClient: DriftClient,
|
||||||
marketConfig: SpotMarketConfig,
|
marketConfig: SpotMarketConfig,
|
||||||
@@ -369,14 +377,21 @@ const main = async () => {
|
|||||||
});
|
});
|
||||||
await dlobSubscriber.subscribe();
|
await dlobSubscriber.subscribe();
|
||||||
|
|
||||||
const handleResponseTime = responseTime((req: Request, _res, time) => {
|
const handleResponseTime = responseTime(
|
||||||
const endpoint = req.url.split('?')[0];
|
(req: Request, res: Response, time: number) => {
|
||||||
|
const endpoint = req.path;
|
||||||
|
|
||||||
const responseTimeMs = time;
|
responseStatusCounter.add(1, {
|
||||||
endpointResponseTimeHistogram.record(responseTimeMs, {
|
endpoint,
|
||||||
endpoint,
|
status: res.statusCode,
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
const responseTimeMs = time;
|
||||||
|
endpointResponseTimeHistogram.record(responseTimeMs, {
|
||||||
|
endpoint,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
MARKET_SUBSCRIBERS = await initializeAllMarketSubscribers(
|
MARKET_SUBSCRIBERS = await initializeAllMarketSubscribers(
|
||||||
driftClient,
|
driftClient,
|
||||||
@@ -462,8 +477,8 @@ const main = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// start http server listening to /health endpoint using http package
|
// start http server listening to /health endpoint using http package
|
||||||
app.get('/health', handleResponseTime, handleHealthCheck);
|
app.get('/health', handleHealthCheck);
|
||||||
app.get('/', handleResponseTime, handleHealthCheck);
|
app.get('/', handleHealthCheck);
|
||||||
|
|
||||||
app.get('/orders/json/raw', handleResponseTime, async (_req, res, next) => {
|
app.get('/orders/json/raw', handleResponseTime, async (_req, res, next) => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in New Issue
Block a user