Bug 830922 - Include version inside measurement payload. r=gps
authorRichard Newman <rnewman@mozilla.com>
Fri, 25 Jan 2013 00:32:33 -0800
changeset 129848 e49e91aefec47ec64691345f07bc098d1ae375c9
parent 129847 2616a8dbe520e4b91c4faa39cde06c841b314283
child 129849 0f28b10053de6f87ee40a4aead2af75105b27b4e
push id2323
push userbbajaj@mozilla.com
push dateMon, 01 Apr 2013 19:47:02 +0000
treeherdermozilla-beta@7712be144d91 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgps
bugs830922
milestone21.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 830922 - Include version inside measurement payload. r=gps
services/healthreport/healthreporter.jsm
services/healthreport/providers.jsm
services/healthreport/tests/xpcshell/test_healthreporter.js
services/healthreport/tests/xpcshell/test_provider_addons.js
services/healthreport/tests/xpcshell/test_provider_appinfo.js
services/healthreport/tests/xpcshell/test_provider_sessions.js
services/healthreport/tests/xpcshell/test_provider_sysinfo.js
services/metrics/dataprovider.jsm
services/metrics/tests/xpcshell/test_metrics_provider.js
--- a/services/healthreport/healthreporter.jsm
+++ b/services/healthreport/healthreporter.jsm
@@ -622,20 +622,22 @@ HealthReporter.prototype = Object.freeze
     for (let provider of this._collector.providers) {
       let providerName = provider.name;
 
       let providerEntry = {
         measurements: {},
       };
 
       for (let [measurementKey, measurement] of provider.measurements) {
-        let name = providerName + "." + measurement.name + "." + measurement.version;
+        let name = providerName + "." + measurement.name;
 
         let serializer;
         try {
+          // The measurement is responsible for returning a serializer which
+          // is aware of the measurement version.
           serializer = measurement.serializer(measurement.SERIALIZE_JSON);
         } catch (ex) {
           this._log.warn("Error obtaining serializer for measurement: " + name +
                          ": " + CommonUtils.exceptionStr(ex));
           errors.push("Could not obtain serializer: " + name);
           continue;
         }
 
--- a/services/healthreport/providers.jsm
+++ b/services/healthreport/providers.jsm
@@ -389,17 +389,17 @@ CurrentSessionMeasurement.prototype = Ob
 
     return Promise.resolve({
       days: new Metrics.DailyValues(),
       singular: fields,
     });
   },
 
   _serializeJSONSingular: function (data) {
-    let result = {};
+    let result = {"_v": this.version};
 
     for (let [field, value] of data) {
       result[field] = value[1];
     }
 
     return result;
   },
 });
@@ -530,17 +530,19 @@ ActiveAddonsMeasurement.prototype = Obje
 
   _serializeJSONSingular: function (data) {
     if (!data.has("addons")) {
       this._log.warn("Don't have active addons info. Weird.");
       return null;
     }
 
     // Exceptions are caught in the caller.
-    return JSON.parse(data.get("addons")[1]);
+    let result = JSON.parse(data.get("addons")[1]);
+    result._v = this.version;
+    return result;
   },
 });
 
 
 function AddonCountsMeasurement() {
   Metrics.Measurement.call(this);
 }
 
--- a/services/healthreport/tests/xpcshell/test_healthreporter.js
+++ b/services/healthreport/tests/xpcshell/test_healthreporter.js
@@ -199,18 +199,20 @@ add_task(function test_json_payload_dumm
   let reporter = yield getReporter("json_payload_dummy_provider");
 
   yield reporter.registerProvider(new DummyProvider());
   yield reporter.collectMeasurements();
   let payload = yield reporter.getJSONPayload();
   print(payload);
   let o = JSON.parse(payload);
 
+  let name = "DummyProvider.DummyMeasurement";
   do_check_eq(Object.keys(o.data.last).length, 1);
-  do_check_true("DummyProvider.DummyMeasurement.1" in o.data.last);
+  do_check_true(name in o.data.last);
+  do_check_eq(o.data.last[name]._v, 1);
 
   reporter._shutdown();
 });
 
 add_task(function test_json_payload_multiple_days() {
   let reporter = yield getReporter("json_payload_multiple_days");
   let provider = new DummyProvider();
   yield reporter.registerProvider(provider);
--- a/services/healthreport/tests/xpcshell/test_provider_addons.js
+++ b/services/healthreport/tests/xpcshell/test_provider_addons.js
@@ -106,19 +106,20 @@ add_task(function test_collect() {
   do_check_eq(typeof(value), "object");
   do_check_eq(Object.keys(value).length, 2);
   do_check_true("addon0" in value);
   do_check_true("addon1" in value);
 
   let serializer = active.serializer(active.SERIALIZE_JSON);
   let serialized = serializer.singular(data.singular);
   do_check_eq(typeof(serialized), "object");
-  do_check_eq(Object.keys(serialized).length, 2);
+  do_check_eq(Object.keys(serialized).length, 3);   // Our two keys, plus _v.
   do_check_true("addon0" in serialized);
   do_check_true("addon1" in serialized);
+  do_check_eq(serialized._v, 1);
 
   let counts = provider.getMeasurement("counts", 1);
   data = yield counts.getValues();
   do_check_eq(data.days.size, 1);
   do_check_eq(data.singular.size, 0);
   do_check_true(data.days.hasDay(now));
 
   value = data.days.getDay(now);
--- a/services/healthreport/tests/xpcshell/test_provider_appinfo.js
+++ b/services/healthreport/tests/xpcshell/test_provider_appinfo.js
@@ -29,16 +29,17 @@ add_task(function test_collect_smoketest
   let now = new Date();
   yield provider.collectConstantData();
 
   let m = provider.getMeasurement("appinfo", 1);
   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.vendor, "Mozilla");
   do_check_eq(d.name, "xpcshell");
   do_check_eq(d.id, "xpcshell@tests.mozilla.org");
   do_check_eq(d.version, "1");
   do_check_eq(d.appBuildID, "20121107");
   do_check_eq(d.platformVersion, "p-ver");
   do_check_eq(d.platformBuildID, "20121106");
   do_check_eq(d.os, "XPCShell");
--- a/services/healthreport/tests/xpcshell/test_provider_sessions.js
+++ b/services/healthreport/tests/xpcshell/test_provider_sessions.js
@@ -165,16 +165,17 @@ add_task(function test_serialization() {
 
   let current = provider.getMeasurement("current", 2);
   let data = yield current.getValues();
   do_check_true("singular" in data);
 
   let serializer = current.serializer(current.SERIALIZE_JSON);
   let fields = serializer.singular(data.singular);
 
+  do_check_eq(fields._v, 2);
   do_check_eq(fields.activeTicks, 0);
   do_check_eq(fields.startDay, Metrics.dateToDays(recorder.startDate));
   do_check_eq(fields.main, 500);
   do_check_eq(fields.firstPaint, 1000);
   do_check_eq(fields.sessionRestored, 1500);
   do_check_true(fields.totalTime > 0);
 
   yield provider.shutdown();
--- a/services/healthreport/tests/xpcshell/test_provider_sysinfo.js
+++ b/services/healthreport/tests/xpcshell/test_provider_sysinfo.js
@@ -27,14 +27,15 @@ add_task(function test_collect_smoketest
 
   yield provider.collectConstantData();
 
   let m = provider.getMeasurement("sysinfo", 1);
   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_true(d.cpuCount > 0);
   do_check_neq(d.name, null);
 
   yield storage.close();
 });
 
--- a/services/metrics/dataprovider.jsm
+++ b/services/metrics/dataprovider.jsm
@@ -241,17 +241,17 @@ Measurement.prototype = Object.freeze({
     return this.storage.deleteLastNumericFromFieldID(this.fieldID(field));
   },
 
   deleteLastText: function (field) {
     return this.storage.deleteLastTextFromFieldID(this.fieldID(field));
   },
 
   _serializeJSONSingular: function (data) {
-    let result = {};
+    let result = {"_v": this.version};
 
     for (let [field, data] of data) {
       // There could be legacy fields in storage we no longer care about.
       if (!this._fieldsByName.has(field)) {
         continue;
       }
 
       let type = this.fieldType(field);
@@ -273,17 +273,17 @@ Measurement.prototype = Object.freeze({
           throw new Error("Unknown field type: " + type);
       }
     }
 
     return result;
   },
 
   _serializeJSONDay: function (data) {
-    let result = {};
+    let result = {"_v": this.version};
 
     for (let [field, data] of data) {
       if (!this._fieldsByName.has(field)) {
         continue;
       }
 
       let type = this.fieldType(field);
 
--- a/services/metrics/tests/xpcshell/test_metrics_provider.js
+++ b/services/metrics/tests/xpcshell/test_metrics_provider.js
@@ -251,25 +251,27 @@ add_task(function test_serialize_json_de
   m.setLastNumeric("last-numeric", 6, now);
   yield m.setLastText("last-text", "hello", now);
 
   let data = yield provider.storage.getMeasurementValues(m.id);
 
   let serializer = m.serializer(m.SERIALIZE_JSON);
   let formatted = serializer.singular(data.singular);
 
-  do_check_eq(Object.keys(formatted).length, 2);
+  do_check_eq(Object.keys(formatted).length, 3);  // Our keys + _v.
   do_check_true("last-numeric" in formatted);
   do_check_true("last-text" in formatted);
   do_check_eq(formatted["last-numeric"], 6);
   do_check_eq(formatted["last-text"], "hello");
+  do_check_eq(formatted["_v"], 1);
 
   formatted = serializer.daily(data.days.getDay(now));
-  do_check_eq(Object.keys(formatted).length, 5);
+  do_check_eq(Object.keys(formatted).length, 6);  // Our keys + _v.
   do_check_eq(formatted["daily-counter"], 2);
+  do_check_eq(formatted["_v"], 1);
 
   do_check_true(Array.isArray(formatted["daily-discrete-numeric"]));
   do_check_eq(formatted["daily-discrete-numeric"].length, 2);
   do_check_eq(formatted["daily-discrete-numeric"][0], 1);
   do_check_eq(formatted["daily-discrete-numeric"][1], 2);
 
   do_check_true(Array.isArray(formatted["daily-discrete-text"]));
   do_check_eq(formatted["daily-discrete-text"].length, 2);