Bug 1402267 - Add a scalar telemetry probe that tracks SessionFile worker restarts. data-r=liuche, r?ttaubert,chutten draft
authorMike de Boer <mdeboer@mozilla.com>
Tue, 17 Oct 2017 12:04:37 +0200
changeset 681455 aded9609532d33d65e7c4d8683d135139f7b6346
parent 681453 6f23983c4b3763f756aa3d25ff2d978bb5dad566
child 681582 b3c00c0d3af9bccf6242d3885c8c5f5c1f503540
child 681583 383a4ad3c390f81d715be69a0196881182f4872e
child 681627 6812ab7251b90354c8f42c263af0f9adf59a71a2
push id84840
push usermdeboer@mozilla.com
push dateTue, 17 Oct 2017 10:10:44 +0000
reviewersttaubert, chutten
bugs1402267
milestone58.0a1
Bug 1402267 - Add a scalar telemetry probe that tracks SessionFile worker restarts. data-r=liuche, r?ttaubert,chutten MozReview-Commit-ID: F3kCfz18kcQ
browser/components/sessionstore/SessionFile.jsm
browser/components/sessionstore/test/unit/test_scalar_worker_restarts.js
browser/components/sessionstore/test/unit/xpcshell.ini
toolkit/components/telemetry/Scalars.yaml
--- a/browser/components/sessionstore/SessionFile.jsm
+++ b/browser/components/sessionstore/SessionFile.jsm
@@ -82,16 +82,20 @@ this.SessionFile = {
   },
 
   /**
    * Return the paths to the files used to store, backup, etc.
    * the state of the file.
    */
   get Paths() {
     return SessionFileInternal.Paths;
+  },
+
+  get MaxWriteFailures() {
+    return kMaxWriteFailures;
   }
 };
 
 Object.freeze(SessionFile);
 
 var Path = OS.Path;
 var profileDir = OS.Constants.Path.profileDir;
 
@@ -347,16 +351,17 @@ var SessionFileInternal = {
    * amount of failures to deal with. This will spawn a fresh worker upon the next
    * write.
    * This also resets the `_workerHealth` stats.
    */
   _checkWorkerHealth() {
     if (this._workerHealth.failures >= kMaxWriteFailures) {
       SessionWorker.terminate();
       this._workerHealth.failures = 0;
+      Telemetry.scalarAdd("browser.session.restore.worker_restart_count", 1);
     }
   },
 
   write(aData) {
     if (RunState.isClosed) {
       return Promise.reject(new Error("SessionFile is closed"));
     }
 
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/unit/test_scalar_worker_restarts.js
@@ -0,0 +1,39 @@
+/*
+ * The primary purpose of this test is to ensure that the sessionstore component
+ * records information about erroneous workers into a scalar.
+ */
+
+"use strict";
+const Telemetry = Services.telemetry;
+const ScalarId = "browser.session.restore.worker_restart_count";
+
+// Prepare the session file.
+var profd = do_get_profile();
+Cu.import("resource:///modules/sessionstore/SessionFile.jsm", this);
+
+/**
+ * In order to use browser.session.restore.worker_restart_count scalar, it has
+ * to be registered in "toolkit/components/telemetry/Scalars.yaml".
+ * This test ensures that the scalar is registered and empty.
+ */
+add_task(async function test_ensure_scalar_is_empty() {
+  const scalars = Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT, false).parent || {};
+  Assert.ok(!(ScalarId in scalars), "Sanity check; no scalars should be there yet.");
+});
+
+/**
+ * Makes sure that the scalar is positively updated when amount of failures
+ * becomes higher than the threshold.
+ */
+add_task(async function test_worker_restart() {
+  let backstagePass = Cu.import("resource:///modules/sessionstore/SessionFile.jsm", {});
+  backstagePass.SessionFileInternal._workerHealth.failures = backstagePass.kMaxWriteFailures + 1;
+  backstagePass.SessionFileInternal._checkWorkerHealth();
+
+  Assert.equal(backstagePass.SessionFileInternal._workerHealth.failures, 0,
+    "Worker failure count should've been reset.");
+
+  // Checking if the scalar is positively updated.
+  const scalars = Telemetry.snapshotScalars(Ci.nsITelemetry.DATASET_RELEASE_CHANNEL_OPTOUT, false).parent;
+  Assert.equal(scalars[ScalarId], 1, "Should be increased with one hit.");
+});
--- a/browser/components/sessionstore/test/unit/xpcshell.ini
+++ b/browser/components/sessionstore/test/unit/xpcshell.ini
@@ -4,13 +4,14 @@ firefox-appdir = browser
 skip-if = toolkit == 'android'
 support-files =
   data/sessionCheckpoints_all.json
   data/sessionstore_invalid.js
   data/sessionstore_valid.js
 
 [test_backup_once.js]
 [test_histogram_corrupt_files.js]
+[test_migration_lz4compression.js]
+[test_scalar_worker_restarts.js]
 [test_shutdown_cleanup.js]
 [test_startup_nosession_async.js]
 [test_startup_session_async.js]
 [test_startup_invalid_session.js]
-[test_migration_lz4compression.js]
--- a/toolkit/components/telemetry/Scalars.yaml
+++ b/toolkit/components/telemetry/Scalars.yaml
@@ -356,16 +356,32 @@ browser.session.restore:
     expires: never
     kind: uint
     notification_emails:
       - bwinton@mozilla.com
     release_channel_collection: opt-out
     record_in_processes:
       - 'main'
 
+  worker_restart_count:
+    bug_numbers:
+      - 1402267
+    description: >
+      A counter incremented every time the SessionFile worker is restarted due
+      to too many failures, as defined in the browser.sessionstore.max_write_failures
+      pref.
+    expires: "64"
+    kind: uint
+    notification_emails:
+      - mdeboer@mozilla.com
+      - session-restore-telemetry-alerts@mozilla.com
+    release_channel_collection: opt-out
+    record_in_processes:
+      - 'main'
+
 # This section is for probes used to measure use of the Webextensions storage.sync API.
 storage.sync.api.usage:
   extensions_using:
     bug_numbers:
       - 1328974
     description: >
       The count of webextensions that have data stored in the chrome.storage.sync API.
       This includes extensions that have not used the storage.sync API this session.