Bug 1135791 - Add a new unified ping type: "saved-session". r=gfritzsche

This commit is contained in:
Alessio Placitelli 2015-02-25 23:54:34 +01:00
parent c7eceb1ee2
commit d5873fb47b
4 changed files with 33 additions and 14 deletions

View File

@ -31,6 +31,7 @@ const IS_CONTENT_PROCESS = (function() {
// When modifying the payload in incompatible ways, please bump this version number
const PAYLOAD_VERSION = 4;
const PING_TYPE_MAIN = "main";
const PING_TYPE_SAVED_SESSION = "saved-session";
const RETENTION_DAYS = 14;
const REASON_DAILY = "daily";
@ -149,6 +150,21 @@ function truncateToDays(date) {
0, 0, 0, 0);
}
/**
* Get the ping type based on the payload.
* @param {Object} aPayload The ping payload.
* @return {String} A string representing the ping type.
*/
function getPingType(aPayload) {
// To remain consistent with server-side ping handling, set "saved-session" as the ping
// type for "saved-session" payload reasons.
if (aPayload.info.reason == REASON_SAVED_SESSION) {
return PING_TYPE_SAVED_SESSION;
}
return PING_TYPE_MAIN;
}
/**
* Date.toISOString() gives us UTC times, this gives us local times in the ISO date format.
* http://www.w3.org/TR/NOTE-datetime
@ -991,7 +1007,7 @@ let Impl = {
addClientId: true,
addEnvironment: true,
};
return TelemetryPing.send(PING_TYPE_MAIN, payload, options);
return TelemetryPing.send(getPingType(payload), payload, options);
},
attachObservers: function attachObservers() {
@ -1213,7 +1229,7 @@ let Impl = {
addClientId: true,
addEnvironment: true,
};
return TelemetryPing.savePendingPings(PING_TYPE_MAIN, payload, options);
return TelemetryPing.savePendingPings(getPingType(payload), payload, options);
},
testSaveHistograms: function testSaveHistograms(file) {
@ -1226,7 +1242,7 @@ let Impl = {
overwrite: true,
filePath: file.path,
};
return TelemetryPing.testSavePingToFile(PING_TYPE_MAIN, payload, options);
return TelemetryPing.testSavePingToFile(getPingType(payload), payload, options);
},
/**
@ -1383,7 +1399,7 @@ let Impl = {
addEnvironment: true,
overwrite: true,
};
TelemetryPing.savePing(PING_TYPE_MAIN, payload, options);
TelemetryPing.savePing(getPingType(payload), payload, options);
}
break;
#endif
@ -1481,7 +1497,7 @@ let Impl = {
addClientId: true,
addEnvironment: true,
};
let promise = TelemetryPing.send(PING_TYPE_MAIN, payload, options);
let promise = TelemetryPing.send(getPingType(payload), payload, options);
this._rescheduleDailyTimer();
// Return the promise so tests can wait on the ping submission.
@ -1552,7 +1568,7 @@ let Impl = {
addClientId: true,
addEnvironment: true,
};
let promise = TelemetryPing.send(PING_TYPE_MAIN, payload, options);
let promise = TelemetryPing.send(getPingType(payload), payload, options);
},
_isClassicReason: function(reason) {

View File

@ -17,7 +17,7 @@ Finally, the structure also contains the `payload`, which is the specific data s
Structure::
{
type: <string>, // "main", "activation", "deletion", ...
type: <string>, // "main", "activation", "deletion", "saved-session", ...
id: <UUID>, // a UUID that identifies this ping
creationDate: <ISO date>, // the date the ping was generated
version: <number>, // the version of the ping format, currently 4

View File

@ -23,6 +23,7 @@ Ping types
==========
* :doc:`main <main-ping>` - contains the information collected by Telemetry (Histograms, hang stacks, ...)
* :doc:`saved-session <main-ping>` - contains the *"classic"* Telemetry payload with measurements covering the whole browser session. Used to make storage of saved-session easier server-side.
* ``activation`` - *planned* - sent right after installation or profile creation
* ``upgrade`` - *planned* - sent right after an upgrade
* ``deletion`` - *planned* - on opt-out we may have to tell the server to delete user data

View File

@ -29,6 +29,7 @@ Cu.import("resource://gre/modules/osfile.jsm", this);
const PING_FORMAT_VERSION = 4;
const PING_TYPE_MAIN = "main";
const PING_TYPE_SAVED_SESSION = "saved-session";
const REASON_SAVED_SESSION = "saved-session";
const REASON_TEST_PING = "test-ping";
@ -634,17 +635,18 @@ add_task(function* test_saveLoadPing() {
let ping1 = decodeRequestPayload(request1);
let ping2 = decodeRequestPayload(request2);
checkPingFormat(ping1, PING_TYPE_MAIN, true, true);
checkPingFormat(ping2, PING_TYPE_MAIN, true, true);
// Check we have the correct two requests. Ordering is not guaranteed.
if (ping1.payload.info.reason === REASON_TEST_PING) {
// Until we change MainPing according to bug 1120982, common ping payload
// will contain another nested payload.
// Check we have the correct two requests. Ordering is not guaranteed. The ping type
// is encoded in the URL.
let requestTypeComponent = request1.path.split("/")[4];
if (requestTypeComponent === PING_TYPE_MAIN) {
checkPingFormat(ping1, PING_TYPE_MAIN, true, true);
checkPayload(ping1.payload, REASON_TEST_PING, 1);
checkPingFormat(ping2, PING_TYPE_SAVED_SESSION, true, true);
checkPayload(ping2.payload, REASON_SAVED_SESSION, 1);
} else {
checkPingFormat(ping1, PING_TYPE_SAVED_SESSION, true, true);
checkPayload(ping1.payload, REASON_SAVED_SESSION, 1);
checkPingFormat(ping2, PING_TYPE_MAIN, true, true);
checkPayload(ping2.payload, REASON_TEST_PING, 1);
}
});