2012-11-14 08:22:09 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-01-27 23:26:48 +04:00
|
|
|
#ifndef MERGED_COMPARTMENT
|
|
|
|
|
2014-08-08 08:52:05 +04:00
|
|
|
"use strict";
|
|
|
|
|
2012-11-14 08:22:09 +04:00
|
|
|
this.EXPORTED_SYMBOLS = ["HealthReporter"];
|
|
|
|
|
|
|
|
const {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
|
|
|
|
2013-01-27 23:26:48 +04:00
|
|
|
const MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000;
|
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/Metrics.jsm");
|
2013-01-30 19:07:22 +04:00
|
|
|
Cu.import("resource://services-common/async.js");
|
2013-02-14 04:32:45 +04:00
|
|
|
|
|
|
|
Cu.import("resource://services-common/bagheeraclient.js");
|
2013-01-27 23:26:48 +04:00
|
|
|
#endif
|
|
|
|
|
2013-08-26 22:55:58 +04:00
|
|
|
Cu.import("resource://gre/modules/Log.jsm");
|
2012-11-14 08:22:09 +04:00
|
|
|
Cu.import("resource://services-common/utils.js");
|
2013-06-14 05:36:21 +04:00
|
|
|
Cu.import("resource://gre/modules/Promise.jsm");
|
2012-11-16 22:05:19 +04:00
|
|
|
Cu.import("resource://gre/modules/osfile.jsm");
|
2013-04-15 23:45:37 +04:00
|
|
|
Cu.import("resource://gre/modules/Preferences.jsm");
|
2013-01-07 00:13:27 +04:00
|
|
|
Cu.import("resource://gre/modules/Services.jsm");
|
|
|
|
Cu.import("resource://gre/modules/Task.jsm");
|
2013-02-02 01:28:02 +04:00
|
|
|
Cu.import("resource://gre/modules/TelemetryStopwatch.jsm");
|
2013-01-07 00:13:27 +04:00
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2012-11-14 08:22:09 +04:00
|
|
|
|
2015-04-27 19:07:58 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "TelemetryController",
|
|
|
|
"resource://gre/modules/TelemetryController.jsm");
|
2015-09-14 21:04:19 +03:00
|
|
|
XPCOMUtils.defineLazyModuleGetter(this, "UpdateUtils",
|
|
|
|
"resource://gre/modules/UpdateUtils.jsm");
|
2012-11-14 08:22:09 +04:00
|
|
|
|
|
|
|
// Oldest year to allow in date preferences. This module was implemented in
|
|
|
|
// 2012 and no dates older than that should be encountered.
|
|
|
|
const OLDEST_ALLOWED_YEAR = 2012;
|
|
|
|
|
2013-01-07 00:13:27 +04:00
|
|
|
const DAYS_IN_PAYLOAD = 180;
|
|
|
|
|
|
|
|
const DEFAULT_DATABASE_NAME = "healthreport.sqlite";
|
|
|
|
|
2013-02-02 01:28:02 +04:00
|
|
|
const TELEMETRY_INIT = "HEALTHREPORT_INIT_MS";
|
2013-02-19 00:45:53 +04:00
|
|
|
const TELEMETRY_INIT_FIRSTRUN = "HEALTHREPORT_INIT_FIRSTRUN_MS";
|
|
|
|
const TELEMETRY_DB_OPEN = "HEALTHREPORT_DB_OPEN_MS";
|
|
|
|
const TELEMETRY_DB_OPEN_FIRSTRUN = "HEALTHREPORT_DB_OPEN_FIRSTRUN_MS";
|
2013-02-02 01:28:02 +04:00
|
|
|
const TELEMETRY_GENERATE_PAYLOAD = "HEALTHREPORT_GENERATE_JSON_PAYLOAD_MS";
|
2013-02-19 00:45:53 +04:00
|
|
|
const TELEMETRY_JSON_PAYLOAD_SERIALIZE = "HEALTHREPORT_JSON_PAYLOAD_SERIALIZE_MS";
|
2013-03-13 21:14:41 +04:00
|
|
|
const TELEMETRY_PAYLOAD_SIZE_UNCOMPRESSED = "HEALTHREPORT_PAYLOAD_UNCOMPRESSED_BYTES";
|
|
|
|
const TELEMETRY_PAYLOAD_SIZE_COMPRESSED = "HEALTHREPORT_PAYLOAD_COMPRESSED_BYTES";
|
2013-02-02 01:28:02 +04:00
|
|
|
const TELEMETRY_UPLOAD = "HEALTHREPORT_UPLOAD_MS";
|
2013-02-19 00:45:53 +04:00
|
|
|
const TELEMETRY_COLLECT_CONSTANT = "HEALTHREPORT_COLLECT_CONSTANT_DATA_MS";
|
|
|
|
const TELEMETRY_COLLECT_DAILY = "HEALTHREPORT_COLLECT_DAILY_MS";
|
|
|
|
const TELEMETRY_SHUTDOWN = "HEALTHREPORT_SHUTDOWN_MS";
|
2013-03-27 01:28:22 +04:00
|
|
|
const TELEMETRY_COLLECT_CHECKPOINT = "HEALTHREPORT_POST_COLLECT_CHECKPOINT_MS";
|
2012-11-14 08:22:09 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper type to assist with management of Health Reporter state.
|
|
|
|
*
|
|
|
|
* Instances are not meant to be created outside of a HealthReporter instance.
|
|
|
|
*
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
* There are two types of IDs associated with clients.
|
|
|
|
*
|
|
|
|
* Since the beginning of FHR, there has existed a per-upload ID: a UUID is
|
|
|
|
* generated at upload time and associated with the state before upload starts.
|
|
|
|
* That same upload includes a request to delete all other upload IDs known by
|
|
|
|
* the client.
|
|
|
|
*
|
|
|
|
* Per-upload IDs had the unintended side-effect of creating "orphaned"
|
|
|
|
* records/upload IDs on the server. So, a stable client identifer has been
|
|
|
|
* introduced. This client identifier is generated when it's missing and sent
|
|
|
|
* as part of every upload.
|
|
|
|
*
|
|
|
|
* There is a high chance we may remove upload IDs in the future.
|
2013-05-10 22:04:48 +04:00
|
|
|
*/
|
|
|
|
function HealthReporterState(reporter) {
|
|
|
|
this._reporter = reporter;
|
|
|
|
|
|
|
|
let profD = OS.Constants.Path.profileDir;
|
|
|
|
|
|
|
|
if (!profD || !profD.length) {
|
|
|
|
throw new Error("Could not obtain profile directory. OS.File not " +
|
|
|
|
"initialized properly?");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log = reporter._log;
|
|
|
|
|
|
|
|
this._stateDir = OS.Path.join(profD, "healthreport");
|
|
|
|
|
|
|
|
// To facilitate testing.
|
|
|
|
let leaf = reporter._stateLeaf || "state.json";
|
|
|
|
|
|
|
|
this._filename = OS.Path.join(this._stateDir, leaf);
|
|
|
|
this._log.debug("Storing state in " + this._filename);
|
|
|
|
this._s = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
HealthReporterState.prototype = Object.freeze({
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
/**
|
|
|
|
* Persistent string identifier associated with this client.
|
|
|
|
*/
|
|
|
|
get clientID() {
|
|
|
|
return this._s.clientID;
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The version associated with the client ID.
|
|
|
|
*/
|
|
|
|
get clientIDVersion() {
|
|
|
|
return this._s.clientIDVersion;
|
|
|
|
},
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
get lastPingDate() {
|
|
|
|
return new Date(this._s.lastPingTime);
|
|
|
|
},
|
|
|
|
|
|
|
|
get lastSubmitID() {
|
|
|
|
return this._s.remoteIDs[0];
|
|
|
|
},
|
|
|
|
|
|
|
|
get remoteIDs() {
|
|
|
|
return this._s.remoteIDs;
|
|
|
|
},
|
|
|
|
|
2013-06-18 22:06:20 +04:00
|
|
|
get _lastPayloadPath() {
|
|
|
|
return OS.Path.join(this._stateDir, "lastpayload.json");
|
|
|
|
},
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
init: function () {
|
2014-10-10 19:21:18 +04:00
|
|
|
return Task.spawn(function* init() {
|
|
|
|
yield OS.File.makeDir(this._stateDir);
|
2013-05-10 22:04:48 +04:00
|
|
|
|
2014-10-17 19:24:04 +04:00
|
|
|
let drs = Cc["@mozilla.org/datareporting/service;1"]
|
|
|
|
.getService(Ci.nsISupports)
|
|
|
|
.wrappedJSObject;
|
|
|
|
let drsClientID = yield drs.getClientID();
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
let resetObjectState = function () {
|
|
|
|
this._s = {
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
// The payload version. This is bumped whenever there is a
|
|
|
|
// backwards-incompatible change.
|
2013-05-10 22:04:48 +04:00
|
|
|
v: 1,
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
// The persistent client identifier.
|
2014-10-17 19:24:04 +04:00
|
|
|
clientID: drsClientID,
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
// Denotes the mechanism used to generate the client identifier.
|
|
|
|
// 1: Random UUID.
|
|
|
|
clientIDVersion: 1,
|
|
|
|
// Upload IDs that might be on the server.
|
2013-05-10 22:04:48 +04:00
|
|
|
remoteIDs: [],
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
// When we last performed an uploaded.
|
2013-05-10 22:04:48 +04:00
|
|
|
lastPingTime: 0,
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
// Tracks whether we removed an outdated payload.
|
2013-06-18 22:06:20 +04:00
|
|
|
removedOutdatedLastpayload: false,
|
2013-05-10 22:04:48 +04:00
|
|
|
};
|
|
|
|
}.bind(this);
|
|
|
|
|
|
|
|
try {
|
|
|
|
this._s = yield CommonUtils.readJSON(this._filename);
|
2014-05-22 10:11:00 +04:00
|
|
|
} catch (ex if ex instanceof OS.File.Error &&
|
|
|
|
ex.becauseNoSuchFile) {
|
2013-05-10 22:04:48 +04:00
|
|
|
this._log.warn("Saved state file does not exist.");
|
|
|
|
resetObjectState();
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Exception when reading state from disk: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
resetObjectState();
|
|
|
|
|
|
|
|
// Don't save in case it goes away on next run.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof(this._s) != "object") {
|
|
|
|
this._log.warn("Read state is not an object. Resetting state.");
|
2013-06-18 22:06:20 +04:00
|
|
|
resetObjectState();
|
2013-05-10 22:04:48 +04:00
|
|
|
yield this.save();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this._s.v != 1) {
|
|
|
|
this._log.warn("Unknown version in state file: " + this._s.v);
|
2013-06-18 22:06:20 +04:00
|
|
|
resetObjectState();
|
2013-05-10 22:04:48 +04:00
|
|
|
// We explicitly don't save here in the hopes an application re-upgrade
|
|
|
|
// comes along and fixes us.
|
|
|
|
}
|
|
|
|
|
2014-10-17 19:24:04 +04:00
|
|
|
this._s.clientID = drsClientID;
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
// Always look for preferences. This ensures that downgrades followed
|
|
|
|
// by reupgrades don't result in excessive data loss.
|
|
|
|
for (let promise of this._migratePrefs()) {
|
|
|
|
yield promise;
|
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
save: function () {
|
|
|
|
this._log.info("Writing state file: " + this._filename);
|
|
|
|
return CommonUtils.writeJSON(this._s, this._filename);
|
|
|
|
},
|
|
|
|
|
|
|
|
addRemoteID: function (id) {
|
|
|
|
this._log.warn("Recording new remote ID: " + id);
|
|
|
|
this._s.remoteIDs.push(id);
|
|
|
|
return this.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
removeRemoteID: function (id) {
|
2013-06-21 21:30:30 +04:00
|
|
|
return this.removeRemoteIDs(id ? [id] : []);
|
|
|
|
},
|
|
|
|
|
|
|
|
removeRemoteIDs: function (ids) {
|
|
|
|
if (!ids || !ids.length) {
|
|
|
|
this._log.warn("No IDs passed for removal.");
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log.warn("Removing documents from remote ID list: " + ids);
|
|
|
|
let filtered = this._s.remoteIDs.filter((x) => ids.indexOf(x) === -1);
|
2013-05-10 22:04:48 +04:00
|
|
|
|
|
|
|
if (filtered.length == this._s.remoteIDs.length) {
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
|
|
|
this._s.remoteIDs = filtered;
|
|
|
|
return this.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
setLastPingDate: function (date) {
|
|
|
|
this._s.lastPingTime = date.getTime();
|
|
|
|
|
|
|
|
return this.save();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateLastPingAndRemoveRemoteID: function (date, id) {
|
2013-06-21 21:30:30 +04:00
|
|
|
return this.updateLastPingAndRemoveRemoteIDs(date, id ? [id] : []);
|
|
|
|
},
|
|
|
|
|
|
|
|
updateLastPingAndRemoveRemoteIDs: function (date, ids) {
|
|
|
|
if (!ids) {
|
2013-05-10 22:04:48 +04:00
|
|
|
return this.setLastPingDate(date);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log.info("Recording last ping time and deleted remote document.");
|
|
|
|
this._s.lastPingTime = date.getTime();
|
2013-06-21 21:30:30 +04:00
|
|
|
return this.removeRemoteIDs(ids);
|
2013-05-10 22:04:48 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_migratePrefs: function () {
|
|
|
|
let prefs = this._reporter._prefs;
|
|
|
|
|
|
|
|
let lastID = prefs.get("lastSubmitID", null);
|
|
|
|
let lastPingDate = CommonUtils.getDatePref(prefs, "lastPingTime",
|
|
|
|
0, this._log, OLDEST_ALLOWED_YEAR);
|
|
|
|
|
|
|
|
// If we have state from prefs, migrate and save it to a file then clear
|
|
|
|
// out old prefs.
|
|
|
|
if (lastID || (lastPingDate && lastPingDate.getTime() > 0)) {
|
|
|
|
this._log.warn("Migrating saved state from preferences.");
|
|
|
|
|
|
|
|
if (lastID) {
|
|
|
|
this._log.info("Migrating last saved ID: " + lastID);
|
|
|
|
this._s.remoteIDs.push(lastID);
|
|
|
|
}
|
|
|
|
|
|
|
|
let ourLast = this.lastPingDate;
|
|
|
|
|
|
|
|
if (lastPingDate && lastPingDate.getTime() > ourLast.getTime()) {
|
|
|
|
this._log.info("Migrating last ping time: " + lastPingDate);
|
|
|
|
this._s.lastPingTime = lastPingDate.getTime();
|
|
|
|
}
|
|
|
|
|
|
|
|
yield this.save();
|
|
|
|
prefs.reset(["lastSubmitID", "lastPingTime"]);
|
|
|
|
} else {
|
2015-01-28 10:22:06 +03:00
|
|
|
this._log.debug("No prefs data found.");
|
2013-05-10 22:04:48 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2012-11-14 08:22:09 +04:00
|
|
|
/**
|
2013-02-14 04:32:45 +04:00
|
|
|
* This is the abstract base class of `HealthReporter`. It exists so that
|
|
|
|
* we can sanely divide work on platforms where control of Firefox Health
|
|
|
|
* Report is outside of Gecko (e.g., Android).
|
2012-11-14 08:22:09 +04:00
|
|
|
*/
|
2013-02-14 04:32:45 +04:00
|
|
|
function AbstractHealthReporter(branch, policy, sessionRecorder) {
|
2012-11-14 08:22:09 +04:00
|
|
|
if (!branch.endsWith(".")) {
|
2013-01-07 00:13:27 +04:00
|
|
|
throw new Error("Branch must end with a period (.): " + branch);
|
2012-11-14 08:22:09 +04:00
|
|
|
}
|
|
|
|
|
2013-01-12 01:45:22 +04:00
|
|
|
if (!policy) {
|
|
|
|
throw new Error("Must provide policy to HealthReporter constructor.");
|
|
|
|
}
|
|
|
|
|
2013-08-26 22:55:58 +04:00
|
|
|
this._log = Log.repository.getLogger("Services.HealthReport.HealthReporter");
|
2013-01-07 00:13:27 +04:00
|
|
|
this._log.info("Initializing health reporter instance against " + branch);
|
2012-11-14 08:22:09 +04:00
|
|
|
|
2013-01-19 10:35:07 +04:00
|
|
|
this._branch = branch;
|
2012-11-14 08:22:09 +04:00
|
|
|
this._prefs = new Preferences(branch);
|
|
|
|
|
2013-01-12 01:45:22 +04:00
|
|
|
this._policy = policy;
|
2013-01-19 10:35:07 +04:00
|
|
|
this.sessionRecorder = sessionRecorder;
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-01-12 01:45:22 +04:00
|
|
|
this._dbName = this._prefs.get("dbName") || DEFAULT_DATABASE_NAME;
|
2013-01-07 00:13:27 +04:00
|
|
|
|
|
|
|
this._storage = null;
|
|
|
|
this._storageInProgress = false;
|
2013-03-07 17:06:46 +04:00
|
|
|
this._providerManager = null;
|
|
|
|
this._providerManagerInProgress = false;
|
2013-05-10 22:04:48 +04:00
|
|
|
this._initializeStarted = false;
|
2013-01-07 00:13:27 +04:00
|
|
|
this._initialized = false;
|
|
|
|
this._initializeHadError = false;
|
|
|
|
this._initializedDeferred = Promise.defer();
|
|
|
|
this._shutdownRequested = false;
|
|
|
|
this._shutdownInitiated = false;
|
|
|
|
this._shutdownComplete = false;
|
2014-05-22 10:11:00 +04:00
|
|
|
this._deferredShutdown = Promise.defer();
|
|
|
|
this._promiseShutdown = this._deferredShutdown.promise;
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-02-28 04:52:26 +04:00
|
|
|
this._errors = [];
|
|
|
|
|
2013-02-05 21:59:15 +04:00
|
|
|
this._lastDailyDate = null;
|
2013-01-31 20:58:19 +04:00
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
// Yes, this will probably run concurrently with remaining constructor work.
|
2013-02-19 00:45:53 +04:00
|
|
|
let hasFirstRun = this._prefs.get("service.firstRun", false);
|
|
|
|
this._initHistogram = hasFirstRun ? TELEMETRY_INIT : TELEMETRY_INIT_FIRSTRUN;
|
|
|
|
this._dbOpenHistogram = hasFirstRun ? TELEMETRY_DB_OPEN : TELEMETRY_DB_OPEN_FIRSTRUN;
|
2014-12-12 16:50:07 +03:00
|
|
|
|
2014-12-24 15:32:51 +03:00
|
|
|
// This is set to the name for the provider that we are currently initializing,
|
|
|
|
// shutting down or collecting data from, if any.
|
|
|
|
// This is used for AsyncShutdownTimeout diagnostics.
|
2014-12-12 16:50:07 +03:00
|
|
|
this._currentProviderInShutdown = null;
|
2014-12-18 18:43:39 +03:00
|
|
|
this._currentProviderInInit = null;
|
2014-12-24 15:32:51 +03:00
|
|
|
this._currentProviderInCollect = null;
|
2012-11-14 08:22:09 +04:00
|
|
|
}
|
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
AbstractHealthReporter.prototype = Object.freeze({
|
2013-01-07 00:13:27 +04:00
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether the service is fully initialized and running.
|
|
|
|
*
|
|
|
|
* If this is false, it is not safe to call most functions.
|
|
|
|
*/
|
|
|
|
get initialized() {
|
|
|
|
return this._initialized;
|
|
|
|
},
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
/**
|
|
|
|
* Initialize the instance.
|
|
|
|
*
|
|
|
|
* This must be called once after object construction or the instance is
|
|
|
|
* useless.
|
|
|
|
*/
|
|
|
|
init: function () {
|
|
|
|
if (this._initializeStarted) {
|
|
|
|
throw new Error("We have already started initialization.");
|
|
|
|
}
|
|
|
|
|
|
|
|
this._initializeStarted = true;
|
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
return Task.spawn(function*() {
|
|
|
|
TelemetryStopwatch.start(this._initHistogram, this);
|
|
|
|
|
|
|
|
try {
|
|
|
|
yield this._state.init();
|
|
|
|
|
|
|
|
if (!this._state._s.removedOutdatedLastpayload) {
|
|
|
|
yield this._deleteOldLastPayload();
|
|
|
|
this._state._s.removedOutdatedLastpayload = true;
|
|
|
|
// Normally we should save this to a file but it directly conflicts with
|
|
|
|
// the "application re-upgrade" decision in HealthReporterState::init()
|
|
|
|
// which specifically does not save the state to a file.
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error deleting last payload: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
|
|
|
|
// As soon as we have could have storage, we need to register cleanup or
|
|
|
|
// else bad things happen on shutdown.
|
|
|
|
Services.obs.addObserver(this, "quit-application", false);
|
2013-05-10 22:04:48 +04:00
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
// The database needs to be shut down by the end of shutdown
|
|
|
|
// phase profileBeforeChange.
|
|
|
|
Metrics.Storage.shutdown.addBlocker("FHR: Flushing storage shutdown",
|
2014-06-09 20:07:00 +04:00
|
|
|
() => {
|
|
|
|
// Workaround bug 1017706
|
|
|
|
// Apparently, in some cases, quit-application is not triggered
|
|
|
|
// (or is triggered after profile-before-change), so we need to
|
|
|
|
// make sure that `_initiateShutdown()` is triggered at least
|
|
|
|
// once.
|
|
|
|
this._initiateShutdown();
|
|
|
|
return this._promiseShutdown;
|
|
|
|
},
|
2014-06-02 06:28:00 +04:00
|
|
|
() => ({
|
|
|
|
shutdownInitiated: this._shutdownInitiated,
|
|
|
|
initialized: this._initialized,
|
|
|
|
shutdownRequested: this._shutdownRequested,
|
|
|
|
initializeHadError: this._initializeHadError,
|
|
|
|
providerManagerInProgress: this._providerManagerInProgress,
|
|
|
|
storageInProgress: this._storageInProgress,
|
|
|
|
hasProviderManager: !!this._providerManager,
|
|
|
|
hasStorage: !!this._storage,
|
2014-12-12 16:50:07 +03:00
|
|
|
shutdownComplete: this._shutdownComplete,
|
|
|
|
currentProviderInShutdown: this._currentProviderInShutdown,
|
2014-12-18 18:43:39 +03:00
|
|
|
currentProviderInInit: this._currentProviderInInit,
|
2014-12-24 20:08:45 +03:00
|
|
|
currentProviderInCollect: this._currentProviderInCollect,
|
2014-06-02 06:28:00 +04:00
|
|
|
}));
|
2013-05-10 22:04:48 +04:00
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
try {
|
|
|
|
this._storageInProgress = true;
|
|
|
|
TelemetryStopwatch.start(this._dbOpenHistogram, this);
|
|
|
|
let storage = yield Metrics.Storage(this._dbName);
|
|
|
|
TelemetryStopwatch.finish(this._dbOpenHistogram, this);
|
|
|
|
yield this._onStorageCreated();
|
|
|
|
|
|
|
|
delete this._dbOpenHistogram;
|
|
|
|
this._log.info("Storage initialized.");
|
|
|
|
this._storage = storage;
|
|
|
|
this._storageInProgress = false;
|
|
|
|
|
|
|
|
if (this._shutdownRequested) {
|
|
|
|
this._initiateShutdown();
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield this._initializeProviderManager();
|
|
|
|
yield this._onProviderManagerInitialized();
|
|
|
|
this._initializedDeferred.resolve();
|
|
|
|
return this.onInit();
|
|
|
|
} catch (ex) {
|
|
|
|
yield this._onInitError(ex);
|
|
|
|
this._initializedDeferred.reject(ex);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-05-10 22:04:48 +04:00
|
|
|
},
|
|
|
|
|
2013-01-07 00:13:27 +04:00
|
|
|
//----------------------------------------------------
|
|
|
|
// SERVICE CONTROL FUNCTIONS
|
|
|
|
//
|
|
|
|
// You shouldn't need to call any of these externally.
|
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
|
|
_onInitError: function (error) {
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.cancel(this._initHistogram, this);
|
|
|
|
TelemetryStopwatch.cancel(this._dbOpenHistogram, this);
|
|
|
|
delete this._initHistogram;
|
|
|
|
delete this._dbOpenHistogram;
|
|
|
|
|
2013-02-28 04:52:26 +04:00
|
|
|
this._recordError("Error during initialization", error);
|
2013-01-07 00:13:27 +04:00
|
|
|
this._initializeHadError = true;
|
|
|
|
this._initiateShutdown();
|
2014-05-22 10:11:00 +04:00
|
|
|
return Promise.reject(error);
|
2013-01-07 00:13:27 +04:00
|
|
|
|
|
|
|
// FUTURE consider poisoning prototype's functions so calls fail with a
|
|
|
|
// useful error message.
|
|
|
|
},
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
|
2013-06-18 22:06:20 +04:00
|
|
|
/**
|
|
|
|
* Removes the outdated lastpaylaod.json and lastpayload.json.tmp files
|
|
|
|
* @see Bug #867902
|
|
|
|
* @return a promise for when all the files have been deleted
|
|
|
|
*/
|
|
|
|
_deleteOldLastPayload: function () {
|
|
|
|
let paths = [this._state._lastPayloadPath, this._state._lastPayloadPath + ".tmp"];
|
|
|
|
return Task.spawn(function removeAllFiles () {
|
|
|
|
for (let path of paths) {
|
|
|
|
try {
|
|
|
|
OS.File.remove(path);
|
|
|
|
} catch (ex) {
|
|
|
|
if (!ex.becauseNoSuchFile) {
|
|
|
|
this._log.error("Exception when removing outdated payload files: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-05-10 22:04:48 +04:00
|
|
|
},
|
|
|
|
|
2014-08-13 22:18:22 +04:00
|
|
|
_initializeProviderManager: Task.async(function* _initializeProviderManager() {
|
2013-01-07 00:13:27 +04:00
|
|
|
if (this._collector) {
|
2013-03-07 17:06:46 +04:00
|
|
|
throw new Error("Provider manager has already been initialized.");
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
|
|
|
|
2013-03-07 17:06:46 +04:00
|
|
|
this._log.info("Initializing provider manager.");
|
|
|
|
this._providerManager = new Metrics.ProviderManager(this._storage);
|
|
|
|
this._providerManager.onProviderError = this._recordError.bind(this);
|
2013-03-12 01:12:24 +04:00
|
|
|
this._providerManager.onProviderInit = this._initProvider.bind(this);
|
2013-03-07 17:06:46 +04:00
|
|
|
this._providerManagerInProgress = true;
|
2013-01-07 00:13:27 +04:00
|
|
|
|
|
|
|
let catString = this._prefs.get("service.providerCategories") || "";
|
|
|
|
if (catString.length) {
|
|
|
|
for (let category of catString.split(",")) {
|
2014-12-18 18:43:39 +03:00
|
|
|
yield this._providerManager.registerProvidersFromCategoryManager(category,
|
|
|
|
providerName => this._currentProviderInInit = providerName);
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
2014-12-18 18:43:39 +03:00
|
|
|
this._currentProviderInInit = null;
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
2014-08-13 22:18:22 +04:00
|
|
|
}),
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-03-07 17:06:46 +04:00
|
|
|
_onProviderManagerInitialized: function () {
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.finish(this._initHistogram, this);
|
|
|
|
delete this._initHistogram;
|
2013-03-07 17:06:46 +04:00
|
|
|
this._log.debug("Provider manager initialized.");
|
|
|
|
this._providerManagerInProgress = false;
|
2013-01-07 01:53:33 +04:00
|
|
|
|
2013-01-07 00:13:27 +04:00
|
|
|
if (this._shutdownRequested) {
|
|
|
|
this._initiateShutdown();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log.info("HealthReporter started.");
|
|
|
|
this._initialized = true;
|
|
|
|
Services.obs.addObserver(this, "idle-daily", false);
|
2013-01-25 12:39:01 +04:00
|
|
|
|
2013-03-13 20:34:41 +04:00
|
|
|
// If upload is not enabled, ensure daily collection works. If upload
|
|
|
|
// is enabled, this will be performed as part of upload.
|
|
|
|
//
|
|
|
|
// This is important because it ensures about:healthreport contains
|
|
|
|
// longitudinal data even if upload is disabled. Having about:healthreport
|
|
|
|
// provide useful info even if upload is disabled was a core launch
|
|
|
|
// requirement.
|
|
|
|
//
|
|
|
|
// We do not catch changes to the backing pref. So, if the session lasts
|
|
|
|
// many days, we may fail to collect. However, most sessions are short and
|
|
|
|
// this code will likely be refactored as part of splitting up policy to
|
|
|
|
// serve Android. So, meh.
|
|
|
|
if (!this._policy.healthReportUploadEnabled) {
|
|
|
|
this._log.info("Upload not enabled. Scheduling daily collection.");
|
|
|
|
// Since the timer manager is a singleton and there could be multiple
|
|
|
|
// HealthReporter instances, we need to encode a unique identifier in
|
|
|
|
// the timer ID.
|
|
|
|
try {
|
2015-03-01 03:51:33 +03:00
|
|
|
let timerName = this._branch.replace(/\./g, "-") + "lastDailyCollection";
|
2013-03-13 20:34:41 +04:00
|
|
|
let tm = Cc["@mozilla.org/updates/timer-manager;1"]
|
|
|
|
.getService(Ci.nsIUpdateTimerManager);
|
|
|
|
tm.registerTimer(timerName, this.collectMeasurements.bind(this),
|
|
|
|
24 * 60 * 60);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error registering collection timer: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-25 12:39:01 +04:00
|
|
|
// Clean up caches and reduce memory usage.
|
|
|
|
this._storage.compact();
|
2013-01-07 00:13:27 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
// nsIObserver to handle shutdown.
|
|
|
|
observe: function (subject, topic, data) {
|
|
|
|
switch (topic) {
|
|
|
|
case "quit-application":
|
|
|
|
Services.obs.removeObserver(this, "quit-application");
|
|
|
|
this._initiateShutdown();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "idle-daily":
|
|
|
|
this._performDailyMaintenance();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_initiateShutdown: function () {
|
|
|
|
// Ensure we only begin the main shutdown sequence once.
|
|
|
|
if (this._shutdownInitiated) {
|
|
|
|
this._log.warn("Shutdown has already been initiated. No-op.");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log.info("Request to shut down.");
|
|
|
|
|
|
|
|
this._initialized = false;
|
|
|
|
this._shutdownRequested = true;
|
|
|
|
|
2013-02-28 04:52:29 +04:00
|
|
|
if (this._initializeHadError) {
|
|
|
|
this._log.warn("Initialization had error. Shutting down immediately.");
|
|
|
|
} else {
|
2014-06-02 06:28:00 +04:00
|
|
|
if (this._providerManagerInProgress) {
|
2013-03-07 17:06:46 +04:00
|
|
|
this._log.warn("Provider manager is in progress of initializing. " +
|
|
|
|
"Waiting to finish.");
|
2013-02-28 04:52:29 +04:00
|
|
|
return;
|
|
|
|
}
|
2013-01-07 01:53:33 +04:00
|
|
|
|
2013-02-28 04:52:29 +04:00
|
|
|
// If storage is in the process of initializing, we need to wait for it
|
|
|
|
// to finish before continuing. The initialization process will call us
|
|
|
|
// again once storage has initialized.
|
|
|
|
if (this._storageInProgress) {
|
|
|
|
this._log.warn("Storage is in progress of initializing. Waiting to finish.");
|
|
|
|
return;
|
|
|
|
}
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
|
|
|
|
2013-01-07 04:24:50 +04:00
|
|
|
this._log.warn("Initiating main shutdown procedure.");
|
|
|
|
|
2013-01-07 00:13:27 +04:00
|
|
|
// Everything from here must only be performed once or else race conditions
|
|
|
|
// could occur.
|
2013-02-19 00:45:53 +04:00
|
|
|
|
|
|
|
TelemetryStopwatch.start(TELEMETRY_SHUTDOWN, this);
|
2013-01-07 00:13:27 +04:00
|
|
|
this._shutdownInitiated = true;
|
|
|
|
|
2013-01-16 02:53:34 +04:00
|
|
|
// We may not have registered the observer yet. If not, this will
|
|
|
|
// throw.
|
|
|
|
try {
|
2013-01-07 04:24:50 +04:00
|
|
|
Services.obs.removeObserver(this, "idle-daily");
|
2013-01-16 02:53:34 +04:00
|
|
|
} catch (ex) { }
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
Task.spawn(function*() {
|
2013-12-04 03:45:17 +04:00
|
|
|
try {
|
2014-05-22 10:11:00 +04:00
|
|
|
if (this._providerManager) {
|
|
|
|
this._log.info("Shutting down provider manager.");
|
|
|
|
for (let provider of this._providerManager.providers) {
|
|
|
|
try {
|
2014-12-12 16:50:07 +03:00
|
|
|
this._log.info("Shutting down provider: " + provider.name);
|
|
|
|
this._currentProviderInShutdown = provider.name;
|
2014-05-22 10:11:00 +04:00
|
|
|
yield provider.shutdown();
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Error when shutting down provider: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this._log.info("Provider manager shut down.");
|
|
|
|
this._providerManager = null;
|
2014-12-12 16:50:07 +03:00
|
|
|
this._currentProviderInShutdown = null;
|
2014-05-22 10:11:00 +04:00
|
|
|
this._onProviderManagerShutdown();
|
|
|
|
}
|
|
|
|
if (this._storage) {
|
|
|
|
this._log.info("Shutting down storage.");
|
|
|
|
try {
|
|
|
|
yield this._storage.close();
|
|
|
|
yield this._onStorageClose();
|
|
|
|
} catch (error) {
|
|
|
|
this._log.warn("Error when closing storage: " +
|
|
|
|
CommonUtils.exceptionStr(error));
|
|
|
|
}
|
|
|
|
this._storage = null;
|
|
|
|
}
|
2013-01-07 04:24:50 +04:00
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
this._log.warn("Shutdown complete.");
|
|
|
|
this._shutdownComplete = true;
|
|
|
|
} finally {
|
|
|
|
this._deferredShutdown.resolve();
|
|
|
|
TelemetryStopwatch.finish(TELEMETRY_SHUTDOWN, this);
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2013-01-07 00:13:27 +04:00
|
|
|
},
|
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
onInit: function() {
|
|
|
|
return this._initializedDeferred.promise;
|
2013-12-04 03:45:17 +04:00
|
|
|
},
|
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
_onStorageCreated: function() {
|
|
|
|
// Do nothing.
|
|
|
|
// This method provides a hook point for the test suite.
|
2013-12-04 03:45:17 +04:00
|
|
|
},
|
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
_onStorageClose: function() {
|
|
|
|
// Do nothing.
|
|
|
|
// This method provides a hook point for the test suite.
|
2013-12-04 03:45:17 +04:00
|
|
|
},
|
|
|
|
|
2014-05-22 10:11:00 +04:00
|
|
|
_onProviderManagerShutdown: function() {
|
|
|
|
// Do nothing.
|
|
|
|
// This method provides a hook point for the test suite.
|
2013-01-07 00:13:27 +04:00
|
|
|
},
|
|
|
|
|
2012-11-14 08:22:09 +04:00
|
|
|
/**
|
2013-01-07 00:13:27 +04:00
|
|
|
* Convenience method to shut down the instance.
|
2012-11-16 22:05:19 +04:00
|
|
|
*
|
2013-01-07 00:13:27 +04:00
|
|
|
* This should *not* be called outside of tests.
|
2012-11-14 08:22:09 +04:00
|
|
|
*/
|
2013-01-07 00:13:27 +04:00
|
|
|
_shutdown: function () {
|
|
|
|
this._initiateShutdown();
|
2014-05-22 10:11:00 +04:00
|
|
|
return this._promiseShutdown;
|
2013-01-07 00:13:27 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_performDailyMaintenance: function () {
|
|
|
|
this._log.info("Request to perform daily maintenance.");
|
|
|
|
|
|
|
|
if (!this._initialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
let now = new Date();
|
|
|
|
let cutoff = new Date(now.getTime() - MILLISECONDS_PER_DAY * (DAYS_IN_PAYLOAD - 1));
|
|
|
|
|
|
|
|
// The operation is enqueued and put in a transaction by the storage module.
|
|
|
|
this._storage.pruneDataBefore(cutoff);
|
2012-11-14 08:22:09 +04:00
|
|
|
},
|
|
|
|
|
2013-01-07 00:13:27 +04:00
|
|
|
//--------------------
|
|
|
|
// Provider Management
|
|
|
|
//--------------------
|
|
|
|
|
2013-02-13 04:32:45 +04:00
|
|
|
/**
|
|
|
|
* Obtain a provider from its name.
|
|
|
|
*
|
|
|
|
* This will only return providers that are currently initialized. If
|
2013-02-19 01:05:07 +04:00
|
|
|
* a provider is lazy initialized (like pull-only providers) this
|
2013-02-13 04:32:45 +04:00
|
|
|
* will likely not return anything.
|
|
|
|
*/
|
|
|
|
getProvider: function (name) {
|
2013-05-01 20:41:55 +04:00
|
|
|
if (!this._providerManager) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2013-03-07 17:06:46 +04:00
|
|
|
return this._providerManager.getProvider(name);
|
2013-02-13 04:32:45 +04:00
|
|
|
},
|
|
|
|
|
2013-03-12 01:12:24 +04:00
|
|
|
_initProvider: function (provider) {
|
2013-01-31 20:58:19 +04:00
|
|
|
provider.healthReporter = this;
|
2013-02-07 07:26:26 +04:00
|
|
|
},
|
|
|
|
|
2013-02-28 04:52:26 +04:00
|
|
|
/**
|
|
|
|
* Record an exception for reporting in the payload.
|
|
|
|
*
|
|
|
|
* A side effect is the exception is logged.
|
|
|
|
*
|
|
|
|
* Note that callers need to be extra sensitive about ensuring personal
|
|
|
|
* or otherwise private details do not leak into this. All of the user data
|
|
|
|
* on the stack in FHR code should be limited to data we were collecting with
|
|
|
|
* the intent to submit. So, it is covered under the user's consent to use
|
|
|
|
* the feature.
|
|
|
|
*
|
|
|
|
* @param message
|
|
|
|
* (string) Human readable message describing error.
|
|
|
|
* @param ex
|
|
|
|
* (Error) The error that should be captured.
|
|
|
|
*/
|
|
|
|
_recordError: function (message, ex) {
|
|
|
|
let recordMessage = message;
|
|
|
|
let logMessage = message;
|
|
|
|
|
|
|
|
if (ex) {
|
2013-03-19 02:07:07 +04:00
|
|
|
recordMessage += ": " + CommonUtils.exceptionStr(ex);
|
2013-02-28 04:52:26 +04:00
|
|
|
logMessage += ": " + CommonUtils.exceptionStr(ex);
|
|
|
|
}
|
|
|
|
|
2013-03-05 22:31:12 +04:00
|
|
|
// Scrub out potentially identifying information from strings that could
|
|
|
|
// make the payload.
|
|
|
|
let appData = Services.dirsvc.get("UAppData", Ci.nsIFile);
|
|
|
|
let profile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
|
|
|
|
|
|
|
let appDataURI = Services.io.newFileURI(appData);
|
|
|
|
let profileURI = Services.io.newFileURI(profile);
|
|
|
|
|
|
|
|
// Order of operation is important here. We do the URI before the path version
|
|
|
|
// because the path may be a subset of the URI. We also have to check for the case
|
|
|
|
// where UAppData is underneath the profile directory (or vice-versa) so we
|
|
|
|
// don't substitute incomplete strings.
|
|
|
|
|
2015-03-01 03:51:33 +03:00
|
|
|
// Return a /g regex that matches the provided string exactly.
|
|
|
|
function regexify(s) {
|
|
|
|
return new RegExp(s.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"), "g");
|
|
|
|
}
|
|
|
|
|
2013-03-05 22:31:12 +04:00
|
|
|
function replace(uri, path, thing) {
|
|
|
|
// Try is because .spec can throw on invalid URI.
|
|
|
|
try {
|
2015-03-01 03:51:33 +03:00
|
|
|
recordMessage = recordMessage.replace(regexify(uri.spec), "<" + thing + "URI>");
|
2013-03-05 22:31:12 +04:00
|
|
|
} catch (ex) { }
|
|
|
|
|
2015-03-01 03:51:33 +03:00
|
|
|
recordMessage = recordMessage.replace(regexify(path), "<" + thing + "Path>");
|
2013-03-05 22:31:12 +04:00
|
|
|
}
|
|
|
|
|
2015-04-29 18:32:05 +03:00
|
|
|
if (appData.path.includes(profile.path)) {
|
2013-03-05 22:31:12 +04:00
|
|
|
replace(appDataURI, appData.path, 'AppData');
|
|
|
|
replace(profileURI, profile.path, 'Profile');
|
|
|
|
} else {
|
|
|
|
replace(profileURI, profile.path, 'Profile');
|
|
|
|
replace(appDataURI, appData.path, 'AppData');
|
|
|
|
}
|
|
|
|
|
2013-02-28 04:52:26 +04:00
|
|
|
this._log.warn(logMessage);
|
|
|
|
this._errors.push(recordMessage);
|
|
|
|
},
|
|
|
|
|
2013-02-07 07:26:26 +04:00
|
|
|
/**
|
|
|
|
* Collect all measurements for all registered providers.
|
|
|
|
*/
|
|
|
|
collectMeasurements: function () {
|
2013-03-16 08:10:08 +04:00
|
|
|
if (!this._initialized) {
|
|
|
|
return Promise.reject(new Error("Not initialized."));
|
|
|
|
}
|
|
|
|
|
2013-02-07 07:26:26 +04:00
|
|
|
return Task.spawn(function doCollection() {
|
2013-04-22 23:33:24 +04:00
|
|
|
yield this._providerManager.ensurePullOnlyProvidersRegistered();
|
|
|
|
|
2013-01-31 20:58:19 +04:00
|
|
|
try {
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.start(TELEMETRY_COLLECT_CONSTANT, this);
|
2014-12-24 15:32:51 +03:00
|
|
|
yield this._providerManager.collectConstantData(name => this._currentProviderInCollect = name);
|
|
|
|
this._currentProviderInCollect = null;
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.finish(TELEMETRY_COLLECT_CONSTANT, this);
|
2013-02-07 07:26:26 +04:00
|
|
|
} catch (ex) {
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.cancel(TELEMETRY_COLLECT_CONSTANT, this);
|
2013-02-07 07:26:26 +04:00
|
|
|
this._log.warn("Error collecting constant data: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
2013-01-31 20:58:19 +04:00
|
|
|
}
|
|
|
|
|
2013-02-05 21:59:15 +04:00
|
|
|
// Daily data is collected if it hasn't yet been collected this
|
|
|
|
// application session or if it has been more than a day since the
|
|
|
|
// last collection. This means that providers could see many calls to
|
|
|
|
// collectDailyData per calendar day. However, this collection API
|
|
|
|
// makes no guarantees about limits. The alternative would involve
|
|
|
|
// recording state. The simpler implementation prevails for now.
|
|
|
|
if (!this._lastDailyDate ||
|
|
|
|
Date.now() - this._lastDailyDate > MILLISECONDS_PER_DAY) {
|
|
|
|
|
|
|
|
try {
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.start(TELEMETRY_COLLECT_DAILY, this);
|
2013-02-05 21:59:15 +04:00
|
|
|
this._lastDailyDate = new Date();
|
2014-12-24 15:32:51 +03:00
|
|
|
yield this._providerManager.collectDailyData(name => this._currentProviderInCollect = name);
|
|
|
|
this._currentProviderInCollect = null;
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.finish(TELEMETRY_COLLECT_DAILY, this);
|
2013-02-05 21:59:15 +04:00
|
|
|
} catch (ex) {
|
2013-02-19 00:45:53 +04:00
|
|
|
TelemetryStopwatch.cancel(TELEMETRY_COLLECT_DAILY, this);
|
2013-02-05 21:59:15 +04:00
|
|
|
this._log.warn("Error collecting daily data from providers: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-22 23:33:24 +04:00
|
|
|
yield this._providerManager.ensurePullOnlyProvidersUnregistered();
|
|
|
|
|
2013-03-27 01:28:22 +04:00
|
|
|
// Flush gathered data to disk. This will incur an fsync. But, if
|
|
|
|
// there is ever a time we want to persist data to disk, it's
|
|
|
|
// after a massive collection.
|
|
|
|
try {
|
|
|
|
TelemetryStopwatch.start(TELEMETRY_COLLECT_CHECKPOINT, this);
|
|
|
|
yield this._storage.checkpoint();
|
|
|
|
TelemetryStopwatch.finish(TELEMETRY_COLLECT_CHECKPOINT, this);
|
|
|
|
} catch (ex) {
|
|
|
|
TelemetryStopwatch.cancel(TELEMETRY_COLLECT_CHECKPOINT, this);
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
2013-02-05 21:59:15 +04:00
|
|
|
throw new Task.Result();
|
2013-01-31 20:58:19 +04:00
|
|
|
}.bind(this));
|
2012-11-14 08:22:09 +04:00
|
|
|
},
|
|
|
|
|
2013-02-06 08:31:48 +04:00
|
|
|
/**
|
|
|
|
* Helper function to perform data collection and obtain the JSON payload.
|
|
|
|
*
|
|
|
|
* If you are looking for an up-to-date snapshot of FHR data that pulls in
|
|
|
|
* new data since the last upload, this is how you should obtain it.
|
|
|
|
*
|
|
|
|
* @param asObject
|
|
|
|
* (bool) Whether to resolve an object or JSON-encoded string of that
|
|
|
|
* object (the default).
|
|
|
|
*
|
|
|
|
* @return Promise<Object | string>
|
|
|
|
*/
|
|
|
|
collectAndObtainJSONPayload: function (asObject=false) {
|
2013-03-16 08:10:08 +04:00
|
|
|
if (!this._initialized) {
|
|
|
|
return Promise.reject(new Error("Not initialized."));
|
|
|
|
}
|
|
|
|
|
2013-02-06 08:31:48 +04:00
|
|
|
return Task.spawn(function collectAndObtain() {
|
2013-04-16 22:45:02 +04:00
|
|
|
yield this._storage.setAutoCheckpoint(0);
|
2013-03-12 01:12:24 +04:00
|
|
|
yield this._providerManager.ensurePullOnlyProvidersRegistered();
|
2013-02-06 08:31:48 +04:00
|
|
|
|
2013-02-07 07:26:26 +04:00
|
|
|
let payload;
|
|
|
|
let error;
|
2013-02-06 08:31:48 +04:00
|
|
|
|
2013-02-07 07:26:26 +04:00
|
|
|
try {
|
|
|
|
yield this.collectMeasurements();
|
|
|
|
payload = yield this.getJSONPayload(asObject);
|
|
|
|
} catch (ex) {
|
|
|
|
error = ex;
|
2013-02-28 04:52:26 +04:00
|
|
|
this._collectException("Error collecting and/or retrieving JSON payload",
|
|
|
|
ex);
|
2013-02-07 07:26:26 +04:00
|
|
|
} finally {
|
2013-03-12 01:12:24 +04:00
|
|
|
yield this._providerManager.ensurePullOnlyProvidersUnregistered();
|
2013-04-16 22:45:02 +04:00
|
|
|
yield this._storage.setAutoCheckpoint(1);
|
2013-02-07 07:26:26 +04:00
|
|
|
|
|
|
|
if (error) {
|
|
|
|
throw error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// We hold off throwing to ensure that behavior between finally
|
|
|
|
// and generators and throwing is sane.
|
2013-02-06 08:31:48 +04:00
|
|
|
throw new Task.Result(payload);
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
2012-11-14 08:22:09 +04:00
|
|
|
|
2013-02-06 08:31:48 +04:00
|
|
|
/**
|
|
|
|
* Obtain the JSON payload for currently-collected data.
|
|
|
|
*
|
|
|
|
* The payload only contains data that has been recorded to FHR. Some
|
|
|
|
* providers may have newer data available. If you want to ensure you
|
|
|
|
* have all available data, call `collectAndObtainJSONPayload`
|
|
|
|
* instead.
|
|
|
|
*
|
|
|
|
* @param asObject
|
|
|
|
* (bool) Whether to return an object or JSON encoding of that
|
|
|
|
* object (the default).
|
2013-02-07 07:26:26 +04:00
|
|
|
*
|
|
|
|
* @return Promise<string|object>
|
2013-02-06 08:31:48 +04:00
|
|
|
*/
|
|
|
|
getJSONPayload: function (asObject=false) {
|
2013-02-02 01:28:02 +04:00
|
|
|
TelemetryStopwatch.start(TELEMETRY_GENERATE_PAYLOAD, this);
|
|
|
|
let deferred = Promise.defer();
|
|
|
|
|
2013-02-06 08:31:48 +04:00
|
|
|
Task.spawn(this._getJSONPayload.bind(this, this._now(), asObject)).then(
|
2013-02-02 01:28:02 +04:00
|
|
|
function onResult(result) {
|
|
|
|
TelemetryStopwatch.finish(TELEMETRY_GENERATE_PAYLOAD, this);
|
|
|
|
deferred.resolve(result);
|
|
|
|
}.bind(this),
|
|
|
|
function onError(error) {
|
|
|
|
TelemetryStopwatch.cancel(TELEMETRY_GENERATE_PAYLOAD, this);
|
|
|
|
deferred.reject(error);
|
|
|
|
}.bind(this)
|
|
|
|
);
|
|
|
|
|
|
|
|
return deferred.promise;
|
2013-01-07 00:13:27 +04:00
|
|
|
},
|
|
|
|
|
2013-02-06 08:31:48 +04:00
|
|
|
_getJSONPayload: function (now, asObject=false) {
|
2013-01-07 00:13:27 +04:00
|
|
|
let pingDateString = this._formatDate(now);
|
|
|
|
this._log.info("Producing JSON payload for " + pingDateString);
|
|
|
|
|
2013-04-22 23:33:24 +04:00
|
|
|
// May not be present if we are generating as a result of init error.
|
|
|
|
if (this._providerManager) {
|
|
|
|
yield this._providerManager.ensurePullOnlyProvidersRegistered();
|
|
|
|
}
|
|
|
|
|
2012-11-14 08:22:09 +04:00
|
|
|
let o = {
|
2013-03-14 22:24:12 +04:00
|
|
|
version: 2,
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
clientID: this._state.clientID,
|
|
|
|
clientIDVersion: this._state.clientIDVersion,
|
2013-01-07 00:13:27 +04:00
|
|
|
thisPingDate: pingDateString,
|
2013-03-14 22:24:12 +04:00
|
|
|
geckoAppInfo: this.obtainAppInfo(this._log),
|
2013-01-07 00:13:27 +04:00
|
|
|
data: {last: {}, days: {}},
|
2012-11-14 08:22:09 +04:00
|
|
|
};
|
|
|
|
|
2013-01-07 00:13:27 +04:00
|
|
|
let outputDataDays = o.data.days;
|
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
// Guard here in case we don't track this (e.g., on Android).
|
2012-11-14 08:22:09 +04:00
|
|
|
let lastPingDate = this.lastPingDate;
|
2013-02-14 04:32:45 +04:00
|
|
|
if (lastPingDate && lastPingDate.getTime() > 0) {
|
2012-11-14 08:22:09 +04:00
|
|
|
o.lastPingDate = this._formatDate(lastPingDate);
|
|
|
|
}
|
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
// We can still generate a payload even if we're not initialized.
|
|
|
|
// This is to facilitate error upload on init failure.
|
|
|
|
if (this._initialized) {
|
|
|
|
for (let provider of this._providerManager.providers) {
|
|
|
|
let providerName = provider.name;
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
let providerEntry = {
|
|
|
|
measurements: {},
|
|
|
|
};
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-03-19 22:08:24 +04:00
|
|
|
// Measurement name to recorded version.
|
|
|
|
let lastVersions = {};
|
|
|
|
// Day string to mapping of measurement name to recorded version.
|
|
|
|
let dayVersions = {};
|
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
for (let [measurementKey, measurement] of provider.measurements) {
|
|
|
|
let name = providerName + "." + measurement.name;
|
2013-03-19 22:08:24 +04:00
|
|
|
let version = measurement.version;
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
let serializer;
|
2013-01-07 00:13:27 +04:00
|
|
|
try {
|
2013-03-16 08:31:07 +04:00
|
|
|
// The measurement is responsible for returning a serializer which
|
|
|
|
// is aware of the measurement version.
|
|
|
|
serializer = measurement.serializer(measurement.SERIALIZE_JSON);
|
2013-01-07 00:13:27 +04:00
|
|
|
} catch (ex) {
|
2013-03-16 08:31:07 +04:00
|
|
|
this._recordError("Error obtaining serializer for measurement: " +
|
|
|
|
name, ex);
|
2013-01-07 00:13:27 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
let data;
|
|
|
|
try {
|
|
|
|
data = yield measurement.getValues();
|
|
|
|
} catch (ex) {
|
|
|
|
this._recordError("Error obtaining data for measurement: " + name,
|
|
|
|
ex);
|
2013-01-07 00:13:27 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
if (data.singular.size) {
|
|
|
|
try {
|
2013-03-19 22:08:24 +04:00
|
|
|
let serialized = serializer.singular(data.singular);
|
|
|
|
if (serialized) {
|
|
|
|
// Only replace the existing data if there is no data or if our
|
|
|
|
// version is newer than the old one.
|
|
|
|
if (!(name in o.data.last) || version > lastVersions[name]) {
|
|
|
|
o.data.last[name] = serialized;
|
|
|
|
lastVersions[name] = version;
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 08:31:07 +04:00
|
|
|
} catch (ex) {
|
|
|
|
this._recordError("Error serializing singular data: " + name,
|
|
|
|
ex);
|
2013-01-07 00:13:27 +04:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-16 08:31:07 +04:00
|
|
|
}
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
let dataDays = data.days;
|
|
|
|
for (let i = 0; i < DAYS_IN_PAYLOAD; i++) {
|
|
|
|
let date = new Date(now.getTime() - i * MILLISECONDS_PER_DAY);
|
|
|
|
if (!dataDays.hasDay(date)) {
|
|
|
|
continue;
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
2013-03-16 08:31:07 +04:00
|
|
|
let dateFormatted = this._formatDate(date);
|
2013-01-07 00:13:27 +04:00
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
try {
|
|
|
|
let serialized = serializer.daily(dataDays.getDay(date));
|
|
|
|
if (!serialized) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!(dateFormatted in outputDataDays)) {
|
|
|
|
outputDataDays[dateFormatted] = {};
|
2013-03-20 00:03:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// This needs to be separate because dayVersions is provider
|
|
|
|
// specific and gets blown away in a loop while outputDataDays
|
|
|
|
// is persistent.
|
|
|
|
if (!(dateFormatted in dayVersions)) {
|
2013-03-19 22:08:24 +04:00
|
|
|
dayVersions[dateFormatted] = {};
|
2013-03-16 08:31:07 +04:00
|
|
|
}
|
|
|
|
|
2013-03-19 22:08:24 +04:00
|
|
|
if (!(name in outputDataDays[dateFormatted]) ||
|
|
|
|
version > dayVersions[dateFormatted][name]) {
|
|
|
|
outputDataDays[dateFormatted][name] = serialized;
|
|
|
|
dayVersions[dateFormatted][name] = version;
|
|
|
|
}
|
2013-03-16 08:31:07 +04:00
|
|
|
} catch (ex) {
|
|
|
|
this._recordError("Error populating data for day: " + name, ex);
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-16 08:31:07 +04:00
|
|
|
} else {
|
|
|
|
o.notInitialized = 1;
|
|
|
|
this._log.warn("Not initialized. Sending report with only error info.");
|
2013-01-07 00:13:27 +04:00
|
|
|
}
|
|
|
|
|
2013-02-28 04:52:26 +04:00
|
|
|
if (this._errors.length) {
|
|
|
|
o.errors = this._errors.slice(0, 20);
|
2012-11-14 08:22:09 +04:00
|
|
|
}
|
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
if (this._initialized) {
|
|
|
|
this._storage.compact();
|
|
|
|
}
|
2013-02-06 08:31:48 +04:00
|
|
|
|
2013-02-19 00:45:53 +04:00
|
|
|
if (!asObject) {
|
|
|
|
TelemetryStopwatch.start(TELEMETRY_JSON_PAYLOAD_SERIALIZE, this);
|
|
|
|
o = JSON.stringify(o);
|
|
|
|
TelemetryStopwatch.finish(TELEMETRY_JSON_PAYLOAD_SERIALIZE, this);
|
|
|
|
}
|
|
|
|
|
2013-04-22 23:33:24 +04:00
|
|
|
if (this._providerManager) {
|
|
|
|
yield this._providerManager.ensurePullOnlyProvidersUnregistered();
|
|
|
|
}
|
|
|
|
|
2013-02-19 00:45:53 +04:00
|
|
|
throw new Task.Result(o);
|
2012-11-14 08:22:09 +04:00
|
|
|
},
|
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
_now: function _now() {
|
|
|
|
return new Date();
|
|
|
|
},
|
2013-03-14 22:24:12 +04:00
|
|
|
|
|
|
|
// These are stolen from AppInfoProvider.
|
|
|
|
appInfoVersion: 1,
|
|
|
|
appInfoFields: {
|
|
|
|
// From nsIXULAppInfo.
|
|
|
|
vendor: "vendor",
|
|
|
|
name: "name",
|
|
|
|
id: "ID",
|
|
|
|
version: "version",
|
|
|
|
appBuildID: "appBuildID",
|
|
|
|
platformVersion: "platformVersion",
|
|
|
|
platformBuildID: "platformBuildID",
|
|
|
|
|
|
|
|
// From nsIXULRuntime.
|
|
|
|
os: "OS",
|
|
|
|
xpcomabi: "XPCOMABI",
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Statically return a bundle of app info data, a subset of that produced by
|
|
|
|
* AppInfoProvider._populateConstants. This allows us to more usefully handle
|
|
|
|
* payloads that, due to error, contain no data.
|
|
|
|
*
|
|
|
|
* Returns a very sparse object if Services.appinfo is unavailable.
|
|
|
|
*/
|
|
|
|
obtainAppInfo: function () {
|
|
|
|
let out = {"_v": this.appInfoVersion};
|
|
|
|
try {
|
|
|
|
let ai = Services.appinfo;
|
|
|
|
for (let [k, v] in Iterator(this.appInfoFields)) {
|
|
|
|
out[k] = ai[v];
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Could not obtain Services.appinfo: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2015-09-14 21:04:19 +03:00
|
|
|
out["updateChannel"] = UpdateUtils.UpdateChannel;
|
2013-03-14 22:24:12 +04:00
|
|
|
} catch (ex) {
|
|
|
|
this._log.warn("Could not obtain update channel: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
|
|
|
|
return out;
|
|
|
|
},
|
2013-02-14 04:32:45 +04:00
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HealthReporter and its abstract superclass coordinate collection and
|
|
|
|
* submission of health report metrics.
|
|
|
|
*
|
|
|
|
* This is the main type for Firefox Health Report on desktop. It glues all the
|
|
|
|
* lower-level components (such as collection and submission) together.
|
|
|
|
*
|
|
|
|
* An instance of this type is created as an XPCOM service. See
|
|
|
|
* DataReportingService.js and
|
|
|
|
* DataReporting.manifest/HealthReportComponents.manifest.
|
|
|
|
*
|
|
|
|
* It is theoretically possible to have multiple instances of this running
|
|
|
|
* in the application. For example, this type may one day handle submission
|
|
|
|
* of telemetry data as well. However, there is some moderate coupling between
|
|
|
|
* this type and *the* Firefox Health Report (e.g., the policy). This could
|
|
|
|
* be abstracted if needed.
|
|
|
|
*
|
|
|
|
* Note that `AbstractHealthReporter` exists to allow for Firefox Health Report
|
|
|
|
* to be more easily implemented on platforms where a separate controlling
|
|
|
|
* layer is responsible for payload upload and deletion.
|
|
|
|
*
|
|
|
|
* IMPLEMENTATION NOTES
|
|
|
|
* ====================
|
|
|
|
*
|
|
|
|
* These notes apply to the combination of `HealthReporter` and
|
|
|
|
* `AbstractHealthReporter`.
|
|
|
|
*
|
|
|
|
* Initialization and shutdown are somewhat complicated and worth explaining
|
|
|
|
* in extra detail.
|
|
|
|
*
|
|
|
|
* The complexity is driven by the requirements of SQLite connection management.
|
|
|
|
* Once you have a SQLite connection, it isn't enough to just let the
|
|
|
|
* application shut down. If there is an open connection or if there are
|
|
|
|
* outstanding SQL statements come XPCOM shutdown time, Storage will assert.
|
|
|
|
* On debug builds you will crash. On release builds you will get a shutdown
|
|
|
|
* hang. This must be avoided!
|
|
|
|
*
|
|
|
|
* During initialization, the second we create a SQLite connection (via
|
|
|
|
* Metrics.Storage) we register observers for application shutdown. The
|
|
|
|
* "quit-application" notification initiates our shutdown procedure. The
|
|
|
|
* subsequent "profile-do-change" notification ensures it has completed.
|
|
|
|
*
|
|
|
|
* The handler for "profile-do-change" may result in event loop spinning. This
|
|
|
|
* is because of race conditions between our shutdown code and application
|
|
|
|
* shutdown.
|
|
|
|
*
|
|
|
|
* All of our shutdown routines are async. There is the potential that these
|
|
|
|
* async functions will not complete before XPCOM shutdown. If they don't
|
|
|
|
* finish in time, we could get assertions in Storage. Our solution is to
|
|
|
|
* initiate storage early in the shutdown cycle ("quit-application").
|
|
|
|
* Hopefully all the async operations have completed by the time we reach
|
|
|
|
* "profile-do-change." If so, great. If not, we spin the event loop until
|
|
|
|
* they have completed, avoiding potential race conditions.
|
|
|
|
*
|
|
|
|
* @param branch
|
|
|
|
* (string) The preferences branch to use for state storage. The value
|
|
|
|
* must end with a period (.).
|
|
|
|
*
|
|
|
|
* @param policy
|
|
|
|
* (HealthReportPolicy) Policy driving execution of HealthReporter.
|
|
|
|
*/
|
2015-04-03 12:42:00 +03:00
|
|
|
this.HealthReporter = function (branch, policy, stateLeaf=null) {
|
2013-05-10 22:04:48 +04:00
|
|
|
this._stateLeaf = stateLeaf;
|
2014-01-30 03:28:57 +04:00
|
|
|
this._uploadInProgress = false;
|
2013-05-10 22:04:48 +04:00
|
|
|
|
2015-04-27 19:07:58 +03:00
|
|
|
AbstractHealthReporter.call(this, branch, policy, TelemetryController.getSessionRecorder());
|
2013-02-14 04:32:45 +04:00
|
|
|
|
|
|
|
if (!this.serverURI) {
|
|
|
|
throw new Error("No server URI defined. Did you forget to define the pref?");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!this.serverNamespace) {
|
|
|
|
throw new Error("No server namespace defined. Did you forget a pref?");
|
|
|
|
}
|
2013-05-10 22:04:48 +04:00
|
|
|
|
|
|
|
this._state = new HealthReporterState(this);
|
2013-02-14 04:32:45 +04:00
|
|
|
}
|
|
|
|
|
2013-09-06 20:08:26 +04:00
|
|
|
this.HealthReporter.prototype = Object.freeze({
|
2013-02-14 04:32:45 +04:00
|
|
|
__proto__: AbstractHealthReporter.prototype,
|
|
|
|
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
get lastSubmitID() {
|
|
|
|
return this._state.lastSubmitID;
|
|
|
|
},
|
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
/**
|
|
|
|
* When we last successfully submitted data to the server.
|
|
|
|
*
|
|
|
|
* This is sent as part of the upload. This is redundant with similar data
|
|
|
|
* in the policy because we like the modules to be loosely coupled and the
|
|
|
|
* similar data in the policy is only used for forensic purposes.
|
|
|
|
*/
|
|
|
|
get lastPingDate() {
|
2013-05-10 22:04:48 +04:00
|
|
|
return this._state.lastPingDate;
|
2013-02-14 04:32:45 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The base URI of the document server to which to submit data.
|
|
|
|
*
|
|
|
|
* This is typically a Bagheera server instance. It is the URI up to but not
|
|
|
|
* including the version prefix. e.g. https://data.metrics.mozilla.com/
|
|
|
|
*/
|
|
|
|
get serverURI() {
|
|
|
|
return this._prefs.get("documentServerURI", null);
|
|
|
|
},
|
|
|
|
|
|
|
|
set serverURI(value) {
|
|
|
|
if (!value) {
|
|
|
|
throw new Error("serverURI must have a value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof(value) != "string") {
|
|
|
|
throw new Error("serverURI must be a string: " + value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._prefs.set("documentServerURI", value);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The namespace on the document server to which we will be submitting data.
|
|
|
|
*/
|
|
|
|
get serverNamespace() {
|
|
|
|
return this._prefs.get("documentServerNamespace", "metrics");
|
|
|
|
},
|
|
|
|
|
|
|
|
set serverNamespace(value) {
|
|
|
|
if (!value) {
|
|
|
|
throw new Error("serverNamespace must have a value.");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof(value) != "string") {
|
|
|
|
throw new Error("serverNamespace must be a string: " + value);
|
|
|
|
}
|
|
|
|
|
|
|
|
this._prefs.set("documentServerNamespace", value);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether this instance will upload data to a server.
|
|
|
|
*/
|
|
|
|
get willUploadData() {
|
2014-07-10 01:32:29 +04:00
|
|
|
return this._policy.userNotifiedOfCurrentPolicy &&
|
|
|
|
this._policy.healthReportUploadEnabled;
|
2013-02-14 04:32:45 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Whether remote data is currently stored.
|
|
|
|
*
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
haveRemoteData: function () {
|
2013-05-10 22:04:48 +04:00
|
|
|
return !!this._state.lastSubmitID;
|
2013-02-14 04:32:45 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called to initiate a data upload.
|
|
|
|
*
|
|
|
|
* The passed argument is a `DataSubmissionRequest` from policy.jsm.
|
|
|
|
*/
|
|
|
|
requestDataUpload: function (request) {
|
2013-03-16 08:10:08 +04:00
|
|
|
if (!this._initialized) {
|
|
|
|
return Promise.reject(new Error("Not initialized."));
|
|
|
|
}
|
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
return Task.spawn(function doUpload() {
|
2013-03-12 01:12:24 +04:00
|
|
|
yield this._providerManager.ensurePullOnlyProvidersRegistered();
|
2013-02-14 04:32:45 +04:00
|
|
|
try {
|
|
|
|
yield this.collectMeasurements();
|
|
|
|
try {
|
|
|
|
yield this._uploadData(request);
|
|
|
|
} catch (ex) {
|
|
|
|
this._onSubmitDataRequestFailure(ex);
|
|
|
|
}
|
|
|
|
} finally {
|
2013-03-12 01:12:24 +04:00
|
|
|
yield this._providerManager.ensurePullOnlyProvidersUnregistered();
|
2013-02-14 04:32:45 +04:00
|
|
|
}
|
|
|
|
}.bind(this));
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Request that server data be deleted.
|
|
|
|
*
|
|
|
|
* If deletion is scheduled to occur immediately, a promise will be returned
|
|
|
|
* that will be fulfilled when the deletion attempt finishes. Otherwise,
|
|
|
|
* callers should poll haveRemoteData() to determine when remote data is
|
|
|
|
* deleted.
|
|
|
|
*/
|
|
|
|
requestDeleteRemoteData: function (reason) {
|
2013-05-10 22:04:48 +04:00
|
|
|
if (!this.haveRemoteData()) {
|
2013-02-14 04:32:45 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._policy.deleteRemoteData(reason);
|
|
|
|
},
|
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
/**
|
|
|
|
* Override default handler to incur an upload describing the error.
|
|
|
|
*/
|
|
|
|
_onInitError: function (error) {
|
|
|
|
// Need to capture this before we call the parent else it's always
|
|
|
|
// set.
|
|
|
|
let inShutdown = this._shutdownRequested;
|
2014-07-12 04:00:08 +04:00
|
|
|
let result;
|
2014-07-10 01:32:29 +04:00
|
|
|
|
2013-03-16 08:31:07 +04:00
|
|
|
try {
|
|
|
|
result = AbstractHealthReporter.prototype._onInitError.call(this, error);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error when calling _onInitError: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
|
|
|
|
|
|
|
// This bypasses a lot of the checks in policy, such as respect for
|
|
|
|
// backoff. We should arguably not do this. However, reporting
|
|
|
|
// startup errors is important. And, they should not occur with much
|
|
|
|
// frequency in the wild. So, it shouldn't be too big of a deal.
|
|
|
|
if (!inShutdown &&
|
2014-07-10 01:32:29 +04:00
|
|
|
this._policy.healthReportUploadEnabled &&
|
|
|
|
this._policy.ensureUserNotified()) {
|
2013-03-16 08:31:07 +04:00
|
|
|
// We don't care about what happens to this request. It's best
|
|
|
|
// effort.
|
|
|
|
let request = {
|
|
|
|
onNoDataAvailable: function () {},
|
|
|
|
onSubmissionSuccess: function () {},
|
|
|
|
onSubmissionFailureSoft: function () {},
|
|
|
|
onSubmissionFailureHard: function () {},
|
2014-01-30 03:28:57 +04:00
|
|
|
onUploadInProgress: function () {},
|
2013-03-16 08:31:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
this._uploadData(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
},
|
|
|
|
|
2013-05-01 20:41:55 +04:00
|
|
|
_onBagheeraResult: function (request, isDelete, date, result) {
|
2013-02-14 04:32:45 +04:00
|
|
|
this._log.debug("Received Bagheera result.");
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
return Task.spawn(function onBagheeraResult() {
|
|
|
|
let hrProvider = this.getProvider("org.mozilla.healthreport");
|
2013-05-01 20:41:55 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
if (!result.transportSuccess) {
|
|
|
|
// The built-in provider may not be initialized if this instance failed
|
|
|
|
// to initialize fully.
|
|
|
|
if (hrProvider && !isDelete) {
|
2014-08-13 22:18:22 +04:00
|
|
|
try {
|
|
|
|
hrProvider.recordEvent("uploadTransportFailure", date);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error recording upload transport failure: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
2013-05-10 22:04:48 +04:00
|
|
|
}
|
2013-02-14 04:32:45 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
request.onSubmissionFailureSoft("Network transport error.");
|
|
|
|
throw new Task.Result(false);
|
2013-05-01 20:41:55 +04:00
|
|
|
}
|
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
if (!result.serverSuccess) {
|
|
|
|
if (hrProvider && !isDelete) {
|
2014-08-13 22:18:22 +04:00
|
|
|
try {
|
|
|
|
hrProvider.recordEvent("uploadServerFailure", date);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error recording server failure: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
2013-05-10 22:04:48 +04:00
|
|
|
}
|
2013-02-14 04:32:45 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
request.onSubmissionFailureHard("Server failure.");
|
|
|
|
throw new Task.Result(false);
|
|
|
|
}
|
2013-02-14 04:32:45 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
if (hrProvider && !isDelete) {
|
2014-08-13 22:18:22 +04:00
|
|
|
try {
|
|
|
|
hrProvider.recordEvent("uploadSuccess", date);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error recording upload success: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
2013-05-10 22:04:48 +04:00
|
|
|
}
|
2013-02-14 04:32:45 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
if (isDelete) {
|
|
|
|
this._log.warn("Marking delete as successful.");
|
2013-06-21 21:30:30 +04:00
|
|
|
yield this._state.removeRemoteIDs([result.id]);
|
2013-05-10 22:04:48 +04:00
|
|
|
} else {
|
|
|
|
this._log.warn("Marking upload as successful.");
|
2013-06-21 21:30:30 +04:00
|
|
|
yield this._state.updateLastPingAndRemoveRemoteIDs(date, result.deleteIDs);
|
2013-05-10 22:04:48 +04:00
|
|
|
}
|
2013-02-14 04:32:45 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
request.onSubmissionSuccess(this._now());
|
2013-03-16 00:19:38 +04:00
|
|
|
|
2013-05-10 22:04:48 +04:00
|
|
|
throw new Task.Result(true);
|
|
|
|
}.bind(this));
|
2013-02-14 04:32:45 +04:00
|
|
|
},
|
|
|
|
|
|
|
|
_onSubmitDataRequestFailure: function (error) {
|
|
|
|
this._log.error("Error processing request to submit data: " +
|
|
|
|
CommonUtils.exceptionStr(error));
|
|
|
|
},
|
|
|
|
|
|
|
|
_formatDate: function (date) {
|
|
|
|
// Why, oh, why doesn't JS have a strftime() equivalent?
|
|
|
|
return date.toISOString().substr(0, 10);
|
|
|
|
},
|
|
|
|
|
|
|
|
_uploadData: function (request) {
|
2014-01-30 03:28:57 +04:00
|
|
|
// Under ideal circumstances, clients should never race to this
|
|
|
|
// function. However, server logs have observed behavior where
|
|
|
|
// racing to this function could be a cause. So, this lock was
|
|
|
|
// instituted.
|
|
|
|
if (this._uploadInProgress) {
|
|
|
|
this._log.warn("Upload requested but upload already in progress.");
|
|
|
|
let provider = this.getProvider("org.mozilla.healthreport");
|
|
|
|
let promise = provider.recordEvent("uploadAlreadyInProgress");
|
|
|
|
request.onUploadInProgress("Upload already in progress.");
|
|
|
|
return promise;
|
|
|
|
}
|
|
|
|
|
2013-02-14 04:32:45 +04:00
|
|
|
let id = CommonUtils.generateUUID();
|
|
|
|
|
|
|
|
this._log.info("Uploading data to server: " + this.serverURI + " " +
|
|
|
|
this.serverNamespace + ":" + id);
|
|
|
|
let client = new BagheeraClient(this.serverURI);
|
2013-05-01 20:41:55 +04:00
|
|
|
let now = this._now();
|
2013-02-14 04:32:45 +04:00
|
|
|
|
|
|
|
return Task.spawn(function doUpload() {
|
2014-01-30 03:28:57 +04:00
|
|
|
try {
|
|
|
|
// The test for upload locking monkeypatches getJSONPayload.
|
|
|
|
// If the next two lines change, be sure to verify the test is
|
|
|
|
// accurate!
|
|
|
|
this._uploadInProgress = true;
|
|
|
|
let payload = yield this.getJSONPayload();
|
2013-02-02 01:28:02 +04:00
|
|
|
|
2014-01-30 03:28:57 +04:00
|
|
|
let histogram = Services.telemetry.getHistogramById(TELEMETRY_PAYLOAD_SIZE_UNCOMPRESSED);
|
|
|
|
histogram.add(payload.length);
|
2013-05-10 22:04:48 +04:00
|
|
|
|
2014-01-30 03:28:57 +04:00
|
|
|
let lastID = this.lastSubmitID;
|
|
|
|
yield this._state.addRemoteID(id);
|
2013-05-01 20:41:55 +04:00
|
|
|
|
2014-01-30 03:28:57 +04:00
|
|
|
let hrProvider = this.getProvider("org.mozilla.healthreport");
|
2013-05-01 20:41:55 +04:00
|
|
|
if (hrProvider) {
|
2014-01-30 03:28:57 +04:00
|
|
|
let event = lastID ? "continuationUploadAttempt"
|
|
|
|
: "firstDocumentUploadAttempt";
|
2014-08-13 22:18:22 +04:00
|
|
|
try {
|
|
|
|
hrProvider.recordEvent(event, now);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error when recording upload attempt: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
2013-05-01 20:41:55 +04:00
|
|
|
}
|
2013-02-02 01:28:02 +04:00
|
|
|
|
2014-01-30 03:28:57 +04:00
|
|
|
TelemetryStopwatch.start(TELEMETRY_UPLOAD, this);
|
|
|
|
let result;
|
|
|
|
try {
|
|
|
|
let options = {
|
|
|
|
deleteIDs: this._state.remoteIDs.filter((x) => { return x != id; }),
|
|
|
|
telemetryCompressed: TELEMETRY_PAYLOAD_SIZE_COMPRESSED,
|
|
|
|
};
|
|
|
|
result = yield client.uploadJSON(this.serverNamespace, id, payload,
|
|
|
|
options);
|
|
|
|
TelemetryStopwatch.finish(TELEMETRY_UPLOAD, this);
|
|
|
|
} catch (ex) {
|
|
|
|
TelemetryStopwatch.cancel(TELEMETRY_UPLOAD, this);
|
|
|
|
if (hrProvider) {
|
2014-08-13 22:18:22 +04:00
|
|
|
try {
|
|
|
|
hrProvider.recordEvent("uploadClientFailure", now);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error when recording client failure: " +
|
|
|
|
CommonUtils.exceptionStr(ex));
|
|
|
|
}
|
2014-01-30 03:28:57 +04:00
|
|
|
}
|
|
|
|
throw ex;
|
|
|
|
}
|
|
|
|
|
|
|
|
yield this._onBagheeraResult(request, false, now, result);
|
|
|
|
} finally {
|
|
|
|
this._uploadInProgress = false;
|
|
|
|
}
|
2013-01-07 00:13:27 +04:00
|
|
|
}.bind(this));
|
2012-11-14 08:22:09 +04:00
|
|
|
},
|
|
|
|
|
2013-02-06 08:31:48 +04:00
|
|
|
/**
|
|
|
|
* Request deletion of remote data.
|
|
|
|
*
|
|
|
|
* @param request
|
|
|
|
* (DataSubmissionRequest) Tracks progress of this request.
|
|
|
|
*/
|
2013-01-12 01:45:22 +04:00
|
|
|
deleteRemoteData: function (request) {
|
2013-05-10 22:04:48 +04:00
|
|
|
if (!this._state.lastSubmitID) {
|
2012-11-14 08:22:09 +04:00
|
|
|
this._log.info("Received request to delete remote data but no data stored.");
|
|
|
|
request.onNoDataAvailable();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
this._log.warn("Deleting remote data.");
|
|
|
|
let client = new BagheeraClient(this.serverURI);
|
|
|
|
|
Bug 968419 - Store and submit a persistent health report identifier; r=rnewman, r=bsmedberg
Up to this point, Firefox Health Report has generated and submitted a
random UUID with each upload. Generated UUIDs were stored on the client.
During upload, the client asked the server to delete all old UUIDs.
Well-behaving clients thus left at most one record/ID on the server.
Unfortunately, clients in the wild have not been behaving properly. We
are seeing multiple documents on the server that appear to come from the
same client. Clients are uploading new records but failing to delete the
old ones. These old, undeleted "orphan" records are severely impacting
the ability to derive useful knowledge from FHR data because it is
difficult, resource intensive, and error prone to filter the records on
the server. This is undermining the ability for FHR data to be put to
good use.
This patch introduces a persistent client identifier. When the client is
initialized, it generates a random UUID. That UUID is persisted to the
profile and sent as part of every upload.
For privacy reasons, if a client opts out of data submission, the client
ID will be reset as soon as all remote data has been deleted.
We still issue and send upload IDs. They exist mostly for forensics
purposes so we may log client behavior and more accurately determine
what exactly misbehaving, orphan-producing clients are doing.
It is worth noting that this persistent client identifier will not solve
all problems of branching and orphaned records. For example, profile
copying will result in multiple clients sharing a client identifier. A
"client ID version" field has been added to facilitate an upgrade path
towards client IDs with different generation semantics.
--HG--
extra : rebase_source : b761daab39fb07b6ab8883819d68bf53462314a0
2014-02-20 23:30:52 +04:00
|
|
|
return Task.spawn(function* doDelete() {
|
|
|
|
try {
|
|
|
|
let result = yield client.deleteDocument(this.serverNamespace,
|
|
|
|
this.lastSubmitID);
|
|
|
|
yield this._onBagheeraResult(request, true, this._now(), result);
|
|
|
|
} catch (ex) {
|
|
|
|
this._log.error("Error processing request to delete data: " +
|
|
|
|
CommonUtils.exceptionStr(error));
|
|
|
|
}
|
|
|
|
}.bind(this));
|
2012-11-16 22:05:19 +04:00
|
|
|
},
|
2013-01-07 00:13:27 +04:00
|
|
|
});
|
2012-11-14 08:22:09 +04:00
|
|
|
|