Bug 1121340 - add telemetry to determine how consistent our geoip country code is with the platform's. r=gavin

This commit is contained in:
Mark Hammond 2015-02-05 12:24:06 +11:00
Родитель ad68417609
Коммит a015a83aaf
4 изменённых файлов: 61 добавлений и 1 удалений

Просмотреть файл

@ -554,6 +554,24 @@ function storeCountryCode(cc) {
if (cc != "US" && isTimezoneUS) { if (cc != "US" && isTimezoneUS) {
Services.telemetry.getHistogramById("SEARCH_SERVICE_US_TIMEZONE_MISMATCHED_COUNTRY").add(1); 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. // Get the country we are in via a XHR geoip request.

Просмотреть файл

@ -24,6 +24,7 @@ const MODE_TRUNCATE = FileUtils.MODE_TRUNCATE;
// nsSearchService.js uses Services.appinfo.name to build a salt for a hash. // nsSearchService.js uses Services.appinfo.name to build a salt for a hash.
var XULRuntime = Components.classesByID["{95d89e3e-a169-41a3-8e56-719978e15b12}"] var XULRuntime = Components.classesByID["{95d89e3e-a169-41a3-8e56-719978e15b12}"]
.getService(Ci.nsIXULRuntime); .getService(Ci.nsIXULRuntime);
var XULAppInfo = { var XULAppInfo = {
vendor: "Mozilla", vendor: "Mozilla",
name: "XPCShell", name: "XPCShell",
@ -34,7 +35,8 @@ var XULAppInfo = {
platformBuildID: "2007010101", platformBuildID: "2007010101",
inSafeMode: false, inSafeMode: false,
logConsoleErrors: true, 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", XPCOMABI: "noarch-spidermonkey",
// mirror processType from the base implementation // mirror processType from the base implementation
processType: XULRuntime.processType, processType: XULRuntime.processType,

Просмотреть файл

@ -18,6 +18,34 @@ function run_test() {
let histogram = Services.telemetry.getHistogramById(hid); let histogram = Services.telemetry.getHistogramById(hid);
let snapshot = histogram.snapshot(); let snapshot = histogram.snapshot();
deepEqual(snapshot.counts, [1,0,0]); // boolean probe so 3 buckets, expect 1 result for |0|. 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(); do_test_finished();
run_next_test(); run_next_test();

Просмотреть файл

@ -4639,6 +4639,18 @@
"kind": "flag", "kind": "flag",
"description": "Set if the time-zone heuristic indicates US but the fetched country code doesn't" "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": { "SOCIAL_ENABLED_ON_SESSION": {
"expires_in_version": "never", "expires_in_version": "never",
"kind": "flag", "kind": "flag",