зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1161515 - Add previousSessionId to Telemetry payloads. r=gfritzsche
This commit is contained in:
Родитель
bac683565f
Коммит
12bb801dbd
|
@ -744,6 +744,7 @@ this.TelemetrySession = Object.freeze({
|
|||
reset: function() {
|
||||
Impl._sessionId = null;
|
||||
Impl._subsessionId = null;
|
||||
Impl._previousSessionId = null;
|
||||
Impl._previousSubsessionId = null;
|
||||
Impl._subsessionCounter = 0;
|
||||
Impl._profileSubsessionCounter = 0;
|
||||
|
@ -816,6 +817,8 @@ let Impl = {
|
|||
_sessionId: null,
|
||||
// Random subsession id.
|
||||
_subsessionId: null,
|
||||
// Session id of the previous session, null on first run.
|
||||
_previousSessionId: null,
|
||||
// Subsession id of the previous subsession (even if it was in a different session),
|
||||
// null on first run.
|
||||
_previousSubsessionId: null,
|
||||
|
@ -1122,6 +1125,7 @@ let Impl = {
|
|||
|
||||
sessionId: this._sessionId,
|
||||
subsessionId: this._subsessionId,
|
||||
previousSessionId: this._previousSessionId,
|
||||
previousSubsessionId: this._previousSubsessionId,
|
||||
|
||||
subsessionCounter: this._subsessionCounter,
|
||||
|
@ -1916,13 +1920,14 @@ let Impl = {
|
|||
let dataFile = OS.Path.join(OS.Constants.Path.profileDir, DATAREPORTING_DIRECTORY,
|
||||
SESSION_STATE_FILE_NAME);
|
||||
|
||||
// Try to load the "profileSubsessionCounter" from the state file.
|
||||
// Try to load info about the previous session from the state file.
|
||||
try {
|
||||
let data = yield CommonUtils.readJSON(dataFile);
|
||||
if (data &&
|
||||
"profileSubsessionCounter" in data &&
|
||||
typeof(data.profileSubsessionCounter) == "number" &&
|
||||
"subsessionId" in data) {
|
||||
"subsessionId" in data && "sessionId" in data) {
|
||||
this._previousSessionId = data.sessionId;
|
||||
this._previousSubsessionId = data.subsessionId;
|
||||
// Add |_subsessionCounter| to the |_profileSubsessionCounter| to account for
|
||||
// new subsession while loading still takes place. This will always be exactly
|
||||
|
@ -1942,6 +1947,7 @@ let Impl = {
|
|||
*/
|
||||
_getSessionDataObject: function() {
|
||||
return {
|
||||
sessionId: this._sessionId,
|
||||
subsessionId: this._subsessionId,
|
||||
profileSubsessionCounter: this._profileSubsessionCounter,
|
||||
};
|
||||
|
|
|
@ -30,6 +30,7 @@ Structure::
|
|||
|
||||
sessionId: <uuid>, // random session id, shared by subsessions
|
||||
subsessionId: <uuid>, // random subsession id
|
||||
previousSessionId: <uuid>, // session id of the previous session, null on first run.
|
||||
previousSubsessionId: <uuid>, // subsession id of the previous subsession (even if it was in a different session),
|
||||
// null on first run.
|
||||
|
||||
|
|
|
@ -42,6 +42,8 @@ let promiseValidateArchivedPings = Task.async(function*(aExpectedReasons) {
|
|||
let previousPing = yield TelemetryArchive.promiseArchivedPingById(list[0].id);
|
||||
Assert.equal(aExpectedReasons.shift(), previousPing.payload.info.reason,
|
||||
"Telemetry should only get pings with expected reasons.");
|
||||
Assert.equal(previousPing.payload.info.previousSessionId, null,
|
||||
"The first session must report a null previous session id.");
|
||||
Assert.equal(previousPing.payload.info.previousSubsessionId, null,
|
||||
"The first subsession must report a null previous subsession id.");
|
||||
Assert.equal(previousPing.payload.info.profileSubsessionCounter, 1,
|
||||
|
@ -50,6 +52,7 @@ let promiseValidateArchivedPings = Task.async(function*(aExpectedReasons) {
|
|||
"subsessionCounter must be 1 the first time.");
|
||||
|
||||
let expectedSubsessionCounter = 1;
|
||||
let expectedPreviousSessionId = previousPing.payload.info.sessionId;
|
||||
|
||||
for (let i = 1; i < list.length; i++) {
|
||||
let currentPing = yield TelemetryArchive.promiseArchivedPingById(list[i].id);
|
||||
|
@ -59,6 +62,8 @@ let promiseValidateArchivedPings = Task.async(function*(aExpectedReasons) {
|
|||
|
||||
Assert.equal(aExpectedReasons.shift(), currentInfo.reason,
|
||||
"Telemetry should only get pings with expected reasons.");
|
||||
Assert.equal(currentInfo.previousSessionId, expectedPreviousSessionId,
|
||||
"Telemetry must correctly chain session identifiers.");
|
||||
Assert.equal(currentInfo.previousSubsessionId, previousInfo.subsessionId,
|
||||
"Telemetry must correctly chain subsession identifiers.");
|
||||
Assert.equal(currentInfo.profileSubsessionCounter, previousInfo.profileSubsessionCounter + 1,
|
||||
|
@ -70,8 +75,13 @@ let promiseValidateArchivedPings = Task.async(function*(aExpectedReasons) {
|
|||
previousPing = currentPing;
|
||||
// Reset the expected subsession counter, if required. Otherwise increment the expected
|
||||
// subsession counter.
|
||||
expectedSubsessionCounter =
|
||||
SESSION_END_PING_REASONS.has(currentInfo.reason) ? 1 : (expectedSubsessionCounter + 1);
|
||||
// If this is the final subsession of a session we need to update expected values accordingly.
|
||||
if (SESSION_END_PING_REASONS.has(currentInfo.reason)) {
|
||||
expectedSubsessionCounter = 1;
|
||||
expectedPreviousSessionId = currentInfo.sessionId;
|
||||
} else {
|
||||
expectedSubsessionCounter++;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1167,6 +1167,7 @@ add_task(function* test_savedSessionData() {
|
|||
// Write test data to the session data file.
|
||||
const dataFilePath = OS.Path.join(DATAREPORTING_PATH, "session-state.json");
|
||||
const sessionState = {
|
||||
sessionId: null,
|
||||
subsessionId: null,
|
||||
profileSubsessionCounter: 3785,
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче