зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1553142 - Leverage ConsoleAPI in Remote Settings r=glasserc
Differential Revision: https://phabricator.services.mozilla.com/D32138 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
356929b6c2
Коммит
b538ac9a32
|
@ -265,6 +265,15 @@ By default, the entries returned by ``.get()`` are filtered based on the JEXL ex
|
|||
Debugging and manual testing
|
||||
============================
|
||||
|
||||
Logging
|
||||
-------
|
||||
|
||||
In order to enable verbose logging, set the log level preference to ``debug``.
|
||||
|
||||
.. code-block:: javascript
|
||||
|
||||
Services.prefs.setCharPref("services.settings.loglevel", "debug");
|
||||
|
||||
Remote Settings Dev Tools
|
||||
-------------------------
|
||||
|
||||
|
|
|
@ -33,6 +33,7 @@ const DB_NAME = "remote-settings";
|
|||
|
||||
const TELEMETRY_COMPONENT = "remotesettings";
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "console", () => Utils.log);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(this, "gServerURL",
|
||||
"services.settings.server");
|
||||
|
||||
|
@ -212,9 +213,11 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
// We'll try to avoid returning an empty list.
|
||||
if (await Utils.hasLocalDump(this.bucketName, this.collectionName)) {
|
||||
// Since there is a JSON dump, load it as default data.
|
||||
console.debug("Local DB is empty, load JSON dump");
|
||||
await RemoteSettingsWorker.importJSONDump(this.bucketName, this.collectionName);
|
||||
} else {
|
||||
// There is no JSON dump, force a synchronization from the server.
|
||||
console.debug("Local DB is empty, pull data from server");
|
||||
await this.sync({ loadDump: false });
|
||||
}
|
||||
// Either from trusted dump, or already done during sync.
|
||||
|
@ -230,8 +233,8 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
const kintoCollection = await this.openCollection();
|
||||
const { data } = await kintoCollection.list({ filters, order });
|
||||
|
||||
// Verify signature of local data.
|
||||
if (verifySignature) {
|
||||
console.debug("Verify signature of local data");
|
||||
const localRecords = data.map(r => kintoCollection.cleanLocalFields(r));
|
||||
const timestamp = await kintoCollection.db.getLastModified();
|
||||
const metadata = await kintoCollection.metadata();
|
||||
|
@ -299,6 +302,7 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
const imported = await RemoteSettingsWorker.importJSONDump(this.bucketName, this.collectionName);
|
||||
// The worker only returns an integer. List the imported records to build the sync event.
|
||||
if (imported > 0) {
|
||||
console.debug(`${imported} records loaded from JSON dump`);
|
||||
({ data: importedFromDump } = await kintoCollection.list());
|
||||
}
|
||||
collectionLastModified = await kintoCollection.db.getLastModified();
|
||||
|
@ -311,6 +315,7 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
// If the data is up to date, there's no need to sync. We still need
|
||||
// to record the fact that a check happened.
|
||||
if (expectedTimestamp <= collectionLastModified) {
|
||||
console.debug(`${this.identifier} local data is up-to-date`);
|
||||
reportStatus = UptakeTelemetry.STATUS.UP_TO_DATE;
|
||||
return;
|
||||
}
|
||||
|
@ -331,6 +336,8 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
// In case the signature is valid, apply the changes locally.
|
||||
return payload;
|
||||
}];
|
||||
} else {
|
||||
console.warn(`Signature disabled on ${this.identifier}`);
|
||||
}
|
||||
|
||||
let syncResult;
|
||||
|
@ -354,6 +361,7 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
// We will attempt to fix this by retrieving the whole
|
||||
// remote collection.
|
||||
try {
|
||||
console.warn(`Signature verified failed for ${this.identifier}. Retry from scratch`);
|
||||
syncResult = await this._retrySyncFromScratch(kintoCollection, expectedTimestamp);
|
||||
} catch (e) {
|
||||
// If the signature fails again, or if an error occured during wiping out the
|
||||
|
@ -392,6 +400,8 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
reportStatus = UptakeTelemetry.STATUS.APPLY_ERROR;
|
||||
throw e;
|
||||
}
|
||||
} else {
|
||||
console.info(`All changes are filtered by JEXL expressions for ${this.identifier}`);
|
||||
}
|
||||
} catch (e) {
|
||||
// IndexedDB errors. See https://developer.mozilla.org/en-US/docs/Web/API/IDBRequest/error
|
||||
|
@ -493,6 +503,7 @@ class RemoteSettingsClient extends EventEmitter {
|
|||
// replace the local data
|
||||
const localLastModified = await kintoCollection.db.getLastModified();
|
||||
if (timestamp >= localLastModified) {
|
||||
console.debug(`Import raw data from server for ${this.identifier}`);
|
||||
await kintoCollection.clear();
|
||||
await kintoCollection.loadDump(remoteRecords);
|
||||
await kintoCollection.db.saveLastModified(timestamp);
|
||||
|
|
|
@ -11,9 +11,25 @@ const {XPCOMUtils} = ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm")
|
|||
|
||||
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
|
||||
|
||||
// Create a new instance of the ConsoleAPI so we can control the maxLogLevel with a pref.
|
||||
// See LOG_LEVELS in Console.jsm. Common examples: "all", "debug", "info", "warn", "error".
|
||||
XPCOMUtils.defineLazyGetter(this, "log", () => {
|
||||
const { ConsoleAPI } = ChromeUtils.import("resource://gre/modules/Console.jsm", {});
|
||||
return new ConsoleAPI({
|
||||
maxLogLevel: "info",
|
||||
maxLogLevelPref: "services.settings.loglevel",
|
||||
prefix: "services.settings",
|
||||
});
|
||||
});
|
||||
|
||||
var Utils = {
|
||||
CHANGES_PATH: "/buckets/monitor/collections/changes/records",
|
||||
|
||||
/**
|
||||
* Logger instance.
|
||||
*/
|
||||
log,
|
||||
|
||||
/**
|
||||
* Check if local data exist for the specified client.
|
||||
*
|
||||
|
|
|
@ -52,6 +52,7 @@ const DEFAULT_SIGNER = "remote-settings.content-signature.mozilla.org";
|
|||
XPCOMUtils.defineLazyGetter(this, "gPrefs", () => {
|
||||
return Services.prefs.getBranch(PREF_SETTINGS_BRANCH);
|
||||
});
|
||||
XPCOMUtils.defineLazyGetter(this, "console", () => Utils.log);
|
||||
XPCOMUtils.defineLazyPreferenceGetter(this, "gServerURL", PREF_SETTINGS_BRANCH + PREF_SETTINGS_SERVER);
|
||||
|
||||
/**
|
||||
|
@ -107,6 +108,7 @@ function remoteSettingsFunction() {
|
|||
// Invalidate the polling status, since we want the new collection to
|
||||
// be taken into account.
|
||||
_invalidatePolling = true;
|
||||
console.debug(`Instantiated new client ${c.identifier}`);
|
||||
}
|
||||
return _clients.get(collectionName);
|
||||
};
|
||||
|
@ -140,6 +142,7 @@ function remoteSettingsFunction() {
|
|||
// Mainly because we cannot guess which `signerName` has to be used for example.
|
||||
// And we don't want to synchronize data for collections in the main bucket that are
|
||||
// completely unknown (ie. no database and no JSON dump).
|
||||
console.debug(`No known client for ${bucketName}/${collectionName}`);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -171,6 +174,7 @@ function remoteSettingsFunction() {
|
|||
}
|
||||
}
|
||||
|
||||
console.info("Start polling for changes");
|
||||
Services.obs.notifyObservers(null, "remote-settings:changes-poll-start", JSON.stringify({ expectedTimestamp }));
|
||||
|
||||
// Do we have the latest version already?
|
||||
|
@ -213,6 +217,7 @@ function remoteSettingsFunction() {
|
|||
|
||||
// Check if the server asked the clients to back off (for next poll).
|
||||
if (backoffSeconds) {
|
||||
console.info("Server asks clients to backoff for ${backoffSeconds} seconds");
|
||||
const backoffReleaseTime = Date.now() + backoffSeconds * 1000;
|
||||
gPrefs.setCharPref(PREF_SETTINGS_SERVER_BACKOFF, backoffReleaseTime);
|
||||
}
|
||||
|
@ -247,6 +252,7 @@ function remoteSettingsFunction() {
|
|||
// Save last time this client was successfully synced.
|
||||
Services.prefs.setIntPref(client.lastCheckTimePref, checkedServerTimeInSeconds);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
if (!firstError) {
|
||||
firstError = e;
|
||||
firstError.details = change;
|
||||
|
@ -276,6 +282,7 @@ function remoteSettingsFunction() {
|
|||
// Report the global synchronization success.
|
||||
await UptakeTelemetry.report(TELEMETRY_COMPONENT, UptakeTelemetry.STATUS.SUCCESS, syncTelemetryArgs);
|
||||
|
||||
console.info("Polling for changes done");
|
||||
Services.obs.notifyObservers(null, "remote-settings:changes-poll-end");
|
||||
};
|
||||
|
||||
|
@ -321,6 +328,7 @@ function remoteSettingsFunction() {
|
|||
* Startup function called from nsBrowserGlue.
|
||||
*/
|
||||
remoteSettings.init = () => {
|
||||
console.info("Initialize Remote Settings");
|
||||
// Hook the Push broadcast and RemoteSettings polling.
|
||||
// When we start on a new profile there will be no ETag stored.
|
||||
// Use an arbitrary ETag that is guaranteed not to occur.
|
||||
|
@ -348,6 +356,8 @@ var remoteSettingsBroadcastHandler = {
|
|||
pushBroadcastService.PHASES.REGISTER,
|
||||
].includes(phase);
|
||||
|
||||
console.info(`Push notification received (version=${version} phase=${phase})`);
|
||||
|
||||
return RemoteSettings.pollChanges({
|
||||
expectedTimestamp: version,
|
||||
trigger: isStartup ? "startup" : "broadcast",
|
||||
|
|
Загрузка…
Ссылка в новой задаче