From 3cfadb8e23e6436db218be19c12e4b93a8b6bf53 Mon Sep 17 00:00:00 2001 From: Kate Ustiuzhanina Date: Mon, 7 Aug 2017 11:09:05 +0100 Subject: [PATCH] Bug 1379125 - Track dicarded for size pending ping with TelemetryHealthPing. r=gfritzsche --HG-- extra : rebase_source : 0c888483fac948cbf70da1834e9c0fbbd022a2bb --- .../components/telemetry/TelemetryStorage.jsm | 10 ++++ .../telemetry/docs/data/health-ping.rst | 2 + .../tests/unit/test_TelemetryHealthPing.js | 47 +++++++++++++++++++ 3 files changed, 59 insertions(+) diff --git a/toolkit/components/telemetry/TelemetryStorage.jsm b/toolkit/components/telemetry/TelemetryStorage.jsm index f315e97d6643..8c0f5b540332 100644 --- a/toolkit/components/telemetry/TelemetryStorage.jsm +++ b/toolkit/components/telemetry/TelemetryStorage.jsm @@ -48,6 +48,8 @@ XPCOMUtils.defineLazyGetter(this, "gDeletionPingFilePath", function() { }); XPCOMUtils.defineLazyModuleGetter(this, "CommonUtils", "resource://services-common/utils.js"); +XPCOMUtils.defineLazyModuleGetter(this, "TelemetryHealthPing", + "resource://gre/modules/TelemetryHealthPing.jsm"); // Maxmimum time, in milliseconds, archive pings should be retained. const MAX_ARCHIVED_PINGS_RETENTION_MS = 60 * 24 * 60 * 60 * 1000; // 60 days @@ -1365,6 +1367,10 @@ var TelemetryStorageImpl = { .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. + TelemetryHealthPing.recordDiscardedPing(""); throw new Error("loadPendingPing - exceeded the maximum ping size: " + fileSize); } @@ -1598,6 +1604,10 @@ var TelemetryStorageImpl = { Telemetry.getHistogramById("TELEMETRY_DISCARDED_PENDING_PINGS_SIZE_MB") .add(Math.floor(info.size / 1024 / 1024)); Telemetry.getHistogramById("TELEMETRY_PING_SIZE_EXCEEDED_PENDING").add(); + + // Currently we don't have the ping type available without loading the ping from disk. + // Bug 1384903 will fix that. + TelemetryHealthPing.recordDiscardedPing(""); } continue; } diff --git a/toolkit/components/telemetry/docs/data/health-ping.rst b/toolkit/components/telemetry/docs/data/health-ping.rst index 882c67708def..36037fa69cb7 100644 --- a/toolkit/components/telemetry/docs/data/health-ping.rst +++ b/toolkit/components/telemetry/docs/data/health-ping.rst @@ -65,6 +65,8 @@ pingDiscardedForSize The ``pingDiscardedForSize`` field contains the information about top ten pings, whose size exceeded the ping size limit (1 mb). This field lists the number of discarded pings per ping type. +The ping type "" is used to indicate that a pending pings size exceeded the limit. This is because we don't have the pending pings type available cheaply at the moment. + This field is optional. sendFailure diff --git a/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js b/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js index 7223e5c1a534..f4e144b30e82 100644 --- a/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js +++ b/toolkit/components/telemetry/tests/unit/test_TelemetryHealthPing.js @@ -240,6 +240,53 @@ add_task(async function test_sendOnlyTopTenDiscardedPings() { }); }); +add_task(async function test_discardedForSizePending() { + TelemetryHealthPing.testReset(); + PingServer.clearRequests(); + + const PING_TYPE = "discarded-for-size-pending"; + + const OVERSIZED_PING_ID = "9b21ec8f-f762-4d28-a2c1-44e1c4694f24"; + // Create a pending oversized ping. + let overSizedPayload = generateRandomString(2 * 1024 * 1024); + const OVERSIZED_PING = { + id: OVERSIZED_PING_ID, + type: PING_TYPE, + creationDate: (new Date()).toISOString(), + // Generate a 2MB string to use as the ping payload. + payload: overSizedPayload, + }; + + // Test loadPendingPing. + await TelemetryStorage.savePendingPing(OVERSIZED_PING); + // Try to manually load the oversized ping. + await Assert.rejects(TelemetryStorage.loadPendingPing(OVERSIZED_PING_ID), + "The oversized ping should have been pruned."); + + let ping = await PingServer.promiseNextPing(); + checkHealthPingStructure(ping, { + [TelemetryHealthPing.FailureType.DISCARDED_FOR_SIZE]: { + "": 1 + }, + "os": TelemetryHealthPing.OsInfo, + "reason": TelemetryHealthPing.Reason.IMMEDIATE + }); + + // Test _scanPendingPings. + TelemetryHealthPing.testReset(); + await TelemetryStorage.savePendingPing(OVERSIZED_PING); + await TelemetryStorage.loadPendingPingList(); + + ping = await PingServer.promiseNextPing(); + checkHealthPingStructure(ping, { + [TelemetryHealthPing.FailureType.DISCARDED_FOR_SIZE]: { + "": 1 + }, + "os": TelemetryHealthPing.OsInfo, + "reason": TelemetryHealthPing.Reason.IMMEDIATE + }); +}); + add_task(async function test_usePingSenderOnShutdown() { if (gIsAndroid || (AppConstants.platform == "linux" && OS.Constants.Sys.bits == 32)) {