Bug 837292 - Part 3: Add a TelemetryEnabled flag to FHR. r=gps

This commit is contained in:
Richard Newman 2013-03-14 22:00:00 -07:00
parent d2b6632bd2
commit 756d780f59
2 changed files with 87 additions and 5 deletions

View File

@ -54,6 +54,13 @@ const DAILY_DISCRETE_NUMERIC_FIELD = {type: Metrics.Storage.FIELD_DAILY_DISCRETE
const DAILY_LAST_NUMERIC_FIELD = {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC};
const DAILY_COUNTER_FIELD = {type: Metrics.Storage.FIELD_DAILY_COUNTER};
// Preprocess to use the correct telemetry pref.
#ifdef MOZ_TELEMETRY_ON_BY_DEFAULT
const TELEMETRY_PREF = "toolkit.telemetry.enabledPreRelease";
#else
const TELEMETRY_PREF = "toolkit.telemetry.enabled";
#endif
/**
* Represents basic application state.
*
@ -68,7 +75,7 @@ AppInfoMeasurement.prototype = Object.freeze({
__proto__: Metrics.Measurement.prototype,
name: "appinfo",
version: 1,
version: 2,
fields: {
vendor: LAST_TEXT_FIELD,
@ -86,6 +93,28 @@ AppInfoMeasurement.prototype = Object.freeze({
hotfixVersion: LAST_TEXT_FIELD,
locale: LAST_TEXT_FIELD,
isDefaultBrowser: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
isTelemetryEnabled: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
},
});
/**
* Legacy version of app info before Telemetry was added.
*
* The "last" fields have all been removed. We only report the longitudinal
* field.
*/
function AppInfoMeasurement1() {
Metrics.Measurement.call(this);
}
AppInfoMeasurement1.prototype = Object.freeze({
__proto__: Metrics.Measurement.prototype,
name: "appinfo",
version: 1,
fields: {
isDefaultBrowser: {type: Metrics.Storage.FIELD_DAILY_LAST_NUMERIC},
},
});
@ -117,7 +146,11 @@ AppInfoProvider.prototype = Object.freeze({
name: "org.mozilla.appInfo",
measurementTypes: [AppInfoMeasurement, AppVersionMeasurement],
measurementTypes: [
AppInfoMeasurement,
AppInfoMeasurement1,
AppVersionMeasurement,
],
pullOnly: true,
@ -230,9 +263,16 @@ AppInfoProvider.prototype = Object.freeze({
}
// FUTURE this should be retrieved periodically or at upload time.
yield this._recordIsTelemetryEnabled(m);
yield this._recordDefaultBrowser(m);
},
_recordIsTelemetryEnabled: function (m) {
let enabled = TELEMETRY_PREF && this._prefs.get(TELEMETRY_PREF, false);
this._log.debug("Recording telemetry enabled (" + TELEMETRY_PREF + "): " + enabled);
yield m.setDailyLastNumeric("isTelemetryEnabled", enabled ? 1 : 0);
},
_recordDefaultBrowser: function (m) {
let shellService;
try {

View File

@ -6,6 +6,7 @@
const {interfaces: Ci, results: Cr, utils: Cu} = Components;
Cu.import("resource://gre/modules/Metrics.jsm");
Cu.import("resource://gre/modules/Services.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
Cu.import("resource://gre/modules/services/healthreport/providers.jsm");
Cu.import("resource://testing-common/services/healthreport/utils.jsm");
@ -29,12 +30,12 @@ add_task(function test_collect_smoketest() {
let now = new Date();
yield provider.collectConstantData();
let m = provider.getMeasurement("appinfo", 1);
let m = provider.getMeasurement("appinfo", 2);
let data = yield storage.getMeasurementValues(m.id);
let serializer = m.serializer(m.SERIALIZE_JSON);
let d = serializer.singular(data.singular);
do_check_eq(d._v, 1);
do_check_eq(d._v, 2);
do_check_eq(d.vendor, "Mozilla");
do_check_eq(d.name, "xpcshell");
do_check_eq(d.id, "xpcshell@tests.mozilla.org");
@ -48,8 +49,9 @@ add_task(function test_collect_smoketest() {
do_check_eq(data.days.size, 1);
do_check_true(data.days.hasDay(now));
let day = data.days.getDay(now);
do_check_eq(day.size, 1);
do_check_eq(day.size, 2);
do_check_true(day.has("isDefaultBrowser"));
do_check_true(day.has("isTelemetryEnabled"));
// TODO Bug 827189 Actually test this properly. On some local builds, this
// is always -1 (the service throws). On buildbot, it seems to always be 0.
@ -112,3 +114,43 @@ add_task(function test_record_version_change() {
yield provider.shutdown();
yield storage.close();
});
add_task(function test_record_telemetry() {
let storage = yield Metrics.Storage("record_telemetry");
let provider;
// We set both prefs, so we don't have to fight the preprocessor.
function setTelemetry(bool) {
Services.prefs.setBoolPref("toolkit.telemetry.enabled", bool);
Services.prefs.setBoolPref("toolkit.telemetry.enabledPreRelease", bool);
}
let now = new Date();
setTelemetry(true);
provider = new AppInfoProvider();
yield provider.init(storage);
yield provider.onInit();
yield provider.collectConstantData();
let m = provider.getMeasurement("appinfo", 2);
let data = yield m.getValues();
let d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now));
do_check_eq(1, d.isTelemetryEnabled);
yield provider.shutdown();
setTelemetry(false);
provider = new AppInfoProvider();
yield provider.init(storage);
yield provider.onInit();
yield provider.collectConstantData();
m = provider.getMeasurement("appinfo", 2);
data = yield m.getValues();
d = yield m.serializer(m.SERIALIZE_JSON).daily(data.days.getDay(now));
do_check_eq(0, d.isTelemetryEnabled);
yield provider.shutdown();
yield storage.close();
});