tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

commit b1b84d814fc4fdc453893b3bd8b9c82750c54f76
parent f58038979749b7bb225c931a870d73dd8ed947e0
Author: Chris H-C <chutten@mozilla.com>
Date:   Mon,  8 Dec 2025 21:42:51 +0000

Bug 1999541 - Implement Nimbus-controlled shutoff switch for "main" ping histograms r=TravisLong

We keep the existing recording and clearing behaviour,
we just refuse to include them in the ping any more.

Differential Revision: https://phabricator.services.mozilla.com/D274466

Diffstat:
Mtoolkit/components/nimbus/FeatureManifest.yaml | 6++++++
Mtoolkit/components/telemetry/pings/TelemetrySession.sys.mjs | 20++++++++++++++++++--
Mtoolkit/components/telemetry/tests/unit/test_MainPingDisablement.js | 41++++++++++++++++++++++++++++++++++++++++-
3 files changed, 64 insertions(+), 3 deletions(-)

diff --git a/toolkit/components/nimbus/FeatureManifest.yaml b/toolkit/components/nimbus/FeatureManifest.yaml @@ -2763,6 +2763,12 @@ legacyTelemetry: `browser.engagement.active_ticks`. These scalars will continue to be reported as normal, even if all others are disabled by this variable. + disableMainPingHgrams: + type: boolean + description: | + If true, histograms will not be included in "main" pings. + Data will still be recorded locally, + it will merely not be included in "main" pings when they are submitted. browserLowMemoryPrefs: description: Prefs which control the browser's behaviour under low memory. diff --git a/toolkit/components/telemetry/pings/TelemetrySession.sys.mjs b/toolkit/components/telemetry/pings/TelemetrySession.sys.mjs @@ -464,19 +464,35 @@ var Impl = { }, getHistograms: function getHistograms(clearSubsession) { - return Services.telemetry.getSnapshotForHistograms( + const snapshot = Services.telemetry.getSnapshotForHistograms( "main", clearSubsession, !this._testing ); + if ( + lazy.NimbusFeatures.legacyTelemetry.getVariable("disableMainPingHgrams") + ) { + this._log.trace("getHistograms - Main ping histograms are disabled."); + return {}; + } + return snapshot; }, getKeyedHistograms(clearSubsession) { - return Services.telemetry.getSnapshotForKeyedHistograms( + const snapshot = Services.telemetry.getSnapshotForKeyedHistograms( "main", clearSubsession, !this._testing ); + if ( + lazy.NimbusFeatures.legacyTelemetry.getVariable("disableMainPingHgrams") + ) { + this._log.trace( + "getKeyedHistograms - Main ping histograms are disabled." + ); + return {}; + } + return snapshot; }, /** diff --git a/toolkit/components/telemetry/tests/unit/test_MainPingDisablement.js b/toolkit/components/telemetry/tests/unit/test_MainPingDisablement.js @@ -55,7 +55,6 @@ add_task(async function test_scalarDisablement() { info("2. Ensure we can disable scalars, leaving important ones intact."); const { cleanup } = await NimbusTestUtils.setupTest(); - registerCleanupFunction(cleanup); let nimbusCleanup = await NimbusTestUtils.enrollWithFeatureConfig({ featureId: NimbusFeatures.legacyTelemetry.featureId, @@ -74,4 +73,44 @@ add_task(async function test_scalarDisablement() { Assert.ok(!(LAST_SHUTDOWN_SCALAR in filtered.processes.parent.scalars)); await nimbusCleanup(); + await cleanup(); +}); + +add_task(async function test_hgramDisablement() { + const ARCHIVE_HGRAM = "TELEMETRY_ARCHIVE_DIRECTORIES_COUNT"; + const SEND_KEYED_HGRAM = "TELEMETRY_SEND_FAILURE_TYPE_PER_PING"; + // Let's check both normal and keyed. + Glean.telemetry.archiveDirectoriesCount.accumulateSingleSample(42); + Glean.telemetry.sendFailureTypePerPing.get("some-ping", "eOK").add(1); + + info("1. Ensure histogram data is reported normally to begin with."); + + let payload = TelemetrySession.getPayload( + "reason", + /*clearSubsession*/ false + ); + + Assert.ok(ARCHIVE_HGRAM in payload.histograms); + Assert.ok(SEND_KEYED_HGRAM in payload.keyedHistograms); + + info("2. Ensure we can disable histograms."); + const { cleanup } = await NimbusTestUtils.setupTest(); + + let nimbusCleanup = await NimbusTestUtils.enrollWithFeatureConfig({ + featureId: NimbusFeatures.legacyTelemetry.featureId, + value: { + disableMainPingHgrams: true, + }, + }); + + let filtered = TelemetrySession.getPayload( + "reason", + /*clearSubsession*/ false + ); + + Assert.ok(!(ARCHIVE_HGRAM in filtered.histograms)); + Assert.ok(!(SEND_KEYED_HGRAM in filtered.keyedHistograms)); + + await nimbusCleanup(); + await cleanup(); });