Merge pull request #218 from drift-labs/wphan/restrict_response_time_endpoints
limit the endpoints to measure response times for
This commit is contained in:
@@ -4,14 +4,20 @@ import {
|
||||
endpointResponseTimeHistogram,
|
||||
responseStatusCounter,
|
||||
} from './metrics';
|
||||
import { MEASURED_ENDPOINTS } from '../utils/constants';
|
||||
|
||||
export const handleResponseTime = responseTime(
|
||||
(req: Request, res: Response, time: number) => {
|
||||
export const handleResponseTime = (
|
||||
measuredEndpoints: string[] = MEASURED_ENDPOINTS
|
||||
) => {
|
||||
return responseTime((req: Request, res: Response, time: number) => {
|
||||
const endpoint = req.path;
|
||||
|
||||
if (endpoint === '/health' || req.url === '/') {
|
||||
if (!measuredEndpoints.includes(endpoint)) {
|
||||
return;
|
||||
}
|
||||
//if (endpoint === '/health' || req.url === '/') {
|
||||
// return;
|
||||
//}
|
||||
|
||||
responseStatusCounter.add(1, {
|
||||
endpoint,
|
||||
@@ -22,5 +28,5 @@ export const handleResponseTime = responseTime(
|
||||
endpointResponseTimeHistogram.record(responseTimeMs, {
|
||||
endpoint,
|
||||
});
|
||||
}
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -90,7 +90,7 @@ app.use(cors({ origin: '*' }));
|
||||
app.use(compression());
|
||||
app.set('trust proxy', 1);
|
||||
app.use(logHttp);
|
||||
app.use(handleResponseTime);
|
||||
app.use(handleResponseTime());
|
||||
|
||||
// strip off /dlob, if the request comes from exchange history server LB
|
||||
app.use((req, _res, next) => {
|
||||
|
||||
@@ -65,7 +65,7 @@ app.use(cors({ origin: '*' }));
|
||||
app.use(compression());
|
||||
app.set('trust proxy', 1);
|
||||
app.use(logHttp);
|
||||
app.use(handleResponseTime);
|
||||
app.use(handleResponseTime());
|
||||
|
||||
// strip off /dlob, if the request comes from exchange history server LB
|
||||
app.use((req, _res, next) => {
|
||||
|
||||
9
src/utils/constants.ts
Normal file
9
src/utils/constants.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export const MEASURED_ENDPOINTS = [
|
||||
'/priorityFees',
|
||||
'/batchPriorityFees',
|
||||
'/topMakers',
|
||||
'/l2',
|
||||
'/batchL2',
|
||||
'/batchL2Cache',
|
||||
'/l3',
|
||||
];
|
||||
Reference in New Issue
Block a user