Bug 1369049 - Moved code that checks for big pings after the ping is compressed. Had to update test_discardBigPings to send a 4MB ping due to the ping being compressed; r?chutten
MozReview-Commit-ID: DlCyF8BKL5Q
--- a/toolkit/components/telemetry/TelemetrySend.jsm
+++ b/toolkit/components/telemetry/TelemetrySend.jsm
@@ -1206,35 +1206,35 @@ var TelemetrySendImpl = {
let converter = Cc["@mozilla.org/intl/scriptableunicodeconverter"]
.createInstance(Ci.nsIScriptableUnicodeConverter);
converter.charset = "UTF-8";
let startTime = Utils.monotonicNow();
let utf8Payload = converter.ConvertFromUnicode(JSON.stringify(networkPayload));
utf8Payload += converter.Finish();
Telemetry.getHistogramById("TELEMETRY_STRINGIFY").add(Utils.monotonicNow() - startTime);
+ let payloadStream = Cc["@mozilla.org/io/string-input-stream;1"]
+ .createInstance(Ci.nsIStringInputStream);
+ startTime = Utils.monotonicNow();
+ payloadStream.data = gzipCompressString(utf8Payload);
+
// Check the size and drop pings which are too big.
- const pingSizeBytes = utf8Payload.length;
- if (pingSizeBytes > TelemetryStorage.MAXIMUM_PING_SIZE) {
- this._log.error("_doPing - submitted ping exceeds the size limit, size: " + pingSizeBytes);
+ const compressedPingSizeBytes = payloadStream.data.length;
+ if (compressedPingSizeBytes > TelemetryStorage.MAXIMUM_PING_SIZE) {
+ this._log.error("_doPing - submitted ping exceeds the size limit, size: " + compressedPingSizeBytes);
Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_SEND").add();
Telemetry.getHistogramById("TELEMETRY_DISCARDED_SEND_PINGS_SIZE_MB")
- .add(Math.floor(pingSizeBytes / 1024 / 1024));
+ .add(Math.floor(compressedPingSizeBytes / 1024 / 1024));
// We don't need to call |request.abort()| as it was not sent yet.
this._pendingPingRequests.delete(id);
TelemetryHealthPing.recordDiscardedPing(ping.type);
return TelemetryStorage.removePendingPing(id);
}
- let payloadStream = Cc["@mozilla.org/io/string-input-stream;1"]
- .createInstance(Ci.nsIStringInputStream);
- startTime = Utils.monotonicNow();
- payloadStream.data = gzipCompressString(utf8Payload);
-
const compressedPingSizeKB = Math.floor(payloadStream.data.length / 1024);
Telemetry.getHistogramById("TELEMETRY_COMPRESS").add(Utils.monotonicNow() - startTime);
request.sendInputStream(payloadStream);
return deferred.promise;
},
/**
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -330,17 +330,17 @@ add_task(async function test_discardBigP
let histSuccess = Telemetry.getHistogramById("TELEMETRY_SUCCESS");
let histSendTimeSuccess = Telemetry.getHistogramById("TELEMETRY_SEND_SUCCESS");
let histSendTimeFail = Telemetry.getHistogramById("TELEMETRY_SEND_FAILURE");
for (let h of [histSizeExceeded, histDiscardedSize, histSuccess, histSendTimeSuccess, histSendTimeFail]) {
h.clear();
}
// Generate a 2MB string and create an oversized payload.
- const OVERSIZED_PAYLOAD = {"data": generateRandomString(2 * 1024 * 1024)};
+ const OVERSIZED_PAYLOAD = {"data": generateRandomString(4 * 1024 * 1024)};
// Submit a ping of a normal size and check that we don't count it in the histogram.
await TelemetryController.submitExternalPing(TEST_PING_TYPE, { test: "test" });
await TelemetrySend.testWaitOnOutgoingPings();
await PingServer.promiseNextPing();
Assert.equal(histSizeExceeded.snapshot().sum, 0, "Telemetry must report no oversized ping submitted.");
Assert.equal(histDiscardedSize.snapshot().sum, 0, "Telemetry must report no oversized pings.");