bug 1463439 - Add a pref to enable 'event' ping. Defaults to true, except for GV. r=Dexter
authorChris H-C <chutten@mozilla.com>
Tue, 29 May 2018 12:24:02 -0400
changeset 423975 a034391b5c152a443baa67fad26866e238e6748c
parent 423974 c78fe269ab6e32eb1c42229db08a242dd9c5211b
child 423976 f02de3ec24e389344449714c4b250e199edbae23
push id34197
push usercsabou@mozilla.com
push dateThu, 28 Jun 2018 09:44:02 +0000
treeherdermozilla-central@db455160668d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersDexter
bugs1463439
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 1463439 - Add a pref to enable 'event' ping. Defaults to true, except for GV. r=Dexter 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,8 +8,10 @@
 
 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);
--- 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]