Backed out changeset 9912325cd073 (bug 1460900) for Linting failure on gecko/toolkit/components/telemetry/TelemetryStorage.jsm on a CLOSED TREE

This commit is contained in:
Gurzau Raul 2018-07-09 18:36:02 +03:00
parent 268ec922a0
commit 51fdfe5279
5 changed files with 117 additions and 0 deletions

View file

@ -6985,6 +6985,26 @@
"n_buckets": 20,
"description": "Time (ms) it takes for checking if the pending pings are over-quota"
},
"TELEMETRY_PENDING_LOAD_MS": {
"record_in_processes": ["main"],
"alert_emails": ["telemetry-client-dev@mozilla.com", "chutten@mozilla.com"],
"expires_in_version": "never",
"kind": "exponential",
"high": 2000,
"n_buckets": 20,
"bug_numbers": [1033860],
"description": "Time (ms) it takes for loading pending pings from disk"
},
"TELEMETRY_ARCHIVE_LOAD_MS": {
"record_in_processes": ["main"],
"alert_emails": ["telemetry-client-dev@mozilla.com", "chutten@mozilla.com"],
"expires_in_version": "never",
"kind": "exponential",
"high": 2000,
"n_buckets": 20,
"bug_numbers": [1033860],
"description": "Time (ms) it takes for loading archived pings from disk"
},
"TELEMETRY_SUCCESSFUL_SEND_PINGS_SIZE_KB": {
"record_in_processes": ["main"],
"alert_emails": ["telemetry-client-dev@mozilla.com", "chutten@mozilla.com"],

View file

@ -111,6 +111,13 @@ var Policy = {
var EXPORTED_SYMBOLS = ["TelemetryController"];
var TelemetryController = Object.freeze({
/**
* Used only for testing purposes.
*/
testAssemblePing(aType, aPayload, aOptions) {
return Impl.assemblePing(aType, aPayload, aOptions);
},
/**
* Used only for testing purposes.
*/

View file

@ -12,6 +12,7 @@ ChromeUtils.import("resource://gre/modules/Log.jsm");
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
ChromeUtils.import("resource://gre/modules/XPCOMUtils.jsm", this);
ChromeUtils.import("resource://gre/modules/osfile.jsm", this);
ChromeUtils.import("resource://gre/modules/TelemetryStopwatch.jsm", this);
ChromeUtils.import("resource://gre/modules/TelemetryUtils.jsm", this);
ChromeUtils.import("resource://gre/modules/Preferences.jsm", this);
@ -165,6 +166,18 @@ var TelemetryStorage = {
return TelemetryStorageImpl.loadArchivedPing(id);
},
/**
* Remove an archived ping from disk.
*
* @param {string} id The ping's id.
* @param {number} timestampCreated The ping's creation timestamp.
* @param {string} type The ping's type.
* @return {promise<object>} Promise that is resolved when the ping is removed.
*/
removeArchivedPing(id, timestampCreated, type) {
return TelemetryStorageImpl._removeArchivedPing(id, timestampCreated, type);
},
/**
* Get a list of info on the archived pings.
* This will scan the archive directory and grab basic data about the existing
@ -679,8 +692,10 @@ var TelemetryStorageImpl = {
*/
async loadArchivedPing(id) {
let idAsObject = {id};
TelemetryStopwatch.start("TELEMETRY_ARCHIVE_LOAD_MS", idAsObject);
const data = this._archivedPings.get(id);
if (!data) {
TelemetryStopwatch.cancel("TELEMETRY_ARCHIVE_LOAD_MS", idAsObject);
this._log.trace("loadArchivedPing - no ping with id: " + id);
return Promise.reject(new Error("TelemetryStorage.loadArchivedPing - no ping with id " + id));
}
@ -695,6 +710,7 @@ var TelemetryStorageImpl = {
Telemetry.getHistogramById("TELEMETRY_DISCARDED_ARCHIVED_PINGS_SIZE_MB")
.add(Math.floor(fileSize / 1024 / 1024));
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_ARCHIVED").add();
TelemetryStopwatch.cancel("TELEMETRY_ARCHIVE_LOAD_MS", idAsObject);
await OS.File.remove(path, {ignoreAbsent: true});
throw new Error("loadArchivedPing - exceeded the maximum ping size: " + fileSize);
}
@ -708,6 +724,7 @@ var TelemetryStorageImpl = {
ping = await this.loadPingFile(pathCompressed, /* compressed*/ true);
} catch (ex) {
if (!ex.becauseNoSuchFile) {
TelemetryStopwatch.cancel("TELEMETRY_ARCHIVE_LOAD_MS", idAsObject);
throw ex;
}
// If that fails, look for the uncompressed version.
@ -716,6 +733,7 @@ var TelemetryStorageImpl = {
ping = await this.loadPingFile(path, /* compressed*/ false);
}
TelemetryStopwatch.finish("TELEMETRY_ARCHIVE_LOAD_MS", idAsObject);
return ping;
},
@ -1311,8 +1329,10 @@ var TelemetryStorageImpl = {
async loadPendingPing(id) {
this._log.trace("loadPendingPing - id: " + id);
TelemetryStopwatch.start("TELEMETRY_PENDING_LOAD_MS");
let info = this._pendingPings.get(id);
if (!info) {
TelemetryStopwatch.cancel("TELEMETRY_PENDING_LOAD_MS");
this._log.trace("loadPendingPing - unknown id " + id);
throw new Error("TelemetryStorage.loadPendingPing - no ping with id " + id);
}
@ -1323,6 +1343,7 @@ var TelemetryStorageImpl = {
fileSize = (await OS.File.stat(info.path)).size;
} catch (e) {
if (!(e instanceof OS.File.Error) || !e.becauseNoSuchFile) {
TelemetryStopwatch.cancel("TELEMETRY_PENDING_LOAD_MS");
throw e;
}
// Fall through and let |loadPingFile| report the error.
@ -1334,6 +1355,7 @@ var TelemetryStorageImpl = {
Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB")
.add(Math.floor(fileSize / 1024 / 1024));
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").add();
TelemetryStopwatch.cancel("TELEMETRY_PENDING_LOAD_MS");
// Currently we don't have the ping type available without loading the ping from disk.
// Bug 1384903 will fix that.
@ -1352,6 +1374,7 @@ var TelemetryStorageImpl = {
} else if (e instanceof PingParseError) {
Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_FAILURE_PARSE").add();
}
TelemetryStopwatch.cancel("TELEMETRY_PENDING_LOAD_MS");
// Remove the ping from the cache, so we don't try to load it again.
this._pendingPings.delete(id);
@ -1359,6 +1382,7 @@ var TelemetryStorageImpl = {
throw e;
}
TelemetryStopwatch.finish("TELEMETRY_PENDING_LOAD_MS");
return ping;
},

View file

@ -0,0 +1,65 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
ChromeUtils.import("resource://gre/modules/TelemetryController.jsm", this);
ChromeUtils.import("resource://gre/modules/TelemetrySession.jsm", this);
ChromeUtils.import("resource://gre/modules/TelemetryStorage.jsm", this);
ChromeUtils.import("resource://gre/modules/Services.jsm", this);
ChromeUtils.import("resource://gre/modules/TelemetryUtils.jsm", this);
const PING_TYPE_MAIN = "main";
const REASON_GATHER_PAYLOAD = "gather-payload";
function getPing() {
TelemetrySession.earlyInit(true);
const payload = TelemetrySession.getPayload(REASON_GATHER_PAYLOAD);
const options = {addClientId: true, addEnvironment: true};
return TelemetryController.testAssemblePing(PING_TYPE_MAIN, payload, options);
}
// Setting up test environment.
add_task(async function test_setup() {
do_get_profile();
});
// Testing whether correct values are being recorded in
// "TELEMETRY_PENDING_LOAD_MS" histogram.
add_task(async function test_pendingLoadTime() {
TelemetryStorage.reset();
var ping = getPing();
var h = Telemetry.getHistogramById("TELEMETRY_PENDING_LOAD_MS");
var initialSum = h.snapshot().sum;
TelemetryStorage.addPendingPing(ping).then(() => {
TelemetryStorage.loadPendingPing(ping.id).then(() => {
TelemetryStorage.removePendingPing(ping.id);
Assert.ok(h.snapshot().sum - initialSum > 0,
"Value must be inserted into the histogram.");
});
});
});
// Testing whether correct values are being recorded in
// "TELEMETRY_ARCHIVE_LOAD_MS" histogram.
add_task(async function test_archiveLoadTime() {
TelemetryStorage.reset();
var ping = getPing();
var creationDate = new Date(ping.creationDate);
var h = Telemetry.getHistogramById("TELEMETRY_ARCHIVE_LOAD_MS");
var initialSum = h.snapshot().sum;
TelemetryStorage.saveArchivedPing(ping).then(() => {
TelemetryStorage.loadArchivedPing(ping.id).then(() => {
TelemetryStorage.removeArchivedPing(ping.id, creationDate, ping.type);
Assert.ok(h.snapshot().sum - initialSum > 0,
"Value must be inserted into the histogram.");
});
});
});

View file

@ -34,6 +34,7 @@ support-files =
test_GeckoView_content_scalars.js
[test_MigratePendingPings.js]
[test_TelemetryHistograms.js]
[test_TelemetryStorage.js]
[test_SubsessionChaining.js]
tags = addons
[test_TelemetryEnvironment.js]