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 {string} status the uptake status (eg. "network_error")
* @param {Object} extra extra values to report * @param {Object} extra extra values to report
* @param {string} extra.source the update source (eg. "recipe-42"). * @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 = {}) { static report(component, status, extra = {}) {
const { source } = extra; const { source } = extra;

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

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

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

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

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

@ -79,6 +79,18 @@ Example:
UptakeTelemetry.report(COMPONENT, status, { source: UPDATE_SOURCE }); 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 Use-cases
--------- ---------