Commit 8f2c2f8a authored by tby's avatar tby Committed by Commit Bot

[Suggested files] Add metrics to ItemSuggestCache.

This CL finalizes the error/status enum for ItemSuggestCache and adds
histogram calls.

Bug: 1034842
Change-Id: I952466a377d8e5e2a2dc30e9c8da6f181b80dba4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2434074Reviewed-by: default avatarThanh Nguyen <thanhdng@chromium.org>
Reviewed-by: default avatarSteven Holte <holte@chromium.org>
Commit-Queue: Tony Yeoman <tby@chromium.org>
Cr-Commit-Position: refs/heads/master@{#811563}
parent 0646a5b4
......@@ -77,34 +77,41 @@ bool IsDisabledByPolicy(const Profile* profile) {
return profile->GetPrefs()->GetBoolean(drive::prefs::kDisableDrive);
}
//----------------
// Error utilities
//----------------
//------------------
// Metrics utilities
//------------------
// Possible error states of the item suggest cache.
enum class Error {
// TODO(crbug.com/1034842): Add unit tests for histograms
// Possible outcomes of a call to the ItemSuggest API. These values persist to
// logs. Entries should not be renumbered and numeric values should never be
// reused.
enum class Status {
kOk = 0,
kDisabledByExperiment = 1,
kDisabledByPolicy = 2,
kInvalidServerUrl = 3,
kNoIdentityManager = 4,
kGoogleAuthError = 5,
kNetError = 6,
k3xxError = 7,
k4xxError = 8,
k5xxError = 9,
kEmptyResponse = 10,
kNoResultsInResponse = 11,
kJsonParseFailure = 12,
kJsonConversionFailure = 13,
kResponseTooLarge = 7,
k3xxStatus = 8,
k4xxStatus = 9,
k5xxStatus = 10,
kEmptyResponse = 11,
kNoResultsInResponse = 12,
kJsonParseFailure = 13,
kJsonConversionFailure = 14,
kMaxValue = kJsonConversionFailure,
};
void LogError(Error error) {
// TODO(crbug.com/1034842): Implement.
void LogStatus(Status status) {
UMA_HISTOGRAM_ENUMERATION("Apps.AppList.ItemSuggestCache.Status", status);
}
void LogResponseSize(const int size) {
// TODO(crbug.com/1034842): Implement.
UMA_HISTOGRAM_COUNTS_100000("Apps.AppList.ItemSuggestCache.ResponseSize",
size);
}
//---------------
......@@ -233,21 +240,21 @@ void ItemSuggestCache::UpdateCache() {
if (url_loader_) {
return;
} else if (!enabled_) {
LogError(Error::kDisabledByExperiment);
LogStatus(Status::kDisabledByExperiment);
return;
} else if (IsDisabledByPolicy(profile_)) {
LogError(Error::kDisabledByPolicy);
LogStatus(Status::kDisabledByPolicy);
return;
} else if (!server_url_.SchemeIs(url::kHttpsScheme) ||
!google_util::IsGoogleAssociatedDomainUrl(server_url_)) {
LogError(Error::kInvalidServerUrl);
LogStatus(Status::kInvalidServerUrl);
return;
}
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile_);
if (!identity_manager) {
LogError(Error::kNoIdentityManager);
LogStatus(Status::kNoIdentityManager);
return;
}
......@@ -268,7 +275,7 @@ void ItemSuggestCache::OnTokenReceived(GoogleServiceAuthError error,
token_fetcher_.reset();
if (error.state() != GoogleServiceAuthError::NONE) {
LogError(Error::kGoogleAuthError);
LogStatus(Status::kGoogleAuthError);
return;
}
......@@ -292,21 +299,25 @@ void ItemSuggestCache::OnSuggestionsReceived(
const int net_error = url_loader_->NetError();
if (net_error != net::OK) {
if (!url_loader_->ResponseInfo() || !url_loader_->ResponseInfo()->headers) {
LogError(Error::kNetError);
if (net_error == net::ERR_INSUFFICIENT_RESOURCES) {
LogStatus(Status::kResponseTooLarge);
} else {
LogStatus(Status::kNetError);
}
} else {
const int status = url_loader_->ResponseInfo()->headers->response_code();
if (status >= 500) {
LogError(Error::k5xxError);
LogStatus(Status::k5xxStatus);
} else if (status >= 400) {
LogError(Error::k4xxError);
LogStatus(Status::k4xxStatus);
} else if (status >= 300) {
LogError(Error::k3xxError);
LogStatus(Status::k3xxStatus);
}
}
return;
} else if (!json_response || json_response->empty()) {
LogError(Error::kEmptyResponse);
LogStatus(Status::kEmptyResponse);
return;
}
......@@ -323,7 +334,7 @@ void ItemSuggestCache::OnJsonParsed(
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!result.value) {
LogError(Error::kJsonParseFailure);
LogStatus(Status::kJsonParseFailure);
return;
}
......@@ -332,10 +343,11 @@ void ItemSuggestCache::OnJsonParsed(
// results.
const auto& results = ConvertResults(&result.value.value());
if (!results) {
LogError(Error::kJsonConversionFailure);
LogStatus(Status::kJsonConversionFailure);
} else if (results->results.empty()) {
LogError(Error::kNoResultsInResponse);
LogStatus(Status::kNoResultsInResponse);
} else {
LogStatus(Status::kOk);
results_ = std::move(results.value());
}
}
......
......@@ -38524,6 +38524,24 @@ Called by update_gpu_driver_bug_workaround_entries.py.-->
<int value="2" label="Saved via list pref"/>
</enum>
<enum name="ItemSuggestCacheStatus">
<int value="0" label="Ok"/>
<int value="1" label="Disabled by experiment"/>
<int value="2" label="Disabled by policy"/>
<int value="3" label="Invalid server URL"/>
<int value="4" label="No identity manager"/>
<int value="5" label="Google auth error"/>
<int value="6" label="Net error"/>
<int value="7" label="Response too large"/>
<int value="8" label="3xx status"/>
<int value="9" label="4xx status"/>
<int value="10" label="5xx status"/>
<int value="11" label="Empty response"/>
<int value="12" label="No results in response"/>
<int value="13" label="JSON parse failure"/>
<int value="14" label="JSON conversion failure"/>
</enum>
<enum name="JavaScriptDialogDismissalCause">
<int value="0" label="Tab closed">The tab owning the dialog was closed</int>
<int value="1" label="New dialog">
......@@ -276,6 +276,30 @@ reviews. Googlers can read more about this at go/gwsq-gerrit.
</summary>
</histogram>
<histogram name="Apps.AppList.ItemSuggestCache.ResponseSize" units="bytes"
expires_after="2021-03-15">
<owner>tby@chromium.org</owner>
<owner>jiameng@chromium.org</owner>
<owner>thanhdng@chromium.org</owner>
<owner>wrong@chromium.org</owner>
<summary>
Records the size of a response from the ItemSuggest API. Reported once per
successful response. Will not be reported if the response exceeds the
maximum size, instead check Apps.AppList.ItemSuggestCache.Status.
</summary>
</histogram>
<histogram name="Apps.AppList.ItemSuggestCache.Status"
enum="ItemSuggestCacheStatus" expires_after="2021-03-15">
<owner>tby@chromium.org</owner>
<owner>jiameng@chromium.org</owner>
<owner>thanhdng@chromium.org</owner>
<owner>wrong@chromium.org</owner>
<summary>
Records the outcome of a call to ItemSuggest. Reported once per call.
</summary>
</histogram>
<histogram name="Apps.AppList.LauncherSearchProvider.QueryTime" units="ms"
expires_after="2020-12-31">
<owner>jennyz@chromium.org</owner>
......
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