This is an automated email from the git hooks/post-receive script.
pierov pushed a commit to branch geckoview-99.0.1-11.0-1 in repository tor-browser.
commit a2102f0afc62cc8a70c9da8f4b2a4d8aac83fa60 Author: Chris H-C chutten@mozilla.com AuthorDate: Mon Mar 21 21:19:26 2022 +0000
Bug 1758795 - Test all IPC-available Glean metric types over GIFFT r=TravisLong a=dmeehan
Differential Revision: https://phabricator.services.mozilla.com/D140772 --- .../glean/tests/browser/browser_labeled_gifft.js | 4 +- toolkit/components/glean/tests/test_metrics.yaml | 25 +- .../components/glean/tests/xpcshell/test_GIFFT.js | 15 +- .../glean/tests/xpcshell/test_GIFFTIPC.js | 308 +++++++++++++++++++++ .../components/glean/tests/xpcshell/xpcshell.ini | 2 + toolkit/components/telemetry/Events.yaml | 3 +- toolkit/components/telemetry/Histograms.json | 5 +- toolkit/components/telemetry/Scalars.yaml | 53 +++- 8 files changed, 400 insertions(+), 15 deletions(-)
diff --git a/toolkit/components/glean/tests/browser/browser_labeled_gifft.js b/toolkit/components/glean/tests/browser/browser_labeled_gifft.js index 7b2d562e63767..2203424e82fc7 100644 --- a/toolkit/components/glean/tests/browser/browser_labeled_gifft.js +++ b/toolkit/components/glean/tests/browser/browser_labeled_gifft.js @@ -33,7 +33,9 @@ add_task(async () => { "Can't get the value when you're error'd" );
- let value = keyedScalarValue("telemetry.test.keyed_unsigned_int"); + let value = keyedScalarValue( + "telemetry.test.another_mirror_for_labeled_counter" + ); Assert.deepEqual( { a_label: 1, diff --git a/toolkit/components/glean/tests/test_metrics.yaml b/toolkit/components/glean/tests/test_metrics.yaml index 3be59d989c3f0..c0e54e931ec3e 100644 --- a/toolkit/components/glean/tests/test_metrics.yaml +++ b/toolkit/components/glean/tests/test_metrics.yaml @@ -348,7 +348,7 @@ test_only.ipc: - store1 no_lint: - COMMON_PREFIX - telemetry_mirror: TELEMETRY_TEST_UNSIGNED_INT_KIND + telemetry_mirror: TELEMETRY_TEST_MIRROR_FOR_COUNTER a_bool: type: boolean description: | @@ -607,7 +607,28 @@ test_only.ipc: - store1 no_lint: - COMMON_PREFIX - telemetry_mirror: TELEMETRY_TEST_KEYED_UNSIGNED_INT + telemetry_mirror: TELEMETRY_TEST_ANOTHER_MIRROR_FOR_LABELED_COUNTER + another_labeled_counter: + type: labeled_counter + description: | + This is a test-only metric. + Just another metric counting labeled things. + bugs: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1688281 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1685406 + - https://bugzilla.mozilla.org/show_bug.cgi?id=1758795 + data_reviews: + - https://bugzilla.mozilla.org/show_bug.cgi?id=1688281#c1 + data_sensitivity: + - technical + notification_emails: + - glean-team@mozilla.com + expires: never + send_in_pings: + - store1 + no_lint: + - COMMON_PREFIX + telemetry_mirror: TELEMETRY_TEST_MIRROR_FOR_LABELED_COUNTER a_quantity: type: quantity unit: squad diff --git a/toolkit/components/glean/tests/xpcshell/test_GIFFT.js b/toolkit/components/glean/tests/xpcshell/test_GIFFT.js index 6aad05d627372..01fd98b7ad3cb 100644 --- a/toolkit/components/glean/tests/xpcshell/test_GIFFT.js +++ b/toolkit/components/glean/tests/xpcshell/test_GIFFT.js @@ -38,11 +38,6 @@ add_task(function test_setup() { true );
- Services.prefs.setBoolPref( - "toolkit.telemetry.testing.overrideProductsCheck", - true - ); - // We need to initialize it once, otherwise operations will be stuck in the pre-init queue. // On Android FOG is set up through head.js. if (AppConstants.platform != "android") { @@ -53,7 +48,7 @@ add_task(function test_setup() { add_task(function test_gifft_counter() { Glean.testOnlyIpc.aCounter.add(20); Assert.equal(20, Glean.testOnlyIpc.aCounter.testGetValue()); - Assert.equal(20, scalarValue("telemetry.test.unsigned_int_kind")); + Assert.equal(20, scalarValue("telemetry.test.mirror_for_counter")); });
add_task(function test_gifft_boolean() { @@ -253,7 +248,9 @@ add_task(function test_gifft_labeled_counter() { "Can't get the value when you're error'd" );
- let value = keyedScalarValue("telemetry.test.keyed_unsigned_int"); + let value = keyedScalarValue( + "telemetry.test.another_mirror_for_labeled_counter" + ); Assert.deepEqual( { a_label: 4, @@ -376,7 +373,7 @@ add_task( /NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/, "Can't get the value when you're error'd" ); - Assert.equal(undefined, scalarValue("telemetry.test.unsigned_int_kind")); + Assert.equal(undefined, scalarValue("telemetry.test.mirror_for_counter")); // Clear the error state Services.fog.testResetFOG();
@@ -393,7 +390,7 @@ add_task( Glean.testOnlyIpc.aCounter.testGetValue() ); // Telemetry will have wrapped around to 1 - Assert.equal(1, scalarValue("telemetry.test.unsigned_int_kind")); + Assert.equal(1, scalarValue("telemetry.test.mirror_for_counter"));
// 2) Quantity: i64 (saturates), mirrored to uint Scalar: u32 (overflows) // 2.1) Negative parameters refused. diff --git a/toolkit/components/glean/tests/xpcshell/test_GIFFTIPC.js b/toolkit/components/glean/tests/xpcshell/test_GIFFTIPC.js new file mode 100644 index 0000000000000..952f4d6246802 --- /dev/null +++ b/toolkit/components/glean/tests/xpcshell/test_GIFFTIPC.js @@ -0,0 +1,308 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +"use strict"; + +const { AppConstants } = ChromeUtils.import( + "resource://gre/modules/AppConstants.jsm" +); +const { ContentTaskUtils } = ChromeUtils.import( + "resource://testing-common/ContentTaskUtils.jsm" +); +const { setTimeout } = ChromeUtils.import("resource://gre/modules/Timer.jsm"); +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const Telemetry = Services.telemetry; +const { TelemetryTestUtils } = ChromeUtils.import( + "resource://testing-common/TelemetryTestUtils.jsm" +); + +function sleep(ms) { + /* eslint-disable mozilla/no-arbitrary-setTimeout */ + return new Promise(resolve => setTimeout(resolve, ms)); +} + +function scalarValue(aScalarName, aProcessName) { + let snapshot = Telemetry.getSnapshotForScalars(); + return aProcessName in snapshot + ? snapshot[aProcessName][aScalarName] + : undefined; +} + +function keyedScalarValue(aScalarName, aProcessName) { + let snapshot = Telemetry.getSnapshotForKeyedScalars(); + return aProcessName in snapshot + ? snapshot[aProcessName][aScalarName] + : undefined; +} + +add_task({ skip_if: () => !runningInParent }, function test_setup() { + // Give FOG a temp profile to init within. + do_get_profile(); + + // Allows these tests to properly run on e.g. Thunderbird + Services.prefs.setBoolPref( + "toolkit.telemetry.testing.overrideProductsCheck", + true + ); + + // We need to initialize it once, otherwise operations will be stuck in the pre-init queue. + // on Android FOG is set up through head.js + if (AppConstants.platform != "android") { + Services.fog.initializeFOG(); + } +}); + +const COUNT = 42; +const CHEESY_STRING = "a very cheesy string!"; +const CHEESIER_STRING = "a much cheesier string!"; +const CUSTOM_SAMPLES = [3, 4]; +const EVENT_EXTRA = { extra1: "so very extra" }; +const MEMORIES = [13, 31]; +const MEMORY_BUCKETS = ["13193", "31378"]; // buckets are strings : | +const A_LABEL_COUNT = 3; +const ANOTHER_LABEL_COUNT = 5; +const INVALID_COUNTERS = 7; +const IRATE_NUMERATOR = 44; +const IRATE_DENOMINATOR = 14; + +add_task({ skip_if: () => runningInParent }, async function run_child_stuff() { + Glean.testOnlyIpc.aCounter.add(COUNT); + Glean.testOnlyIpc.aStringList.add(CHEESY_STRING); + Glean.testOnlyIpc.aStringList.add(CHEESIER_STRING); + + Glean.testOnlyIpc.noExtraEvent.record(); + Glean.testOnlyIpc.anEvent.record(EVENT_EXTRA); + + for (let memory of MEMORIES) { + Glean.testOnlyIpc.aMemoryDist.accumulate(memory); + } + + let t1 = Glean.testOnlyIpc.aTimingDist.start(); + let t2 = Glean.testOnlyIpc.aTimingDist.start(); + + await sleep(5); + + let t3 = Glean.testOnlyIpc.aTimingDist.start(); + Glean.testOnlyIpc.aTimingDist.cancel(t1); + + await sleep(5); + + Glean.testOnlyIpc.aTimingDist.stopAndAccumulate(t2); // 10ms + Glean.testOnlyIpc.aTimingDist.stopAndAccumulate(t3); // 5ms + + Glean.testOnlyIpc.aCustomDist.accumulateSamples(CUSTOM_SAMPLES); + + Glean.testOnlyIpc.aLabeledCounter.a_label.add(A_LABEL_COUNT); + Glean.testOnlyIpc.aLabeledCounter.another_label.add(ANOTHER_LABEL_COUNT); + + // Has to be different from aLabeledCounter so the error we record doesn't + // get in the way. + Glean.testOnlyIpc.anotherLabeledCounter.InvalidLabel.add(INVALID_COUNTERS); + + Glean.testOnlyIpc.irate.addToNumerator(IRATE_NUMERATOR); + Glean.testOnlyIpc.irate.addToDenominator(IRATE_DENOMINATOR); +}); + +add_task( + { skip_if: () => !runningInParent }, + async function test_child_metrics() { + Telemetry.setEventRecordingEnabled("telemetry.test", true); + + // Clear any stray Telemetry data + Telemetry.clearScalars(); + Telemetry.getSnapshotForHistograms("main", true); + Telemetry.clearEvents(); + + await run_test_in_child("test_GIFFTIPC.js"); + + // Wait for both IPC mechanisms to flush. + await Services.fog.testFlushAllChildren(); + await ContentTaskUtils.waitForCondition(() => { + let snapshot = Telemetry.getSnapshotForKeyedScalars(); + return ( + "content" in snapshot && + "telemetry.test.mirror_for_rate" in snapshot.content + ); + }); + + // boolean + // Doesn't work over IPC + + // counter + Assert.equal(Glean.testOnlyIpc.aCounter.testGetValue(), COUNT); + Assert.equal( + scalarValue("telemetry.test.mirror_for_counter", "content"), + COUNT, + "content-process Scalar has expected count" + ); + + // custom_distribution + const customSampleSum = CUSTOM_SAMPLES.reduce((acc, a) => acc + a, 0); + const customData = Glean.testOnlyIpc.aCustomDist.testGetValue("store1"); + Assert.equal(customSampleSum, customData.sum, "Sum's correct"); + for (let [bucket, count] of Object.entries(customData.values)) { + Assert.ok( + count == 0 || (count == CUSTOM_SAMPLES.length && bucket == 1), // both values in the low bucket + `Only two buckets have a sample ${bucket} ${count}` + ); + } + const histSnapshot = Telemetry.getSnapshotForHistograms( + "main", + false, + false + ); + const histData = histSnapshot.content.TELEMETRY_TEST_MIRROR_FOR_CUSTOM; + Assert.equal(customSampleSum, histData.sum, "Sum in histogram's correct"); + Assert.equal(2, histData.values["1"], "Two samples in the first bucket"); + + // datetime + // Doesn't work over IPC + + // event + var events = Glean.testOnlyIpc.noExtraEvent.testGetValue(); + Assert.equal(1, events.length); + Assert.equal("test_only.ipc", events[0].category); + Assert.equal("no_extra_event", events[0].name); + + events = Glean.testOnlyIpc.anEvent.testGetValue(); + Assert.equal(1, events.length); + Assert.equal("test_only.ipc", events[0].category); + Assert.equal("an_event", events[0].name); + Assert.deepEqual(EVENT_EXTRA, events[0].extra); + + TelemetryTestUtils.assertEvents( + [ + [ + "telemetry.test", + "not_expired_optout", + "object1", + undefined, + undefined, + ], + ["telemetry.test", "mirror_with_extra", "object1", null, EVENT_EXTRA], + ], + { category: "telemetry.test" }, + { process: "content" } + ); + + // labeled_boolean + // Doesn't work over IPC + + // labeled_counter + const counters = Glean.testOnlyIpc.aLabeledCounter; + Assert.equal(counters.a_label.testGetValue(), A_LABEL_COUNT); + Assert.equal(counters.another_label.testGetValue(), ANOTHER_LABEL_COUNT); + + Assert.throws( + () => Glean.testOnlyIpc.anotherLabeledCounter.__other__.testGetValue(), + /NS_ERROR_LOSS_OF_SIGNIFICANT_DATA/, + "Invalid labels record errors, which throw" + ); + + let value = keyedScalarValue( + "telemetry.test.another_mirror_for_labeled_counter", + "content" + ); + Assert.deepEqual( + { + a_label: A_LABEL_COUNT, + another_label: ANOTHER_LABEL_COUNT, + }, + value + ); + value = keyedScalarValue( + "telemetry.test.mirror_for_labeled_counter", + "content" + ); + Assert.deepEqual( + { + InvalidLabel: INVALID_COUNTERS, + }, + value + ); + + // labeled_string + // Doesn't work over IPC + + // memory_distribution + const memoryData = Glean.testOnlyIpc.aMemoryDist.testGetValue(); + const memorySum = MEMORIES.reduce((acc, a) => acc + a, 0); + // The sum's in bytes, but the metric's in KB + Assert.equal(memorySum * 1024, memoryData.sum); + for (let [bucket, count] of Object.entries(memoryData.values)) { + // We could assert instead, but let's skip to save the logspam. + if (count == 0) { + continue; + } + Assert.ok(count == 1 && MEMORY_BUCKETS.includes(bucket)); + } + + const memoryHist = histSnapshot.content.TELEMETRY_TEST_LINEAR; + Assert.equal( + memorySum, + memoryHist.sum, + "Histogram's in `memory_unit` units" + ); + Assert.equal(2, memoryHist.values["1"], "Samples are in the right bucket"); + + // quantity + // Doesn't work over IPC + + // rate + Assert.deepEqual( + { numerator: IRATE_NUMERATOR, denominator: IRATE_DENOMINATOR }, + Glean.testOnlyIpc.irate.testGetValue() + ); + Assert.deepEqual( + { numerator: IRATE_NUMERATOR, denominator: IRATE_DENOMINATOR }, + keyedScalarValue("telemetry.test.mirror_for_rate", "content") + ); + + // string + // Doesn't work over IPC + + // string_list + // Note: this will break if string list ever rearranges its items. + const cheesyStrings = Glean.testOnlyIpc.aStringList.testGetValue(); + Assert.deepEqual(cheesyStrings, [CHEESY_STRING, CHEESIER_STRING]); + // Note: this will break if keyed scalars rearrange their items. + Assert.deepEqual( + { + [CHEESY_STRING]: true, + [CHEESIER_STRING]: true, + }, + keyedScalarValue("telemetry.test.keyed_boolean_kind", "content") + ); + + // timespan + // Doesn't work over IPC + + // timing_distribution + const NANOS_IN_MILLIS = 1e6; + const EPSILON = 40000; // bug 1701949 + const times = Glean.testOnlyIpc.aTimingDist.testGetValue(); + Assert.greater(times.sum, 15 * NANOS_IN_MILLIS - EPSILON); + // We can't guarantee any specific time values (thank you clocks), + // but we can assert there are only two samples. + Assert.equal( + 2, + Object.entries(times.values).reduce( + (acc, [bucket, count]) => acc + count, + 0 + ) + ); + const timingHist = histSnapshot.content.TELEMETRY_TEST_EXPONENTIAL; + Assert.greaterOrEqual(timingHist.sum, 15, "Histogram's in milliseconds."); + Assert.equal( + 2, + Object.entries(timingHist.values).reduce( + (acc, [bucket, count]) => acc + count, + 0 + ), + "Only two samples" + ); + + // uuid + // Doesn't work over IPC + } +); diff --git a/toolkit/components/glean/tests/xpcshell/xpcshell.ini b/toolkit/components/glean/tests/xpcshell/xpcshell.ini index a196cf90232b0..2be9d081fe672 100644 --- a/toolkit/components/glean/tests/xpcshell/xpcshell.ini +++ b/toolkit/components/glean/tests/xpcshell/xpcshell.ini @@ -10,6 +10,8 @@ skip-if = os == "android" # FOG isn't responsible for monitoring prefs and contr
[test_GIFFT.js]
+[test_GIFFTIPC.js] + [test_Glean.js]
[test_GleanIPC.js] diff --git a/toolkit/components/telemetry/Events.yaml b/toolkit/components/telemetry/Events.yaml index 2153b8b0ee0ec..ef5f0c14fdd2d 100644 --- a/toolkit/components/telemetry/Events.yaml +++ b/toolkit/components/telemetry/Events.yaml @@ -1321,7 +1321,7 @@ telemetry.test: - "firefox" - "fennec" - "thunderbird" - record_in_processes: ["main"] + record_in_processes: ["main", "content"] expiry_version: "999" main_only: objects: ["object1"] @@ -1405,6 +1405,7 @@ telemetry.test: extra1: "This must be kept in-sync" extra2: "With the extra_keys in the Glean metric" products: ["firefox", "thunderbird"] + release_channel_collection: opt-out
# This is a secondary category used for Telemetry tests. # The events here will not be sent out with any pings. diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 041b96d54b72c..a0b0143a12db3 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -9714,6 +9714,7 @@ "high": 2147483646, "n_buckets": 10, "bug_numbers": [1288745, 1685406], + "releaseChannelCollection": "opt-out", "description": "a testing histogram; not meant to be touched" }, "TELEMETRY_TEST_LINEAR": { @@ -9726,10 +9727,11 @@ "high": 2147483646, "n_buckets": 10, "bug_numbers": [1288745, 1685406], + "releaseChannelCollection": "opt-out", "description": "a testing histogram; not meant to be touched" }, "TELEMETRY_TEST_MIRROR_FOR_CUSTOM": { - "record_in_processes": ["main"], + "record_in_processes": ["main", "content"], "products": ["firefox"], "alert_emails": ["chutten@mozilla.com"], "expires_in_version": "never", @@ -9738,6 +9740,7 @@ "high": 2147483646, "n_buckets": 10, "bug_numbers": [1716340], + "releaseChannelCollection": "opt-out", "description": "a testing histogram; not meant to be touched" }, "TELEMETRY_TEST_BOOLEAN": { diff --git a/toolkit/components/telemetry/Scalars.yaml b/toolkit/components/telemetry/Scalars.yaml index 2b4b9a01914e9..449b21b3d6a9c 100644 --- a/toolkit/components/telemetry/Scalars.yaml +++ b/toolkit/components/telemetry/Scalars.yaml @@ -7704,7 +7704,7 @@ telemetry.test: - 'geckoview_streaming' - 'thunderbird' record_in_processes: - - 'main' + - 'main' # test_ChildScalars.js depends on this being main-only.
string_kind: bug_numbers: @@ -7865,12 +7865,32 @@ telemetry.test: notification_emails: - telemetry-client-dev@mozilla.com release_channel_collection: opt-out + products: + - 'firefox' + - 'fennec' + - 'thunderbird' + record_in_processes: + - 'main' # test_ChildScalars.js depends on this being main-only + + mirror_for_labeled_counter: + bug_numbers: + - 1277806 + - 1685406 + - 1758795 + description: A testing keyed uint scalar; not meant to be touched. + expires: never + kind: uint + keyed: true + notification_emails: + - telemetry-client-dev@mozilla.com + release_channel_collection: opt-out products: - 'firefox' - 'fennec' - 'thunderbird' record_in_processes: - 'main' + - 'content'
keyed_with_keys: bug_numbers: @@ -7926,6 +7946,7 @@ telemetry.test: record_in_processes: - 'main' - 'content' + release_channel_collection: opt-out
content_only_uint: bug_numbers: @@ -8214,6 +8235,7 @@ telemetry.test: notification_emails: [glean-team@mozilla.com] products: ["firefox", "thunderbird"] record_in_processes: ["all"] + release_channel_collection: opt-out
mirror_for_timespan: bug_numbers: [1685406] @@ -8223,6 +8245,7 @@ telemetry.test: notification_emails: [glean-team@mozilla.com] products: ["firefox", "thunderbird"] record_in_processes: ["all"] + release_channel_collection: opt-out
mirror_for_timespan_nanos: bug_numbers: [1704106] @@ -8232,6 +8255,7 @@ telemetry.test: notification_emails: [glean-team@mozilla.com] products: ["firefox", "thunderbird"] record_in_processes: ["all"] + release_channel_collection: opt-out
mirror_for_labeled_bool: bug_numbers: [1685406] @@ -8242,6 +8266,7 @@ telemetry.test: notification_emails: [glean-team@mozilla.com] products: ["firefox", "thunderbird"] record_in_processes: ["all"] + release_channel_collection: opt-out
mirror_for_quantity: bug_numbers: [1704846] @@ -8251,6 +8276,7 @@ telemetry.test: notification_emails: [glean-team@mozilla.com] products: ["firefox", "thunderbird"] record_in_processes: ["all"] + release_channel_collection: opt-out
mirror_for_rate: bug_numbers: [1694496] @@ -8263,6 +8289,31 @@ telemetry.test: notification_emails: [glean-team@mozilla.com] products: ["firefox", "thunderbird"] record_in_processes: ["all"] + release_channel_collection: opt-out + + mirror_for_counter: + bug_numbers: [1758795] + description: > + Test only. This is a mirror probe for a Glean counter metric. + expires: never + kind: uint + notification_emails: [glean-team@mozilla.com] + products: ["firefox", "thunderbird"] + record_in_processes: ["all"] + release_channel_collection: opt-out + + another_mirror_for_labeled_counter: + bug_numbers: [1758795] + description: > + Test only. This is a mirror probe for a Glean labeled_counter metric. + Keys are labels in the mirrored metric. + expires: never + kind: uint + keyed: true + notification_emails: [glean-team@mozilla.com] + products: ["firefox", "thunderbird"] + record_in_processes: ["all"] + release_channel_collection: opt-out
# The following section contains counters for corruption of internal omni jar files.