diff --git a/gfx/metrics.yaml b/gfx/metrics.yaml index 419eba8a8ef2..76720b10d195 100644 --- a/gfx/metrics.yaml +++ b/gfx/metrics.yaml @@ -89,6 +89,9 @@ wr: - gfx-telemetry-alerts@mozilla.com expires: never telemetry_mirror: WR_RENDERER_TIME + send_in_pings: + - metrics + - pseudo-main renderer_time_no_sc: type: timing_distribution description: > diff --git a/toolkit/components/glean/metrics_index.py b/toolkit/components/glean/metrics_index.py index 6028593f9907..92d09d0b1d40 100644 --- a/toolkit/components/glean/metrics_index.py +++ b/toolkit/components/glean/metrics_index.py @@ -39,6 +39,7 @@ pings_yamls = [ "browser/components/newtab/pings.yaml", "toolkit/components/glean/pings.yaml", "toolkit/components/glean/tests/test_pings.yaml", + "toolkit/components/telemetry/pings.yaml", "toolkit/mozapps/update/pings.yaml", ] diff --git a/toolkit/components/telemetry/app/TelemetryControllerParent.jsm b/toolkit/components/telemetry/app/TelemetryControllerParent.jsm index a21fa1a623ae..9595ba65be33 100644 --- a/toolkit/components/telemetry/app/TelemetryControllerParent.jsm +++ b/toolkit/components/telemetry/app/TelemetryControllerParent.jsm @@ -483,6 +483,20 @@ var Impl = { let pingData = this.assemblePing(aType, aPayload, aOptions); this._log.trace("submitExternalPing - ping assembled, id: " + pingData.id); + if (aType == PING_TYPE_MAIN) { + try { + Glean.legacyTelemetry.profileSubsessionCounter.set( + aPayload?.info?.profileSubsessionCounter + ); + GleanPings.pseudoMain.submit( + aPayload?.info?.reason?.replaceAll("-", "_") + ); + } catch (e) { + this._log.warn("submitExternalPing - Failed to send 'pseudo-main'", e); + // Definitely continue, even if things explode. + } + } + if (aOptions.useEncryption === true) { try { if (!aOptions.publicKey) { diff --git a/toolkit/components/telemetry/metrics.yaml b/toolkit/components/telemetry/metrics.yaml index 4b92b6ff1738..9ad89f25eea2 100644 --- a/toolkit/components/telemetry/metrics.yaml +++ b/toolkit/components/telemetry/metrics.yaml @@ -41,3 +41,25 @@ legacy.telemetry: - 'events' - 'newtab' - 'baseline' + - 'pseudo-main' + + profile_subsession_counter: + type: quantity + unit: subsessions + description: | + The `profileSubsessionCounter` from the Legacy Telemetry "main" ping. + This is a value that monotonically increases once for every "main" ping + that has been submitted. + It is a sequence number by a longer name. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1785251 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1785251 + data_sensitivity: + - technical + notification_emails: + - chutten@mozilla.com + - glean-team@mozilla.com + expires: 113 + send_in_pings: + - 'pseudo-main' diff --git a/toolkit/components/telemetry/pings.yaml b/toolkit/components/telemetry/pings.yaml new file mode 100644 index 000000000000..328de45ea32f --- /dev/null +++ b/toolkit/components/telemetry/pings.yaml @@ -0,0 +1,35 @@ +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. + +--- +$schema: moz://mozilla.org/schemas/glean/pings/2-0-0 + +pseudo-main: + description: | + A ping designed to be submitted on the same schedule as the Legacy + Telemetry "main" ping. + See "main" ping documentation for details. + include_client_id: true + send_if_empty: true + reasons: + shutdown: | + Submitted at shutdown. Likely not uploaded until the following app + session. See "main" ping documentation for details. + environment_change: | + Submitted when something in the "main" ping's Environment changed. + See "main" ping documentation for details. + aborted_session: | + Submitted when the previous session failed to submit a "shutdown"-reason + "main" ping. + See "main" ping documentation for details. + daily: | + Submitted around local midnight. + See "main" ping documentation for details. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1785251 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1785251 + notification_emails: + - chutten@mozilla.com + - glean-team@mozilla.com diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js index 2e5f53e20579..843fc7fa1c72 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js @@ -152,6 +152,11 @@ add_task(async function test_setup() { await new Promise(resolve => Telemetry.asyncFetchTelemetryData(wrapWithExceptionHandler(resolve)) ); + + // On Android FOG is set up through head.js. + if (AppConstants.platform != "android") { + Services.fog.initializeFOG(); + } }); add_task(async function asyncSetup() { @@ -1217,6 +1222,45 @@ add_task(function test_scalar_filtering() { ); }); +add_task( + /* After bug 1752139 we should be able to re-enable this. */ + { skip_if: () => AppConstants.platform == "android" }, + function test_pseudo_main() { + const PING_REASON = "test-reason"; + const PROFILE_SUBSESSION_COUNTER = 42; + + // Step 0: Clear values. + TelemetryController.testReset(); + Services.fog.testResetFOG(); + + // Step 1: Assert no value. + Assert.ok(!Glean.legacyTelemetry.profileSubsessionCounter.testGetValue()); + + // Step 3: Assert correct value. + let pingSubmitted = false; + GleanPings.pseudoMain.testBeforeNextSubmit(reason => { + pingSubmitted = true; + Assert.equal(reason, PING_REASON.replaceAll("-", "_")); + Assert.equal( + Glean.legacyTelemetry.profileSubsessionCounter.testGetValue(), + PROFILE_SUBSESSION_COUNTER + ); + }); + + // Step 2: Express behaviour. + const payload = { + info: { + reason: PING_REASON, + profileSubsessionCounter: PROFILE_SUBSESSION_COUNTER, + }, + }; + TelemetryController.submitExternalPing("main", payload, {}); + + // Step 3a: Assert we actually ran Step 3. + Assert.ok(pingSubmitted, "'pseudo-main' ping was actually submitted"); + } +); + add_task(async function stopServer() { await PingServer.stop(); });