Commit 56aa7a6b authored by Ryan Sturm's avatar Ryan Sturm Committed by Commit Bot

Adding finch params for missing via headers

Bug: 768256
Change-Id: Ie965ca7eae7fa094e23e0d9e294a341136975300
Reviewed-on: https://chromium-review.googlesource.com/683241Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Ryan Sturm <ryansturm@chromium.org>
Cr-Commit-Position: refs/heads/master@{#505875}
parent d3262c01
......@@ -27,5 +27,10 @@ const base::Feature kDataReductionProxyLowMemoryDevicePromo{
"DataReductionProxyLowMemoryDevicePromo",
base::FEATURE_DISABLED_BY_DEFAULT};
// Enables logic to modify the bypass behavior when a missing via header is
// detected.
const base::Feature kMissingViaHeaderShortDuration{
"MissingViaHeaderShortDuration", base::FEATURE_DISABLED_BY_DEFAULT};
} // namespace features
} // namespace data_reduction_proxy
......@@ -14,6 +14,7 @@ extern const base::Feature kDataReductionMainMenu;
extern const base::Feature kDataReductionSiteBreakdown;
extern const base::Feature kDataReductionProxyDecidesTransform;
extern const base::Feature kDataReductionProxyLowMemoryDevicePromo;
extern const base::Feature kMissingViaHeaderShortDuration;
} // namespace features
} // namespace data_reduction_proxy
......
......@@ -24,7 +24,6 @@
#include "net/url_request/url_request.h"
using base::StringPiece;
using base::TimeDelta;
namespace {
......@@ -64,12 +63,17 @@ const char kChromeProxyActionFingerprintContentLength[] = "fcl";
const int kShortBypassMaxSeconds = 59;
const int kMediumBypassMaxSeconds = 300;
base::TimeDelta GetRandomBypassTime(base::TimeDelta min_time,
base::TimeDelta max_time) {
const int64_t delta_ms =
base::RandInt(min_time.InMilliseconds(), max_time.InMilliseconds());
return base::TimeDelta::FromMilliseconds(delta_ms);
}
// Returns a random bypass duration between 1 and 5 minutes.
base::TimeDelta GetDefaultBypassDuration() {
const int64_t delta_ms =
base::RandInt(base::TimeDelta::FromMinutes(1).InMilliseconds(),
base::TimeDelta::FromMinutes(5).InMilliseconds());
return TimeDelta::FromMilliseconds(delta_ms);
return GetRandomBypassTime(base::TimeDelta::FromMinutes(1),
base::TimeDelta::FromMinutes(5));
}
bool StartsWithActionPrefix(base::StringPiece header_value,
......@@ -292,7 +296,7 @@ bool ParseHeadersAndSetBypassDuration(const net::HttpResponseHeaders& headers,
continue; // In case there is a well formed instruction.
}
if (seconds != 0) {
*bypass_duration = TimeDelta::FromSeconds(seconds);
*bypass_duration = base::TimeDelta::FromSeconds(seconds);
} else {
// Server deferred to us to choose a duration. Default to a random
// duration between one and five minutes.
......@@ -344,7 +348,7 @@ bool ParseHeadersForBypassInfo(const net::HttpResponseHeaders& headers,
if (headers.HasHeaderValue(kChromeProxyHeader, kChromeProxyActionBlockOnce)) {
proxy_info->bypass_all = true;
proxy_info->mark_proxies_as_bad = false;
proxy_info->bypass_duration = TimeDelta();
proxy_info->bypass_duration = base::TimeDelta();
proxy_info->bypass_action = BYPASS_ACTION_TYPE_BLOCK_ONCE;
return true;
}
......@@ -399,10 +403,11 @@ DataReductionProxyBypassType GetDataReductionProxyBypassType(
if (!data_reduction_proxy_info->mark_proxies_as_bad)
return BYPASS_EVENT_TYPE_CURRENT;
const TimeDelta& duration = data_reduction_proxy_info->bypass_duration;
if (duration <= TimeDelta::FromSeconds(kShortBypassMaxSeconds))
const base::TimeDelta& duration =
data_reduction_proxy_info->bypass_duration;
if (duration <= base::TimeDelta::FromSeconds(kShortBypassMaxSeconds))
return BYPASS_EVENT_TYPE_SHORT;
if (duration <= TimeDelta::FromSeconds(kMediumBypassMaxSeconds))
if (duration <= base::TimeDelta::FromSeconds(kMediumBypassMaxSeconds))
return BYPASS_EVENT_TYPE_MEDIUM;
return BYPASS_EVENT_TYPE_LONG;
}
......@@ -441,10 +446,24 @@ DataReductionProxyBypassType GetDataReductionProxyBypassType(
// bypass the data reduction proxy for the current request.
data_reduction_proxy_info->bypass_all = true;
data_reduction_proxy_info->mark_proxies_as_bad = false;
data_reduction_proxy_info->bypass_duration = TimeDelta();
data_reduction_proxy_info->bypass_duration = base::TimeDelta();
return BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_4XX;
}
bool connection_is_cellular =
net::NetworkChangeNotifier::IsConnectionCellular(
net::NetworkChangeNotifier::GetConnectionType());
if (!params::ShouldBypassMissingViaHeader(connection_is_cellular)) {
return BYPASS_EVENT_TYPE_MAX;
}
data_reduction_proxy_info->mark_proxies_as_bad = true;
std::pair<base::TimeDelta, base::TimeDelta> bypass_range =
params::GetMissingViaHeaderBypassDurationRange(connection_is_cellular);
data_reduction_proxy_info->bypass_duration =
GetRandomBypassTime(bypass_range.first, bypass_range.second);
return BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER;
}
// There is no bypass event.
......
......@@ -12,8 +12,11 @@
#include "base/macros.h"
#include "base/metrics/field_trial.h"
#include "base/strings/string_number_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_storage_delegate_test_utils.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_features.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_headers_test_utils.h"
#include "net/http/http_response_headers.h"
#include "net/proxy/proxy_service.h"
......@@ -617,6 +620,51 @@ TEST_F(DataReductionProxyHeadersTest, HasDataReductionProxyViaHeader) {
}
}
TEST_F(DataReductionProxyHeadersTest, MissingViaHeaderFallback) {
const struct {
const char* headers;
bool should_retry;
DataReductionProxyBypassType expected_result;
base::TimeDelta expected_bypass_length;
} tests[] = {
{"HTTP/1.1 200 OK\n", true, BYPASS_EVENT_TYPE_MAX,
base::TimeDelta::FromSeconds(30)},
{"HTTP/1.1 200 OK\n", false, BYPASS_EVENT_TYPE_MISSING_VIA_HEADER_OTHER,
base::TimeDelta::FromSeconds(30)}};
for (auto test : tests) {
std::string headers(test.headers);
HeadersToRaw(&headers);
scoped_refptr<net::HttpResponseHeaders> parsed(
new net::HttpResponseHeaders(headers));
DataReductionProxyInfo proxy_info;
base::test::ScopedFeatureList scoped_feature_list_;
std::string bypass_duration =
base::IntToString(test.expected_bypass_length.InSeconds());
std::string should_bypass = test.should_retry ? "false" : "true";
std::map<std::string, std::string> feature_parameters = {
{"should_bypass_missing_via_cellular", should_bypass},
{"missing_via_min_bypass_cellular_in_seconds", bypass_duration},
{"missing_via_max_bypass_cellular_in_seconds", bypass_duration},
{"should_bypass_missing_via_wifi", should_bypass},
{"missing_via_min_bypass_wifi_in_seconds", bypass_duration},
{"missing_via_max_bypass_wifi_in_seconds", bypass_duration}};
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kMissingViaHeaderShortDuration, feature_parameters);
EXPECT_EQ(test.expected_result,
GetDataReductionProxyBypassType(std::vector<GURL>(), *parsed,
&proxy_info));
if (!test.should_retry) {
EXPECT_EQ(test.expected_bypass_length.InSeconds(),
proxy_info.bypass_duration.InSeconds());
EXPECT_TRUE(proxy_info.mark_proxies_as_bad);
}
}
}
TEST_F(DataReductionProxyHeadersTest, GetDataReductionProxyBypassEventType) {
const struct {
const char* headers;
......
......@@ -10,6 +10,7 @@
#include "base/command_line.h"
#include "base/metrics/field_trial.h"
#include "base/metrics/field_trial_params.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
......@@ -170,6 +171,31 @@ GURL GetWarmupURL() {
params, "warmup_url", kDefaultWarmupUrl));
}
bool ShouldBypassMissingViaHeader(bool connection_is_cellular) {
return GetFieldTrialParamByFeatureAsBool(
data_reduction_proxy::features::kMissingViaHeaderShortDuration,
connection_is_cellular ? "should_bypass_missing_via_cellular"
: "should_bypass_missing_via_wifi",
true);
}
std::pair<base::TimeDelta, base::TimeDelta>
GetMissingViaHeaderBypassDurationRange(bool connection_is_cellular) {
base::TimeDelta bypass_max =
base::TimeDelta::FromSeconds(GetFieldTrialParamByFeatureAsInt(
data_reduction_proxy::features::kMissingViaHeaderShortDuration,
connection_is_cellular ? "missing_via_max_bypass_cellular_in_seconds"
: "missing_via_max_bypass_wifi_in_seconds",
300));
base::TimeDelta bypass_min =
base::TimeDelta::FromSeconds(GetFieldTrialParamByFeatureAsInt(
data_reduction_proxy::features::kMissingViaHeaderShortDuration,
connection_is_cellular ? "missing_via_min_bypass_cellular_in_seconds"
: "missing_via_min_bypass_wifi_in_seconds",
60));
return {bypass_min, bypass_max};
}
bool IsLoFiOnViaFlags() {
return IsLoFiAlwaysOnViaFlags() || IsLoFiCellularOnlyViaFlags() ||
IsLoFiSlowConnectionsOnlyViaFlags();
......
......@@ -6,10 +6,12 @@
#define COMPONENTS_DATA_REDUCTION_PROXY_CORE_COMMON_DATA_REDUCTION_PROXY_PARAMS_H_
#include <string>
#include <utility>
#include <vector>
#include "base/macros.h"
#include "base/strings/string_piece.h"
#include "base/time/time.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_config_values.h"
#include "url/gurl.h"
......@@ -129,6 +131,15 @@ bool ShouldForceEnableDataReductionProxy();
// instead of the prefs-based rules.
bool IsBlackListEnabledForServerPreviews();
// Returns whether the proxy should be bypassed for requests that are proxied
// but missing the via header based on if the connection is cellular.
bool ShouldBypassMissingViaHeader(bool connection_is_cellular);
// Returns the range of acceptable bypass lengths for requests that are proxied
// but missing the via header based on if the connection is cellular.
std::pair<base::TimeDelta, base::TimeDelta>
GetMissingViaHeaderBypassDurationRange(bool connection_is_cellular);
// The current LitePage experiment blacklist version.
int LitePageVersion();
......
......@@ -458,4 +458,46 @@ TEST(DataReductionProxyParamsStandaloneTest, OverrideProxiesForHttp) {
EXPECT_EQ(expected_override_proxies_for_http, params.proxies_for_http());
}
TEST(DataReductionProxyParamsStandaloneTest, TestMissingViaHeaderParams) {
EXPECT_TRUE(
params::ShouldBypassMissingViaHeader(true /* connection_is_cellular */));
EXPECT_TRUE(
params::ShouldBypassMissingViaHeader(false /* connection_is_cellular */));
std::pair<base::TimeDelta, base::TimeDelta> cell_range =
params::GetMissingViaHeaderBypassDurationRange(
true /* connection_is_cellular */);
EXPECT_EQ(base::TimeDelta::FromMinutes(1), cell_range.first);
EXPECT_EQ(base::TimeDelta::FromMinutes(5), cell_range.second);
std::pair<base::TimeDelta, base::TimeDelta> wifi_range =
params::GetMissingViaHeaderBypassDurationRange(
false /* connection_is_cellular */);
EXPECT_EQ(base::TimeDelta::FromMinutes(1), wifi_range.first);
EXPECT_EQ(base::TimeDelta::FromMinutes(5), wifi_range.second);
std::map<std::string, std::string> feature_parameters = {
{"should_bypass_missing_via_cellular", "false"},
{"missing_via_min_bypass_cellular_in_seconds", "10"},
{"missing_via_max_bypass_cellular_in_seconds", "20"},
{"should_bypass_missing_via_wifi", "false"},
{"missing_via_min_bypass_wifi_in_seconds", "30"},
{"missing_via_max_bypass_wifi_in_seconds", "40"}};
base::test::ScopedFeatureList scoped_feature_list_;
scoped_feature_list_.InitAndEnableFeatureWithParameters(
features::kMissingViaHeaderShortDuration, feature_parameters);
EXPECT_FALSE(
params::ShouldBypassMissingViaHeader(true /* connection_is_cellular */));
EXPECT_FALSE(
params::ShouldBypassMissingViaHeader(false /* connection_is_cellular */));
cell_range = params::GetMissingViaHeaderBypassDurationRange(
true /* connection_is_cellular */);
EXPECT_EQ(base::TimeDelta::FromSeconds(10), cell_range.first);
EXPECT_EQ(base::TimeDelta::FromSeconds(20), cell_range.second);
wifi_range = params::GetMissingViaHeaderBypassDurationRange(
false /* connection_is_cellular */);
EXPECT_EQ(base::TimeDelta::FromSeconds(30), wifi_range.first);
EXPECT_EQ(base::TimeDelta::FromSeconds(40), wifi_range.second);
}
} // namespace data_reduction_proxy
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