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 <bsimonnet@chromium.org>
Commit-Queue: Bertrand Simonnet <bsimonnet@chromium.org>
Tested-by: Bertrand Simonnet <bsimonnet@chromium.org>
This commit is contained in:
Bertrand SIMONNET 2014-09-11 07:38:17 -07:00 committed by chrome-internal-fetch
parent 51bf92a3cb
commit eb815be5a9
7 changed files with 18 additions and 16 deletions

View file

@ -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();
}
}

View file

@ -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(),

View file

@ -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 = "";

View file

@ -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<chromeos_metrics::PersistentInteger> session_id_;
SystemProfile profile_;
};

View file

@ -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)) {
}

View file

@ -54,7 +54,7 @@ class SystemProfileSetter;
//
class UploadService : public base::HistogramFlattener {
public:
UploadService();
explicit UploadService(bool testing);
void Init();

View file

@ -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<metrics::MetricSample> 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()));