Bug 1311893 - HSTS Priming timing telemetry r=ckerschb,francois p=francois
authorKate McKinley <kmckinley@mozilla.com>
Wed, 26 Oct 2016 14:36:44 +0900
changeset 319914 2aa6df19f5f214bb3d28db836ba259ca6afb6ff3
parent 319913 bb8f38a1583fcb632acf1941bf8063c7d0e7dd73
child 319915 011fe8bad1ebd4d0cc8ff267c9841b101098536d
push id20749
push userryanvm@gmail.com
push dateSat, 29 Oct 2016 13:21:21 +0000
treeherderfx-team@1b170b39ed6b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersckerschb, francois
bugs1311893
milestone52.0a1
Bug 1311893 - HSTS Priming timing telemetry r=ckerschb,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
@@ -7798,16 +7798,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"
   },