From eb815be5a9c3df5fcede522f02623e525d65bbc0 Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Thu, 11 Sep 2014 07:38:17 -0700 Subject: [PATCH] metrics: Fix metrics_uploader on VMs metrics_uploader must be in testing mode so that it does not try to grab the real hardware id (not available on VMs). BUG=chromium:413256 TEST=FEATURES=test emerge-amd64-generic metrics. TEST=platform_MetricsUploader succeeds on a gizmo VM. Change-Id: I9e508c8661dfdb7933161b0d41ef4cf9bd7db2c6 Reviewed-on: https://chromium-review.googlesource.com/217760 Reviewed-by: Bertrand Simonnet Commit-Queue: Bertrand Simonnet Tested-by: Bertrand Simonnet --- metrics/metrics_daemon.cc | 4 +++- metrics/metrics_daemon_main.cc | 2 +- metrics/uploader/system_profile_cache.cc | 8 ++++---- metrics/uploader/system_profile_cache.h | 4 ++-- metrics/uploader/upload_service.cc | 4 ++-- metrics/uploader/upload_service.h | 2 +- metrics/uploader/upload_service_test.cc | 10 +++++----- 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc index 07c32209d..c0c77faea 100644 --- a/metrics/metrics_daemon.cc +++ b/metrics/metrics_daemon.cc @@ -187,6 +187,8 @@ void MetricsDaemon::Run(bool run_as_daemon) { } void MetricsDaemon::RunUploaderTest() { + upload_service_.reset(new UploadService(testing_)); + upload_service_->Init(); upload_service_->UploadEvent(); } @@ -311,7 +313,7 @@ void MetricsDaemon::Init(bool testing, g_timeout_add(kUpdateStatsIntervalMs, &HandleUpdateStatsTimeout, this); if (uploader_active) { - upload_service_.reset(new UploadService()); + upload_service_.reset(new UploadService(testing_)); upload_service_->Init(); } } diff --git a/metrics/metrics_daemon_main.cc b/metrics/metrics_daemon_main.cc index 93e24142b..e529afd4d 100644 --- a/metrics/metrics_daemon_main.cc +++ b/metrics/metrics_daemon_main.cc @@ -65,7 +65,7 @@ int main(int argc, char** argv) { MetricsLibrary metrics_lib; metrics_lib.Init(); MetricsDaemon daemon; - daemon.Init(false, + daemon.Init(FLAGS_uploader_test, FLAGS_uploader | FLAGS_uploader_test, &metrics_lib, MetricsMainDiskStatsPath(), diff --git a/metrics/uploader/system_profile_cache.cc b/metrics/uploader/system_profile_cache.cc index 12e8bece3..604c060ca 100644 --- a/metrics/uploader/system_profile_cache.cc +++ b/metrics/uploader/system_profile_cache.cc @@ -22,9 +22,9 @@ const char* SystemProfileCache::kPersistentGUIDFile = const char* SystemProfileCache::kPersistentSessionIdFilename = "Sysinfo.SessionId"; -SystemProfileCache::SystemProfileCache() +SystemProfileCache::SystemProfileCache(bool testing) : initialized_(false), - is_testing_(false), + testing_(testing), session_id_(new chromeos_metrics::PersistentInteger( kPersistentSessionIdFilename)) { } @@ -49,7 +49,7 @@ bool SystemProfileCache::Initialize() { profile_.channel = ProtoChannelFromString(channel_string); profile_.client_id = - is_testing_ ? "client_id_test" : GetPersistentGUID(kPersistentGUIDFile); + testing_ ? "client_id_test" : GetPersistentGUID(kPersistentGUIDFile); // Increment the session_id everytime we initialize this. If metrics_daemon // does not crash, this should correspond to the number of reboots of the @@ -105,7 +105,7 @@ std::string SystemProfileCache::GetPersistentGUID(const std::string& filename) { bool SystemProfileCache::GetHardwareId(std::string* hwid) { CHECK(hwid); - if (is_testing_) { + if (testing_) { // if we are in test mode, we do not call crossystem directly. DLOG(INFO) << "skipping hardware id"; *hwid = ""; diff --git a/metrics/uploader/system_profile_cache.h b/metrics/uploader/system_profile_cache.h index 03e92fca5..f85c1b190 100644 --- a/metrics/uploader/system_profile_cache.h +++ b/metrics/uploader/system_profile_cache.h @@ -36,7 +36,7 @@ struct SystemProfile { // The cache is populated lazily. The only method needed is Populate. class SystemProfileCache : public SystemProfileSetter { public: - SystemProfileCache(); + explicit SystemProfileCache(bool testing); // Populates the ProfileSystem protobuf with system information. void Populate(metrics::ChromeUserMetricsExtension* profile_proto) override; @@ -69,7 +69,7 @@ class SystemProfileCache : public SystemProfileSetter { bool GetHardwareId(std::string* hwid); bool initialized_; - bool is_testing_; + bool testing_; scoped_ptr session_id_; SystemProfile profile_; }; diff --git a/metrics/uploader/upload_service.cc b/metrics/uploader/upload_service.cc index 8094fecdf..8e08f28c7 100644 --- a/metrics/uploader/upload_service.cc +++ b/metrics/uploader/upload_service.cc @@ -38,8 +38,8 @@ DEFINE_string(metrics_file, const int UploadService::kMaxFailedUpload = 10; -UploadService::UploadService() - : system_profile_setter_(new SystemProfileCache()), +UploadService::UploadService(bool testing) + : system_profile_setter_(new SystemProfileCache(testing)), histogram_snapshot_manager_(this), sender_(new HttpSender(FLAGS_server)) { } diff --git a/metrics/uploader/upload_service.h b/metrics/uploader/upload_service.h index 0d17e0e39..114c5e4ea 100644 --- a/metrics/uploader/upload_service.h +++ b/metrics/uploader/upload_service.h @@ -54,7 +54,7 @@ class SystemProfileSetter; // class UploadService : public base::HistogramFlattener { public: - UploadService(); + explicit UploadService(bool testing); void Init(); diff --git a/metrics/uploader/upload_service_test.cc b/metrics/uploader/upload_service_test.cc index d60413d45..94453b24a 100644 --- a/metrics/uploader/upload_service_test.cc +++ b/metrics/uploader/upload_service_test.cc @@ -22,7 +22,9 @@ class UploadServiceTest : public testing::Test { protected: UploadServiceTest() - : upload_service_(), exit_manager_(new base::AtExitManager()) { + : cache_(true), + upload_service_(true), + exit_manager_(new base::AtExitManager()) { sender_ = new SenderMock; upload_service_.sender_.reset(sender_); upload_service_.system_profile_setter_.reset(new MockSystemProfileSetter()); @@ -34,7 +36,6 @@ class UploadServiceTest : public testing::Test { upload_service_.GatherHistograms(); upload_service_.Reset(); sender_->Reset(); - cache_.is_testing_ = true; chromeos_metrics::PersistentInteger::SetTestingMode(true); cache_.session_id_.reset(new chromeos_metrics::PersistentInteger( @@ -123,7 +124,7 @@ TEST_F(UploadServiceTest, EmptyLogsAreNotSent) { } TEST_F(UploadServiceTest, LogEmptyByDefault) { - UploadService upload_service; + UploadService upload_service(true); // current_log_ should be initialized later as it needs AtExitManager to exit // in order to gather system information from SysInfo. @@ -191,8 +192,7 @@ TEST_F(UploadServiceTest, ValuesInConfigFileAreSent) { base::SysInfo::SetChromeOSVersionInfoForTest(content, base::Time()); scoped_ptr histogram = metrics::MetricSample::SparseHistogramSample("myhistogram", 1); - SystemProfileCache* local_cache_ = new SystemProfileCache; - local_cache_->is_testing_ = true; + SystemProfileCache* local_cache_ = new SystemProfileCache(true); local_cache_->session_id_.reset(new chromeos_metrics::PersistentInteger( dir_.path().Append("session_id").value()));