Bug 1140037 - Improve midnight fuzzing readability and comments. r=vladan

This commit is contained in:
Georg Fritzsche
2015-05-21 15:12:43 +07:00
parent 7ce65ac743
commit e33cc2d7bc
2 changed files with 23 additions and 11 deletions

View File

@@ -24,6 +24,8 @@ Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
const Utils = TelemetryUtils;
const LOGGER_NAME = "Toolkit.Telemetry";
const LOGGER_PREFIX = "TelemetryController::";
@@ -52,12 +54,11 @@ const TELEMETRY_TEST_DELAY = 100;
// Timeout after which we consider a ping submission failed.
const PING_SUBMIT_TIMEOUT_MS = 2 * 60 * 1000;
// We treat pings before midnight as happening "at midnight" with this tolerance.
const MIDNIGHT_TOLERANCE_MS = 15 * 60 * 1000;
// For midnight fuzzing we want to affect pings around midnight with this tolerance.
const MIDNIGHT_TOLERANCE_FUZZ_MS = 5 * 60 * 1000;
// We try to spread "midnight" pings out over this interval.
const MIDNIGHT_FUZZING_INTERVAL_MS = 60 * 60 * 1000;
// We delay sending "midnight" pings on this client by this interval.
const MIDNIGHT_FUZZING_DELAY_MS = Math.random() * MIDNIGHT_FUZZING_INTERVAL_MS;
// Ping types.
@@ -532,7 +533,16 @@ let Impl = {
* @return Number The next time (ms from UNIX epoch) when we can send pings.
*/
_getNextPingSendTime: function(now) {
const midnight = TelemetryUtils.getNearestMidnight(now, MIDNIGHT_FUZZING_INTERVAL_MS);
// 1. First we check if the time is between 11pm and 1am. If it's not, we send
// immediately.
// 2. If we confirmed the time is indeed between 11pm and 1am in step 1, we
// then check if the time is also 11:55pm or later. If it's not, we send
// immediately.
// 3. Finally, if the time is between 11:55pm and 1am, we disallow sending
// before (midnight + fuzzing delay), which is a random time between 12am-1am
// (decided at startup).
const midnight = Utils.getNearestMidnight(now, MIDNIGHT_FUZZING_INTERVAL_MS);
// Don't delay ping if we are not close to midnight.
if (!midnight) {

View File

@@ -22,6 +22,8 @@ Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/Timer.jsm");
Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
const Utils = TelemetryUtils;
const myScope = this;
const IS_CONTENT_PROCESS = (function() {
@@ -424,7 +426,7 @@ let TelemetryScheduler = {
timeout = SCHEDULER_TICK_IDLE_INTERVAL_MS;
// We need to make sure though that we don't miss sending pings around
// midnight when we use the longer idle intervals.
const nextMidnight = TelemetryUtils.getNextMidnight(now);
const nextMidnight = Utils.getNextMidnight(now);
timeout = Math.min(timeout, nextMidnight.getTime() - now.getTime());
}
@@ -435,8 +437,8 @@ let TelemetryScheduler = {
_sentDailyPingToday: function(nowDate) {
// This is today's date and also the previous midnight (0:00).
const todayDate = TelemetryUtils.truncateToDays(nowDate);
const nearestMidnight = TelemetryUtils.getNearestMidnight(nowDate, SCHEDULER_MIDNIGHT_TOLERANCE_MS);
const todayDate = Utils.truncateToDays(nowDate);
const nearestMidnight = Utils.getNearestMidnight(nowDate, SCHEDULER_MIDNIGHT_TOLERANCE_MS);
// If we are close to midnight, we check against that, otherwise against the last midnight.
const checkDate = nearestMidnight || todayDate;
// We consider a ping sent for today if it occured after midnight, or prior within the tolerance.
@@ -457,7 +459,7 @@ let TelemetryScheduler = {
return false;
}
const nearestMidnight = TelemetryUtils.getNearestMidnight(nowDate, SCHEDULER_MIDNIGHT_TOLERANCE_MS);
const nearestMidnight = Utils.getNearestMidnight(nowDate, SCHEDULER_MIDNIGHT_TOLERANCE_MS);
if (!sentPingToday && !nearestMidnight) {
// Computer must have gone to sleep, the daily ping is overdue.
this._log.trace("_isDailyPingDue - daily ping is overdue... computer went to sleep?");
@@ -567,7 +569,7 @@ let TelemetryScheduler = {
let nextSessionCheckpoint =
this._lastSessionCheckpointTime + ABORTED_SESSION_UPDATE_INTERVAL_MS;
let combineActions = (shouldSendDaily && isAbortedPingDue) || (shouldSendDaily &&
TelemetryUtils.areTimesClose(now, nextSessionCheckpoint,
Utils.areTimesClose(now, nextSessionCheckpoint,
SCHEDULER_COALESCE_THRESHOLD_MS));
if (combineActions) {
@@ -613,7 +615,7 @@ let TelemetryScheduler = {
// update the schedules.
this._saveAbortedPing(now.getTime(), competingPayload);
// If we're close to midnight, skip today's daily ping and reschedule it for tomorrow.
let nearestMidnight = TelemetryUtils.getNearestMidnight(now, SCHEDULER_MIDNIGHT_TOLERANCE_MS);
let nearestMidnight = Utils.getNearestMidnight(now, SCHEDULER_MIDNIGHT_TOLERANCE_MS);
if (nearestMidnight) {
this._lastDailyPingTime = now.getTime();
}
@@ -1102,8 +1104,8 @@ let Impl = {
getMetadata: function getMetadata(reason) {
this._log.trace("getMetadata - Reason " + reason);
let sessionStartDate = toLocalTimeISOString(TelemetryUtils.truncateToDays(this._sessionStartDate));
let subsessionStartDate = toLocalTimeISOString(TelemetryUtils.truncateToDays(this._subsessionStartDate));
let sessionStartDate = toLocalTimeISOString(Utils.truncateToDays(this._sessionStartDate));
let subsessionStartDate = toLocalTimeISOString(Utils.truncateToDays(this._subsessionStartDate));
// Compute the subsession length in milliseconds, then convert to seconds.
let subsessionLength =
Math.floor((Policy.now() - this._subsessionStartDate.getTime()) / 1000);