Server error and endpoint metrics

Summary: Better than using logs.

Reviewed By: antonk52

Differential Revision: D50012506

fbshipit-source-id: 2f0e9bf8cb7282d35dc5619e620d005b96663fd5
This commit is contained in:
Lorenzo Blasa
2023-10-06 08:26:09 -07:00
committed by Facebook GitHub Bot
parent 66dac8112b
commit b11a85c4b3
2 changed files with 8 additions and 1 deletions

View File

@@ -152,11 +152,12 @@ async function startHTTPServer(
});
app.get('/ready', (_req, res) => {
tracker.track('server-endpoint-hit', {name: 'ready'});
res.json({isReady});
});
app.get('/info', (_req, res) => {
console.info('[flipper-server] Received info request');
tracker.track('server-endpoint-hit', {name: 'info'});
res.json(environmentInfo);
});
@@ -164,6 +165,7 @@ async function startHTTPServer(
console.info(
'[flipper-server] Received shutdown request, process will terminate',
);
tracker.track('server-endpoint-hit', {name: 'shutdown'});
res.json({success: true});
// Just exit the process, this will trigger the shutdown hooks.
@@ -171,6 +173,7 @@ async function startHTTPServer(
});
app.get('/health', (_req, res) => {
tracker.track('server-endpoint-hit', {name: 'health'});
res.end('flipper-ok');
});
@@ -186,6 +189,8 @@ async function startHTTPServer(
server.on('error', (e: NodeJS.ErrnoException) => {
console.warn('[flipper-server] HTTP server error: ', e.code);
tracker.track('server-error', {code: e.code, message: e.message});
if (e.code === 'EADDRINUSE') {
console.warn(
`[flipper-server] Unable to listen at port: ${config.port}, is already in use`,

View File

@@ -39,6 +39,8 @@ type ServerBootstrapPerformancePayload = {
type TrackerEvents = {
'server-bootstrap-performance': ServerBootstrapPerformancePayload;
'server-started': {port: number};
'server-error': {code: string | undefined; message: string};
'server-endpoint-hit': {name: string};
'server-auth-token-verification': {
successful: boolean;
present: boolean;