Bug 1311893 - HSTS Priming timing telemetry r?ckerschb r?francois p=francois draft
authorKate McKinley <kmckinley@mozilla.com>
Wed, 26 Oct 2016 14:36:44 +0900
changeset 430663 2fa779ed85788fcacf88d181f4294a5220483c87
parent 429595 c141993d03eeebd21e4d5a3a07ae9c92695a125f
child 535241 d912f25b1f7f62db32198f0063090c4f5f43a50c
push id33864
push userbmo:kmckinley@mozilla.com
push dateFri, 28 Oct 2016 02:19:48 +0000
reviewersckerschb, francois
bugs1311893
milestone52.0a1
Bug 1311893 - HSTS Priming timing telemetry r?ckerschb r?francois p=francois MozReview-Commit-ID: WKmlCqDOKT
netwerk/protocol/http/HSTSPrimerListener.cpp
toolkit/components/telemetry/Histograms.json
--- a/netwerk/protocol/http/HSTSPrimerListener.cpp
+++ b/netwerk/protocol/http/HSTSPrimerListener.cpp
@@ -31,23 +31,38 @@ HSTSPrimingListener::GetInterface(const 
 {
   return QueryInterface(aIID, aResult);
 }
 
 NS_IMETHODIMP
 HSTSPrimingListener::OnStartRequest(nsIRequest *aRequest,
                                     nsISupports *aContext)
 {
-  nsresult rv = CheckHSTSPrimingRequestStatus(aRequest);
+  nsresult primingResult = CheckHSTSPrimingRequestStatus(aRequest);
   nsCOMPtr<nsIHstsPrimingCallback> callback(mCallback);
   mCallback = nullptr;
 
-  if (NS_FAILED(rv)) {
+  nsCOMPtr<nsITimedChannel> timingChannel =
+    do_QueryInterface(callback);
+  if (timingChannel) {
+    TimeStamp channelCreationTime;
+    nsresult rv = timingChannel->GetChannelCreation(&channelCreationTime);
+    if (NS_SUCCEEDED(rv) && !channelCreationTime.IsNull()) {
+      PRUint32 interval =
+        (PRUint32) (TimeStamp::Now() - channelCreationTime).ToMilliseconds();
+      Telemetry::Accumulate(Telemetry::HSTS_PRIMING_REQUEST_DURATION,
+          (NS_SUCCEEDED(primingResult)) ? NS_LITERAL_CSTRING("success")
+                                        : NS_LITERAL_CSTRING("failure"),
+          interval);
+    }
+  }
+
+  if (NS_FAILED(primingResult)) {
     LOG(("HSTS Priming Failed (request was not approved)"));
-    return callback->OnHSTSPrimingFailed(rv, false);
+    return callback->OnHSTSPrimingFailed(primingResult, false);
   }
 
   LOG(("HSTS Priming Succeeded (request was approved)"));
   return callback->OnHSTSPrimingSucceeded(false);
 }
 
 NS_IMETHODIMP
 HSTSPrimingListener::OnStopRequest(nsIRequest *aRequest,
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -7791,16 +7791,27 @@
   "MIXED_CONTENT_HSTS_PRIMING_RESULT": {
     "alert_emails": ["seceng@mozilla.org"],
     "bug_numbers": [1246540],
     "expires_in_version": "60",
     "kind": "enumerated",
     "n_values": 16,
     "description": "How often do we get back an HSTS priming result which upgrades the connection to HTTPS? 0=cached (no upgrade), 1=cached (do upgrade), 2=cached (blocked), 3=already upgraded, 4=priming succeeded, 5=priming succeeded (block due to pref), 6=priming succeeded (no upgrade due to pref), 7=priming failed (block), 8=priming failed (accept)"
   },
+  "HSTS_PRIMING_REQUEST_DURATION": {
+    "alert_emails": ["seceng-telemetry@mozilla.org"],
+    "bug_numbers": [1311893],
+    "expires_in_version": "58",
+    "kind": "exponential",
+    "low": 100,
+    "high": 30000,
+    "n_buckets": 100,
+    "keyed": true,
+    "description": "The amount of time required for HSTS priming requests (ms), keyed by success or failure of the priming request. (success, failure)"
+  },
   "MIXED_CONTENT_OBJECT_SUBREQUEST": {
     "alert_emails": ["seceng@mozilla.org"],
     "bug_numbers": [1244116],
     "expires_in_version": "55",
     "kind": "enumerated",
     "n_values": 10,
     "description": "How often objects load insecure content on secure pages (counting pages, not objects). 0=pages with no mixed object subrequests, 1=pages with mixed object subrequests"
   },