From 62654a44a2f7c2d064a49461c0bcb05c02c889bd Mon Sep 17 00:00:00 2001 From: Alessio Placitelli Date: Tue, 2 Jun 2015 01:41:00 +0200 Subject: [PATCH] Bug 1149537 - Daily subsession splits should not occur before midnight. r=gfritzsche --- .../components/telemetry/TelemetrySend.jsm | 33 ++++++------------- .../components/telemetry/TelemetrySession.jsm | 25 ++------------ 2 files changed, 13 insertions(+), 45 deletions(-) diff --git a/toolkit/components/telemetry/TelemetrySend.jsm b/toolkit/components/telemetry/TelemetrySend.jsm index dac97691ef17..17d324b3d261 100644 --- a/toolkit/components/telemetry/TelemetrySend.jsm +++ b/toolkit/components/telemetry/TelemetrySend.jsm @@ -53,8 +53,6 @@ const IS_UNIFIED_TELEMETRY = Preferences.get(PREF_UNIFIED, false); const PING_FORMAT_VERSION = 4; -// 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. @@ -432,39 +430,28 @@ let TelemetrySendImpl = { /** * This helper calculates the next time that we can send pings at. - * Currently this mostly redistributes ping sends around midnight to avoid submission - * spikes around local midnight for daily pings. + * Currently this mostly redistributes ping sends from midnight until one hour after + * to avoid submission spikes around local midnight for daily pings. * * @param now Date The current time. * @return Number The next time (ms from UNIX epoch) when we can send pings. */ _getNextPingSendTime: function(now) { - // 1. First we check if the time is between 11pm and 1am. If it's not, we send + // 1. First we check if the time is between 0am 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 + // 2. If we confirmed the time is indeed between 0am and 1am in step 1, we disallow + // sending before (midnight + fuzzing delay), which is a random time between 0am-1am // (decided at startup). - const midnightDate = Utils.getNearestMidnight(now, MIDNIGHT_FUZZING_INTERVAL_MS); - - // Don't delay ping if we are not close to midnight. - if (!midnightDate) { + const midnight = Utils.truncateToDays(now); + // Don't delay pings if we are not within the fuzzing interval. + if ((now.getTime() - midnight.getTime()) > MIDNIGHT_FUZZING_INTERVAL_MS) { return now.getTime(); } // Delay ping send if we are within the midnight fuzzing range. - // This is from: |midnight - MIDNIGHT_TOLERANCE_FUZZ_MS| - // to: |midnight + MIDNIGHT_FUZZING_INTERVAL_MS| - const midnightRangeStart = midnightDate.getTime() - MIDNIGHT_TOLERANCE_FUZZ_MS; - if (now.getTime() >= midnightRangeStart) { - // We spread those ping sends out between |midnight| and |midnight + midnightPingFuzzingDelay|. - return midnightDate.getTime() + Policy.midnightPingFuzzingDelay(); - } - - return now.getTime(); + // We spread those ping sends out between |midnight| and |midnight + midnightPingFuzzingDelay|. + return midnight.getTime() + Policy.midnightPingFuzzingDelay(); }, /** diff --git a/toolkit/components/telemetry/TelemetrySession.jsm b/toolkit/components/telemetry/TelemetrySession.jsm index 6e5db9d4f214..d4a16cd2aaa5 100644 --- a/toolkit/components/telemetry/TelemetrySession.jsm +++ b/toolkit/components/telemetry/TelemetrySession.jsm @@ -439,11 +439,8 @@ let TelemetryScheduler = { _sentDailyPingToday: function(nowDate) { // This is today's date and also the previous midnight (0:00). 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. - return (this._lastDailyPingTime >= (checkDate.getTime() - SCHEDULER_MIDNIGHT_TOLERANCE_MS)); + // We consider a ping sent for today if it occured after or at 00:00 today. + return (this._lastDailyPingTime >= todayDate.getTime()); }, /** @@ -452,21 +449,12 @@ let TelemetryScheduler = { * @return {Boolean} True if we can send the daily ping, false otherwise. */ _isDailyPingDue: function(nowDate) { - const sentPingToday = this._sentDailyPingToday(nowDate); - // The daily ping is not due if we already sent one today. - if (sentPingToday) { + if (this._sentDailyPingToday(nowDate)) { this._log.trace("_isDailyPingDue - already sent one today"); return false; } - 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?"); - return true; - } - // Avoid overly short sessions. const timeSinceLastDaily = nowDate.getTime() - this._lastDailyPingTime; if (timeSinceLastDaily < MIN_SUBSESSION_LENGTH_MS) { @@ -474,13 +462,6 @@ let TelemetryScheduler = { return false; } - // To fight jank, we allow daily pings to be collected on user idle before midnight - // within the tolerance interval. - if (!this._isUserIdle && (nowDate.getTime() < nearestMidnight.getTime())) { - this._log.trace("_isDailyPingDue - waiting for user idle period"); - return false; - } - this._log.trace("_isDailyPingDue - is due"); return true; },