Bug 1505289 - Handle unplugged devices in telemetry middleware r=Ola,ladybenko
authorJulian Descottes <jdescottes@mozilla.com>
Mon, 15 Apr 2019 22:24:48 +0000
changeset 469621 3b2597e84231
parent 469620 d864f9d6ce00
child 469622 c3aea0459e5c
push id35878
push userapavel@mozilla.com
push dateTue, 16 Apr 2019 15:43:40 +0000
treeherdermozilla-central@258af4e91151 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersOla, ladybenko
bugs1505289
milestone68.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1505289 - Handle unplugged devices in telemetry middleware r=Ola,ladybenko Depends on D25780 Differential Revision: https://phabricator.services.mozilla.com/D25782
devtools/client/aboutdebugging-new/src/middleware/event-recording.js
--- a/devtools/client/aboutdebugging-new/src/middleware/event-recording.js
+++ b/devtools/client/aboutdebugging-new/src/middleware/event-recording.js
@@ -97,45 +97,52 @@ function onRemoteRuntimesUpdated(action,
   const newRuntimes = action.runtimes;
   const allRuntimes = getAllRuntimes(store.getState().runtimes);
   const oldRuntimes = allRuntimes.filter(r => r.type === action.runtimeType);
 
   // Check if all the old runtimes and devices are still available in the updated
   // array.
   for (const oldRuntime of oldRuntimes) {
     const runtimeRemoved = newRuntimes.every(r => r.id !== oldRuntime.id);
-    if (runtimeRemoved) {
+    if (runtimeRemoved && !oldRuntime.isUnplugged) {
       recordEvent("runtime_removed", getRuntimeEventExtras(oldRuntime));
     }
   }
 
+  // Using device names as unique IDs is inaccurate. See Bug 1544582.
   const oldDeviceNames = new Set(oldRuntimes.map(r => r.extra.deviceName));
   for (const oldDeviceName of oldDeviceNames) {
-    const deviceRemoved = newRuntimes.every(r => r.extra.deviceName !== oldDeviceName);
-    if (oldDeviceName && deviceRemoved) {
+    const newRuntime = newRuntimes.find(r => r.extra.deviceName === oldDeviceName);
+    const oldRuntime = oldRuntimes.find(r => r.extra.deviceName === oldDeviceName);
+    const isUnplugged = newRuntime && newRuntime.isUnplugged && !oldRuntime.isUnplugged;
+    if (oldDeviceName && (!newRuntime || isUnplugged)) {
       recordEvent("device_removed", {
         "connection_type": action.runtimeType,
         "device_name": oldDeviceName,
       });
     }
   }
 
   // Check if the new runtimes and devices were already available in the existing
   // array.
   for (const newRuntime of newRuntimes) {
     const runtimeAdded = oldRuntimes.every(r => r.id !== newRuntime.id);
-    if (runtimeAdded) {
+    if (runtimeAdded && !newRuntime.isUnplugged) {
       recordEvent("runtime_added", getRuntimeEventExtras(newRuntime));
     }
   }
 
+  // Using device names as unique IDs is inaccurate. See Bug 1544582.
   const newDeviceNames = new Set(newRuntimes.map(r => r.extra.deviceName));
   for (const newDeviceName of newDeviceNames) {
-    const deviceAdded = oldRuntimes.every(r => r.extra.deviceName !== newDeviceName);
-    if (newDeviceName && deviceAdded) {
+    const newRuntime = newRuntimes.find(r => r.extra.deviceName === newDeviceName);
+    const oldRuntime = oldRuntimes.find(r => r.extra.deviceName === newDeviceName);
+    const isPlugged = oldRuntime && oldRuntime.isUnplugged && !newRuntime.isUnplugged;
+
+    if (newDeviceName && (!oldRuntime || isPlugged)) {
       recordEvent("device_added", {
         "connection_type": action.runtimeType,
         "device_name": newDeviceName,
       });
     }
   }
 }