bug 1410907 - Add CanRecord(Pre)Release data to nsITTelemetry r=Dexter draft
authorChris H-C <chutten@mozilla.com>
Fri, 03 Nov 2017 12:44:23 -0400
changeset 694193 27fe8a6bc6ffc103faf3802d37b8fb190dedbfeb
parent 694164 7851d6768dfd9fe5568d1315a98f142d9bb9234f
child 739290 7b67fb4f87e9703d9ad69f2874352bf48f34637a
push id88081
push userbmo:chutten@mozilla.com
push dateTue, 07 Nov 2017 14:50:32 +0000
reviewersDexter
bugs1410907
milestone58.0a1
bug 1410907 - Add CanRecord(Pre)Release data to nsITTelemetry r=Dexter We're starting a shift towards talking about release/prerelease data instead of base/extended collection. For now this is just a naming change. At the same time, we can render these attributes read-only, which is nice. MozReview-Commit-ID: IRuKpzLYW7i
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/Telemetry.h
toolkit/components/telemetry/nsITelemetry.idl
toolkit/components/telemetry/tests/unit/test_TelemetryController.js
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -157,16 +157,18 @@ public:
     struct Stat otherThreads;
   };
   typedef nsBaseHashtableET<nsCStringHashKey, StmtStats> SlowSQLEntryType;
 
   static void RecordIceCandidates(const uint32_t iceCandidateBitmask,
                                   const bool success);
   static bool CanRecordBase();
   static bool CanRecordExtended();
+  static bool CanRecordReleaseData();
+  static bool CanRecordPrereleaseData();
 private:
   TelemetryImpl();
   ~TelemetryImpl();
 
   static nsCString SanitizeSQL(const nsACString& sql);
 
   enum SanitizedState { Sanitized, Unsanitized };
 
@@ -1169,16 +1171,27 @@ TelemetryImpl::SetCanRecordExtended(bool
     TelemetryHistogram::SetCanRecordExtended(canRecord);
     TelemetryScalar::SetCanRecordExtended(canRecord);
     TelemetryEvent::SetCanRecordExtended(canRecord);
     mCanRecordExtended = canRecord;
   }
   return NS_OK;
 }
 
+NS_IMETHODIMP
+TelemetryImpl::GetCanRecordReleaseData(bool* ret) {
+  *ret = mCanRecordBase;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+TelemetryImpl::GetCanRecordPrereleaseData(bool* ret) {
+  *ret = mCanRecordExtended;
+  return NS_OK;
+}
 
 NS_IMETHODIMP
 TelemetryImpl::GetIsOfficialTelemetry(bool *ret) {
 #if defined(MOZILLA_OFFICIAL) && defined(MOZ_TELEMETRY_REPORTING) && !defined(DEBUG)
   *ret = true;
 #else
   *ret = false;
 #endif
@@ -1563,16 +1576,28 @@ TelemetryImpl::CanRecordExtended()
   if (!sTelemetry) {
     return false;
   }
   bool canRecordExtended;
   nsresult rv = sTelemetry->GetCanRecordExtended(&canRecordExtended);
   return NS_SUCCEEDED(rv) && canRecordExtended;
 }
 
+bool
+TelemetryImpl::CanRecordReleaseData()
+{
+  return CanRecordBase();
+}
+
+bool
+TelemetryImpl::CanRecordPrereleaseData()
+{
+  return CanRecordExtended();
+}
+
 NS_IMPL_ISUPPORTS(TelemetryImpl, nsITelemetry, nsIMemoryReporter)
 NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsITelemetry, TelemetryImpl::CreateTelemetryInstance)
 
 #define NS_TELEMETRY_CID \
   {0xaea477f2, 0xb3a2, 0x469c, {0xaa, 0x29, 0x0a, 0x82, 0xd1, 0x32, 0xb8, 0x29}}
 NS_DEFINE_NAMED_CID(NS_TELEMETRY_CID);
 
 const Module::CIDEntry kTelemetryCIDs[] = {
@@ -1949,16 +1974,28 @@ CanRecordBase()
 }
 
 bool
 CanRecordExtended()
 {
   return TelemetryImpl::CanRecordExtended();
 }
 
+bool
+CanRecordReleaseData()
+{
+  return TelemetryImpl::CanRecordReleaseData();
+}
+
+bool
+CanRecordPrereleaseData()
+{
+  return TelemetryImpl::CanRecordPrereleaseData();
+}
+
 void
 RecordSlowSQLStatement(const nsACString &statement,
                        const nsACString &dbName,
                        uint32_t delay)
 {
   TelemetryImpl::RecordSlowStatement(statement, dbName, delay);
 }
 
--- a/toolkit/components/telemetry/Telemetry.h
+++ b/toolkit/components/telemetry/Telemetry.h
@@ -254,16 +254,31 @@ bool CanRecordBase();
 
 /**
  * Indicates whether Telemetry extended data recording is turned on.  This is intended
  * to guard calls to Accumulate when the statistic being recorded is expensive to compute.
  */
 bool CanRecordExtended();
 
 /**
+ * Indicates whether Telemetry release data recording is turned on. Usually true.
+ *
+ * @see nsITelemetry.canRecordReleaseData
+ */
+bool CanRecordReleaseData();
+
+/**
+ * Indicates whether Telemetry pre-release data recording is turned on. Tends
+ * to be true on pre-release channels.
+ *
+ * @see nsITelemetry.canRecordPrereleaseData
+ */
+bool CanRecordPrereleaseData();
+
+/**
  * Records slow SQL statements for Telemetry reporting.
  *
  * @param statement - offending SQL statement to record
  * @param dbName - DB filename
  * @param delay - execution time in milliseconds
  */
 void RecordSlowSQLStatement(const nsACString &statement,
                             const nsACString &dbName,
--- a/toolkit/components/telemetry/nsITelemetry.idl
+++ b/toolkit/components/telemetry/nsITelemetry.idl
@@ -270,16 +270,44 @@ interface nsITelemetry : nsISupports
    * user has explicitly opted out of Telemetry on Nightly/Aurora/Beta or if manually
    * set to false during tests.
    *
    * Set this to false in tests to disable gathering of extended telemetry statistics.
    */
   attribute boolean canRecordExtended;
 
   /**
+   * A flag indicating whether Telemetry is recording release data, which is a
+   * smallish subset of our usage data that we're prepared to handle from our
+   * largish release population.
+   *
+   * This is true most of the time.
+   *
+   * This does not indicate whether Telemetry will send any data. That is
+   * governed by user preference and other mechanisms.
+   *
+   * You may use this to determine if it's okay to record your data.
+   */
+  readonly attribute boolean canRecordReleaseData;
+
+  /**
+   * A flag indicating whether Telemetry is recording prerelease data, which is
+   * a largish amount of usage data that we're prepared to handle from our
+   * smallish pre-release population.
+   *
+   * This is true on pre-release branches of Firefox.
+   *
+   * This does not indicate whether Telemetry will send any data. That is
+   * governed by user preference and other mechanisms.
+   *
+   * You may use this to determine if it's okay to record your data.
+   */
+  readonly attribute boolean canRecordPrereleaseData;
+
+  /**
    * A flag indicating whether Telemetry can submit official results (for base or extended
    * data). This is true on official, non-debug builds with built in support for Mozilla
    * Telemetry reporting.
    */
   readonly attribute boolean isOfficialTelemetry;
 
   /**
    * Enable/disable recording for this histogram at runtime.
--- a/toolkit/components/telemetry/tests/unit/test_TelemetryController.js
+++ b/toolkit/components/telemetry/tests/unit/test_TelemetryController.js
@@ -594,11 +594,18 @@ add_task(async function test_sendNewProf
 add_task(async function test_pingRejection() {
   await TelemetryController.testReset();
   await TelemetryController.testShutdown();
   await sendPing(false, false)
     .then(() => Assert.ok(false, "Pings submitted after shutdown must be rejected."),
           () => Assert.ok(true, "Ping submitted after shutdown correctly rejected."));
 });
 
+add_task(async function test_newCanRecordsMatchTheOld() {
+  Assert.equal(Telemetry.canRecordBase, Telemetry.canRecordReleaseData,
+               "Release Data is the new way to say Base Collection");
+  Assert.equal(Telemetry.canRecordExtended, Telemetry.canRecordPrereleaseData,
+               "Prerelease Data is the new way to say Extended Collection");
+});
+
 add_task(async function stopServer() {
   await PingServer.stop();
 });