Skip to content

Commit

Permalink
Add optimization target to GetModelsResponse metrics
Browse files Browse the repository at this point in the history
Bug: 1279614
Change-Id: Id300e2557691ea53b5144495fff8c64124f7315f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3514583
Reviewed-by: Sophie Chang <sophiechang@chromium.org>
Commit-Queue: Raj T <rajendrant@chromium.org>
Cr-Commit-Position: refs/heads/main@{#985702}
  • Loading branch information
rajendrant authored and Chromium LUCI CQ committed Mar 26, 2022
1 parent fa6bc33 commit 12e71bf
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
Expand Up @@ -323,6 +323,10 @@ IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
// Should not have made fetch request.
histogram_tester.ExpectTotalCount(
"OptimizationGuide.PredictionModelFetcher.GetModelsResponse.Status", 0);
histogram_tester.ExpectTotalCount(
"OptimizationGuide.PredictionModelFetcher.GetModelsResponse.Status."
"PainfulPageLoad",
0);
}

IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
Expand Down Expand Up @@ -368,6 +372,10 @@ IN_PROC_BROWSER_TEST_F(PredictionManagerBrowserTest,
histogram_tester.ExpectBucketCount(
"OptimizationGuide.PredictionModelFetcher.GetModelsResponse.Status",
net::HTTP_NOT_FOUND, 1);
histogram_tester.ExpectBucketCount(
"OptimizationGuide.PredictionModelFetcher.GetModelsResponse.Status."
"PainfulPageLoad",
net::HTTP_NOT_FOUND, 1);

histogram_tester.ExpectTotalCount(
"OptimizationGuide.PredictionManager.PredictionModelsStored", 0);
Expand Down
Expand Up @@ -12,6 +12,7 @@
#include "base/feature_list.h"
#include "base/metrics/histogram_functions.h"
#include "base/metrics/histogram_macros.h"
#include "components/optimization_guide/core/model_util.h"
#include "components/optimization_guide/core/optimization_guide_features.h"
#include "components/optimization_guide/core/optimization_guide_util.h"
#include "components/optimization_guide/proto/models.pb.h"
Expand Down Expand Up @@ -155,6 +156,26 @@ void PredictionModelFetcherImpl::HandleResponse(
"GetModelsResponse.NetErrorCode",
-net_status);

for (const auto& model_info : pending_models_request_->requested_models()) {
if (response_code >= 0 &&
response_code <= net::HTTP_VERSION_NOT_SUPPORTED) {
base::UmaHistogramEnumeration(
"OptimizationGuide.PredictionModelFetcher."
"GetModelsResponse.Status." +
optimization_guide::GetStringNameForOptimizationTarget(
model_info.optimization_target()),
static_cast<net::HttpStatusCode>(response_code),
net::HTTP_VERSION_NOT_SUPPORTED);
}
// Net error codes are negative but histogram enums must be positive.
base::UmaHistogramSparse(
"OptimizationGuide.PredictionModelFetcher."
"GetModelsResponse.NetErrorCode." +
optimization_guide::GetStringNameForOptimizationTarget(
model_info.optimization_target()),
-net_status);
}

if (net_status == net::OK && response_code == net::HTTP_OK &&
get_models_response->ParseFromString(get_models_response_data)) {
std::move(models_fetched_callback_).Run(std::move(get_models_response));
Expand Down
Expand Up @@ -137,12 +137,20 @@ TEST_F(PredictionModelFetcherTest, FetchReturned404) {
"OptimizationGuide.PredictionModelFetcher."
"GetModelsResponse.Status",
net::HTTP_NOT_FOUND, 1);
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.PredictionModelFetcher."
"GetModelsResponse.Status.PainfulPageLoad",
net::HTTP_NOT_FOUND, 1);

// Net error codes are negative but UMA histograms require positive values.
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.PredictionModelFetcher."
"GetModelsResponse.NetErrorCode",
-net::ERR_HTTP_RESPONSE_CODE_FAILURE, 1);
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.PredictionModelFetcher."
"GetModelsResponse.NetErrorCode.PainfulPageLoad",
-net::ERR_HTTP_RESPONSE_CODE_FAILURE, 1);
}

TEST_F(PredictionModelFetcherTest, FetchReturnBadResponse) {
Expand Down
42 changes: 40 additions & 2 deletions tools/metrics/histograms/metadata/optimization/histograms.xml
Expand Up @@ -961,19 +961,57 @@ chromium-metrics-reviews@google.com.
<owner>sophiechang@chromium.org</owner>
<summary>
Net error codes for GetModelsRequest to the Optimization Guide Service on
success and failure.
success and failure. Recorded once per GetModelsRequest where the model was
fetched for. It is not advisable to sum up the counts across
OptimizationTargets as the GetModelsRequests bundle requests for various
OptimizationTargets into single request to the server.
</summary>
</histogram>

<histogram
name="OptimizationGuide.PredictionModelFetcher.GetModelsResponse.NetErrorCode.{OptimizationTarget}"
enum="NetErrorCodes" expires_after="M106">
<owner>mcrouse@chromium.org</owner>
<owner>sophiechang@chromium.org</owner>
<summary>
Net error codes for GetModelsRequest to the Optimization Guide Service on
success and failure for {OptimizationTarget}. Recorded once per
GetModelsRequest where the model for {OptimizationTarget} was fetched for.
It is not advisable to sum up the counts across OptimizationTargets as the
GetModelsRequests bundle requests for various OptimizationTargets into
single request to the server.
</summary>
<token key="OptimizationTarget" variants="OptimizationTarget"/>
</histogram>

<histogram
name="OptimizationGuide.PredictionModelFetcher.GetModelsResponse.Status"
enum="HttpResponseCode" expires_after="M106">
<owner>mcrouse@chromium.org</owner>
<owner>sophiechang@chromium.org</owner>
<summary>
For each GetModelsRequest to the Optimization Guide Service, log the HTTP
response code on success and failure.
response code on success and failure. Recorded once per GetModelsRequest
where the model was fetched for. It is not advisable to sum up the counts
across OptimizationTargets as the GetModelsRequests bundle requests for
various OptimizationTargets into single request to the server.
</summary>
</histogram>

<histogram
name="OptimizationGuide.PredictionModelFetcher.GetModelsResponse.Status.{OptimizationTarget}"
enum="HttpResponseCode" expires_after="M106">
<owner>mcrouse@chromium.org</owner>
<owner>sophiechang@chromium.org</owner>
<summary>
For each GetModelsRequest to the Optimization Guide Service for
{OptimizationTarget}, log the HTTP response code on success and failure.
Recorded once per GetModelsRequest where the model for {OptimizationTarget}
was fetched for. It is not advisable to sum up the counts across
OptimizationTargets as the GetModelsRequests bundle requests for various
OptimizationTargets into single request to the server.
</summary>
<token key="OptimizationTarget" variants="OptimizationTarget"/>
</histogram>

<histogram
Expand Down

0 comments on commit 12e71bf

Please sign in to comment.