Bug 1015525: changes to translation prefs are now recorded by FHR. r=rnewman
authorMike de Boer <mdeboer@mozilla.com>
Wed, 04 Jun 2014 15:32:08 +0200
changeset 207260 eddaac20ab8579256ff1cb4e845b6611bfaed47e
parent 207107 365fc5eb11697b1f6cbbfcd2f2f867b43c2d0556
child 207261 62385fdd6577156b0e855b1355eb7d491983ec12
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrnewman
bugs1015525
milestone32.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 1015525: changes to translation prefs are now recorded by FHR. r=rnewman
browser/components/translation/Translation.jsm
browser/components/translation/test/unit/test_healthreport.js
services/healthreport/docs/dataformat.rst
--- a/browser/components/translation/Translation.jsm
+++ b/browser/components/translation/Translation.jsm
@@ -15,16 +15,17 @@ const TRANSLATION_PREF_SHOWUI = "browser
 
 Cu.import("resource://gre/modules/Services.jsm");
 Cu.import("resource://gre/modules/Promise.jsm");
 Cu.import("resource://gre/modules/Metrics.jsm", this);
 Cu.import("resource://gre/modules/Task.jsm", this);
 
 const DAILY_COUNTER_FIELD = {type: Metrics.Storage.FIELD_DAILY_COUNTER};
 const DAILY_LAST_TEXT_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_TEXT};
+const DAILY_LAST_NUMERIC_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC};
 
 
 this.Translation = {
   supportedSourceLanguages: ["en", "zh", "ja", "es", "de", "fr", "ru", "ar", "ko", "pt"],
   supportedTargetLanguages: ["en", "pl", "tr", "vi"],
 
   _defaultTargetLanguage: "",
   get defaultTargetLanguage() {
@@ -295,16 +296,18 @@ TranslationMeasurement1.prototype = Obje
   fields: {
     translationOpportunityCount: DAILY_COUNTER_FIELD,
     pageTranslatedCount: DAILY_COUNTER_FIELD,
     charactersTranslatedCount: DAILY_COUNTER_FIELD,
     translationOpportunityCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     pageTranslatedCountsByLanguage: DAILY_LAST_TEXT_FIELD,
     detectedLanguageChangedBefore: DAILY_COUNTER_FIELD,
     detectedLanguageChangedAfter: DAILY_COUNTER_FIELD,
+    detectLanguageEnabled: DAILY_LAST_NUMERIC_FIELD,
+    showTranslationUI: DAILY_LAST_NUMERIC_FIELD,
   },
 
   shouldIncludeField: function (field) {
     if (!Services.prefs.getBoolPref("toolkit.telemetry.enabled")) {
       // This measurement should only be included when telemetry is
       // enabled, so we will not include any fields.
       return false;
     }
@@ -319,17 +322,17 @@ TranslationMeasurement1.prototype = Obje
       if (data.hasDay(date)) {
         data = JSON.parse(data.getDay(date));
       } else {
         data = {};
       }
 
       return data;
     });
-},
+  },
 
   _wrapJSONSerializer: function (serializer) {
     let _parseInPlace = function(o, k) {
       if (k in o) {
         o[k] = JSON.parse(o[k]);
       }
     };
 
@@ -409,16 +412,29 @@ TranslationProvider.prototype = Object.f
       if (beforeFirstTranslation) {
           yield m.incrementDailyCounter("detectedLanguageChangedBefore");
         } else {
           yield m.incrementDailyCounter("detectedLanguageChangedAfter");
         }
     }.bind(this));
   },
 
+  collectDailyData: function () {
+    let m = this.getMeasurement(TranslationMeasurement1.prototype.name,
+                                TranslationMeasurement1.prototype.version);
+
+    return this._enqueueTelemetryStorageTask(function* recordTask() {
+      let detectLanguageEnabled = Services.prefs.getBoolPref("browser.translation.detectLanguage");
+      yield m.setDailyLastNumeric("detectLanguageEnabled", detectLanguageEnabled ? 1 : 0);
+
+      let showTranslationUI = Services.prefs.getBoolPref("browser.translation.ui.show");
+      yield m.setDailyLastNumeric("showTranslationUI", showTranslationUI ? 1 : 0);
+    }.bind(this));
+  },
+
   _enqueueTelemetryStorageTask: function (task) {
     if (!Services.prefs.getBoolPref("toolkit.telemetry.enabled")) {
       // This measurement should only be included when telemetry is
       // enabled, so don't record any data.
       return Promise.resolve(null);
     }
 
     return this.enqueueStorageOperation(() => {
--- a/browser/components/translation/test/unit/test_healthreport.js
+++ b/browser/components/translation/test/unit/test_healthreport.js
@@ -165,16 +165,54 @@ add_task(function* test_record_translati
   Assert.equal(day.get("detectedLanguageChangedBefore"), 1);
   Assert.ok(day.has("detectedLanguageChangedAfter"));
   Assert.equal(day.get("detectedLanguageChangedAfter"), 2);
 
   yield provider.shutdown();
   yield storage.close();
 });
 
+add_task(function* test_collect_daily() {
+  let storage = yield Metrics.Storage("translation");
+  let provider = new TranslationProvider();
+  yield provider.init(storage);
+  let now = new Date();
+
+  // Set the prefs we test here to `false` initially.
+  const kPrefDetectLanguage = "browser.translation.detectLanguage";
+  const kPrefShowUI = "browser.translation.ui.show";
+  Services.prefs.setBoolPref(kPrefDetectLanguage, false);
+  Services.prefs.setBoolPref(kPrefShowUI, false);
+
+  // Initially nothing should be configured.
+  yield provider.collectDailyData();
+
+  let m = provider.getMeasurement("translation", 1);
+  let values = yield m.getValues();
+  Assert.equal(values.days.size, 1);
+  Assert.ok(values.days.hasDay(now));
+  let day = values.days.getDay(now);
+  Assert.ok(day.has("detectLanguageEnabled"));
+  Assert.ok(day.has("showTranslationUI"));
+
+  // Changes to the repective prefs should be picked up.
+  Services.prefs.setBoolPref(kPrefDetectLanguage, true);
+  Services.prefs.setBoolPref(kPrefShowUI, true);
+
+  yield provider.collectDailyData();
+
+  values = yield m.getValues();
+  day = values.days.getDay(now);
+  Assert.equal(day.get("detectLanguageEnabled"), 1);
+  Assert.equal(day.get("showTranslationUI"), 1);
+
+  yield provider.shutdown();
+  yield storage.close();
+});
+
 // Test the payload after recording with telemetry enabled.
 add_task(function* test_healthreporter_json() {
   Services.prefs.setBoolPref("toolkit.telemetry.enabled", true);
 
   let reporter = yield getHealthReporter("healthreporter_json");
   yield reporter.init();
   try {
     let now = new Date();
@@ -222,17 +260,17 @@ add_task(function* test_healthreporter_j
     Assert.ok("detectedLanguageChangedAfter" in translations);
     Assert.equal(translations["detectedLanguageChangedAfter"], 1);
   } finally {
     reporter._shutdown();
   }
 });
 
 // Test the payload after recording with telemetry disabled.
-add_task(function* test_healthreporter_json() {
+add_task(function* test_healthreporter_json2() {
   Services.prefs.setBoolPref("toolkit.telemetry.enabled", false);
 
   let reporter = yield getHealthReporter("healthreporter_json");
   yield reporter.init();
   try {
     let now = new Date();
     let provider = new TranslationProvider();
     yield reporter._providerManager.registerProvider(provider);
--- a/services/healthreport/docs/dataformat.rst
+++ b/services/healthreport/docs/dataformat.rst
@@ -1559,23 +1559,32 @@ properties:
 translationOpportunityCountsByLanguage
     A mapping from language to count of opportunities to translate that
     language.
 pageTranslatedCountsByLanguage
     A mapping from language to the counts of pages translated from that
     language. Each language entry will be an object containing a "total" member
     along with individual counts for each language translated to.
 
+Other properties:
+
+detectLanguageEnabled
+    Whether automatic language detection is enabled. This is an integer, 0 or 1.
+showTranslationUI
+    Whether the translation feature UI will be shown. This is an integer, 0 or 1.
+
 Example
 ^^^^^^^
 
 ::
 
     "org.mozilla.translation.translation": {
       "_v": 1,
+      "detectLanguageEnabled": 1,
+      "showTranslationUI": 1,
       "translationOpportunityCount": 134,
       "pageTranslatedCount": 6,
       "charactersTranslatedCount": "1126",
       "detectedLanguageChangedBefore": 1,
       "detectedLanguageChangedAfter": 2,
       "translationOpportunityCountsByLanguage": {
         "fr": 100,
         "es": 34