Bug 1465129 - Collect telemetry data related to the storage.local "JSONFile to IDBBackend" data migrations. r=mixedpuppy

MozReview-Commit-ID: 3iGv5XkqeA3

--HG--
extra : rebase_source : fc18cd0c43c3930a5fbac3ed86c31835e16bc170
This commit is contained in:
Luca Greco 2018-06-17 13:38:02 +02:00
parent ba31bba005
commit bd7fd86aa9
3 changed files with 51 additions and 4 deletions

View File

@ -27,6 +27,7 @@ XPCOMUtils.defineLazyGetter(this, "WEBEXT_STORAGE_USER_CONTEXT_ID", () => {
const IDB_NAME = "webExtensions-storage-local";
const IDB_DATA_STORENAME = "storage-local-data";
const IDB_VERSION = 1;
const IDB_MIGRATE_RESULT_HISTOGRAM = "WEBEXT_STORAGE_LOCAL_IDB_MIGRATE_RESULT_COUNT";
// Whether or not the installed extensions should be migrated to the storage.local IndexedDB backend.
const BACKEND_ENABLED_PREF = "extensions.webextensions.ExtensionStorageIDB.enabled";
@ -238,6 +239,7 @@ async function migrateJSONFileData(extension, storagePrincipal) {
let hasEmptyIDB;
let oldDataRead = false;
let migrated = false;
let histogram = Services.telemetry.getHistogramById(IDB_MIGRATE_RESULT_HISTOGRAM);
try {
idbConn = await ExtensionStorageLocalIDB.openForPrincipal(storagePrincipal);
@ -279,6 +281,9 @@ async function migrateJSONFileData(extension, storagePrincipal) {
// the data migration promise explicitly (which would prevent the new backend
// from being enabled for this session).
Services.qms.clearStoragesForPrincipal(storagePrincipal);
histogram.add("failure");
throw err;
}
} finally {
@ -290,6 +295,8 @@ async function migrateJSONFileData(extension, storagePrincipal) {
}
}
histogram.add("success");
// If the IDB backend has been enabled, try to remove the old storage.local data file,
// but keep using the selected backend even if it fails to be removed.
if (oldStorageExists && migrated) {
@ -307,6 +314,7 @@ async function migrateJSONFileData(extension, storagePrincipal) {
*/
this.ExtensionStorageIDB = {
BACKEND_ENABLED_PREF,
IDB_MIGRATE_RESULT_HISTOGRAM,
// Map<extension-id, Set<Function>>
listeners: new Map(),

View File

@ -6,13 +6,16 @@
// from the JSONFile backend to the IDB backend.
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm");
ChromeUtils.import("resource://gre/modules/ExtensionStorage.jsm");
ChromeUtils.import("resource://gre/modules/ExtensionStorageIDB.jsm");
XPCOMUtils.defineLazyModuleGetters(this, {
ExtensionStorage: "resource://gre/modules/ExtensionStorage.jsm",
ExtensionStorageIDB: "resource://gre/modules/ExtensionStorageIDB.jsm",
OS: "resource://gre/modules/osfile.jsm",
});
const {IDB_MIGRATE_RESULT_HISTOGRAM} = ExtensionStorageIDB;
const CATEGORIES = ["success", "failure"];
async function createExtensionJSONFileWithData(extensionId, data) {
await ExtensionStorage.set(extensionId, data);
const jsonFile = await ExtensionStorage.getFile(extensionId);
@ -23,6 +26,20 @@ async function createExtensionJSONFileWithData(extensionId, data) {
return {jsonFile, oldStorageFilename};
}
function clearMigrationHistogram() {
const histogram = Services.telemetry.getHistogramById(IDB_MIGRATE_RESULT_HISTOGRAM);
histogram.clear();
equal(histogram.snapshot().sum, 0,
`No data recorded for histogram ${IDB_MIGRATE_RESULT_HISTOGRAM}`);
}
function assertMigrationHistogramCount(category, expectedCount) {
const histogram = Services.telemetry.getHistogramById(IDB_MIGRATE_RESULT_HISTOGRAM);
equal(histogram.snapshot().counts[CATEGORIES.indexOf(category)], expectedCount,
`Got the expected count on category "${category}" for histogram ${IDB_MIGRATE_RESULT_HISTOGRAM}`);
}
add_task(async function setup() {
Services.prefs.setBoolPref(ExtensionStorageIDB.BACKEND_ENABLED_PREF, true);
});
@ -56,6 +73,8 @@ add_task(async function test_storage_local_data_migration() {
browser.test.sendMessage("storage-local-data-migrated");
}
clearMigrationHistogram();
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["storage"],
@ -82,6 +101,9 @@ add_task(async function test_storage_local_data_migration() {
equal(await OS.File.exists(oldStorageFilename), false,
"The old json storage file should have been removed");
assertMigrationHistogramCount("success", 1);
assertMigrationHistogramCount("failure", 0);
await extension.unload();
});
@ -110,13 +132,15 @@ add_task(async function test_storage_local_corrupted_data_migration() {
const storedData = await browser.storage.local.get();
browser.test.assertEq(Object.keys(storedData).length, 0,
"No data should be found found on invalid data migration");
"No data should be found on invalid data migration");
await browser.storage.local.set({"test_key_string_on_IDBBackend": "expected-value"});
browser.test.sendMessage("storage-local-data-migrated-and-set");
}
clearMigrationHistogram();
let extension = ExtensionTestUtils.loadExtension({
manifest: {
permissions: ["storage"],
@ -143,6 +167,11 @@ add_task(async function test_storage_local_corrupted_data_migration() {
equal(await OS.File.exists(`${oldStorageFilename}.corrupt`), true,
"The old json storage should still be available if failed to be read");
// The extension is still migrated successfully to the new backend if the file from the
// original json file was corrupted.
assertMigrationHistogramCount("success", 1);
assertMigrationHistogramCount("failure", 0);
await extension.unload();
});

View File

@ -13439,7 +13439,7 @@
"n_buckets": 100,
"description": "The amount of time it takes to perform a set via storage.local using the JSONFile backend."
},
"WEBEXT_STORAGE_LOCAL_IDB_GET_MS": {
"WEBEXT_STORAGE_LOCAL_IDB_GET_MS": {
"record_in_processes": ["main", "content"],
"alert_emails": ["addons-dev-internal@mozilla.com"],
"bug_numbers": [1465120],
@ -13461,6 +13461,16 @@
"n_buckets": 100,
"description": "The amount of time it takes to perform a set via storage.local using the IndexedDB backend."
},
"WEBEXT_STORAGE_LOCAL_IDB_MIGRATE_RESULT_COUNT": {
"record_in_processes": ["main"],
"bug_numbers": [1465129],
"alert_emails": ["addons-dev-internal@mozilla.com"],
"expires_in_version": "67",
"kind": "categorical",
"labels": ["success", "failure"],
"releaseChannelCollection": "opt-out",
"description": "The number of times a storage.local backend data migration has been completed and results in one of the categories."
},
"EXTENSION_UPDATE_TYPE": {
"record_in_processes": ["main"],
"alert_emails": ["addons-dev-internal@mozilla.com"],