Bug 1908727 - Add probes for the initial state and configuration for BackupService. r=backup-reviewers,kpatenio

Differential Revision: https://phabricator.services.mozilla.com/D221531
This commit is contained in:
Mike Conley
2024-11-04 20:22:54 +00:00
parent 80db9dce32
commit 69ffa598ec
4 changed files with 306 additions and 6 deletions

View File

@@ -133,7 +133,13 @@ XPCOMUtils.defineLazyPreferenceGetter(
*/
null,
async function onUpdateLocationDirPath(_pref, _prevVal, newVal) {
let bs = BackupService.get();
let bs;
try {
bs = BackupService.get();
} catch (e) {
// This can throw if the BackupService hasn't initialized yet, which
// is a case we're okay to ignore.
}
if (bs) {
await bs.onUpdateLocationDirPath(newVal);
}
@@ -677,6 +683,14 @@ export class BackupService extends EventTarget {
*/
#regenerationDebouncer = null;
/**
* True if takeMeasurements has been called and various measurements related
* to the BackupService have been taken.
*
* @type {boolean}
*/
#takenMeasurements = false;
/**
* The path of the default parent directory for saving backups.
* The current default is the Documents directory.
@@ -903,10 +917,7 @@ export class BackupService extends EventTarget {
}
this.#instance = new BackupService(DefaultBackupResources);
this.#instance.checkForPostRecovery().then(() => {
this.#instance.takeMeasurements();
});
this.#instance.checkForPostRecovery();
this.#instance.initBackupScheduler();
return this.#instance;
}
@@ -2869,7 +2880,19 @@ export class BackupService extends EventTarget {
async takeMeasurements() {
lazy.logConsole.debug("Taking Telemetry measurements");
// We'll start by measuring the available disk space on the storage
// We'll start by taking some basic BackupService state measurements.
Glean.browserBackup.enabled.set(true);
Glean.browserBackup.schedulerEnabled.set(lazy.scheduledBackupsPref);
await this.loadEncryptionState();
Glean.browserBackup.pswdEncrypted.set(this.#_state.encryptionEnabled);
const USING_DEFAULT_DIR_PATH =
lazy.backupDirPref ==
PathUtils.join(lazy.defaultParentDirPath, BackupService.BACKUP_DIR_NAME);
Glean.browserBackup.locationOnDevice.set(USING_DEFAULT_DIR_PATH ? 1 : 2);
// Next, we'll measure the available disk space on the storage
// device that the profile directory is on.
let profileDir = await IOUtils.getFile(PathUtils.profileDir);
@@ -3301,6 +3324,11 @@ export class BackupService extends EventTarget {
*/
onIdle() {
lazy.logConsole.debug("Saw idle callback");
if (!this.#takenMeasurements) {
this.takeMeasurements();
this.#takenMeasurements = true;
}
if (lazy.scheduledBackupsPref) {
lazy.logConsole.debug("Scheduled backups enabled.");
let now = Math.floor(Date.now() / 1000);

View File

@@ -11,6 +11,68 @@ $tags:
- 'Firefox :: Profiles'
browser.backup:
enabled:
type: boolean
description: >
True if the BackupService is enabled by default.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_sensitivity:
- technical
notification_emails:
- mconley@mozilla.com
expires: never
telemetry_mirror: BROWSER_BACKUP_ENABLED
scheduler_enabled:
type: boolean
description: >
True if the BackupService is configured to automatically create backups
in the background.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_sensitivity:
- technical
notification_emails:
- mconley@mozilla.com
expires: never
telemetry_mirror: BROWSER_BACKUP_SCHEDULER_ENABLED
pswd_encrypted:
type: boolean
description: >
True if the BackupService is configured to encrypt backups.
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_sensitivity:
- technical
notification_emails:
- mconley@mozilla.com
expires: never
telemetry_mirror: BROWSER_BACKUP_PSWD_ENCRYPTED
location_on_device:
type: quantity
unit: enum (see description)
description: >
1 = the default location, 2 = a non-default location
bugs:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_reviews:
- https://bugzilla.mozilla.org/show_bug.cgi?id=1908727
data_sensitivity:
- technical
notification_emails:
- mconley@mozilla.com
expires: never
telemetry_mirror: BROWSER_BACKUP_LOCATION_ON_DEVICE
prof_d_disk_space:
type: quantity
unit: kilobyte

View File

@@ -41,6 +41,8 @@ add_task(async function test_takeMeasurements() {
* Tests that we can measure the disk space available in the profile directory.
*/
add_task(async function test_profDDiskSpace() {
Services.telemetry.clearScalars();
let bs = new BackupService();
await bs.takeMeasurements();
let measurement = Glean.browserBackup.profDDiskSpace.testGetValue();
@@ -57,3 +59,154 @@ add_task(async function test_profDDiskSpace() {
"device"
);
});
/**
* Tests that we record a scalar if the BackupService is configured to
* initialize on launch.
*/
add_task(async function test_BackupService_enabled_state() {
Services.telemetry.clearScalars();
let bs = new BackupService();
await bs.takeMeasurements();
Assert.ok(
Glean.browserBackup.enabled.testGetValue(),
"Should have set the enabled scalar."
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.enabled",
true,
"Should have set the enabled scalar in legacy Telemetry."
);
});
/**
* Tests that we record a scalar if the BackupService is configured to
* initialize on launch.
*/
add_task(async function test_BackupService_scheduler_enabled_state() {
Services.telemetry.clearScalars();
const SCHEDULED_BACKUPS_ENABLED_PREF_NAME =
"browser.backup.scheduled.enabled";
Services.prefs.setBoolPref(SCHEDULED_BACKUPS_ENABLED_PREF_NAME, false);
let bs = new BackupService();
await bs.takeMeasurements();
Assert.ok(
!Glean.browserBackup.schedulerEnabled.testGetValue(),
"Scalar for scheduled backups should be false"
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.scheduler_enabled",
false,
"Scalar for scheduled backups should be false in legacy Telemetry."
);
Services.telemetry.clearScalars();
Services.prefs.setBoolPref(SCHEDULED_BACKUPS_ENABLED_PREF_NAME, true);
await bs.takeMeasurements();
Assert.ok(
Glean.browserBackup.schedulerEnabled.testGetValue(),
"Scalar for scheduled backups should be true"
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.scheduler_enabled",
true,
"Scalar for scheduled backups should be true in legacy Telemetry."
);
// Now reset the scheduling state to the default to not interfere with
// other tests.
Services.prefs.clearUserPref(SCHEDULED_BACKUPS_ENABLED_PREF_NAME);
});
/**
* Tests that we record a scalar if the BackupService is configured to
* encrypt backups.
*/
add_task(async function test_BackupService_pswd_encrypted_state() {
Services.telemetry.clearScalars();
let bs = new BackupService();
await bs.takeMeasurements();
Assert.ok(
!Glean.browserBackup.pswdEncrypted.testGetValue(),
"Scalar for encrypted backups should be false"
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.pswd_encrypted",
false,
"Scalar for encrypted backups should be false in legacy Telemetry."
);
Services.telemetry.clearScalars();
const tempDir = await IOUtils.createUniqueDirectory(
PathUtils.tempDir,
"BackupService-takeMeasurements-test"
);
await bs.enableEncryption("some-fake-password", tempDir);
await bs.takeMeasurements();
Assert.ok(
Glean.browserBackup.pswdEncrypted.testGetValue(),
"Scalar for encrypted backups should be true"
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.pswd_encrypted",
true,
"Scalar for encrypted backups should be true in legacy Telemetry."
);
await maybeRemovePath(tempDir);
});
/**
* Tests that we record a scalar that tells us if backups are configured to
* be written to the default location, or somewhere else entirely.
*/
add_task(async function test_BackupService_location_on_device() {
Services.telemetry.clearScalars();
const DEFAULT_LOCATION = 1;
const NON_DEFAULT_LOCATION = 2;
let bs = new BackupService();
bs.setParentDirPath(PathUtils.tempDir);
await bs.takeMeasurements();
Assert.equal(
Glean.browserBackup.locationOnDevice.testGetValue(),
NON_DEFAULT_LOCATION,
"Scalar for location on device should indicate the non-default " +
"location"
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.location_on_device",
NON_DEFAULT_LOCATION,
"Scalar for location on device should indicate the non-default " +
"location in legacy Telemetry."
);
Services.telemetry.clearScalars();
// The system "Docs" folder is considered the default location.
bs.setParentDirPath(Services.dirsvc.get("Docs", Ci.nsIFile).path);
await bs.takeMeasurements();
Assert.equal(
Glean.browserBackup.locationOnDevice.testGetValue(),
DEFAULT_LOCATION,
"Scalar for location on device should indicate the default location"
);
TelemetryTestUtils.assertScalar(
TelemetryTestUtils.getProcessScalars("parent", false, true),
"browser.backup.location_on_device",
DEFAULT_LOCATION,
"Scalar for location on device should indicate the default " +
"location in legacy Telemetry."
);
});

View File

@@ -373,6 +373,63 @@ installation.firstSeen:
- 'new-profile'
browser.backup:
enabled:
bug_numbers:
- 1908727
description: >
True if the BackupService is enabled by default.
expires: never
kind: boolean
notification_emails:
- mconley@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
record_in_processes:
- 'main'
scheduler_enabled:
bug_numbers:
- 1908727
description: >
True if the BackupService is configured to automatically create backups
in the background.
expires: never
kind: boolean
notification_emails:
- mconley@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
record_in_processes:
- 'main'
pswd_encrypted:
bug_numbers:
- 1908727
description: >
True if the BackupService is configured to encrypt backups.
expires: never
kind: boolean
notification_emails:
- mconley@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
record_in_processes:
- 'main'
location_on_device:
bug_numbers:
- 1908727
description: >
1 = the default location, 2 = a non-default location
expires: never
kind: uint
notification_emails:
- mconley@mozilla.com
release_channel_collection: opt-out
products:
- 'firefox'
record_in_processes:
- 'main'
prof_d_disk_space:
bug_numbers:
- 1884407