From 3cc9dc4388c04550f16716976e9220d845865d92 Mon Sep 17 00:00:00 2001 From: Rehan Dalal Date: Mon, 29 Jan 2018 22:27:30 -0500 Subject: [PATCH] Fix some prefs and match new schema --- extension/Config.jsm | 11 +++--- extension/bootstrap.js | 22 +++++------ extension/lib/LogHandler.jsm | 72 ++++++++++++++++-------------------- 3 files changed, 48 insertions(+), 57 deletions(-) diff --git a/extension/Config.jsm b/extension/Config.jsm index 8ce7867..bf17acf 100644 --- a/extension/Config.jsm +++ b/extension/Config.jsm @@ -4,10 +4,10 @@ Cu.import("resource://gre/modules/XPCOMUtils.jsm"); const EXPORTED_SYMBOLS = ["Config"]; -const TELEMETRY_ENV_PREF = "extensions.pioneer-online-news.telemetryEnv"; -const LOG_INTERVAL_PREF = "extensions.pioneer-online-news.logSubmissionInterval"; -const IDLE_DELAY_PREF = "extensions.pioneer-online-news.idleDelaySeconds"; -const LOG_UPLOAD_ATTEMPT_PREF = "extensions.pioneer-online-news.logUploadAttemptInterval"; +const TELEMETRY_ENV_PREF = "extensions.pioneer-pathfinder.telemetryEnv"; +const LOG_INTERVAL_PREF = "extensions.pioneer-pathfinder.logSubmissionInterval"; +const IDLE_DELAY_PREF = "extensions.pioneer-pathfinder.idleDelaySeconds"; +const LOG_UPLOAD_ATTEMPT_PREF = "extensions.pioneer-pathfinder.logUploadAttemptInterval"; const SECOND = 1000; const MINUTE = 60 * SECOND; @@ -17,10 +17,9 @@ const WEEK = 7 * DAY; const Config = { addonId: "pioneer-study-pathfinder@pioneer.mozilla.org", - studyName: "online-news", + studyName: "pathfinder", branches: [ { name: "control", weight: 1 }, - { name: "treatment", weight: 1, showDoorhanger: true }, ], telemetryEnv: Services.prefs.getCharPref(TELEMETRY_ENV_PREF, "prod"), diff --git a/extension/bootstrap.js b/extension/bootstrap.js index e446fc9..c231b84 100644 --- a/extension/bootstrap.js +++ b/extension/bootstrap.js @@ -36,7 +36,7 @@ const REASONS = { ADDON_DOWNGRADE: 8, // The add-on is being downgraded. }; const UI_AVAILABLE_NOTIFICATION = "sessionstore-windows-restored"; -const EXPIRATION_DATE_PREF = "extensions.pioneer-online-news.expirationDate"; +const EXPIRATION_DATE_PREF = "extensions.pioneer-pathfinder.expirationDate"; let isStartupFinished; @@ -55,12 +55,12 @@ this.Bootstrap = { return; } - const entries = [{ - url: 'pathfinder', + const payload = { + eventId: 'startup', timestamp: Math.round(Date.now() / 1000), - details: `startup:${reason}`, - }]; - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { entries }); + context: `${reason}`, + }; + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, payload); // Always set EXPIRATION_DATE_PREF if it not set, even if outside of install. // This is a failsafe if opt-out expiration doesn't work, so should be resilient. @@ -109,12 +109,12 @@ this.Bootstrap = { // It must already be removed! } - const entries = [{ - url: 'pathfinder', + const payload = { + eventId: 'shutdown', timestamp: Math.round(Date.now() / 1000), - details: `shutdown:${reason}`, - }]; - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { entries }); + context: `${reason}`, + }; + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, payload); if (isStartupFinished) { LogHandler.shutdown(); diff --git a/extension/lib/LogHandler.jsm b/extension/lib/LogHandler.jsm index ab035a7..d9456f1 100644 --- a/extension/lib/LogHandler.jsm +++ b/extension/lib/LogHandler.jsm @@ -58,22 +58,22 @@ this.LogHandler = { }, async handleInterval() { - const entries = [{ - url: "pathfinder", + const payload = { + eventId: "intervalFired", timestamp: Math.round(Date.now() / 1000), - details: "intervalFired", - }]; - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { entries }); + context: "", + }; + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, payload); this.uploadPings("interval"); }, async handleTimer() { - const entries = [{ - url: "pathfinder", + const payload = { + eventId: "timerFired", timestamp: Math.round(Date.now() / 1000), - details: "timerFired", - }]; - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { entries }); + context: "", + }; + await Pioneer.utils.submitEncryptedPing("pathfinder-log", 1, payload); this.uploadPings("timer"); }, @@ -91,10 +91,10 @@ this.LogHandler = { // Calculate and cache the size increase of adding one entry to a ping let sizeDelta = perEntryPingSizeIncrease[type]; if (!sizeDelta) { - const oneEntrySize = await Pioneer.utils.getEncryptedPingSize("online-news-log", 1, { + const oneEntrySize = await Pioneer.utils.getEncryptedPingSize("pathfinder-log", 1, { entries: [entry], }); - const twoEntrySize = await Pioneer.utils.getEncryptedPingSize("online-news-log", 1, { + const twoEntrySize = await Pioneer.utils.getEncryptedPingSize("pathfinder-log", 1, { entries: [ entry, entry, @@ -108,20 +108,16 @@ this.LogHandler = { const entries = Array(entryCount).fill(entry); - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { - entries: [{ - url: "pathfinder", - timestamp: Math.round(Date.now() / 1000), - details: `pingsGenerated:${pingCount}`, - }] + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, { + eventId: "pingsGenerated", + timestamp: Math.round(Date.now() / 1000), + context: `${pingCount}`, }); - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { - entries: [{ - url: "pathfinder", - timestamp: Math.round(Date.now() / 1000), - details: `entriesGenerated:${entries.length}`, - }] + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, { + eventId: "entriesGenerated", + timestamp: Math.round(Date.now() / 1000), + context: `${entries.length}`, }); return entries; @@ -139,20 +135,18 @@ this.LogHandler = { let entries = await this.generateEntries(type); let payload = { entries }; const entriesPingSize = await Pioneer.utils.getEncryptedPingSize( - "online-news-log", 1, payload + "pathfinder-log", 1, payload ); if (entriesPingSize < UPLOAD_LIMIT) { // If the ping is small enough, just submit it directly - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, payload); + await Pioneer.utils.submitEncryptedPing("pathfinder-log", 1, payload); PrefUtils.setLongPref(uploadDatePrefName, Date.now()); - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { - entries: [{ - url: "pathfinder", - timestamp: Math.round(Date.now() / 1000), - details: "pingsSent:1", - }] + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, { + eventId: "pingsSent", + timestamp: Math.round(Date.now() / 1000), + context: "1", }); } else { // Otherwise, break it into batches below the minimum size @@ -169,7 +163,7 @@ this.LogHandler = { batch = entries.splice(0, batchSize); payload = { entries: batch }; const batchPingSize = await Pioneer.utils.getEncryptedPingSize( - "online-news-log", 1, payload + "pathfinder-log", 1, payload ); if (batchPingSize >= UPLOAD_LIMIT) { @@ -180,16 +174,14 @@ this.LogHandler = { continue; } - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, payload); + await Pioneer.utils.submitEncryptedPing("pathfinder-log", 1, payload); pingCount++; } - await Pioneer.utils.submitEncryptedPing("online-news-log", 1, { - entries: [{ - url: "pathfinder", - timestamp: Math.round(Date.now() / 1000), - details: `pingsSent:${pingCount}`, - }] + await Pioneer.utils.submitEncryptedPing("pathfinder-event", 1, { + eventId: "pingsSent", + timestamp: Math.round(Date.now() / 1000), + context: `${pingCount}`, }); PrefUtils.setLongPref(uploadDatePrefName, Date.now());