am 6b8fd10a: am 300b1a6b: Merge "metricsd: Don\'t crash when some metadata is missing."

* commit '6b8fd10a79b3254662a73016a09de2099a15d0f5':
  metricsd: Don't crash when some metadata is missing.
This commit is contained in:
Bertrand Simonnet 2015-08-20 20:34:25 +00:00 committed by Android Git Automerger
commit d227679b35
6 changed files with 22 additions and 16 deletions

View file

@ -48,6 +48,6 @@ void MetricsLog::IncrementUncleanShutdownCount() {
stability->set_unclean_system_shutdown_count(current + 1); stability->set_unclean_system_shutdown_count(current + 1);
} }
void MetricsLog::PopulateSystemProfile(SystemProfileSetter* profile_setter) { bool MetricsLog::PopulateSystemProfile(SystemProfileSetter* profile_setter) {
profile_setter->Populate(uma_proto()); return profile_setter->Populate(uma_proto());
} }

View file

@ -39,7 +39,7 @@ class MetricsLog : public metrics::MetricsLogBase {
void IncrementUncleanShutdownCount(); void IncrementUncleanShutdownCount();
// Populate the system profile with system information using setter. // Populate the system profile with system information using setter.
void PopulateSystemProfile(SystemProfileSetter* setter); bool PopulateSystemProfile(SystemProfileSetter* setter);
private: private:
FRIEND_TEST(UploadServiceTest, LogContainsAggregatedValues); FRIEND_TEST(UploadServiceTest, LogContainsAggregatedValues);

View file

@ -75,7 +75,7 @@ bool SystemProfileCache::Initialize() {
if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID", if (!base::SysInfo::GetLsbReleaseValue("BRILLO_BUILD_TARGET_ID",
&profile_.build_target_id)) { &profile_.build_target_id)) {
LOG(ERROR) << "Could not initialize system profile."; LOG(ERROR) << "BRILLO_BUILD_TARGET_ID is not set in /etc/lsb-release.";
return false; return false;
} }
@ -109,11 +109,12 @@ bool SystemProfileCache::InitializeOrCheck() {
return initialized_ || Initialize(); return initialized_ || Initialize();
} }
void SystemProfileCache::Populate( bool SystemProfileCache::Populate(
metrics::ChromeUserMetricsExtension* metrics_proto) { metrics::ChromeUserMetricsExtension* metrics_proto) {
CHECK(metrics_proto); CHECK(metrics_proto);
CHECK(InitializeOrCheck()) if (not InitializeOrCheck()) {
<< "failed to initialize system information."; return false;
}
// The client id is hashed before being sent. // The client id is hashed before being sent.
metrics_proto->set_client_id( metrics_proto->set_client_id(
@ -132,6 +133,8 @@ void SystemProfileCache::Populate(
metrics::SystemProfileProto_BrilloDeviceData* device_data = metrics::SystemProfileProto_BrilloDeviceData* device_data =
profile_proto->mutable_brillo(); profile_proto->mutable_brillo();
device_data->set_build_target_id(profile_.build_target_id); device_data->set_build_target_id(profile_.build_target_id);
return true;
} }
std::string SystemProfileCache::GetPersistentGUID( std::string SystemProfileCache::GetPersistentGUID(

View file

@ -52,7 +52,7 @@ class SystemProfileCache : public SystemProfileSetter {
SystemProfileCache(bool testing, const std::string& config_root); SystemProfileCache(bool testing, const std::string& config_root);
// Populates the ProfileSystem protobuf with system information. // Populates the ProfileSystem protobuf with system information.
void Populate(metrics::ChromeUserMetricsExtension* metrics_proto) override; bool Populate(metrics::ChromeUserMetricsExtension* metrics_proto) override;
// Converts a string representation of the channel to a // Converts a string representation of the channel to a
// SystemProfileProto_Channel // SystemProfileProto_Channel

View file

@ -27,7 +27,7 @@ class SystemProfileSetter {
public: public:
virtual ~SystemProfileSetter() {} virtual ~SystemProfileSetter() {}
// Populates the protobuf with system informations. // Populates the protobuf with system informations.
virtual void Populate(metrics::ChromeUserMetricsExtension* profile_proto) = 0; virtual bool Populate(metrics::ChromeUserMetricsExtension* profile_proto) = 0;
}; };
#endif // METRICS_UPLOADER_SYSTEM_PROFILE_SETTER_H_ #endif // METRICS_UPLOADER_SYSTEM_PROFILE_SETTER_H_

View file

@ -73,7 +73,6 @@ void UploadService::StartNewLog() {
CHECK(!staged_log_) << "the staged log should be discarded before starting " CHECK(!staged_log_) << "the staged log should be discarded before starting "
"a new metrics log"; "a new metrics log";
MetricsLog* log = new MetricsLog(); MetricsLog* log = new MetricsLog();
log->PopulateSystemProfile(system_profile_setter_.get());
current_log_.reset(log); current_log_.reset(log);
} }
@ -97,13 +96,12 @@ void UploadService::UploadEvent() {
// Previous upload successful, reading metrics sample from the file. // Previous upload successful, reading metrics sample from the file.
ReadMetrics(); ReadMetrics();
GatherHistograms(); GatherHistograms();
// No samples found. Exit to avoid sending an empty log.
if (!current_log_)
return;
StageCurrentLog(); StageCurrentLog();
SendStagedLog();
// If a log is available for upload, upload it.
if (staged_log_) {
SendStagedLog();
}
} }
void UploadService::SendStagedLog() { void UploadService::SendStagedLog() {
@ -225,6 +223,11 @@ void UploadService::StageCurrentLog() {
staged_log_.swap(current_log_); staged_log_.swap(current_log_);
staged_log_->CloseLog(); staged_log_->CloseLog();
if (!staged_log_->PopulateSystemProfile(system_profile_setter_.get())) {
LOG(WARNING) << "Error while adding metadata to the log. Discarding the "
<< "log.";
staged_log_.reset();
}
failed_upload_count_ = 0; failed_upload_count_ = 0;
} }