instead of sampling report high ping events (#49922)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/49922

Spamming the DB with "heartbeat" events with close to 0 ping didn't give us any useful information. Instead, report high ping situations.

Changelog:
[General][Internal] Remove reporting all device and debugger heartbeat events, only report heartbeats with high round trip latency

Reviewed By: GijsWeterings

Differential Revision: D70707457

fbshipit-source-id: 6bc8a55fd32dfa60fb4f7764ac00a6218417dcb5
This commit is contained in:
Vitali Zaidman
2025-03-10 07:07:49 -07:00
committed by Facebook GitHub Bot
parent 0928406530
commit d50cb768c9
2 changed files with 24 additions and 20 deletions
@@ -44,6 +44,8 @@ const HEARTBEAT_TIMEOUT_MS = 60000;
const HEARTBEAT_INTERVAL_MS = 10000;
const PROXY_IDLE_TIMEOUT_MS = 10000;
const MIN_PING_TO_REPORT = 500;
const INTERNAL_ERROR_CODE = 1011;
export type GetPageDescriptionsConfig = {
@@ -339,7 +341,7 @@ export default class InspectorProxy implements InspectorProxyQueries {
intervalMs: HEARTBEAT_INTERVAL_MS,
debuggerSessionIDs,
timeoutEventName: 'device_timeout',
heartbeatEventName: 'device_heartbeat',
highPingEventName: 'device_high_ping',
});
this.#trackLastMessageTimestamp(socket);
@@ -430,7 +432,7 @@ export default class InspectorProxy implements InspectorProxyQueries {
intervalMs: HEARTBEAT_INTERVAL_MS,
debuggerSessionIDs,
timeoutEventName: 'debugger_timeout',
heartbeatEventName: 'debugger_heartbeat',
highPingEventName: 'debugger_high_ping',
});
device.handleDebuggerConnection(socket, pageId, {
@@ -488,14 +490,14 @@ export default class InspectorProxy implements InspectorProxyQueries {
intervalMs,
debuggerSessionIDs,
timeoutEventName,
heartbeatEventName,
highPingEventName,
}: {
socketName: string,
socket: WS,
intervalMs: number,
debuggerSessionIDs: DebuggerSessionIDs,
timeoutEventName: 'debugger_timeout' | 'device_timeout',
heartbeatEventName: 'debugger_heartbeat' | 'device_heartbeat',
highPingEventName: 'debugger_high_ping' | 'device_high_ping',
}) {
let latestPingMs = Date.now();
let terminateTimeout: ?Timeout;
@@ -549,23 +551,25 @@ export default class InspectorProxy implements InspectorProxyQueries {
socket.on('pong', () => {
const roundtripDuration = Date.now() - latestPingMs;
const isIdle = this.#isIdle();
if (debug.enabled && roundtripDuration >= MIN_PING_TO_REPORT) {
const isIdle = this.#isIdle();
debug(
"[heartbeat ping-pong] [%s] %sms for app='%s' on device='%s' with idle='%s'",
socketName.padStart(7).padEnd(8),
String(roundtripDuration).padStart(5),
debuggerSessionIDs.appId,
debuggerSessionIDs.deviceName,
isIdle ? 'true' : 'false',
);
debug(
"[high ping] [%s] %sms for app='%s' on device='%s' with idle='%s'",
socketName.padStart(7).padEnd(8),
String(roundtripDuration).padStart(5),
debuggerSessionIDs.appId,
debuggerSessionIDs.deviceName,
isIdle ? 'true' : 'false',
);
this.#eventReporter?.logEvent({
type: heartbeatEventName,
duration: roundtripDuration,
isIdle,
...debuggerSessionIDs,
});
this.#eventReporter?.logEvent({
type: highPingEventName,
duration: roundtripDuration,
isIdle,
...debuggerSessionIDs,
});
}
terminateTimeout?.refresh();
pingTimeout.refresh();
@@ -94,7 +94,7 @@ export type ReportableEvent =
...DebuggerSessionIDs,
}
| {
type: 'debugger_heartbeat' | 'device_heartbeat',
type: 'debugger_high_ping' | 'device_high_ping',
duration: number,
isIdle: boolean,
...DebuggerSessionIDs,