Bug 1438896 : Add a probe to count Telemetry failures by ping type. , r?chutten
MozReview-Commit-ID: r2KEm2LZl7
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -7108,16 +7108,36 @@
"eRedirect",
"abort",
"timeout",
"eTooLate",
"eTerminated"
],
"description": "Counts of the different ways sending a Telemetry ping can fail."
},
+ "TELEMETRY_SEND_FAILURE_TYPE_PER_PING" : {
+ "record_in_processes": ["main"],
+ "alert_emails": ["telemetry-client-dev@mozilla.com", "chutten@mozilla.com"],
+ "bug_numbers": [1438896],
+ "expires_in_version": "66",
+ "kind": "categorical",
+ "keyed": true,
+ "labels": [
+ "eOK",
+ "eRequest",
+ "eUnreachable",
+ "eChannelOpen",
+ "eRedirect",
+ "abort",
+ "timeout",
+ "eTooLate",
+ "eTerminated"
+ ],
+ "description": "Counts the number of times a failure occures while sending a Telemetry ping. It is a keyed histogram where the type of ping will serve as the key and may include the following ping types : {common, main, deletion, crash, sync, new-profile, core, modules, environment, health, heartbeat, malware-addon-states, activation, saved-session, backgroundhangmonitor, first-shutdown, anonymous, uitour-tag}."
+ },
"TELEMETRY_STRINGIFY" : {
"record_in_processes": ["main"],
"alert_emails": ["telemetry-client-dev@mozilla.com"],
"expires_in_version": "never",
"kind": "exponential",
"high": 3000,
"n_buckets": 10,
"description": "Time to stringify telemetry object (ms)"
--- a/toolkit/components/telemetry/TelemetrySend.jsm
+++ b/toolkit/components/telemetry/TelemetrySend.jsm
@@ -1103,16 +1103,17 @@ var TelemetrySendImpl = {
this._log.trace("_doPing - Can't send ping " + ping.id);
return Promise.resolve();
}
if (this._tooLateToSend) {
// Too late to send now. Reject so we pend the ping to send it next time.
this._log.trace("_doPing - Too late to send ping " + ping.id);
Telemetry.getHistogramById("TELEMETRY_SEND_FAILURE_TYPE").add("eTooLate");
+ Telemetry.getKeyedHistogramById("TELEMETRY_SEND_FAILURE_TYPE_PER_PING").add(ping.type, "eTooLate");
return Promise.reject();
}
this._log.trace("_doPing - server: " + this._server + ", persisted: " + isPersisted +
", id: " + id);
const url = this._buildSubmissionURL(ping);
@@ -1159,16 +1160,23 @@ var TelemetrySendImpl = {
let errorhandler = (event) => {
let failure = event.type;
if (failure === "error") {
failure = XHR_ERROR_TYPE[request.errorCode];
}
TelemetryHealthPing.recordSendFailure(failure);
Telemetry.getHistogramById("TELEMETRY_SEND_FAILURE_TYPE").add(failure);
+ try {
+ Telemetry.getKeyedHistogramById("TELEMETRY_SEND_FAILURE_TYPE_PER_PING").add(ping.type, failure);
+ } catch (e) {
+ if (e.result != Cr.NS_ERROR_FAILURE) {
+ throw e;
+ }
+ }
this._log.error("_doPing - error making request to " + url + ": " + failure);
onRequestFinished(false, event);
};
request.onerror = errorhandler;
request.ontimeout = errorhandler;
request.onabort = errorhandler;
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -312,17 +312,16 @@ add_task(async function test_backoffTime
Assert.deepEqual(histSuccess.snapshot().counts, [sendAttempts, 3, 0],
"Should have recorded sending failure in histograms.");
Assert.greaterOrEqual(histSendTimeSuccess.snapshot().sum, 0,
"Should have recorded sending success in histograms.");
Assert.equal(histogramValueCount(histSendTimeSuccess.snapshot()), 3,
"Should have recorded sending success in histograms.");
Assert.equal(histogramValueCount(histSendTimeFail.snapshot()), sendAttempts,
"Should have recorded send failure times in histograms.");
-
// Restore the default ping id generator.
fakeGeneratePingId(() => TelemetryUtils.generateUUID());
});
add_task(async function test_discardBigPings() {
const TEST_PING_TYPE = "test-ping-type";
let histSizeExceeded = Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_SEND");
@@ -453,16 +452,26 @@ add_task(async function test_tooLateToSe
// Triggering a shutdown should persist the pings
await TelemetrySend.shutdown();
const pendingPings = TelemetryStorage.getPendingPingList();
Assert.equal(pendingPings.length, 1, "Should have a pending ping in storage");
Assert.equal(pendingPings[0].id, id, "Should have pended our test's ping");
Assert.equal(Telemetry.getHistogramById("TELEMETRY_SEND_FAILURE_TYPE").snapshot().counts[7], 1,
"Should have registered the failed attempt to send");
+ try {
+ let histSnapshot = Telemetry.getKeyedHistogramById("TELEMETRY_SEND_FAILURE_TYPE_PER_PING").snapshot();
+ Assert.equal(histSnapshot[pendingPings[0].type].counts[7], 1, "Should have registered the failed attempt to send");
+ } catch (e) {
+ // This throws if the key is not already registered, but that
+ // doesn't matter.
+ if (e.result != Cr.NS_ERROR_FAILURE) {
+ throw e;
+ }
+ }
await TelemetryStorage.reset();
Assert.equal(TelemetrySend.pendingPingCount, 0, "Should clean up after yourself");
});
// Test that the current, non-persisted pending pings are properly saved on shutdown.
add_task(async function test_persistCurrentPingsOnShutdown() {
const TEST_TYPE = "test-persistCurrentPingsOnShutdown";