Refactor browser connection performance tracking

Reviewed By: lblasa

Differential Revision: D51158256

fbshipit-source-id: 17e020dd3c26ac73bf2cf0ceb4c664638c6778e9
This commit is contained in:
Andrey Goncharov
2023-11-09 08:25:28 -08:00
committed by Facebook GitHub Bot
parent 54217f2c79
commit d54bd7c3ba
4 changed files with 27 additions and 16 deletions

View File

@@ -168,6 +168,7 @@ export type FlipperServerEvents = {
'plugins-server-add-on-message': ExecuteMessage;
'download-file-update': DownloadFileUpdate;
'server-log': LoggerInfo;
'browser-connection-created': {};
};
export type OS =

View File

@@ -27,7 +27,6 @@ import {
} from 'flipper-server-companion';
import {URLSearchParams} from 'url';
import {tracker} from '../tracker';
import {performance} from 'perf_hooks';
import {getFlipperServerConfig} from '../FlipperServerConfig';
const safe = (f: () => void) => {
@@ -53,14 +52,6 @@ export function attachSocketServer(
server: FlipperServerImpl,
companionEnv: FlipperServerCompanionEnv,
) {
const t0 = performance.now();
const browserConnectionTimeout = setTimeout(() => {
tracker.track('browser-connection-created', {
successful: false,
timeMS: performance.now() - t0,
});
}, 20000);
socket.on('connection', (client, req) => {
const clientAddress =
(req.socket.remoteAddress &&
@@ -74,11 +65,7 @@ export function attachSocketServer(
clearTimeout(disconnectTimeout);
}
clearTimeout(browserConnectionTimeout);
tracker.track('browser-connection-created', {
successful: true,
timeMS: performance.now() - t0,
});
server.emit('browser-connection-created', {});
let connected = true;

View File

@@ -54,6 +54,7 @@ type TrackerEvents = {
'browser-connection-created': {
successful: boolean;
timeMS: number;
timedOut: boolean;
};
'app-connection-created': AppConnectionPayload;
'app-connection-secure-attempt': AppConnectionPayload;

View File

@@ -95,9 +95,25 @@ const rootPath = argv.bundler
: path.resolve(__dirname, '..'); // In pre-packaged versions of the server, static is copied inside the package.
const staticPath = path.join(rootPath, 'static');
async function start() {
const t0 = performance.now();
const browserConnectionTimeout = setTimeout(() => {
tracker.track('browser-connection-created', {
successful: false,
timeMS: performance.now() - t0,
timedOut: true,
});
}, 10000);
const reportBrowserConnection = (successful: boolean) => {
clearTimeout(browserConnectionTimeout);
tracker.track('browser-connection-created', {
successful,
timeMS: performance.now() - t0,
timedOut: false,
});
};
async function start() {
const isProduction =
process.env.NODE_ENV !== 'development' && process.env.NODE_ENV !== 'test';
const environmentInfo = await getEnvironmentInfo(
@@ -206,6 +222,10 @@ async function start() {
environmentInfo,
);
flipperServer.once('browser-connection-created', () => {
reportBrowserConnection(true);
});
const t5 = performance.now();
const serverCreatedMS = t5 - t4;
console.info(
@@ -311,6 +331,7 @@ process.on('uncaughtException', (error) => {
'[flipper-server] uncaught exception, process will exit.',
error,
);
reportBrowserConnection(false);
process.exit(1);
});
@@ -325,5 +346,6 @@ process.on('unhandledRejection', (reason, promise) => {
start().catch((e) => {
console.error(chalk.red('Server startup error: '), e);
reportBrowserConnection(false);
process.exit(1);
});