Bug 1527299 - Update devtools' Event Telemetry doc and example r=miker
authorChris H-C <chutten@mozilla.com>
Thu, 28 Feb 2019 09:23:14 +0000
changeset 519666 0b75d7939fe20aeddccecb4426bb738d365c5130
parent 519665 30cf58a30352c23a8d6070f7d1bc17534854d3da
child 519667 5dc14c7be6268b387ca085cdc996ef715f4a47b9
push id10862
push userffxbld-merge
push dateMon, 11 Mar 2019 13:01:11 +0000
treeherdermozilla-beta@a2e7f5c935da [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmiker
bugs1527299
milestone67.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 1527299 - Update devtools' Event Telemetry doc and example r=miker Differential Revision: https://phabricator.services.mozilla.com/D20866
devtools/client/framework/test/browser_toolbox_telemetry_close.js
devtools/docs/frontend/telemetry.md
--- a/devtools/client/framework/test/browser_toolbox_telemetry_close.js
+++ b/devtools/client/framework/test/browser_toolbox_telemetry_close.js
@@ -1,50 +1,47 @@
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { Toolbox } = require("devtools/client/framework/toolbox");
+const { TelemetryTestUtils } = ChromeUtils.import("resource://testing-common/TelemetryTestUtils.jsm");
 
 const URL = "data:text/html;charset=utf8,browser_toolbox_telemetry_close.js";
-const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
 const { RIGHT, BOTTOM } = Toolbox.HostType;
 const DATA = [
   {
-    timestamp: null,
     category: "devtools.main",
     method: "close",
     object: "tools",
     value: null,
     extra: {
       host: "right",
-      width: "1440",
+      width: w => w > 0,
     },
   },
   {
-    timestamp: null,
     category: "devtools.main",
     method: "close",
     object: "tools",
     value: null,
     extra: {
       host: "bottom",
-      width: "1440",
+      width: w => w > 0,
     },
   },
 ];
 
 add_task(async function() {
   // Let's reset the counts.
   Services.telemetry.clearEvents();
 
   // Ensure no events have been logged
-  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
-  ok(!snapshot.parent, "No events have been logged for the main process");
+  TelemetryTestUtils.assertNumberOfEvents(0);
 
   await openAndCloseToolbox("webconsole", RIGHT);
   await openAndCloseToolbox("webconsole", BOTTOM);
 
   checkResults();
 });
 
 async function openAndCloseToolbox(toolId, host) {
@@ -52,30 +49,10 @@ async function openAndCloseToolbox(toolI
   const target = await TargetFactory.forTab(tab);
   const toolbox = await gDevTools.showToolbox(target, toolId);
 
   await toolbox.switchHost(host);
   await toolbox.destroy();
 }
 
 function checkResults() {
-  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
-  const events = snapshot.parent.filter(event => event[1] === "devtools.main" &&
-                                                 event[2] === "close" &&
-                                                 event[3] === "tools" &&
-                                                 event[4] === null
-  );
-
-  for (const i in DATA) {
-    const [ timestamp, category, method, object, value, extra ] = events[i];
-    const expected = DATA[i];
-
-    // ignore timestamp
-    ok(timestamp > 0, "timestamp is greater than 0");
-    is(category, expected.category, "category is correct");
-    is(method, expected.method, "method is correct");
-    is(object, expected.object, "object is correct");
-    is(value, expected.value, "value is correct");
-
-    is(extra.host, expected.extra.host, "host is correct");
-    ok(extra.width > 0, "width is greater than 0");
-  }
+  TelemetryTestUtils.assertEvents(DATA, {category: "devtools.main", method: "close", object: "tools"});
 }
--- a/devtools/docs/frontend/telemetry.md
+++ b/devtools/docs/frontend/telemetry.md
@@ -333,52 +333,49 @@ This is best shown via an example:
 
 ```js
 /* Any copyright is dedicated to the Public Domain.
  * http://creativecommons.org/publicdomain/zero/1.0/ */
 
 "use strict";
 
 const { Toolbox } = require("devtools/client/framework/toolbox");
+const { TelemetryTestUtils } = ChromeUtils.import("resource://testing-common/TelemetryTestUtils.jsm");
 
 const URL = "data:text/html;charset=utf8,browser_toolbox_telemetry_close.js";
-const OPTOUT = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
-const { SIDE, BOTTOM } = Toolbox.HostType;
-const TELEMETRY_DATA = [
+const { RIGHT, BOTTOM } = Toolbox.HostType;
+const DATA = [
   {
-    timestamp: null,
     category: "devtools.main",
     method: "close",
     object: "tools",
     value: null,
     extra: {
       host: "right",
-      width: "1440"
+      width: w => w > 0,
     }
   },
   {
-    timestamp: null,
     category: "devtools.main",
     method: "close",
     object: "tools",
     value: null,
     extra: {
       host: "bottom",
-      width: "1440"
+      width: w => w > 0,
     }
   }
 ];
 
 add_task(async function() {
   // Let's reset the counts.
   Services.telemetry.clearEvents();
 
   // Ensure no events have been logged
-  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
-  ok(!snapshot.parent, "No events have been logged for the main process");
+  TelemetryTestUtils.assertNumberOfEvents(0);
 
   await openAndCloseToolbox("webconsole", SIDE);
   await openAndCloseToolbox("webconsole", BOTTOM);
 
   checkResults();
 });
 
 async function openAndCloseToolbox(toolId, host) {
@@ -386,37 +383,17 @@ async function openAndCloseToolbox(toolI
   const target = await TargetFactory.forTab(tab);
   const toolbox = await gDevTools.showToolbox(target, toolId);
 
   await toolbox.switchHost(host);
   await toolbox.destroy();
 }
 
 function checkResults() {
-  const snapshot = Services.telemetry.snapshotEvents(OPTOUT, true);
-  const events = snapshot.parent.filter(event => event[1] === "devtools.main" &&
-                                                 event[2] === "close" &&
-                                                 event[3] === "tools" &&
-                                                 event[4] === null
-  );
-
-  for (const i in TELEMETRY_DATA) {
-    const [ timestamp, category, method, object, value, extra ] = events[i];
-    const expected = TELEMETRY_DATA[i];
-
-    // ignore timestamp
-    ok(timestamp > 0, "timestamp is greater than 0");
-    is(category, expected.category, "category is correct");
-    is(method, expected.method, "method is correct");
-    is(object, expected.object, "object is correct");
-    is(value, expected.value, "value is correct");
-
-    is(extra.host, expected.extra.host, "host is correct");
-    ok(extra.width > 0, "width is greater than 0");
-  }
+  TelemetryTestUtils.assertEvents(DATA, {category: "devtools.main", method: "close", object: "tools"});
 }
 ```
 
 #### Compile it
 
 You need to do a full Firefox build if you have edited either `Histograms.json` or `Events.yaml`, as they are processed at build time, and various checks will be run on them to guarantee they are valid.
 
 ```bash