mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-13 05:15:45 +00:00
Bug 1122480 - Part 1 - Allow collecting the current ping data from TelemetryController. r=rvitillo
This commit is contained in:
parent
15408ebb1e
commit
ec775ba761
@ -44,7 +44,6 @@ const PREF_UNIFIED = PREF_BRANCH + "unified";
|
||||
const IS_UNIFIED_TELEMETRY = Preferences.get(PREF_UNIFIED, false);
|
||||
|
||||
const PING_FORMAT_VERSION = 4;
|
||||
const PING_TYPE_MAIN = "main";
|
||||
|
||||
// Delay before intializing telemetry (ms)
|
||||
const TELEMETRY_DELAY = 60000;
|
||||
@ -63,6 +62,13 @@ const MIDNIGHT_TOLERANCE_FUZZ_MS = 5 * 60 * 1000;
|
||||
const MIDNIGHT_FUZZING_INTERVAL_MS = 60 * 60 * 1000;
|
||||
const MIDNIGHT_FUZZING_DELAY_MS = Math.random() * MIDNIGHT_FUZZING_INTERVAL_MS;
|
||||
|
||||
// Ping types.
|
||||
const PING_TYPE_MAIN = "main";
|
||||
|
||||
// Session ping reasons.
|
||||
const REASON_GATHER_PAYLOAD = "gather-payload";
|
||||
const REASON_GATHER_SUBSESSION_PAYLOAD = "gather-subsession-payload";
|
||||
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "ClientID",
|
||||
"resource://gre/modules/ClientID.jsm");
|
||||
XPCOMUtils.defineLazyServiceGetter(this, "Telemetry",
|
||||
@ -82,6 +88,8 @@ XPCOMUtils.defineLazyModuleGetter(this, "UpdateChannel",
|
||||
"resource://gre/modules/UpdateChannel.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryArchive",
|
||||
"resource://gre/modules/TelemetryArchive.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "TelemetrySession",
|
||||
"resource://gre/modules/TelemetrySession.jsm");
|
||||
|
||||
/**
|
||||
* Setup Telemetry logging. This function also gets called when loggin related
|
||||
@ -212,6 +220,16 @@ this.TelemetryController = Object.freeze({
|
||||
return Impl.submitExternalPing(aType, aPayload, aOptions);
|
||||
},
|
||||
|
||||
/**
|
||||
* Get the current session ping data as it would be sent out or stored.
|
||||
*
|
||||
* @param {bool} aSubsession Whether to get subsession data. Optional, defaults to false.
|
||||
* @return {object} The current ping data in object form.
|
||||
*/
|
||||
getCurrentPingData: function(aSubsession = false) {
|
||||
return Impl.getCurrentPingData(aSubsession);
|
||||
},
|
||||
|
||||
/**
|
||||
* Add the ping to the pending ping list and save all pending pings.
|
||||
*
|
||||
@ -1189,4 +1207,16 @@ let Impl = {
|
||||
promiseInitialized: function() {
|
||||
return this._delayedInitTaskDeferred.promise;
|
||||
},
|
||||
|
||||
getCurrentPingData: function(aSubsession) {
|
||||
this._log.trace("getCurrentPingData - subsession: " + aSubsession)
|
||||
|
||||
const reason = aSubsession ? REASON_GATHER_PAYLOAD : REASON_GATHER_SUBSESSION_PAYLOAD;
|
||||
const type = PING_TYPE_MAIN;
|
||||
const payload = TelemetrySession.getPayload(reason);
|
||||
const options = { addClientId: true, addEnvironment: true };
|
||||
const ping = this.assemblePing(type, payload, options);
|
||||
|
||||
return ping;
|
||||
},
|
||||
};
|
||||
|
@ -41,6 +41,7 @@ const REASON_ABORTED_SESSION = "aborted-session";
|
||||
const REASON_DAILY = "daily";
|
||||
const REASON_SAVED_SESSION = "saved-session";
|
||||
const REASON_GATHER_PAYLOAD = "gather-payload";
|
||||
const REASON_GATHER_SUBSESSION_PAYLOAD = "gather-subsession-payload";
|
||||
const REASON_TEST_PING = "test-ping";
|
||||
const REASON_ENVIRONMENT_CHANGE = "environment-change";
|
||||
const REASON_SHUTDOWN = "shutdown";
|
||||
|
@ -7,6 +7,7 @@
|
||||
"use strict";
|
||||
|
||||
Cu.import("resource://gre/modules/TelemetryController.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
|
||||
Cu.import("resource://gre/modules/TelemetryArchive.jsm", this);
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm", this);
|
||||
Cu.import("resource://gre/modules/osfile.jsm", this);
|
||||
@ -17,6 +18,7 @@ XPCOMUtils.defineLazyGetter(this, "gPingsArchivePath", function() {
|
||||
return OS.Path.join(OS.Constants.Path.profileDir, "datareporting", "archived");
|
||||
});
|
||||
|
||||
const Telemetry = Cc["@mozilla.org/base/telemetry;1"].getService(Ci.nsITelemetry);
|
||||
|
||||
function run_test() {
|
||||
do_get_profile(true);
|
||||
@ -165,3 +167,32 @@ add_task(function* test_clientId() {
|
||||
// Finish setup.
|
||||
yield promiseSetup;
|
||||
});
|
||||
|
||||
add_task(function* test_currentPingData() {
|
||||
yield TelemetrySession.setup();
|
||||
|
||||
// Setup test data.
|
||||
let h = Telemetry.getHistogramById("TELEMETRY_TEST_COUNT");
|
||||
h.clear();
|
||||
h.add(1);
|
||||
let k = Telemetry.getKeyedHistogramById("TELEMETRY_TEST_KEYED_FLAG");
|
||||
k.clear();
|
||||
k.add("a", 1);
|
||||
|
||||
// Get current ping data objects and check that their data is sane.
|
||||
for (let subsession of [true, false]) {
|
||||
let ping = yield TelemetryController.getCurrentPingData(subsession);
|
||||
|
||||
Assert.ok(!!ping, "Should have gotten a ping.");
|
||||
Assert.equal(ping.type, "main", "Ping should have correct type.");
|
||||
Assert.equal(ping.payload.info.reason, subsession ? "gather-payload" : "gather-subsession-payload",
|
||||
"Ping should have the correct reason.");
|
||||
|
||||
let id = "TELEMETRY_TEST_COUNT";
|
||||
Assert.ok(id in ping.payload.histograms, "Payload should have test count histogram.");
|
||||
Assert.equal(ping.payload.histograms[id].sum, 1, "Test count value should match.");
|
||||
id = "TELEMETRY_TEST_KEYED_FLAG";
|
||||
Assert.ok(id in ping.payload.keyedHistograms, "Payload should have keyed test histogram.");
|
||||
Assert.equal(ping.payload.keyedHistograms[id]["a"].sum, 1, "Keyed test value should match.");
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user