Bug 1523310 - Distinguish broadcast from scheduled sync in Remote Settings r=glasserc

Distinguish broadcast from scheduled sync in Remote Settings

Differential Revision: https://phabricator.services.mozilla.com/D22339

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mathieu Leplatre 2019-03-07 14:44:52 +00:00
Родитель 5e459d846d
Коммит f3d65462af
5 изменённых файлов: 28 добавлений и 8 удалений

Просмотреть файл

@ -87,6 +87,7 @@ class UptakeTelemetry {
* @param {string} status the uptake status (eg. "network_error")
* @param {Object} extra extra values to report
* @param {string} extra.source the update source (eg. "recipe-42").
* @param {string} extra.trigger what triggered the polling/fetching (eg. "broadcast", "timer").
*/
static report(component, status, extra = {}) {
const { source } = extra;

Просмотреть файл

@ -282,7 +282,7 @@ class RemoteSettingsClient extends EventEmitter {
* @return {Promise} which rejects on sync or process failure.
*/
async maybeSync(expectedTimestamp, options = { loadDump: true }) {
const { loadDump } = options;
const { loadDump, trigger } = options;
let reportStatus = null;
try {
@ -399,7 +399,7 @@ class RemoteSettingsClient extends EventEmitter {
reportStatus = UptakeTelemetry.STATUS.SUCCESS;
}
// Report success/error status to Telemetry.
UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, { source: this.identifier });
UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, { source: this.identifier, trigger });
}
}

Просмотреть файл

@ -156,15 +156,19 @@ function remoteSettingsFunction() {
* @returns {Promise} or throws error if something goes wrong.
*/
remoteSettings.pollChanges = async ({ expectedTimestamp } = {}) => {
const trigger = expectedTimestamp ? "broadcast" : "timer";
const telemetryArgs = {
source: TELEMETRY_SOURCE,
trigger,
};
// Check if the server backoff time is elapsed.
if (gPrefs.prefHasUserValue(PREF_SETTINGS_SERVER_BACKOFF)) {
const backoffReleaseTime = gPrefs.getCharPref(PREF_SETTINGS_SERVER_BACKOFF);
const remainingMilliseconds = parseInt(backoffReleaseTime, 10) - Date.now();
if (remainingMilliseconds > 0) {
// Backoff time has not elapsed yet.
UptakeTelemetry.report(TELEMETRY_COMPONENT,
UptakeTelemetry.STATUS.BACKOFF,
{ source: TELEMETRY_SOURCE });
UptakeTelemetry.report(TELEMETRY_COMPONENT, UptakeTelemetry.STATUS.BACKOFF, telemetryArgs);
throw new Error(`Server is asking clients to back off; retry in ${Math.ceil(remainingMilliseconds / 1000)}s.`);
} else {
gPrefs.clearUserPref(PREF_SETTINGS_SERVER_BACKOFF);
@ -194,7 +198,7 @@ function remoteSettingsFunction() {
} else {
reportStatus = UptakeTelemetry.STATUS.UNKNOWN_ERROR;
}
UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, { source: TELEMETRY_SOURCE });
UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, telemetryArgs);
// No need to go further.
throw new Error(`Polling for changes failed: ${e.message}.`);
}
@ -204,7 +208,7 @@ function remoteSettingsFunction() {
// Report polling success to Uptake Telemetry.
const reportStatus = changes.length === 0 ? UptakeTelemetry.STATUS.UP_TO_DATE
: UptakeTelemetry.STATUS.SUCCESS;
UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, { source: TELEMETRY_SOURCE });
UptakeTelemetry.report(TELEMETRY_COMPONENT, reportStatus, telemetryArgs);
// Check if the server asked the clients to back off (for next poll).
if (backoffSeconds) {
@ -236,7 +240,7 @@ function remoteSettingsFunction() {
// Start synchronization! It will be a no-op if the specified `lastModified` equals
// the one in the local database.
try {
await client.maybeSync(last_modified, { loadDump });
await client.maybeSync(last_modified, { loadDump, trigger });
// Save last time this client was successfully synced.
Services.prefs.setIntPref(client.lastCheckTimePref, checkedServerTimeInSeconds);

Просмотреть файл

@ -1009,6 +1009,9 @@ uptake.remotecontent.result:
source: >
A label to distinguish what is being pulled or updated in the component (eg. recipe id,
settings collection name, ...).
trigger: >
A label to distinguish what triggered the polling/fetching of remote content (eg. "broadcast",
"timer")
bug_numbers:
- 1517469
record_in_processes: ["main"]

Просмотреть файл

@ -79,6 +79,18 @@ Example:
UptakeTelemetry.report(COMPONENT, status, { source: UPDATE_SOURCE });
Additional Event Info
'''''''''''''''''''''
The Event API allows to report additional information. We support the following optional fields:
- ``trigger``: A label to distinguish what triggered the polling/fetching of remote content (eg. ``"broadcast"``, ``"timer"``)
.. code-block:: js
UptakeTelemetry.report(component, status, { source, trigger: "timer" });
Use-cases
---------