Bug 1741674 - Record active_ticks and uri_count in Glean as well as Telemetry r=TravisLong

Differential Revision: https://phabricator.services.mozilla.com/D131641
This commit is contained in:
Chris H-C 2021-11-22 20:07:38 +00:00
Родитель 8d0d430403
Коммит 5ee0631774
8 изменённых файлов: 117 добавлений и 13 удалений

Просмотреть файл

@ -37,6 +37,8 @@ XPCOMUtils.defineLazyPreferenceGetter(
"browser.engagement.recent_visited_origins.expiry"
);
Cu.importGlobalProperties(["Glean"]);
// The upper bound for the count of the visited unique domain names.
const MAX_UNIQUE_VISITED_DOMAINS = 100;
@ -341,6 +343,7 @@ let URICountListener = {
TOTAL_URI_COUNT_NORMAL_AND_PRIVATE_MODE_SCALAR_NAME,
1
);
Glean.browserEngagement.uriCount.add(1);
if (!shouldCountURI) {
return;

Просмотреть файл

@ -0,0 +1,63 @@
# 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/.
# Adding a new metric? We have docs for that!
# https://firefox-source-docs.mozilla.org/toolkit/components/glean/user/new_definitions_file.html
---
$schema: moz://mozilla.org/schemas/glean/metrics/2-0-0
browser.engagement:
active_ticks:
type: counter
description: |
The number of five-second intervals ('ticks') the user was considered
'active'.
'active' means keyboard or mouse interaction with the application.
It doesn't take into account whether or not the window has focus or is in
the foreground, only if it is receiving these interaction events.
Migrated from Telemetry's `browser.engagement.active_ticks`.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1376942 # Telemetry
- https://bugzilla.mozilla.org/show_bug.cgi?id=1545172 # Telemetry
- https://bugzilla.mozilla.org/show_bug.cgi?id=1741674
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1545172#c8
data_sensitivity:
- interaction
notification_emails:
- loines@mozilla.com
expires: "100"
send_in_pings:
- baseline
- metrics
no_lint:
- BASELINE_PING
uri_count:
type: counter
description: |
The number of total non-unique http(s) URIs visited, including page
reloads, after the session has been restored. URIs on minimized or
background tabs may also be counted. Private browsing uris are included.
Migrated from Telemetry's
`browser.engagement.total_uri_count_normal_and_private_mode`.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1535169 # Telemetry
- https://bugzilla.mozilla.org/show_bug.cgi?id=1741674
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1535169#c14
data_sensitivity:
- interaction
notification_emails:
- loines@mozilla.com
expires: "100"
send_in_pings:
- baseline
- metrics
no_lint:
- BASELINE_PING

Просмотреть файл

@ -26,13 +26,16 @@ const { SessionStore } = ChromeUtils.import(
"resource:///modules/sessionstore/SessionStore.jsm"
);
// Glean's here on `window`, but eslint doesn't know that. bug 1715542.
/* global Glean:false */
// Reset internal URI counter in case URIs were opened by other tests.
Services.obs.notifyObservers(null, TELEMETRY_SUBSESSION_TOPIC);
/**
* Get a snapshot of the scalars and check them against the provided values.
*/
let checkScalars = countsObject => {
let checkScalars = (countsObject, skipGleanCheck = false) => {
const scalars = TelemetryTestUtils.getProcessScalars("parent");
// Check the expected values. Scalars that are never set must not be reported.
@ -90,6 +93,21 @@ let checkScalars = countsObject => {
countsObject.totalURIsNormalAndPrivateMode,
"The total URI count for both normal and private mode must match the expected value."
);
if (!skipGleanCheck) {
if (countsObject.totalURIsNormalAndPrivateMode == 0) {
Assert.equal(
Glean.browserEngagement.uriCount.testGetValue(),
undefined,
"Total URI count reported in Glean must be unset."
);
} else {
Assert.equal(
countsObject.totalURIsNormalAndPrivateMode,
Glean.browserEngagement.uriCount.testGetValue(),
"The total URI count reported in Glean must be as expected."
);
}
}
};
add_task(async function test_tabsAndWindows() {
@ -266,18 +284,21 @@ add_task(async function test_subsessionSplit() {
// must not be reported.
expectedTotalURIs = 0;
checkScalars({
maxTabs: 4,
tabOpenCount: 0,
maxWindows: 2,
windowsOpenCount: 0,
totalURIs: expectedTotalURIs,
domainCount: 0,
totalUnfilteredURIs: 0,
maxTabsPinned: 0,
tabPinnedCount: 0,
totalURIsNormalAndPrivateMode: expectedTotalURIs,
});
checkScalars(
{
maxTabs: 4,
tabOpenCount: 0,
maxWindows: 2,
windowsOpenCount: 0,
totalURIs: expectedTotalURIs,
domainCount: 0,
totalUnfilteredURIs: 0,
maxTabsPinned: 0,
tabPinnedCount: 0,
totalURIsNormalAndPrivateMode: expectedTotalURIs,
},
true
);
// Remove all the extra windows and tabs.
for (let tab of openedTabs) {

Просмотреть файл

@ -4,6 +4,9 @@ const { E10SUtils } = ChromeUtils.import(
);
const triggeringPrincipal_base64 = E10SUtils.SERIALIZED_SYSTEMPRINCIPAL;
// Glean's here on `window`, but eslint doesn't know that. bug 1715542.
/* global Glean:false */
const MAX_CONCURRENT_TABS = "browser.engagement.max_concurrent_tab_count";
const TAB_EVENT_COUNT = "browser.engagement.tab_open_event_count";
const MAX_CONCURRENT_WINDOWS = "browser.engagement.max_concurrent_window_count";
@ -80,6 +83,7 @@ add_task(async function test_privateMode() {
1,
"We should include URIs in private mode as part of the actual total URI count."
);
is(Glean.browserEngagement.uriCount.testGetValue(), 1);
// Clean up.
await BrowserTestUtils.closeWindow(privateWin);

Просмотреть файл

@ -77,3 +77,6 @@ user_pref("browser.region.network.url", "");
user_pref("browser.tabs.unloadOnLowMemory", false);
// Don't pull Top Sites content from the network
user_pref("browser.topsites.contile.enabled", false);
// Default Glean to "record but don't report" mode. Docs:
// https://firefox-source-docs.mozilla.org/toolkit/components/glean/dev/preferences.html
user_pref("telemetry.fog.test.localhost_port", -1);

Просмотреть файл

@ -18,6 +18,7 @@ metrics_yamls = [
"browser/base/content/metrics.yaml",
"gfx/metrics.yaml",
"toolkit/components/processtools/metrics.yaml",
"browser/modules/metrics.yaml",
"browser/components/metrics.yaml",
]

Просмотреть файл

@ -27,6 +27,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {
TelemetryScheduler: "resource://gre/modules/TelemetryScheduler.jsm",
});
Cu.importGlobalProperties(["Glean"]);
const Utils = TelemetryUtils;
const myScope = this;
@ -1121,6 +1123,7 @@ var Impl = {
if (needsUpdate) {
this._sessionActiveTicks++;
Services.telemetry.scalarAdd("browser.engagement.active_ticks", 1);
Glean.browserEngagement.activeTicks.add(1);
}
},

Просмотреть файл

@ -9,6 +9,8 @@ const { TelemetrySession } = ChromeUtils.import(
"resource://gre/modules/TelemetrySession.jsm"
);
Cu.importGlobalProperties(["Glean"]);
function tick(aHowMany) {
for (let i = 0; i < aHowMany; i++) {
Services.obs.notifyObservers(null, "user-interaction-active");
@ -44,6 +46,9 @@ add_task(async function test_setup() {
do_get_profile();
// Make sure we don't generate unexpected pings due to pref changes.
await setEmptyPrefWatchlist();
// Ensure FOG's init
let FOG = Cc["@mozilla.org/toolkit/glean;1"].getService(Ci.nsIFOG);
FOG.initializeFOG();
});
add_task(async function test_record_activeTicks() {
@ -65,6 +70,7 @@ add_task(async function test_record_activeTicks() {
"TelemetrySession must record the expected number of active ticks (in scalars)."
);
}
Assert.equal(Glean.browserEngagement.activeTicks.testGetValue(), expected);
};
for (let i = 0; i < 3; i++) {