Bug 1615985 - Collect number of calendars with types and readonly status. r=mkmelin,pmorris
authorPing Chen <remotenonsense@gmail.com>
Fri, 05 Jun 2020 13:56:56 +0300
changeset 29793 6602b6ca210fe75a9e65d19acc80635b287a52fe
parent 29792 41df9fb58b55af38c3334efce65cc0514c53a944
child 29794 bb0273cc41d33f270637ac2490b0b22ca46d333d
push id17534
push usermkmelin@iki.fi
push dateFri, 05 Jun 2020 10:58:24 +0000
treeherdercomm-central@68ea43e43f5d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin, pmorris
bugs1615985
Bug 1615985 - Collect number of calendars with types and readonly status. r=mkmelin,pmorris
calendar/base/content/calendar-management.js
calendar/test/browser/browser.ini
calendar/test/browser/browser_calendarTelemetry.js
mail/components/telemetry/Scalars.yaml
--- a/calendar/base/content/calendar-management.js
+++ b/calendar/base/content/calendar-management.js
@@ -119,18 +119,36 @@ function loadCalendarManager() {
       }
     }
   } else {
     initHomeCalendar();
   }
 
   let calendarManager = cal.getCalendarManager();
 
-  for (let calendar of sortCalendarArray(cal.getCalendarManager().getCalendars())) {
+  let telemetryReport = {};
+
+  for (let calendar of sortCalendarArray(calendarManager.getCalendars())) {
     addCalendarItem(calendar);
+    if (!telemetryReport[calendar.type]) {
+      telemetryReport[calendar.type] = { count: 0, readOnlyCount: 0 };
+    }
+    telemetryReport[calendar.type].count++;
+    if (calendar.readOnly) {
+      telemetryReport[calendar.type].readOnlyCount++;
+    }
+  }
+
+  for (let [type, { count, readOnlyCount }] of Object.entries(telemetryReport)) {
+    Services.telemetry.keyedScalarSet("tb.calendar.calendar_count", type.toLowerCase(), count);
+    Services.telemetry.keyedScalarSet(
+      "tb.calendar.read_only_calendar_count",
+      type.toLowerCase(),
+      readOnlyCount
+    );
   }
 
   function addCalendarItem(calendar) {
     let item = document.createXULElement("richlistitem");
     item.searchLabel = calendar.name;
     item.setAttribute("calendar-id", calendar.id);
     if (calendar.getProperty("disabled")) {
       item.setAttribute("calendar-disabled", "true");
--- a/calendar/test/browser/browser.ini
+++ b/calendar/test/browser/browser.ini
@@ -7,16 +7,17 @@ prefs =
   mail.winsearch.firstRunDone=true
   mailnews.start_page.override_url=about:blank
   mailnews.start_page.url=about:blank
 subsuite = thunderbird
 support-files = data/**
 
 [browser_basicFunctionality.js]
 [browser_calendarList.js]
+[browser_calendarTelemetry.js]
 [browser_eventDisplay.js]
 [browser_import.js]
 [browser_localICS.js]
 [browser_tabs.js]
 [browser_taskDisplay.js]
 [browser_todayPane.js]
 skip-if = debug
 [browser_todayPane_visibility.js]
new file mode 100644
--- /dev/null
+++ b/calendar/test/browser/browser_calendarTelemetry.js
@@ -0,0 +1,40 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+/**
+ * Test telemetry related to calendar.
+ */
+
+let { TelemetryTestUtils } = ChromeUtils.import("resource://testing-common/TelemetryTestUtils.jsm");
+
+/**
+ * Check that we're counting calendars and read only calendars.
+ */
+add_task(async function test_calendar_count() {
+  Services.telemetry.clearScalars();
+
+  let manager = cal.getCalendarManager();
+  let uri = Services.io.newURI("moz-memory-calendar://");
+  let calendars = manager.getCalendars();
+  for (let i = 1; i <= 3; i++) {
+    calendars[i] = manager.createCalendar("memory", uri);
+    calendars[i].name = `Mochitest ${i}`;
+    if (i === 1 || i === 3) {
+      calendars[i].readOnly = true;
+    }
+    manager.registerCalendar(calendars[i]);
+  }
+
+  await loadCalendarManager();
+  let scalars = TelemetryTestUtils.getProcessScalars("parent", true);
+  Assert.equal(
+    scalars["tb.calendar.calendar_count"]["memory"],
+    3,
+    "Count of calendars must be correct."
+  );
+  Assert.equal(
+    scalars["tb.calendar.read_only_calendar_count"]["memory"],
+    2,
+    "Count of readonly calendars must be correct."
+  );
+});
--- a/mail/components/telemetry/Scalars.yaml
+++ b/mail/components/telemetry/Scalars.yaml
@@ -141,8 +141,37 @@ tb.websearch:
     products:
       - 'thunderbird'
     keyed: true
     kind: uint
     notification_emails:
       - "telemetry-client-dev@thunderbird.net"
     record_in_processes:
       - 'main'
+
+tb.calendar:
+  calendar_count:
+    bug_numbers:
+      - 1615985
+    description: How many calendars were set up, keyed by caldendar type.
+    expires: never
+    products:
+      - 'thunderbird'
+    keyed: true
+    kind: uint
+    notification_emails:
+      - "telemetry-client-dev@thunderbird.net"
+    record_in_processes:
+      - 'main'
+
+  read_only_calendar_count:
+    bug_numbers:
+      - 1615985
+    description: How many read only calendars were set up, keyed by caldendar type.
+    expires: never
+    products:
+      - 'thunderbird'
+    keyed: true
+    kind: uint
+    notification_emails:
+      - "telemetry-client-dev@thunderbird.net"
+    record_in_processes:
+      - 'main'