bug 1463439 - Add a pref to enable 'event' ping. Defaults to true, except for GV. r=Dexter a=lizzard
authorChris H-C <chutten@mozilla.com>
Tue, 29 May 2018 12:24:02 -0400
changeset 477875 3281d05908701c28a17589cadaec3550b430029b
parent 477874 58935e7bb1480e7b2d08776fef1770edfe5eb340
child 477876 32cde6cdb297933f18c086dfa4d6aed28a239a1a
push id9448
push userarchaeopteryx@coole-files.de
push dateMon, 09 Jul 2018 17:22:41 +0000
treeherdermozilla-beta@32cde6cdb297 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter, lizzard
bugs1463439
milestone62.0
bug 1463439 - Add a pref to enable 'event' ping. Defaults to true, except for GV. r=Dexter a=lizzard When it's false we also disable collecting events completely, in case the reason we're disabling it is due to storage issues. GeckoView doesn't presently support Events, so the 'event' ping is disabled by default for that platform. MozReview-Commit-ID: 9eKAtRiuER0
mobile/android/app/geckoview-prefs.js
toolkit/components/telemetry/TelemetryEvent.cpp
toolkit/components/telemetry/TelemetryEventPing.jsm
toolkit/components/telemetry/TelemetryUtils.jsm
toolkit/components/telemetry/docs/internals/preferences.rst
toolkit/components/telemetry/tests/unit/test_TelemetryEventPing_disabled.js
toolkit/components/telemetry/tests/unit/xpcshell.ini
--- a/mobile/android/app/geckoview-prefs.js
+++ b/mobile/android/app/geckoview-prefs.js
@@ -8,12 +8,14 @@
 
 pref("privacy.trackingprotection.pbmode.enabled", false);
 pref("dom.ipc.processCount", 1);
 pref("dom.ipc.keepProcessesAlive.web", 1);
 pref("dom.ipc.processPrelaunch.enabled", false);
 
 // Tell Telemetry that we're in GeckoView mode.
 pref("toolkit.telemetry.isGeckoViewMode", true);
+// Disable the Telemetry Event Ping
+pref("toolkit.telemetry.eventping.enabled", false);
 
 // Disable Web Push until we get it working
 pref("dom.push.enabled", false);
 
--- a/toolkit/components/telemetry/TelemetryEvent.cpp
+++ b/toolkit/components/telemetry/TelemetryEvent.cpp
@@ -488,16 +488,22 @@ RecordEvent(const StaticMutexAutoLock& l
   TelemetryScalar::SummarizeEvent(UniqueEventName(category, method, object),
                                   processType, eventKey->dynamic);
 
   // Check whether this event's category has recording enabled
   if (!gEnabledCategories.GetEntry(GetCategory(lock, *eventKey))) {
     return RecordEventResult::Ok;
   }
 
+  static bool sEventPingEnabled =
+    mozilla::Preferences::GetBool("toolkit.telemetry.eventping.enabled", true);
+  if (!sEventPingEnabled) {
+    return RecordEventResult::Ok;
+  }
+
   EventRecordArray* eventRecords =
     GetEventRecordsForProcess(lock, processType, *eventKey);
   eventRecords->AppendElement(EventRecord(timestamp, *eventKey, value, extra));
 
   // Notify observers when we hit the "event" ping event record limit.
   static uint32_t sEventPingLimit =
     mozilla::Preferences::GetUint("toolkit.telemetry.eventping.eventLimit", 1000);
   if (eventRecords->Length() == sEventPingLimit) {
--- a/toolkit/components/telemetry/TelemetryEventPing.jsm
+++ b/toolkit/components/telemetry/TelemetryEventPing.jsm
@@ -67,16 +67,19 @@ var TelemetryEventPing = {
   _lastSendTime: -DEFAULT_MIN_FREQUENCY_MS,
 
   get dataset() {
     return Telemetry.canRecordPrereleaseData ? Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN
                                              : Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT;
   },
 
   startup() {
+    if (!Services.prefs.getBoolPref(Utils.Preferences.EventPingEnabled, true)) {
+      return;
+    }
     Services.obs.addObserver(this, EVENT_LIMIT_REACHED_TOPIC);
     Services.obs.addObserver(this, PROFILE_BEFORE_CHANGE_TOPIC);
 
     XPCOMUtils.defineLazyPreferenceGetter(this, "maxEventsPerPing",
                                           Utils.Preferences.EventPingEventLimit,
                                           DEFAULT_EVENT_LIMIT);
     XPCOMUtils.defineLazyPreferenceGetter(this, "maxFrequency",
                                           Utils.Preferences.EventPingMaximumFrequency,
--- a/toolkit/components/telemetry/TelemetryUtils.jsm
+++ b/toolkit/components/telemetry/TelemetryUtils.jsm
@@ -92,16 +92,17 @@ var TelemetryUtils = {
     TelemetryEnabled: "toolkit.telemetry.enabled",
     Unified: "toolkit.telemetry.unified",
     UpdatePing: "toolkit.telemetry.updatePing.enabled",
     NewProfilePingEnabled: "toolkit.telemetry.newProfilePing.enabled",
     NewProfilePingDelay: "toolkit.telemetry.newProfilePing.delay",
     PreviousBuildID: "toolkit.telemetry.previousBuildID",
 
     // Event Ping Preferences
+    EventPingEnabled: "toolkit.telemetry.eventping.enabled",
     EventPingEventLimit: "toolkit.telemetry.eventping.eventLimit",
     EventPingMinimumFrequency: "toolkit.telemetry.eventping.minimumFrequency",
     EventPingMaximumFrequency: "toolkit.telemetry.eventping.maximumFrequency",
 
     // Log Preferences
     LogLevel: "toolkit.telemetry.log.level",
     LogDump: "toolkit.telemetry.log.dump",
 
--- a/toolkit/components/telemetry/docs/internals/preferences.rst
+++ b/toolkit/components/telemetry/docs/internals/preferences.rst
@@ -137,16 +137,21 @@ Preferences
 
   Enable the :doc:`../data/update-ping` on browser updates.
 
 ``toolkit.telemetry.maxEventSummaryKeys``
 
   Set the maximum number of keys per process of the :ref:`Event Summary <events.event-summary>`
   :ref:`keyed scalars <scalars.keyed-scalars>`. Default is 500. Change requires restart.
 
+``toolkit.telemetry.eventping.enabled``
+
+  Whether the :doc:`../data/event-ping` is enabled.
+  Default is true except for GeckoView where it defaults to false. Change requires restart.
+
 ``toolkit.telemetry.eventping.eventLimit``
 
   The maximum number of event records permitted in the :doc:`../data/event-ping`.
   Default is 1000.
 
 ``toolkit.telemetry.eventping.minimumFrequency``
 
   The minimum frequency at which an :doc:`../data/event-ping` will be sent.
new file mode 100644
--- /dev/null
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryEventPing_disabled.js
@@ -0,0 +1,35 @@
+/* Any copyright is dedicated to the Public Domain.
+ http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+ChromeUtils.import("resource://gre/modules/TelemetryController.jsm", this);
+ChromeUtils.import("resource://gre/modules/TelemetryStorage.jsm", this);
+ChromeUtils.import("resource://gre/modules/TelemetryUtils.jsm", this);
+ChromeUtils.import("resource://gre/modules/Preferences.jsm", this);
+ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
+ChromeUtils.import("resource://testing-common/TelemetryArchiveTesting.jsm", this);
+
+ChromeUtils.defineModuleGetter(this, "TelemetryEventPing",
+                               "resource://gre/modules/TelemetryEventPing.jsm");
+
+const OPTIN = Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTIN;
+
+add_task(async function setup() {
+  Services.prefs.setBoolPref(TelemetryUtils.Preferences.EventPingEnabled, false);
+  // Trigger a proper telemetry init.
+  do_get_profile(true);
+  // Make sure we don't generate unexpected pings due to pref changes.
+  await setEmptyPrefWatchlist();
+
+  await TelemetryController.testSetup();
+  TelemetryEventPing.testReset();
+  Telemetry.setEventRecordingEnabled("telemetry.test", true);
+});
+
+add_task(async function test_EventsNotRecorded() {
+  Telemetry.recordEvent("telemetry.test", "test1", "object1");
+  let snapshot = Telemetry.snapshotEvents(OPTIN, true);
+  Assert.equal(Object.keys(snapshot).length, 0, "Should not have recorded any events.");
+});
--- a/toolkit/components/telemetry/tests/unit/xpcshell.ini
+++ b/toolkit/components/telemetry/tests/unit/xpcshell.ini
@@ -85,8 +85,9 @@ skip-if = os == "android" # Disabled due
 skip-if = os == "android" # Disabled due to crashes (see bug 1331366)
 [test_TelemetryModules.js]
 [test_PingSender.js]
 skip-if = (os == "android") || (os == "linux" && bits == 32)
 [test_TelemetryGC.js]
 [test_TelemetryAndroidEnvironment.js]
 [test_TelemetryUtils.js]
 [test_TelemetryEventPing.js]
+[test_TelemetryEventPing_disabled.js]