Bug 1443560: register telemetry events statically r=Gijs
authorEthan Glasser-Camp <ethan@betacantrips.com>
Fri, 15 Feb 2019 15:48:51 +0000
changeset 459600 ec979e0f73ce73f4fe1015783b12df90a67008b1
parent 459599 a1dd47617412e8932b94fb3d57f370feeb4486ed
child 459601 48d98388c29cfa5d0e4dd92acfb3327f160fc774
push id35563
push userccoroiu@mozilla.com
push dateSat, 16 Feb 2019 09:36:04 +0000
treeherdermozilla-central@1cfd69d05aa1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1443560
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 1443560: register telemetry events statically r=Gijs This also means we no longer have direct access to the event schema, so rely on Telemetry to throw when we send an invalid event. Differential Revision: https://phabricator.services.mozilla.com/D19540
toolkit/components/normandy/lib/TelemetryEvents.jsm
toolkit/components/normandy/test/browser/head.js
toolkit/components/telemetry/Events.yaml
--- a/toolkit/components/normandy/lib/TelemetryEvents.jsm
+++ b/toolkit/components/normandy/lib/TelemetryEvents.jsm
@@ -5,60 +5,16 @@
 
 const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
 var EXPORTED_SYMBOLS = ["TelemetryEvents"];
 
 const TELEMETRY_CATEGORY = "normandy";
 
 const TelemetryEvents = {
-  eventSchema: {
-    enroll: {
-      methods: ["enroll"],
-      objects: ["preference_study", "addon_study", "preference_rollout"],
-      extra_keys: ["experimentType", "branch", "addonId", "addonVersion"],
-      record_on_release: true,
-    },
-
-    enroll_failed: {
-      methods: ["enrollFailed"],
-      objects: ["addon_study", "preference_rollout", "preference_study"],
-      extra_keys: ["reason", "preference", "detail"],
-      record_on_release: true,
-    },
-
-    update: {
-      methods: ["update"],
-      objects: ["preference_rollout"],
-      extra_keys: ["previousState"],
-      record_on_release: true,
-    },
-
-    unenroll: {
-      methods: ["unenroll"],
-      objects: ["preference_study", "addon_study", "preference_rollback"],
-      extra_keys: ["reason", "didResetValue", "addonId", "addonVersion", "branch"],
-      record_on_release: true,
-    },
-
-    unenroll_failed: {
-      methods: ["unenrollFailed"],
-      objects: ["preference_rollback", "preference_study"],
-      extra_keys: ["reason"],
-      record_on_release: true,
-    },
-
-    graduate: {
-      methods: ["graduate"],
-      objects: ["preference_rollout"],
-      extra_keys: [],
-      record_on_release: true,
-    },
-  },
-
   init() {
-    Services.telemetry.registerEvents(TELEMETRY_CATEGORY, this.eventSchema);
+    Services.telemetry.setEventRecordingEnabled(TELEMETRY_CATEGORY, true);
   },
 
   sendEvent(method, object, value, extra) {
     Services.telemetry.recordEvent(TELEMETRY_CATEGORY, method, object, value, extra);
   },
 };
--- a/toolkit/components/normandy/test/browser/head.js
+++ b/toolkit/components/normandy/test/browser/head.js
@@ -342,45 +342,22 @@ this.studyEndObserved = function(recipeI
   return TestUtils.topicObserved(
     "shield-study-ended",
     (subject, endedRecipeId) => Number.parseInt(endedRecipeId) === recipeId,
   );
 };
 
 this.withSendEventStub = function(testFunction) {
   return async function wrappedTestFunction(...args) {
-    /* Checks that calls match the event schema. */
-    function checkEventMatchesSchema(method, object, value, extra) {
-      let match = true;
-      const spec = Array.from(Object.values(TelemetryEvents.eventSchema))
-        .filter(spec => spec.methods.includes(method))[0];
-
-      if (spec) {
-        if (!spec.objects.includes(object)) {
-          match = false;
-        }
-
-        for (const key of Object.keys(extra)) {
-          if (!spec.extra_keys.includes(key)) {
-            match = false;
-          }
-        }
-      } else {
-        match = false;
-      }
-
-      ok(match, `sendEvent(${method}, ${object}, ${value}, ${JSON.stringify(extra)}) should match spec`);
-    }
-
-    const stub = sinon.stub(TelemetryEvents, "sendEvent");
-    stub.callsFake(checkEventMatchesSchema);
+    const stub = sinon.spy(TelemetryEvents, "sendEvent");
     try {
       await testFunction(...args, stub);
     } finally {
       stub.restore();
+      Assert.ok(!stub.threw(), "some telemetry call failed");
     }
   };
 };
 
 let _recipeId = 1;
 this.recipeFactory = function(overrides = {}) {
   return Object.assign({
     id: _recipeId++,
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -215,16 +215,113 @@ navigation:
     bug_numbers: [1316281, 1496764]
     notification_emails:
       - "mdeboer@mozilla.com"
       - "rharter@mozilla.com"
     expiry_version: never
     extra_keys:
       engine: The id of the search engine used.
 
+normandy:
+  enroll:
+    objects: ["preference_study", "addon_study", "preference_rollout"]
+    description: >
+      Sent when applying a Normandy recipe of the above types has succeeded.
+    extra_keys:
+      experimentType: >
+        For preference_study recipes, the type of experiment this is ("exp" or "exp-highpop").
+      branch: >
+        For preference_study recipes, the slug of the branch that was chosen for this client.
+      addonId: For addon_study recipes, the ID of the addon that was installed.
+      addonVersion: For addon_study recipes, the version of the addon that was installed.
+    bug_numbers: [1443560]
+    notification_emails: ["normandy-notifications@mozilla.com"]
+    record_in_processes: [main]
+    release_channel_collection: opt-out
+    expiry_version: never
+
+  enroll_failed:
+    methods: ["enrollFailed"]
+    objects: ["addon_study", "preference_rollout", "preference_study"]
+    description: >
+      Sent when applying a Normandy recipe of the above types has failed.
+    extra_keys:
+      reason: An error code describing the failure.
+      preference: >
+        For preference_rollout when reason=conflict, the name of the preference
+        that was going to be modified.
+      detail: >
+        Extra text describing the failure.
+        Currently only provided for addon_study.
+    bug_numbers: [1443560]
+    notification_emails: ["normandy-notifications@mozilla.com"]
+    record_in_processes: [main]
+    release_channel_collection: opt-out
+    expiry_version: never
+
+  update:
+    objects: ["preference_rollout"]
+    description: >
+      This event is fired when a client detects that a preference
+      rollout has changed on the server, and the new version of the
+      preference rollout is being applied over an existing, older
+      version previously fetched from the server.
+    extra_keys:
+      previousState: >
+        This is the state of the rollout that had been applied previously.
+    bug_numbers: [1443560]
+    notification_emails: ["normandy-notifications@mozilla.com"]
+    record_in_processes: [main]
+    release_channel_collection: opt-out
+    expiry_version: never
+
+  unenroll:
+    objects: ["preference_study", "addon_study", "preference_rollback"]
+    description: >
+      Sent when a Normandy recipe of certain types "ends".  N.B. For
+      preference_rollback, this is fired when the recipe is fired (the
+      recipe that "ends" is a corresponding preference_rollout).
+    extra_keys:
+      reason: A code describing the reason why the recipe ended.
+      didResetValue: >
+        For preference_study, "true" or "false" according to whether we put the preference back the way it was.
+      addonId: For addon_study, the ID of the addon that ended.
+      addonVersion: For addon_study, the version of the addon for which the recipe ended.
+      branch: For preference_study, the branch of the experiment that this client was on.
+    bug_numbers: [1443560]
+    notification_emails: ["normandy-notifications@mozilla.com"]
+    record_in_processes: [main]
+    release_channel_collection: opt-out
+    expiry_version: never
+
+  unenroll_failed:
+    methods: ["unenrollFailed"]
+    description: >
+      Sent when unenrolling a user fails (see the unenroll event).
+    objects: ["preference_rollback", "preference_study"]
+    extra_keys:
+      reason: A code describing the reason the unenroll failed.
+    bug_numbers: [1443560]
+    notification_emails: ["normandy-notifications@mozilla.com"]
+    record_in_processes: [main]
+    release_channel_collection: opt-out
+    expiry_version: never
+
+  graduate:
+    objects: ["preference_rollout"]
+    description: >
+      Sent when a preference rollout ends due to the rolled-out
+      preference becoming a new default.
+    bug_numbers: [1443560]
+    notification_emails: ["normandy-notifications@mozilla.com"]
+    record_in_processes: [main]
+    release_channel_collection: opt-out
+    expiry_version: never
+
+
 # This category contains event entries used for Telemetry tests.
 # They will not be sent out with any pings.
 telemetry.test:
   test:
     methods: ["test1", "test2"]
     objects: ["object1", "object2"]
     bug_numbers: [1286606]
     notification_emails: ["telemetry-client-dev@mozilla.com"]