From be272fdeb55a4260c6ccfbc5eb1a24d59400588d Mon Sep 17 00:00:00 2001 From: pmcmanis Date: Wed, 12 Oct 2022 20:19:58 +0000 Subject: [PATCH] Bug 1791000 - Implement a custom ping in FOG to emulate a possible nodc implementation r=chutten Differential Revision: https://phabricator.services.mozilla.com/D158963 --- browser/modules/metrics.yaml | 2 + gfx/metrics.yaml | 1 + .../glean/src/init/user_activity.rs | 4 ++ toolkit/components/telemetry/pings.yaml | 22 ++++++++ .../telemetry_harness/fog_ping_filters.py | 1 + .../client/test_fog_new_metric_capture.py | 54 +++++++++++++++++++ 6 files changed, 84 insertions(+) create mode 100644 toolkit/components/telemetry/tests/marionette/tests/client/test_fog_new_metric_capture.py diff --git a/browser/modules/metrics.yaml b/browser/modules/metrics.yaml index 1f130a6e3f58..f4e32422ae8b 100644 --- a/browser/modules/metrics.yaml +++ b/browser/modules/metrics.yaml @@ -39,6 +39,7 @@ browser.engagement: send_in_pings: - baseline - metrics + - new-metric-capture-emulation no_lint: - BASELINE_PING @@ -67,5 +68,6 @@ browser.engagement: send_in_pings: - baseline - metrics + - new-metric-capture-emulation no_lint: - BASELINE_PING diff --git a/gfx/metrics.yaml b/gfx/metrics.yaml index 76720b10d195..3ec0e891cb47 100644 --- a/gfx/metrics.yaml +++ b/gfx/metrics.yaml @@ -92,6 +92,7 @@ wr: send_in_pings: - metrics - pseudo-main + - new-metric-capture-emulation renderer_time_no_sc: type: timing_distribution description: > diff --git a/toolkit/components/glean/src/init/user_activity.rs b/toolkit/components/glean/src/init/user_activity.rs index dbafeca4e864..018a4678cdae 100644 --- a/toolkit/components/glean/src/init/user_activity.rs +++ b/toolkit/components/glean/src/init/user_activity.rs @@ -34,6 +34,8 @@ impl UserActivityObserver { // First and foremost, even if we can't get the ObserverService, // init always means client activity. glean::handle_client_active(); + // send emulation ping at startup + glean::submit_ping_by_name("new-metric-capture-emulation", Some("active")); // SAFETY: Everything here is self-contained. // @@ -96,6 +98,7 @@ impl UserActivityObserver { inactivity.as_secs() ); glean::handle_client_active(); + glean::submit_ping_by_name("new-metric-capture-emulation", Some("active")); } let mut edge = self.last_edge.write().expect("Edge lock poisoned."); *edge = Instant::now(); @@ -120,6 +123,7 @@ impl UserActivityObserver { activity.as_secs() ); glean::handle_client_inactive(); + glean::submit_ping_by_name("new-metric-capture-emulation", Some("inactive")); } let mut edge = self.last_edge.write().expect("Edge lock poisoned."); *edge = Instant::now(); diff --git a/toolkit/components/telemetry/pings.yaml b/toolkit/components/telemetry/pings.yaml index 328de45ea32f..7b3e7ec9bf4c 100644 --- a/toolkit/components/telemetry/pings.yaml +++ b/toolkit/components/telemetry/pings.yaml @@ -33,3 +33,25 @@ pseudo-main: notification_emails: - chutten@mozilla.com - glean-team@mozilla.com +new-metric-capture-emulation: + description: | + Experimental ping to emulate the capture of new measures + that would usually be collected in the metrics ping, + to see if it would speed up measure completeness. + Sends only EXISTING measures. + reasons: + active: | + Submitted when application is marked active, + when started, or when a user interacts with + Firefox after a 20min period of inactivity + inactive: | + Submitted when the user stops interacting with + Firefox after 20min of activity. + include_client_id: true + notification_emails: + - pmcmanis@mozilla.com + - glean-team@mozilla.com + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1791000 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1791000#c2 diff --git a/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/fog_ping_filters.py b/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/fog_ping_filters.py index d0d006fc0aa8..834e9f57cd34 100644 --- a/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/fog_ping_filters.py +++ b/toolkit/components/telemetry/tests/marionette/harness/telemetry_harness/fog_ping_filters.py @@ -29,3 +29,4 @@ FOG_BACKGROUND_UPDATE_PING = FOGDocTypePingFilter("background-update") FOG_BASELINE_PING = FOGDocTypePingFilter("baseline") FOG_DELETION_REQUEST_PING = FOGDocTypePingFilter("deletion-request") FOG_ONE_PING_ONLY_PING = FOGDocTypePingFilter("one-ping-only") +FOG_NODC_PING = FOGDocTypePingFilter("new-metric-capture-emulation") diff --git a/toolkit/components/telemetry/tests/marionette/tests/client/test_fog_new_metric_capture.py b/toolkit/components/telemetry/tests/marionette/tests/client/test_fog_new_metric_capture.py new file mode 100644 index 000000000000..e6480b291ee0 --- /dev/null +++ b/toolkit/components/telemetry/tests/marionette/tests/client/test_fog_new_metric_capture.py @@ -0,0 +1,54 @@ +# 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/. + +from telemetry_harness.fog_ping_filters import FOG_NODC_PING +from telemetry_harness.fog_testcase import FOGTestCase + + +class TestNewMetricCaptureEmulation(FOGTestCase): + """Test for the New Metric Capture Emulation Ping (aka NODC)""" + + @staticmethod + def user_active(active, marionette): + script = ( + "Services.obs.notifyObservers(null, 'user-interaction-{}active')".format( + "" if active else "in" + ) + ) + with marionette.using_context(marionette.CONTEXT_CHROME): + marionette.execute_script(script) + + def test_user_activity(self): + # tests send on active, inactive and restart + with self.marionette.using_context(self.marionette.CONTEXT_CHROME): + zero_prefs_script = """\ + Services.prefs.setIntPref("telemetry.fog.test.inactivity_limit", 0); + Services.prefs.setIntPref("telemetry.fog.test.activity_limit", 0); + """ + self.marionette.execute_script(zero_prefs_script) + + active_ping = self.wait_for_ping( + lambda: self.user_active(True, self.marionette), + FOG_NODC_PING, + ping_server=self.fog_ping_server, + ) + + inactive_ping = self.wait_for_ping( + lambda: self.user_active(False, self.marionette), + FOG_NODC_PING, + ping_server=self.fog_ping_server, + ) + + self.assertEqual("active", active_ping["payload"]["ping_info"]["reason"]) + self.assertEqual("inactive", inactive_ping["payload"]["ping_info"]["reason"]) + + # Restarting the browser sends the experiment ping with + # reason "active". One should be sent with this reason on initialization + # of FOG, the same way it would for baseline. This has to go last. + + fog_init_ping = self.wait_for_ping( + self.restart_browser, FOG_NODC_PING, ping_server=self.fog_ping_server + ) + self.assertEqual("active", fog_init_ping["payload"]["ping_info"]["reason"]) + return