From d50cb768c9d0867f773a4a6ef65db91d157cb3fc Mon Sep 17 00:00:00 2001 From: Vitali Zaidman Date: Mon, 10 Mar 2025 07:07:49 -0700 Subject: [PATCH] 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 --- .../src/inspector-proxy/InspectorProxy.js | 42 ++++++++++--------- .../dev-middleware/src/types/EventReporter.js | 2 +- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js index 69c5a7a14f6..89a3f501b37 100644 --- a/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js +++ b/packages/dev-middleware/src/inspector-proxy/InspectorProxy.js @@ -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(); diff --git a/packages/dev-middleware/src/types/EventReporter.js b/packages/dev-middleware/src/types/EventReporter.js index 6c115e9d61b..3c42f8d1fb0 100644 --- a/packages/dev-middleware/src/types/EventReporter.js +++ b/packages/dev-middleware/src/types/EventReporter.js @@ -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,