Commit 3074bf4d authored by jeremyim's avatar jeremyim Committed by Commit bot

Add net_log events for the Data Reduction Proxy config service client.

The start and completion of the config retrieval requests will be logged,
and made available to the chrome://net-internals/#bandwidth page.

BUG=466753

Review URL: https://codereview.chromium.org/1105443003

Cr-Commit-Position: refs/heads/master@{#327389}
parent eaf365a0
......@@ -19,6 +19,7 @@
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_mutable_config_values.h"
#include "components/data_reduction_proxy/core/browser/data_reduction_proxy_request_options.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_client_config_parser.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_event_creator.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_params.h"
#include "components/data_reduction_proxy/core/common/data_reduction_proxy_switches.h"
#include "components/data_reduction_proxy/proto/client_config.pb.h"
......@@ -111,11 +112,15 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
const net::BackoffEntry::Policy& backoff_policy,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
DataReductionProxyConfig* config)
DataReductionProxyConfig* config,
DataReductionProxyEventCreator* event_creator,
net::NetLog* net_log)
: params_(params.Pass()),
request_options_(request_options),
config_values_(config_values),
config_(config),
event_creator_(event_creator),
net_log_(net_log),
backoff_entry_(&backoff_policy),
config_service_url_(
GetConfigServiceURL(*base::CommandLine::ForCurrentProcess())),
......@@ -124,6 +129,8 @@ DataReductionProxyConfigServiceClient::DataReductionProxyConfigServiceClient(
DCHECK(request_options);
DCHECK(config_values);
DCHECK(config);
DCHECK(event_creator);
DCHECK(net_log);
// Constructed on the UI thread, but should be checked on the IO thread.
thread_checker_.DetachFromThread();
}
......@@ -142,6 +149,9 @@ void DataReductionProxyConfigServiceClient::InitializeOnIOThread(
void DataReductionProxyConfigServiceClient::RetrieveConfig() {
DCHECK(thread_checker_.CalledOnValidThread());
bound_net_log_ = net::BoundNetLog::Make(
net_log_, net::NetLog::SOURCE_DATA_REDUCTION_PROXY);
event_creator_->BeginConfigRequest(bound_net_log_, config_service_url_);
if (use_local_config_) {
ReadAndApplyStaticConfig();
return;
......@@ -251,6 +261,9 @@ void DataReductionProxyConfigServiceClient::HandleResponse(
CalculateNextConfigRefreshTime(succeeded, expiration_time, Now(),
GetBackoffEntry()->GetTimeUntilRelease());
SetConfigRefreshTimer(next_config_refresh_time);
event_creator_->EndConfigRequest(
bound_net_log_, status.error(), response_code,
GetBackoffEntry()->failure_count(), next_config_refresh_time);
}
bool DataReductionProxyConfigServiceClient::ParseAndApplyProxyConfig(
......
......@@ -14,6 +14,7 @@
#include "base/timer/timer.h"
#include "net/base/backoff_entry.h"
#include "net/base/network_change_notifier.h"
#include "net/log/net_log.h"
#include "net/url_request/url_fetcher_delegate.h"
#include "url/gurl.h"
......@@ -33,6 +34,7 @@ namespace data_reduction_proxy {
class ClientConfig;
class DataReductionProxyConfig;
class DataReductionProxyEventCreator;
class DataReductionProxyMutableConfigValues;
class DataReductionProxyParams;
class DataReductionProxyRequestOptions;
......@@ -55,14 +57,15 @@ class DataReductionProxyConfigServiceClient
// The caller must ensure that all parameters remain alive for the lifetime of
// the |DataReductionProxyConfigClient|, with the exception of |params|
// which this instance will own. The |io_task_runner| is used to enforce that
// configurations are applied on the IO thread.
// which this instance will own.
DataReductionProxyConfigServiceClient(
scoped_ptr<DataReductionProxyParams> params,
const net::BackoffEntry::Policy& backoff_policy,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
DataReductionProxyConfig* config);
DataReductionProxyConfig* config,
DataReductionProxyEventCreator* event_creator,
net::NetLog* net_log);
~DataReductionProxyConfigServiceClient() override;
......@@ -140,6 +143,12 @@ class DataReductionProxyConfigServiceClient
// The caller must ensure that the |config_| outlives this instance.
DataReductionProxyConfig* config_;
// The caller must ensure that the |event_creator_| outlives this instance.
DataReductionProxyEventCreator* event_creator_;
// The caller must ensure that the |net_log_| outlives this instance.
net::NetLog* net_log_;
// Used to calculate the backoff time on request failures.
net::BackoffEntry backoff_entry_;
......@@ -162,6 +171,9 @@ class DataReductionProxyConfigServiceClient
// A |net::URLFetcher| to retrieve the Data Reduction Proxy configuration.
scoped_ptr<net::URLFetcher> fetcher_;
// Used to correlate the start and end of requests.
net::BoundNetLog bound_net_log_;
// Enforce usage on the IO thread.
base::ThreadChecker thread_checker_;
......
......@@ -106,7 +106,8 @@ class DataReductionProxyConfigServiceClientTest : public testing::Test {
new DataReductionProxyConfigServiceClient(
params.Pass(), GetBackoffPolicy(), request_options_.get(),
test_context_->mutable_config_values(),
test_context_->io_data()->config()));
test_context_->io_data()->config(), test_context_->event_creator(),
test_context_->net_log()));
}
void ResetBackoffEntryReleaseTime() {
......
......@@ -137,7 +137,7 @@ DataReductionProxyIOData::DataReductionProxyIOData(
if (use_config_client) {
config_client_.reset(new DataReductionProxyConfigServiceClient(
params.Pass(), GetBackoffPolicy(), request_options_.get(),
raw_mutable_config, config_.get()));
raw_mutable_config, config_.get(), event_creator_.get(), net_log_));
}
proxy_delegate_.reset(
......@@ -236,32 +236,39 @@ void DataReductionProxyIOData::UpdateContentLengths(
data_reduction_proxy_enabled, request_type));
}
void DataReductionProxyIOData::AddEnabledEvent(scoped_ptr<base::Value> entry,
void DataReductionProxyIOData::AddEvent(scoped_ptr<base::Value> event) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&DataReductionProxyService::AddEvent, service_,
base::Passed(&event)));
}
void DataReductionProxyIOData::AddEnabledEvent(scoped_ptr<base::Value> event,
bool enabled) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
ui_task_runner_->PostTask(
FROM_HERE, base::Bind(&DataReductionProxyService::AddEnabledEvent,
service_, base::Passed(&entry), enabled));
service_, base::Passed(&event), enabled));
}
void DataReductionProxyIOData::AddEventAndSecureProxyCheckState(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
SecureProxyCheckState state) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyService::AddEventAndSecureProxyCheckState,
service_, base::Passed(&entry), state));
service_, base::Passed(&event), state));
}
void DataReductionProxyIOData::AddAndSetLastBypassEvent(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
int64 expiration_ticks) {
DCHECK(io_task_runner_->BelongsToCurrentThread());
ui_task_runner_->PostTask(
FROM_HERE,
base::Bind(&DataReductionProxyService::AddAndSetLastBypassEvent, service_,
base::Passed(&entry), expiration_ticks));
base::Passed(&event), expiration_ticks));
}
void DataReductionProxyIOData::SetUnreachable(bool unreachable) {
......
......@@ -93,10 +93,11 @@ class DataReductionProxyIOData : public DataReductionProxyEventStorageDelegate {
// Overrides of DataReductionProxyEventStorageDelegate. Bridges to the UI
// thread objects.
void AddEnabledEvent(scoped_ptr<base::Value> entry, bool enabled) override;
void AddEventAndSecureProxyCheckState(scoped_ptr<base::Value> entry,
void AddEvent(scoped_ptr<base::Value> event) override;
void AddEnabledEvent(scoped_ptr<base::Value> event, bool enabled) override;
void AddEventAndSecureProxyCheckState(scoped_ptr<base::Value> event,
SecureProxyCheckState state) override;
void AddAndSetLastBypassEvent(scoped_ptr<base::Value> entry,
void AddAndSetLastBypassEvent(scoped_ptr<base::Value> event,
int64 expiration_ticks) override;
// Returns true if the Data Reduction Proxy is enabled and false otherwise.
......
......@@ -70,24 +70,29 @@ void DataReductionProxyService::UpdateContentLengths(
}
}
void DataReductionProxyService::AddEnabledEvent(scoped_ptr<base::Value> entry,
void DataReductionProxyService::AddEvent(scoped_ptr<base::Value> event) {
DCHECK(CalledOnValidThread());
event_store_->AddEvent(event.Pass());
}
void DataReductionProxyService::AddEnabledEvent(scoped_ptr<base::Value> event,
bool enabled) {
DCHECK(CalledOnValidThread());
event_store_->AddEnabledEvent(entry.Pass(), enabled);
event_store_->AddEnabledEvent(event.Pass(), enabled);
}
void DataReductionProxyService::AddEventAndSecureProxyCheckState(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
SecureProxyCheckState state) {
DCHECK(CalledOnValidThread());
event_store_->AddEventAndSecureProxyCheckState(entry.Pass(), state);
event_store_->AddEventAndSecureProxyCheckState(event.Pass(), state);
}
void DataReductionProxyService::AddAndSetLastBypassEvent(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
int64 expiration_ticks) {
DCHECK(CalledOnValidThread());
event_store_->AddAndSetLastBypassEvent(entry.Pass(), expiration_ticks);
event_store_->AddAndSetLastBypassEvent(event.Pass(), expiration_ticks);
}
void DataReductionProxyService::SetUnreachable(bool unreachable) {
......
......@@ -79,10 +79,11 @@ class DataReductionProxyService
DataReductionProxyRequestType request_type);
// Overrides of DataReductionProxyEventStorageDelegate.
void AddEnabledEvent(scoped_ptr<base::Value> entry, bool enabled) override;
void AddEventAndSecureProxyCheckState(scoped_ptr<base::Value> entry,
void AddEvent(scoped_ptr<base::Value> event) override;
void AddEnabledEvent(scoped_ptr<base::Value> event, bool enabled) override;
void AddEventAndSecureProxyCheckState(scoped_ptr<base::Value> event,
SecureProxyCheckState state) override;
void AddAndSetLastBypassEvent(scoped_ptr<base::Value> entry,
void AddAndSetLastBypassEvent(scoped_ptr<base::Value> event,
int64 expiration_ticks) override;
// Records whether the Data Reduction Proxy is unreachable or not.
......
......@@ -93,12 +93,16 @@ TestDataReductionProxyConfigServiceClient::
scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
DataReductionProxyConfig* config)
DataReductionProxyConfig* config,
DataReductionProxyEventCreator* event_creator,
net::NetLog* net_log)
: DataReductionProxyConfigServiceClient(params.Pass(),
kTestBackoffPolicy,
request_options,
config_values,
config),
config,
event_creator,
net_log),
tick_clock_(base::Time::UnixEpoch()),
test_backoff_entry_(&kTestBackoffPolicy, &tick_clock_) {
}
......@@ -364,12 +368,12 @@ DataReductionProxyTestContext::Builder::Build() {
if (use_test_config_client_) {
test_context_flags |= USE_TEST_CONFIG_CLIENT;
config_client.reset(new TestDataReductionProxyConfigServiceClient(
params.Pass(), request_options.get(), raw_mutable_config,
config.get()));
params.Pass(), request_options.get(), raw_mutable_config, config.get(),
event_creator.get(), net_log.get()));
} else if (use_config_client_) {
config_client.reset(new DataReductionProxyConfigServiceClient(
params.Pass(), GetBackoffPolicy(), request_options.get(),
raw_mutable_config, config.get()));
raw_mutable_config, config.get(), event_creator.get(), net_log.get()));
}
scoped_ptr<DataReductionProxySettings> settings(
......
......@@ -99,7 +99,9 @@ class TestDataReductionProxyConfigServiceClient
scoped_ptr<DataReductionProxyParams> params,
DataReductionProxyRequestOptions* request_options,
DataReductionProxyMutableConfigValues* config_values,
DataReductionProxyConfig* config);
DataReductionProxyConfig* config,
DataReductionProxyEventCreator* event_creator,
net::NetLog* net_log);
~TestDataReductionProxyConfigServiceClient() override;
......
......@@ -125,6 +125,23 @@ base::Value* EndCanaryRequestCallback(
return dict;
}
// A callback that creates a base::Value containing information about
// completing the Data Reduction Proxy configuration request. Ownership of the
// base::Value is passed to the caller.
base::Value* EndConfigRequestCallback(
int net_error,
int http_response_code,
int failure_count,
int64 expiration_ticks,
net::NetLogCaptureMode /* capture_mode */) {
base::DictionaryValue* dict = new base::DictionaryValue();
dict->SetInteger("net_error", net_error);
dict->SetInteger("http_response_code", http_response_code);
dict->SetInteger("failure_count", failure_count);
dict->SetString("expiration", base::Int64ToString(expiration_ticks));
return dict;
}
} // namespace
namespace data_reduction_proxy {
......@@ -224,6 +241,32 @@ void DataReductionProxyEventCreator::EndSecureProxyCheck(
parameters_callback);
}
void DataReductionProxyEventCreator::BeginConfigRequest(
const net::BoundNetLog& net_log,
const GURL& url) {
// This callback must be invoked synchronously.
const net::NetLog::ParametersCallback& parameters_callback =
net::NetLog::StringCallback("url", &url.spec());
PostBoundNetLogConfigRequestEvent(
net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_CONFIG_REQUEST,
net::NetLog::PHASE_BEGIN, parameters_callback);
}
void DataReductionProxyEventCreator::EndConfigRequest(
const net::BoundNetLog& net_log,
int net_error,
int http_response_code,
int failure_count,
const base::TimeDelta& retry_delay) {
int64 expiration_ticks = GetExpirationTicks(retry_delay.InSeconds());
const net::NetLog::ParametersCallback& parameters_callback =
base::Bind(&EndConfigRequestCallback, net_error, http_response_code,
failure_count, expiration_ticks);
PostBoundNetLogConfigRequestEvent(
net_log, net::NetLog::TYPE_DATA_REDUCTION_PROXY_CONFIG_REQUEST,
net::NetLog::PHASE_END, parameters_callback);
}
void DataReductionProxyEventCreator::PostEnabledEvent(
net::NetLog* net_log,
net::NetLog::EventType type,
......@@ -264,4 +307,17 @@ void DataReductionProxyEventCreator::PostBoundNetLogSecureProxyCheckEvent(
net_log.AddEntry(type, phase, callback);
}
void DataReductionProxyEventCreator::PostBoundNetLogConfigRequestEvent(
const net::BoundNetLog& net_log,
net::NetLog::EventType type,
net::NetLog::EventPhase phase,
const net::NetLog::ParametersCallback& callback) {
scoped_ptr<base::Value> event(
BuildDataReductionProxyEvent(type, net_log.source(), phase, callback));
if (event) {
storage_delegate_->AddEvent(event.Pass());
net_log.AddEntry(type, phase, callback);
}
}
} // namespace data_reduction_proxy
......@@ -80,6 +80,18 @@ class DataReductionProxyEventCreator {
int http_response_code,
bool succeeded);
// Adds a DATA_REDUCTION_PROXY_CONFIG_REQUEST event to the event store
// when the config request has started.
void BeginConfigRequest(const net::BoundNetLog& net_log, const GURL& url);
// Adds a DATA_REDUCTION_PROXY_CONFIG_REQUEST event to the event store
// when the config request has ended.
void EndConfigRequest(const net::BoundNetLog& net_log,
int net_error,
int http_response_code,
int failure_count,
const base::TimeDelta& retry_delay);
private:
// Prepare and post enabling/disabling proxy events for the event store on the
// a net::NetLog.
......@@ -106,6 +118,14 @@ class DataReductionProxyEventCreator {
DataReductionProxyEventStorageDelegate::SecureProxyCheckState state,
const net::NetLog::ParametersCallback& callback);
// Prepare and post a config request event for the event store on a
// BoundNetLog.
void PostBoundNetLogConfigRequestEvent(
const net::BoundNetLog& net_log,
net::NetLog::EventType type,
net::NetLog::EventPhase phase,
const net::NetLog::ParametersCallback& callback);
// Must outlive |this|. Used for posting calls to the UI thread.
DataReductionProxyEventStorageDelegate* storage_delegate_;
......
......@@ -24,6 +24,9 @@ class DataReductionProxyEventStorageDelegate {
CHECK_FAILED,
};
// Stores a DATA_REDUCTION_PROXY event with no parameters.
virtual void AddEvent(scoped_ptr<base::Value> event) = 0;
// Stores a DATA_REDUCTION_PROXY_ENABLED event.
virtual void AddEnabledEvent(scoped_ptr<base::Value> event, bool enabled) = 0;
......
......@@ -25,6 +25,12 @@ void TestDataReductionProxyEventStorageDelegate::SetStorageDelegate(
delegate_ = delegate;
}
void TestDataReductionProxyEventStorageDelegate::AddEvent(
scoped_ptr<base::Value> event) {
if (delegate_)
delegate_->AddEvent(event.Pass());
}
void TestDataReductionProxyEventStorageDelegate::AddEnabledEvent(
scoped_ptr<base::Value> event,
bool enabled) {
......
......@@ -27,6 +27,7 @@ class TestDataReductionProxyEventStorageDelegate
void SetStorageDelegate(DataReductionProxyEventStorageDelegate* delegate);
// Overrides of DataReductionProxyEventStorageDelegate:
void AddEvent(scoped_ptr<base::Value> event) override;
void AddEnabledEvent(scoped_ptr<base::Value> event, bool enabled) override;
void AddAndSetLastBypassEvent(scoped_ptr<base::Value> event,
int64 expiration_ticks) override;
......
......@@ -101,43 +101,43 @@ base::Value* DataReductionProxyEventStore::GetSummaryValue() const {
return data_reduction_proxy_values.release();
}
void DataReductionProxyEventStore::AddEvent(scoped_ptr<base::Value> entry) {
void DataReductionProxyEventStore::AddEvent(scoped_ptr<base::Value> event) {
if (stored_events_.size() == kMaxEventsToStore) {
base::Value* head = stored_events_.front();
stored_events_.pop_front();
delete head;
}
stored_events_.push_back(entry.release());
stored_events_.push_back(event.release());
}
void DataReductionProxyEventStore::AddEnabledEvent(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
bool enabled) {
DCHECK(thread_checker_.CalledOnValidThread());
enabled_ = enabled;
if (enabled)
current_configuration_.reset(entry->DeepCopy());
current_configuration_.reset(event->DeepCopy());
else
current_configuration_.reset();
AddEvent(entry.Pass());
AddEvent(event.Pass());
}
void DataReductionProxyEventStore::AddEventAndSecureProxyCheckState(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
SecureProxyCheckState state) {
DCHECK(thread_checker_.CalledOnValidThread());
secure_proxy_check_state_ = state;
AddEvent(entry.Pass());
AddEvent(event.Pass());
}
void DataReductionProxyEventStore::AddAndSetLastBypassEvent(
scoped_ptr<base::Value> entry,
scoped_ptr<base::Value> event,
int64 expiration_ticks) {
DCHECK(thread_checker_.CalledOnValidThread());
last_bypass_event_.reset(entry->DeepCopy());
last_bypass_event_.reset(event->DeepCopy());
expiration_ticks_ = expiration_ticks;
AddEvent(entry.Pass());
AddEvent(event.Pass());
}
} // namespace data_reduction_proxy
......@@ -42,6 +42,9 @@ class DataReductionProxyEventStore
// The caller is responsible for deleting the returned value.
base::Value* GetSummaryValue() const;
// Adds DATA_REDUCTION_PROXY event with no parameters to the event store.
void AddEvent(scoped_ptr<base::Value> event) override;
// Override of DataReductionProxyEventStorageDelegate.
// Put |entry| on the deque of stored events and set |current_configuration_|.
void AddEnabledEvent(scoped_ptr<base::Value> entry, bool enabled) override;
......@@ -73,9 +76,6 @@ class DataReductionProxyEventStore
FRIEND_TEST_ALL_PREFIXES(DataReductionProxyEventStoreTest,
TestEndSecureProxyCheck);
// Put |entry| on a deque of events to store
void AddEvent(scoped_ptr<base::Value> entry);
// A deque of data reduction proxy related events. It is used as a circular
// buffer to prevent unbounded memory utilization.
std::deque<base::Value*> stored_events_;
......
......@@ -2500,6 +2500,9 @@ EVENT_TYPE(DATA_REDUCTION_PROXY_ENABLED)
// The END phase contains the following parameters:
// {
// "net_error": <The net_error of the completion of the canary request>,
// "http_response_code": <The HTTP response code of the canary request>,
// "check_succeeded": <Whether a secure Data Reduction Proxy can be used or
// not>
// }
EVENT_TYPE(DATA_REDUCTION_PROXY_CANARY_REQUEST)
......@@ -2530,3 +2533,21 @@ EVENT_TYPE(DATA_REDUCTION_PROXY_BYPASS_REQUESTED)
// can be 0 if the proxy server is explicitly skipped>,
// }
EVENT_TYPE(DATA_REDUCTION_PROXY_FALLBACK)
// The start/end of a config request is sent to the Data Saver Config API
// service.
//
// The BEGIN phase contains the following parameters:
// {
// "url": <The URL of the service endpoint>,
// }
//
// The END phase contains the following parameters:
// {
// "net_error": <The net_error of the completion of the config request>,
// "http_response_code": <The HTTP response code of the config request>,
// "failure_count": <The number of consecutive config request failures>,
// "retry_delay_seconds": <The length of time after which another config
// request will be made>,
// }
EVENT_TYPE(DATA_REDUCTION_PROXY_CONFIG_REQUEST)
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