Commit e54b3fe4 authored by Michael Crouse's avatar Michael Crouse Committed by Commit Bot

Checks if model exists before validating the prediction model.

This change adds an earlier check for whether a model is included
in the PredictionModel proto before validating it. This should
resolve the prediction model validation histogram being recording
as invalid when the model is not provided by the remote
optimization guide as there is not a newer one.

Bug: 1046848
Change-Id: I0a974b45883f5940a1a63f77876c615ae420d8dc
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2035050
Auto-Submit: Michael Crouse <mcrouse@chromium.org>
Reviewed-by: default avatarSophie Chang <sophiechang@chromium.org>
Commit-Queue: Michael Crouse <mcrouse@chromium.org>
Cr-Commit-Position: refs/heads/master@{#737970}
parent 6c05a152
......@@ -728,6 +728,8 @@ bool PredictionManager::ProcessAndStorePredictionModel(
SEQUENCE_CHECKER(sequence_checker_);
if (!model.model_info().has_optimization_target())
return false;
if (!model.has_model())
return false;
if (!registered_optimization_targets_.contains(
model.model_info().optimization_target())) {
return false;
......
......@@ -68,6 +68,7 @@ std::unique_ptr<proto::PredictionModel> CreatePredictionModel() {
proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD);
model_info->add_supported_model_types(
proto::ModelType::MODEL_TYPE_DECISION_TREE);
prediction_model->mutable_model()->mutable_threshold()->set_value(5.0);
return prediction_model;
}
......@@ -625,14 +626,13 @@ TEST_F(PredictionManagerTest, EvaluatePredictionModel) {
GURL("https://foo.com"));
CreatePredictionManager({});
// The model will be loaded from the store.
prediction_manager()->SetPredictionModelFetcherForTesting(
BuildTestPredictionModelFetcher(
PredictionModelFetcherEndState::
kFetchSuccessWithModelsAndHostsModelFeatures));
PredictionModelFetcherEndState::kFetchSuccessWithEmptyResponse));
prediction_manager()->RegisterOptimizationTargets(
{proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD});
SetStoreInitialized();
EXPECT_TRUE(prediction_model_fetcher()->models_fetched());
......@@ -654,14 +654,14 @@ TEST_F(PredictionManagerTest, EvaluatePredictionModel) {
optimization_guide::proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD),
1);
histogram_tester.ExpectBucketCount(
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.IsPredictionModelValid." +
GetStringNameForOptimizationTarget(
optimization_guide::proto::OPTIMIZATION_TARGET_PAINFUL_PAGE_LOAD),
true, 1);
histogram_tester.ExpectBucketCount("OptimizationGuide.IsPredictionModelValid",
true, 1);
histogram_tester.ExpectUniqueSample(
"OptimizationGuide.IsPredictionModelValid", true, 1);
histogram_tester.ExpectTotalCount(
"OptimizationGuide.PredictionModelValidationLatency." +
......
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