Bug 1887765 - BackupService total backup size metric r=backup-reviewers,mconley

Differential Revision: https://phabricator.services.mozilla.com/D214438
This commit is contained in:
Stephen Thompson
2024-06-25 17:35:34 +00:00
parent 8a1025245f
commit e789eddb3e
8 changed files with 195 additions and 8 deletions

View File

@@ -17,6 +17,9 @@ const { ClientID } = ChromeUtils.importESModule(
);
add_setup(function () {
// FOG needs to be initialized in order for data to flow.
Services.fog.initializeFOG();
// Much of this setup is copied from toolkit/profile/xpcshell/head.js. It is
// needed in order to put the xpcshell test environment into the state where
// it thinks its profile is the one pointed at by
@@ -80,6 +83,11 @@ add_setup(function () {
* @returns {Promise<undefined>}
*/
async function testCreateBackupHelper(sandbox, taskFn) {
Services.fog.testResetFOG();
// Handle for the metric for total byte size of staging folder
let totalBackupSizeHistogram = TelemetryTestUtils.getAndClearHistogram(
"BROWSER_BACKUP_TOTAL_BACKUP_SIZE"
);
const EXPECTED_CLIENT_ID = await ClientID.getClientID();
let fake1ManifestEntry = { fake1: "hello from 1" };
@@ -222,6 +230,28 @@ async function testCreateBackupHelper(sandbox, taskFn) {
"The client ID was stored properly."
);
// 1 mebibyte minimum recorded value if staging folder is under 1 mebibyte
// This assumes that these BackupService tests do not create sizable fake files
const SMALLEST_BACKUP_SIZE_BYTES = 1048576;
const SMALLEST_BACKUP_SIZE_MEBIBYTES = 1;
let totalBackupSize = Glean.browserBackup.totalBackupSize.testGetValue();
Assert.equal(
totalBackupSize.count,
1,
"Should have collected a single measurement for the total backup size"
);
Assert.equal(
totalBackupSize.sum,
SMALLEST_BACKUP_SIZE_BYTES,
"Should have collected the right value for the total backup size"
);
TelemetryTestUtils.assertHistogram(
totalBackupSizeHistogram,
SMALLEST_BACKUP_SIZE_MEBIBYTES,
1
);
taskFn(manifest);
// After createBackup is more fleshed out, we're going to want to make sure

View File

@@ -0,0 +1,71 @@
/* Any copyright is dedicated to the Public Domain.
https://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const { MeasurementUtils } = ChromeUtils.importESModule(
"resource:///modules/backup/MeasurementUtils.sys.mjs"
);
add_task(async function test_minimumFallback() {
const fuzzed = MeasurementUtils.fuzzByteSize(250, 1000);
Assert.equal(
fuzzed,
1000,
"Should fall back to the `nearest` value when `bytes` are below `nearest`"
);
});
add_task(async function test_roundUp() {
const fuzzed = MeasurementUtils.fuzzByteSize(1500, 1000);
Assert.equal(
fuzzed,
2000,
"Should round up to 2000 when `bytes` is 1500 since that is the nearest 1000 bytes"
);
});
add_task(async function test_roundDown() {
const fuzzed = MeasurementUtils.fuzzByteSize(1499, 1000);
Assert.equal(
fuzzed,
1000,
"Should round down to 1000 when `bytes` is 1499 since that is the nearest 1000 bytes"
);
});
add_task(async function test_roundDownSmallerUnit() {
const fuzzed = MeasurementUtils.fuzzByteSize(1025, 10);
Assert.equal(
fuzzed,
1030,
"Should round 1025 up to 1030 since that is the nearest 10 bytes"
);
});
add_task(async function test_roundDownSmallerUnit() {
const fuzzed = MeasurementUtils.fuzzByteSize(1024, 10);
Assert.equal(
fuzzed,
1020,
"Should round 1024 down to 1020 since that is the nearest 10 bytes"
);
});
add_task(async function test_roundUpBinary() {
const fuzzed = MeasurementUtils.fuzzByteSize(1500, 1024);
Assert.equal(
fuzzed,
1024,
"Should round 1500 down to 1024 nearest kibibyte value"
);
});
add_task(async function test_roundDownBinary() {
const fuzzed = MeasurementUtils.fuzzByteSize(1800, 1024);
Assert.equal(
fuzzed,
2048,
"Should round 1800 up to 2048 since that is the nearest kibibyte value"
);
});

View File

@@ -35,6 +35,8 @@ skip-if = ["apple_silicon && automation"] # bug 1729538
["test_BackupService_takeMeasurements.js"]
["test_MeasurementUtils_fuzzByteSize.js"]
["test_CookiesBackupResource.js"]
["test_CredentialsAndSecurityBackupResource.js"]