Bug 1332780 - Add telemetry to record network error while SafeBrowsing update. r=francois
authorDimi Lee <dlee@mozilla.com>
Fri, 24 Feb 2017 09:54:49 +0800
changeset 344579 9d135a51856f1432c902d51bc8805a6609c3b3b1
parent 344578 2f37bb06b731305284ef4a4e760a2b7dff2ea9ad
child 344580 2c2b324b9afbfc444d4983e8f88b2d9d500b4485
push id37907
push usercbook@mozilla.com
push dateFri, 24 Feb 2017 09:02:18 +0000
treeherderautoland@9d135a51856f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfrancois
bugs1332780
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1332780 - Add telemetry to record network error while SafeBrowsing update. r=francois MozReview-Commit-ID: 7Yqxs0XHmNP
toolkit/components/telemetry/Histograms.json
toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -4115,16 +4115,25 @@
   "URLCLASSIFIER_LC_COMPLETIONS": {
     "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
     "expires_in_version": "never",
     "kind": "exponential",
     "high": 200,
     "n_buckets": 10,
     "description": "Size of the completion cache in entries"
   },
+  "URLCLASSIFIER_UPDATE_REMOTE_NETWORK_ERROR": {
+    "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
+    "expires_in_version": "60",
+    "kind": "enumerated",
+    "keyed": true,
+    "n_values": 30,
+    "bug_numbers": [1332780],
+    "description": "Network error from SafeBrowsing database updates. (0=sucess, 1=unknown error, 2=already connected, 3=not connected, 4=connection refused,5=net timeout, 6=offline, 7=port access not allowed, 8=net reset, 9=net interrupt, 10=proxy connection refused,11=partial transfer,12=inadequate security,13=unknown host,14=dns lookup queue full,15=unknown proxy host"
+  },
   "URLCLASSIFIER_UPDATE_REMOTE_STATUS2": {
     "alert_emails": ["safebrowsing-telemetry@mozilla.org"],
     "expires_in_version": "never",
     "kind": "enumerated",
     "keyed": true,
     "n_values": 16,
     "bug_numbers": [1311910],
     "description": "Server HTTP status code from SafeBrowsing database updates. (0=1xx, 1=200, 2=2xx, 3=204, 4=3xx, 5=400, 6=4xx, 7=403, 8=404, 9=408, 10=413, 11=5xx, 12=502|504|511, 13=503, 14=505, 15=Other). Keyed by provider"
--- a/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
+++ b/toolkit/components/url-classifier/nsUrlClassifierStreamUpdater.cpp
@@ -504,16 +504,42 @@ nsUrlClassifierStreamUpdater::AddRequest
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = httpChannel->SetRequestMethod(NS_LITERAL_CSTRING("POST"));
   NS_ENSURE_SUCCESS(rv, rv);
 
   return NS_OK;
 }
 
+// We might need to expand the bucket here if telemetry shows lots of errors
+// are neither connection errors nor DNS errors.
+static uint8_t NetworkErrorToBucket(nsresult rv)
+{
+  switch(rv) {
+  // Connection errors
+  case NS_ERROR_ALREADY_CONNECTED:        return 2;
+  case NS_ERROR_NOT_CONNECTED:            return 3;
+  case NS_ERROR_CONNECTION_REFUSED:       return 4;
+  case NS_ERROR_NET_TIMEOUT:              return 5;
+  case NS_ERROR_OFFLINE:                  return 6;
+  case NS_ERROR_PORT_ACCESS_NOT_ALLOWED:  return 7;
+  case NS_ERROR_NET_RESET:                return 8;
+  case NS_ERROR_NET_INTERRUPT:            return 9;
+  case NS_ERROR_PROXY_CONNECTION_REFUSED: return 10;
+  case NS_ERROR_NET_PARTIAL_TRANSFER:     return 11;
+  case NS_ERROR_NET_INADEQUATE_SECURITY:  return 12;
+  // DNS errors
+  case NS_ERROR_UNKNOWN_HOST:             return 13;
+  case NS_ERROR_DNS_LOOKUP_QUEUE_FULL:    return 14;
+  case NS_ERROR_UNKNOWN_PROXY_HOST:       return 15;
+  // Others
+  default:                                return 1;
+  }
+}
+
 // Map the HTTP response code to a Telemetry bucket
 static uint32_t HTTPStatusToBucket(uint32_t status)
 {
   uint32_t statusBucket;
   switch (status) {
   case 100:
   case 101:
     // Unexpected 1xx return code
@@ -644,22 +670,24 @@ nsUrlClassifierStreamUpdater::OnStartReq
       if (NS_SUCCEEDED(rv) && uri) {
         uri->GetAsciiSpec(spec);
       }
       LOG(("nsUrlClassifierStreamUpdater::OnStartRequest "
            "(status=%s, uri=%s, this=%p)", errorName.get(),
            spec.get(), this));
     }
 
+    uint8_t netErrCode = NS_FAILED(status) ? NetworkErrorToBucket(status) : 0;
+    mozilla::Telemetry::Accumulate(
+      mozilla::Telemetry::URLCLASSIFIER_UPDATE_REMOTE_NETWORK_ERROR,
+      mTelemetryProvider, netErrCode);
+
     if (NS_FAILED(status)) {
       // Assume we're overloading the server and trigger backoff.
       downloadError = true;
-      mozilla::Telemetry::Accumulate(mozilla::Telemetry::URLCLASSIFIER_UPDATE_REMOTE_STATUS2,
-                                     mTelemetryProvider, 15 /* unknown response code */);
-
     } else {
       bool succeeded = false;
       rv = httpChannel->GetRequestSucceeded(&succeeded);
       NS_ENSURE_SUCCESS(rv, rv);
 
       uint32_t requestStatus;
       rv = httpChannel->GetResponseStatus(&requestStatus);
       NS_ENSURE_SUCCESS(rv, rv);