Bug 1675533 - Collect telemetry which content types get upgraded by HTTPS-Only and if they load successfully. r=ckerschb a=pascal
authorjulianwels <julianwels@mozilla.com>
Mon, 09 Nov 2020 14:20:25 +0000
changeset 623455 4d7a26229928912a4753830f82926a1ca3648c77
parent 623454 b4d233ef14ae136259150de988085b3847a8af2b
child 623456 e4e70188ad75abd6a726d0f13df9a0e48737479e
push id2459
push userryanvm@gmail.com
push dateThu, 12 Nov 2020 14:23:46 +0000
treeherdermozilla-release@21bb5006852e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb, pascal
bugs1675533
milestone83.0
Bug 1675533 - Collect telemetry which content types get upgraded by HTTPS-Only and if they load successfully. r=ckerschb a=pascal Differential Revision: https://phabricator.services.mozilla.com/D96087
dom/security/nsHTTPSOnlyStreamListener.cpp
toolkit/components/telemetry/Histograms.json
--- a/dom/security/nsHTTPSOnlyStreamListener.cpp
+++ b/dom/security/nsHTTPSOnlyStreamListener.cpp
@@ -91,19 +91,19 @@ void nsHTTPSOnlyStreamListener::RecordUp
   nsresult rv;
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(request, &rv);
   if (NS_FAILED(rv)) {
     return;
   }
 
   nsAutoCString category;
   nsCOMPtr<nsILoadInfo> loadInfo = channel->LoadInfo();
+  nsContentPolicyType internalType = loadInfo->InternalContentPolicyType();
 
-  if (loadInfo->InternalContentPolicyType() ==
-      nsIContentPolicy::TYPE_DOCUMENT) {
+  if (internalType == nsIContentPolicy::TYPE_DOCUMENT) {
     category.AppendLiteral("top_");
   } else {
     category.AppendLiteral("sub_");
   }
 
   if (NS_SUCCEEDED(aStatus)) {
     category.AppendLiteral("successful");
   } else {
@@ -131,19 +131,106 @@ void nsHTTPSOnlyStreamListener::RecordUp
         default:
           category.AppendLiteral("f_ssl_other");
           break;
       }
     } else {
       category.AppendLiteral("f_other");
     }
   }
+  mozilla::Telemetry::Accumulate(
+      mozilla::Telemetry::HTTPS_ONLY_MODE_UPGRADE_TIME_MS, category, duration);
+
+  bool success = NS_SUCCEEDED(aStatus);
+  nsContentPolicyType externalType = loadInfo->GetExternalContentPolicyType();
+  auto typeKey = nsAutoCString("unknown");
+
+  if (externalType == nsIContentPolicy::TYPE_MEDIA) {
+    switch (internalType) {
+      case nsIContentPolicy::TYPE_INTERNAL_AUDIO:
+      case nsIContentPolicy::TYPE_INTERNAL_TRACK:
+        typeKey = "audio"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_INTERNAL_VIDEO:
+        typeKey = "video"_ns;
+        break;
+    }
+  } else {
+    switch (externalType) {
+      case nsIContentPolicy::TYPE_SCRIPT:
+        typeKey = "script"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_OBJECT:
+      case nsIContentPolicy::TYPE_OBJECT_SUBREQUEST:
+        typeKey = "object"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_DOCUMENT:
+        typeKey = "document"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_SUBDOCUMENT:
+        typeKey = "subdocument"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_XMLHTTPREQUEST:
+        typeKey = "xmlhttprequest"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_IMAGE:
+      case nsIContentPolicy::TYPE_IMAGESET:
+        typeKey = "image"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_DTD:
+        typeKey = "dtd"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_FONT:
+        typeKey = "font"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_FETCH:
+        typeKey = "fetch"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_WEBSOCKET:
+        typeKey = "websocket"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_STYLESHEET:
+        typeKey = "stylesheet"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_CSP_REPORT:
+        typeKey = "cspreport"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_WEB_MANIFEST:
+        typeKey = "webmanifest"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_PING:
+        typeKey = "ping"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_REFRESH:
+        typeKey = "refresh"_ns;
+        break;
+
+      case nsIContentPolicy::TYPE_XSLT:
+        typeKey = "xslt"_ns;
+        break;
+    }
+  }
 
   mozilla::Telemetry::Accumulate(
-      mozilla::Telemetry::HTTPS_ONLY_MODE_UPGRADE_TIME_MS, category, duration);
+      mozilla::Telemetry::HTTPS_ONLY_MODE_UPGRADE_TYPE, typeKey, success);
 }
 
 void nsHTTPSOnlyStreamListener::LogUpgradeFailure(nsIRequest* request,
                                                   nsresult aStatus) {
   // If the request failed we'll log it to the console with the error-code
   if (NS_SUCCEEDED(aStatus)) {
     return;
   }
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -5800,16 +5800,27 @@
       "sub_f_ssl_unkwnissr",
       "top_f_ssl_other",
       "sub_f_ssl_other",
       "top_f_other",
       "sub_f_other"
     ],
     "description": "Time it takes for a request that has been upgraded with HTTPS-Only Mode to complete, broken down by top-level (top) / sub-resource (sub) and status"
   },
+  "HTTPS_ONLY_MODE_UPGRADE_TYPE": {
+    "record_in_processes": ["main"],
+    "products": ["firefox"],
+    "alert_emails": ["seceng-telemetry@mozilla.com", "julianwels@mozilla.com"],
+    "bug_numbers": [1675533],
+    "releaseChannelCollection": "opt-out",
+    "expires_in_version": "never",
+    "kind": "boolean",
+    "keyed": true,
+    "description": "What content type did we upgrade, and did it load successfully?"
+  },
   "PLACES_DATABASE_CORRUPTION_HANDLING_STAGE": {
     "record_in_processes": ["main"],
     "products": ["firefox", "fennec", "thunderbird"],
     "alert_emails": ["mbonardo@mozilla.com", "mbanner@mozilla.com"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "n_values": 6,
     "releaseChannelCollection": "opt-out",