Commit 39ffd677 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Collect network metrics of PasswordRequirementsSpecFetcher

This CL introduces metrics to learn about problems with fetching the password
requirements from gstatic.com. They will be used to see whether the current
timeout is reasonable and to set up alerting in case something breaks.

NOTRY=true

Bug: 846694
Change-Id: I3e23944b3d638aab483169eb78f657dc3ab7588f
Reviewed-on: https://chromium-review.googlesource.com/1100460
Commit-Queue: Dominic Battré <battre@chromium.org>
Reviewed-by: default avatarVaclav Brozek <vabr@chromium.org>
Reviewed-by: default avatarGayane Petrosyan <gayane@chromium.org>
Cr-Commit-Position: refs/heads/master@{#567555}
parent 29dc6f79
......@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/md5.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "base/strings/stringprintf.h"
#include "base/time/time.h"
......@@ -145,6 +146,7 @@ void PasswordRequirementsSpecFetcherImpl::Fetch(
// Start another lookup otherwise.
auto lookup = std::make_unique<LookupInFlight>();
lookup->callbacks.push_back(std::make_pair(origin, std::move(callback)));
lookup->start_of_request = base::TimeTicks::Now();
net::NetworkTrafficAnnotationTag traffic_annotation =
net::DefineNetworkTrafficAnnotation("password_requirements_spec_fetch",
......@@ -194,6 +196,17 @@ void PasswordRequirementsSpecFetcherImpl::OnFetchComplete(
std::unique_ptr<LookupInFlight> lookup = RemoveLookupInFlight(hash_prefix);
lookup->download_timer.Stop();
UMA_HISTOGRAM_TIMES("PasswordManager.RequirementsSpecFetcher.NetworkDuration",
base::TimeTicks::Now() - lookup->start_of_request);
base::UmaHistogramSparse(
"PasswordManager.RequirementsSpecFetcher.NetErrorCode",
lookup->url_loader->NetError());
if (lookup->url_loader->ResponseInfo() &&
lookup->url_loader->ResponseInfo()->headers) {
base::UmaHistogramSparse(
"PasswordManager.RequirementsSpecFetcher.HttpResponseCode",
lookup->url_loader->ResponseInfo()->headers->response_code());
}
if (!response_body || lookup->url_loader->NetError() != net::Error::OK) {
VLOG(1) << "Fetch for " << hash_prefix << ": failed to fetch "
......@@ -264,6 +277,8 @@ void PasswordRequirementsSpecFetcherImpl::OnFetchComplete(
void PasswordRequirementsSpecFetcherImpl::OnFetchTimeout(
const std::string& hash_prefix) {
std::unique_ptr<LookupInFlight> lookup = RemoveLookupInFlight(hash_prefix);
UMA_HISTOGRAM_TIMES("PasswordManager.RequirementsSpecFetcher.NetworkDuration",
base::TimeTicks::Now() - lookup->start_of_request);
TriggerCallbackToAll(&lookup->callbacks, ResultCode::kErrorTimeout,
PasswordRequirementsSpec());
}
......@@ -281,7 +296,6 @@ void PasswordRequirementsSpecFetcherImpl::TriggerCallback(
FetchCallback callback,
ResultCode result,
const PasswordRequirementsSpec& spec) {
// TODO(crbug.com/846694) Record latencies.
UMA_HISTOGRAM_ENUMERATION("PasswordManager.RequirementsSpecFetcher.Result",
result);
std::move(callback).Run(spec);
......
......@@ -78,6 +78,9 @@ class PasswordRequirementsSpecFetcherImpl
std::unique_ptr<network::SimpleURLLoader> url_loader;
// Time when the network request is started.
base::TimeTicks start_of_request;
private:
DISALLOW_COPY_AND_ASSIGN(LookupInFlight);
};
......
......@@ -67884,9 +67884,34 @@ uploading your change for review.
</summary>
</histogram>
<histogram name="PasswordManager.RequirementsSpecFetcher.HttpResponseCode"
enum="HttpResponseCode">
<owner>battre@chromium.org</owner>
<summary>
HTTP response code of fetching a password requirements file.
</summary>
</histogram>
<histogram name="PasswordManager.RequirementsSpecFetcher.NetErrorCode"
enum="NetErrorCodes">
<owner>battre@chromium.org</owner>
<summary>
Network error code of fetching a password requirements file.
</summary>
</histogram>
<histogram name="PasswordManager.RequirementsSpecFetcher.NetworkDuration"
units="ms">
<owner>battre@chromium.org</owner>
<summary>
Time until the lookup for a password requirements file completed (or was
aborted).
</summary>
</histogram>
<histogram name="PasswordManager.RequirementsSpecFetcher.Result"
enum="PasswordRequirementsFetcherResult">
<owner>battre@google.com</owner>
<owner>battre@chromium.org</owner>
<summary>
Result of fetching requirements for password during password generation.
</summary>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment