Bug 1121340 - add telemetry to determine how consistent our geoip country code is with the platform's. r=gavin
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 05 Feb 2015 12:24:06 +1100
changeset 227567 eef81ecfb729e8c3acc2a294ca5ce2b71961313b
parent 227566 525132c2c6429ca5413559ca0484e45b6c68de22
child 227568 04dda44ac71a4907a06e4445f1f17114e783ed3b
push id28234
push usercbook@mozilla.com
push dateThu, 05 Feb 2015 13:37:15 +0000
treeherdermozilla-central@759ee85bf3f0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs1121340
milestone38.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 1121340 - add telemetry to determine how consistent our geoip country code is with the platform's. r=gavin
toolkit/components/search/nsSearchService.js
toolkit/components/search/tests/xpcshell/head_search.js
toolkit/components/search/tests/xpcshell/test_location.js
toolkit/components/telemetry/Histograms.json
--- a/toolkit/components/search/nsSearchService.js
+++ b/toolkit/components/search/nsSearchService.js
@@ -549,16 +549,34 @@ function storeCountryCode(cc) {
   // and telemetry...
   let isTimezoneUS = isUSTimezone();
   if (cc == "US" && !isTimezoneUS) {
     Services.telemetry.getHistogramById("SEARCH_SERVICE_US_COUNTRY_MISMATCHED_TIMEZONE").add(1);
   }
   if (cc != "US" && isTimezoneUS) {
     Services.telemetry.getHistogramById("SEARCH_SERVICE_US_TIMEZONE_MISMATCHED_COUNTRY").add(1);
   }
+  // telemetry to compare our geoip response with platform-specific country data.
+  // On Mac, we can get a country code via nsIGfxInfo2
+  let gfxInfo2;
+  try {
+    gfxInfo2 = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo2);
+  } catch (ex) {
+    // not on Mac.
+  }
+  if (gfxInfo2) {
+    let macCC = gfxInfo2.countryCode;
+    if (cc == "US" || macCC == "US") {
+      // one of the 2 said US, so record if they are the same.
+      Services.telemetry.getHistogramById("SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX").add(cc != macCC);
+    } else {
+      // different country - record if they are the same
+      Services.telemetry.getHistogramById("SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX").add(cc != macCC);
+    }
+  }
 }
 
 // Get the country we are in via a XHR geoip request.
 function fetchCountryCode() {
   // values for the SEARCH_SERVICE_COUNTRY_FETCH_RESULT 'enum' telemetry probe.
   const TELEMETRY_RESULT_ENUM = {
     SUCCESS: 0,
     SUCCESS_WITHOUT_DATA: 1,
--- a/toolkit/components/search/tests/xpcshell/head_search.js
+++ b/toolkit/components/search/tests/xpcshell/head_search.js
@@ -19,27 +19,29 @@ const NS_APP_SEARCH_DIR = "SrchPlugns";
 const MODE_RDONLY = FileUtils.MODE_RDONLY;
 const MODE_WRONLY = FileUtils.MODE_WRONLY;
 const MODE_CREATE = FileUtils.MODE_CREATE;
 const MODE_TRUNCATE = FileUtils.MODE_TRUNCATE;
 
 // nsSearchService.js uses Services.appinfo.name to build a salt for a hash.
 var XULRuntime = Components.classesByID["{95d89e3e-a169-41a3-8e56-719978e15b12}"]
                            .getService(Ci.nsIXULRuntime);
+
 var XULAppInfo = {
   vendor: "Mozilla",
   name: "XPCShell",
   ID: "xpcshell@test.mozilla.org",
   version: "5",
   appBuildID: "2007010101",
   platformVersion: "1.9",
   platformBuildID: "2007010101",
   inSafeMode: false,
   logConsoleErrors: true,
-  OS: "XPCShell",
+  // mirror OS from the base impl as some of the "location" tests rely on it
+  OS: XULRuntime.OS,
   XPCOMABI: "noarch-spidermonkey",
   // mirror processType from the base implementation
   processType: XULRuntime.processType,
 
   QueryInterface: XPCOMUtils.generateQI([Ci.nsIXULAppInfo, Ci.nsIXULRuntime,
                                          Ci.nsISupports])
 };
 
--- a/toolkit/components/search/tests/xpcshell/test_location.js
+++ b/toolkit/components/search/tests/xpcshell/test_location.js
@@ -13,14 +13,42 @@ function run_test() {
     // check we have "success" recorded in telemetry
     checkCountryResultTelemetry(TELEMETRY_RESULT_ENUM.SUCCESS);
     // a false value for each of SEARCH_SERVICE_COUNTRY_TIMEOUT and SEARCH_SERVICE_COUNTRY_FETCH_CAUSED_SYNC_INIT
     for (let hid of ["SEARCH_SERVICE_COUNTRY_TIMEOUT",
                      "SEARCH_SERVICE_COUNTRY_FETCH_CAUSED_SYNC_INIT"]) {
       let histogram = Services.telemetry.getHistogramById(hid);
       let snapshot = histogram.snapshot();
       deepEqual(snapshot.counts, [1,0,0]); // boolean probe so 3 buckets, expect 1 result for |0|.
+
+    }
+
+    // simple checks for our platform-specific telemetry.  We can't influence
+    // what they return (as we can't influence the countryCode the platform
+    // thinks we are in), but we can check the values are correct given reality.
+    // NOTE: head_search.js mocks the XULRuntime values, but saves the original
+    // OS in an OS global
+    if (Services.appinfo.OS == "Darwin") {
+      let gfxInfo2 = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo2);
+      print("OSX says the country-code is", gfxInfo2.countryCode);
+      let expectedResult;
+      let hid;
+      // We know geoip said AU - if mac thinks US then we expect
+      // SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX with true (ie, a mismatch)
+      if (gfxInfo2.countryCode == "US") {
+        hid = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        expectedResult = [0,1,0]; // boolean probe so 3 buckets, expect 1 result for |1|.
+      } else {
+        // We are expecting SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX
+        // with false if OSX says AU (not a mismatch) and true otherwise.
+        hid = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        expectedResult = gfxInfo2.countryCode == "AU" ? [1,0,0] : [0,1,0];
+      }
+
+      let histogram = Services.telemetry.getHistogramById(hid);
+      let snapshot = histogram.snapshot();
+      deepEqual(snapshot.counts, expectedResult);
     }
     do_test_finished();
     run_next_test();
   });
   do_test_pending();
 }
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4634,16 +4634,28 @@
     "description": "Set if the fetched country-code indicates US but the time-zone heuristic doesn't"
   },
   "SEARCH_SERVICE_US_TIMEZONE_MISMATCHED_COUNTRY": {
     "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"],
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Set if the time-zone heuristic indicates US but the fetched country code doesn't"
   },
+  "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX": {
+    "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "description": "If we are on OSX and either the OSX countryCode or the geoip countryCode indicates we are in the US, set to false if they both do or true otherwise"
+  },
+  "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX": {
+    "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "description": "If we are on OSX and neither the OSX countryCode nor the geoip countryCode indicates we are in the US, set to false if they both agree on the value or true otherwise"
+  },
   "SOCIAL_ENABLED_ON_SESSION": {
     "expires_in_version": "never",
     "kind": "flag",
     "description": "Social has been enabled at least once on the current session"
   },
   "ENABLE_PRIVILEGE_EVER_CALLED": {
     "expires_in_version": "never",
     "kind": "flag",