Bug 1130132 - Add telemetry to determine how consistent our geoip country code is with Windows. r+a=gavin
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 12 Feb 2015 12:49:18 +1100
changeset 249721 19957a73625f0d59e0848a051a554bfc1ec21b92
parent 249720 cfdc976a78d5e7c5ebb8862b84d651f5f7edfd87
child 249722 55e36fd42ae6142a98480c6b32d43ac02d13c2f5
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1130132
milestone37.0a2
Bug 1130132 - Add telemetry to determine how consistent our geoip country code is with Windows. r+a=gavin
toolkit/components/search/nsSearchService.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
@@ -550,31 +550,47 @@ function storeCountryCode(cc) {
   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
+  // On Mac and Windows, 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.
+    // not available on this platform.
   }
   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);
+    let probeUSMismatched, probeNonUSMismatched;
+    switch (Services.appinfo.OS) {
+      case "Darwin":
+        probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        break;
+      case "WINNT":
+        probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_WIN";
+        probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_WIN";
+        break;
+      default:
+        Cu.reportError("Platform " + Services.appinfo.OS + " has nsIGfxInfo2 but no search service telemetry probes");
+        break;
+    }
+    if (probeUSMismatched && probeNonUSMismatched) {
+      let platformCC = gfxInfo2.countryCode;
+      if (cc == "US" || platformCC == "US") {
+        // one of the 2 said US, so record if they are the same.
+        Services.telemetry.getHistogramById(probeUSMismatched).add(cc != platformCC);
+      } else {
+        // different country - record if they are the same
+        Services.telemetry.getHistogramById(probeNonUSMismatched).add(cc != platformCC);
+      }
     }
   }
 }
 
 // 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 = {
--- a/toolkit/components/search/tests/xpcshell/test_location.js
+++ b/toolkit/components/search/tests/xpcshell/test_location.js
@@ -19,32 +19,44 @@ function run_test() {
       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 probeUSMismatched, probeNonUSMismatched;
+    switch (Services.appinfo.OS) {
+      case "Darwin":
+        probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        break;
+      case "WINNT":
+        probeUSMismatched = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_WIN";
+        probeNonUSMismatched = "SEARCH_SERVICE_NONUS_COUNTRY_MISMATCHED_PLATFORM_WIN";
+        break;
+      default:
+        break;
+    }
+
+    if (probeUSMismatched && probeNonUSMismatched) {
       let gfxInfo2 = Cc["@mozilla.org/gfx/info;1"].getService(Ci.nsIGfxInfo2);
-      print("OSX says the country-code is", gfxInfo2.countryCode);
+      print("Platform 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)
+      // We know geoip said AU - if the platform thinks US then we expect
+      // probeUSMismatched with true (ie, a mismatch)
       if (gfxInfo2.countryCode == "US") {
-        hid = "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_OSX";
+        hid = probeUSMismatched;
         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";
+        // We are expecting probeNonUSMismatched with false if the platform
+        // says AU (not a mismatch) and true otherwise.
+        hid = probeNonUSMismatched;
         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();
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4623,16 +4623,28 @@
     "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"
   },
+  "SEARCH_SERVICE_US_COUNTRY_MISMATCHED_PLATFORM_WIN": {
+    "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "description": "If we are on Windows and either the Windows 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_WIN": {
+    "alert_emails": ["mhammond@mozilla.com", "gavin@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "description": "If we are on Windows and neither the Windows 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",