Bug 1367094 - Measure the size of successful and failed pings. r=gfritzsche
authorKate Ustiuzhanina <kustiuzhanina@mozilla.com>
Tue, 06 Jun 2017 16:52:41 +0100
changeset 410651 7df33990054eb90ee719d62fe125e01bd336bb84
parent 410650 02fb002e96bf32429d571ab854596269add0195e
child 410652 4a2407f32c27960136418b03e479c3703fd29e94
push id7391
push usermtabara@mozilla.com
push dateMon, 12 Jun 2017 13:08:53 +0000
treeherdermozilla-beta@2191d7f87e2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1367094
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1367094 - Measure the size of successful and failed pings. r=gfritzsche MozReview-Commit-ID: KSt07czm7Kt
toolkit/components/telemetry/Histograms.json
toolkit/components/telemetry/TelemetrySend.jsm
toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -7167,23 +7167,43 @@
     "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",
+    "expires_in_version": "61",
     "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"],
+    "expires_in_version": "61",
+    "kind": "exponential",
+    "low": 10,
+    "high": 1024,
+    "n_buckets": 20,
+    "description": "The size (KB) of the Telemetry successfully sent pings"
+  },
+  "TELEMETRY_FAILED_SEND_PINGS_SIZE_KB": {
+    "record_in_processes": ["main"],
+    "alert_emails": ["telemetry-client-dev@mozilla.com"],
+    "expires_in_version": "never",
+    "kind": "exponential",
+    "low": 10,
+    "high": 1024,
+    "n_buckets": 20,
+    "description": "The size (KB) of the Telemetry unsuccessfully sent pings"
+  },
   "TELEMETRY_PING_SIZE_EXCEEDED_SEND": {
     "record_in_processes": ["main", "content"],
     "alert_emails": ["telemetry-client-dev@mozilla.com"],
     "expires_in_version": "never",
     "kind": "count",
     "description": "Number of Telemetry pings discarded before sending because they exceeded the maximum size"
   },
   "TELEMETRY_PING_SIZE_EXCEEDED_PENDING": {
--- a/toolkit/components/telemetry/TelemetrySend.jsm
+++ b/toolkit/components/telemetry/TelemetrySend.jsm
@@ -1096,18 +1096,22 @@ var TelemetrySendImpl = {
     request.channel.loadFlags &= ~Ci.nsIChannel.LOAD_CLASSIFY_URI;
 
     const monotonicStartTime = monotonicNow();
     let deferred = PromiseUtils.defer();
 
     let onRequestFinished = (success, event) => {
       let onCompletion = () => {
         if (success) {
+          let histogram = Telemetry.getHistogramById("TELEMETRY_SUCCESSFUL_SEND_PINGS_SIZE_KB");
+          histogram.add(compressedPingSizeKB);
           deferred.resolve();
         } else {
+          let histogram = Telemetry.getHistogramById("TELEMETRY_FAILED_SEND_PINGS_SIZE_KB");
+          histogram.add(compressedPingSizeKB);
           deferred.reject(event);
         }
       };
 
       this._pendingPingRequests.delete(id);
       this._onPingRequestFinished(success, monotonicStartTime, id, isPersisted)
         .then(() => onCompletion(),
               (error) => {
@@ -1182,16 +1186,18 @@ var TelemetrySendImpl = {
       this._pendingPingRequests.delete(id);
       return TelemetryStorage.removePendingPing(id);
     }
 
     let payloadStream = Cc["@mozilla.org/io/string-input-stream;1"]
                         .createInstance(Ci.nsIStringInputStream);
     startTime = new Date();
     payloadStream.data = gzipCompressString(utf8Payload);
+
+    const compressedPingSizeKB = Math.floor(payloadStream.data.length / 1024);
     Telemetry.getHistogramById("TELEMETRY_COMPRESS").add(new Date() - startTime);
     startTime = new Date();
     request.send(payloadStream);
 
     return deferred.promise;
   },
 
   /**
--- a/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetrySend.js
@@ -2,16 +2,17 @@
    http://creativecommons.org/publicdomain/zero/1.0/
 */
 
 // This tests the public Telemetry API for submitting pings.
 
 "use strict";
 
 Cu.import("resource://gre/modules/TelemetryController.jsm", this);
+Cu.import("resource://testing-common/ContentTaskUtils.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySession.jsm", this);
 Cu.import("resource://gre/modules/TelemetrySend.jsm", this);
 Cu.import("resource://gre/modules/TelemetryStorage.jsm", this);
 Cu.import("resource://gre/modules/TelemetryUtils.jsm", this);
 Cu.import("resource://gre/modules/Services.jsm", this);
 Cu.import("resource://gre/modules/Preferences.jsm", this);
 Cu.import("resource://gre/modules/osfile.jsm", this);
 
@@ -463,11 +464,60 @@ add_task(async function test_sendCheckOv
   const ping = await PingServer.promiseNextPing();
   Assert.equal(ping.type, TEST_PING_TYPE, "Must receive a ping of the expected type");
 
   // Restore the test mode and disable the override.
   TelemetrySend.setTestModeEnabled(true);
   Preferences.reset(PREF_OVERRIDE_OFFICIAL_CHECK);
 });
 
+add_task(async function test_measurePingsSize() {
+  const TEST_TYPE = "test-measure-ping-size";
+
+  let histSuccessPingSize = Telemetry.getHistogramById("TELEMETRY_SUCCESSFUL_SEND_PINGS_SIZE_KB");
+  let histFailedPingSize = Telemetry.getHistogramById("TELEMETRY_FAILED_SEND_PINGS_SIZE_KB");
+
+  for (let h of [histSuccessPingSize, histFailedPingSize]) {
+    h.clear();
+  }
+
+  await TelemetryController.submitExternalPing(TEST_TYPE, {});
+  await TelemetrySend.testWaitOnOutgoingPings();
+
+  // Check that we recorded the ping sizes correctly into histograms.
+  Assert.equal(histogramValueCount(histSuccessPingSize.snapshot()), 1,
+    "Should have recorded 1 successful ping into histogram.");
+  Assert.equal(histogramValueCount(histFailedPingSize.snapshot()), 0,
+    "Should have recorded 0 failed ping into histogram.");
+
+  // Submit the same ping a second time.
+  await TelemetryController.submitExternalPing(TEST_TYPE, {});
+  await TelemetrySend.testWaitOnOutgoingPings();
+
+  // Check that we recorded the ping sizes correctly into histograms.
+  Assert.equal(histogramValueCount(histSuccessPingSize.snapshot()), 2,
+    "Should have recorded 2 successful ping into histogram.");
+  Assert.equal(histogramValueCount(histFailedPingSize.snapshot()), 0,
+    "Should have recorded 0 failed ping into histogram.");
+
+  // Register a custom ping handler which will return 601.
+  PingServer.registerPingHandler((req, res) => {
+    res.setStatusLine(null, 601, "Not Implemented");
+    res.processAsync();
+    res.finish();
+  });
+
+  await TelemetryController.submitExternalPing(TEST_TYPE, {});
+  await ContentTaskUtils.waitForCondition(() => {
+    return histogramValueCount(histFailedPingSize.snapshot()) > 0;
+  });
+
+  // Check that we recorded the ping sizes correctly into histograms.
+  Assert.equal(histogramValueCount(histSuccessPingSize.snapshot()), 2,
+    "Should have recorded 2 successful ping into histogram.");
+  Assert.equal(histogramValueCount(histFailedPingSize.snapshot()), 1,
+    "Should have recorded 1 failed ping into histogram.");
+});
+
+
 add_task(async function cleanup() {
   await PingServer.stop();
 });