Bug 1462725 - Add 'end_study' event; r=rhelmer draft
authorBianca Danforth <bdanforth@mozilla.com>
Wed, 23 May 2018 07:29:32 -0700
changeset 803325 950900b42e9320b21a07f8e18cf3826796c4c1d7
parent 803324 d8f6dcf3105968a3cc2381b28fd277c207e446e1
child 803327 1e94c2a11aaab6690317d41c62fd0382f03428bf
push id112069
push userbdanforth@mozilla.com
push dateSun, 03 Jun 2018 04:54:10 +0000
reviewersrhelmer
bugs1462725
milestone62.0a1
Bug 1462725 - Add 'end_study' event; r=rhelmer This `end_study` event will be recorded when an ending condition has been met: the study has expired, the user is ineligible, or the study has been disabled (the study pref has been turned off). MozReview-Commit-ID: 6WKL4hqWliz
browser/modules/SavantShieldStudy.jsm
toolkit/components/telemetry/Events.yaml
--- a/browser/modules/SavantShieldStudy.jsm
+++ b/browser/modules/SavantShieldStudy.jsm
@@ -54,17 +54,17 @@ class SavantShieldStudyClass {
   observe(subject, topic, data) {
     if (topic === "nsPref:changed" && data === this.STUDY_PREF) {
       // toggle state of the pref
       this.shouldCollect = !this.shouldCollect;
       if (this.shouldCollect) {
         this.startupStudy();
       } else {
         // The pref has been turned off
-        this.endStudy("study-disabled");
+        this.endStudy("study_disable");
       }
     }
   }
 
   startupStudy() {
     // enable before any possible calls to endStudy, since it sends an 'end_study' event
     this.TelemetryEvents.enableCollection();
 
@@ -128,25 +128,21 @@ class SavantShieldStudyClass {
     }
 
     if (Date.now() > expirationDateInt) {
       return true;
     }
     return false;
   }
 
-
-  sendEvent(method, object, value, extra) {
-    this.TelemetryEvents.sendEvent(method, object, value, extra);
-  }
-
   endStudy(reason) {
     log.debug(`Ending the study due to reason: ${ reason }`);
     const isStudyEnding = true;
-    // Services.telemetry.recordEvent(this.STUDY_TELEMETRY_CATEGORY, "end_study", reason);
+    Services.telemetry.recordEvent(this.STUDY_TELEMETRY_CATEGORY, "end_study", reason, null,
+                                  { subcategory: "shield" });
     this.TelemetryEvents.disableCollection();
     this.uninit(isStudyEnding);
     // These prefs needs to persist between restarts, so only reset on endStudy
     Services.prefs.clearUserPref(this.STUDY_PREF);
     Services.prefs.clearUserPref(this.STUDY_EXPIRATION_DATE_PREF);
   }
 
   // Called on every Firefox shutdown and endStudy
@@ -166,19 +162,17 @@ class SavantShieldStudyClass {
     Services.prefs.clearUserPref(this.STUDY_DURATION_OVERRIDE_PREF);
   }
 
   async getFlowID(str) {
     return this.TelemetryEvents.getFlowID(str);
   }
 }
 
-const SavantShieldStudy = new SavantShieldStudyClass();
-
-// references:
+// References:
 //  - https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/normandy/lib/TelemetryEvents.jsm
 // - https://hg.mozilla.org/mozilla-central/file/tip/toolkit/components/normandy/lib/PreferenceExperiments.jsm#l357
 class TelemetryEvents {
   constructor(studyCategory, clientID) {
     this.STUDY_TELEMETRY_CATEGORY = studyCategory;
     this.TELEMETRY_CLIENT_ID = clientID;
   }
 
@@ -199,8 +193,10 @@ class TelemetryEvents {
     const saltedStr = `${ str }${ this.TELEMETRY_CLIENT_ID }`;
     const messageBuffer = new TextEncoder("utf-8").encode(saltedStr);
     const hashBuffer = await crypto.subtle.digest("SHA-256", messageBuffer);
     const hashArray = Array.from(new Uint8Array(hashBuffer));
     const hashHex = hashArray.map(b => ("00" + b.toString(16)).slice(-2)).join("");
     return hashHex.substring(0, 10);
   }
 }
+
+const SavantShieldStudy = new SavantShieldStudyClass();
--- a/toolkit/components/telemetry/Events.yaml
+++ b/toolkit/components/telemetry/Events.yaml
@@ -101,16 +101,30 @@ savant:
     bug_numbers: [1316281, 1457226, 1462725]
     notification_emails:
       - "bdanforth@mozilla.com"
       - "shong@mozilla.com"
     expiry_version: "65"
     extra_keys:
       subcategory: The broad event category for this probe. E.g. navigation
       engine: The id of the search engine used.
+  end_study:
+    objects: ["ineligible", "study_disable", "expired"]
+    release_channel_collection: opt-out
+    record_in_processes: ["main"]
+    description: >
+      This is recorded any time a study ending condition occurs for the Savant
+      Shield study. The object field records the reason that caused the ending.
+    bug_numbers: [1457226, 1462725]
+    notification_emails:
+      - "bdanforth@mozilla.com"
+      - "shong@mozilla.com"
+    expiry_version: "65"
+    extra_keys:
+      subcategory: The broad event category for this probe. E.g. navigation
 
 # 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]