Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 71a62efc authored by Bertrand SIMONNET's avatar Bertrand SIMONNET Committed by chrome-internal-fetch
Browse files

metrics: add support for other product id

metrics_uploader should use the GOOGLE_METRICS_PRODUCT_ID field from os-release
whenever possible instead of the default Chrome product id.

BUG=chromium:415744
TEST=FEATURES=test emerge-gizmo metrics succeeds.
TEST=test_that platform_MetricsUploader succeeds.

CQ-DEPEND=CL:221963

Change-Id: I69b1a6ca766048ad80d93008a2fe3b18879bf1da
Reviewed-on: https://chromium-review.googlesource.com/221953


Tested-by: default avatarBertrand Simonnet <bsimonnet@chromium.org>
Reviewed-by: default avatarAlex Vakulenko <avakulenko@chromium.org>
Commit-Queue: Bertrand Simonnet <bsimonnet@chromium.org>
parent 67906c6b
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -187,7 +187,9 @@ void MetricsDaemon::Run(bool run_as_daemon) {
}

void MetricsDaemon::RunUploaderTest() {
  upload_service_.reset(new UploadService(testing_, server_));
  upload_service_.reset(new UploadService(new SystemProfileCache(true,
                                                                 config_root_),
                                          server_));
  upload_service_->Init(upload_interval_secs_, metrics_file_);
  upload_service_->UploadEvent();
}
@@ -218,8 +220,10 @@ void MetricsDaemon::Init(bool testing,
                         const string& cpuinfo_max_freq_path,
                         int upload_interval_secs,
                         const string& server,
                         const string& metrics_file) {
                         const string& metrics_file,
                         const string& config_root) {
  testing_ = testing;
  config_root_ = config_root;
  DCHECK(metrics_lib != nullptr);
  metrics_lib_ = metrics_lib;

@@ -321,7 +325,7 @@ void MetricsDaemon::Init(bool testing,

  if (uploader_active) {
    LOG(INFO) << "uploader enabled";
    upload_service_.reset(new UploadService(testing_, server_));
    upload_service_.reset(new UploadService(new SystemProfileCache(), server_));
    upload_service_->Init(upload_interval_secs_, metrics_file_);
  }
}
+5 −1
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ class MetricsDaemon {
            const std::string& scaling_max_freq_path,
            int upload_interval_secs,
            const std::string& server,
            const std::string& metrics_file);
            const std::string& metrics_file,
            const std::string& config_root);

  // Does all the work. If |run_as_daemon| is true, daemonizes by
  // forking.
@@ -300,6 +301,9 @@ class MetricsDaemon {
  // Test mode.
  bool testing_;

  // Root of the configuration files to use.
  std::string config_root_;

  // The metrics library handle.
  MetricsLibraryInterface* metrics_lib_;

+4 −1
Original line number Diff line number Diff line
@@ -65,6 +65,8 @@ int main(int argc, char** argv) {
  DEFINE_string(metrics_file,
                "/var/run/metrics/uma-events",
                "File to use as a proxy for uploading the metrics");
  DEFINE_string(config_root,
                "/", "Root of the configuration files (testing only)");

  chromeos::FlagHelper::Init(argc, argv, "Chromium OS Metrics Daemon");

@@ -83,7 +85,8 @@ int main(int argc, char** argv) {
              kCpuinfoMaxFreqPath,
              FLAGS_upload_interval_secs,
              FLAGS_server,
              FLAGS_metrics_file);
              FLAGS_metrics_file,
              FLAGS_config_root);


  base::AtExitManager at_exit_manager;
+2 −1
Original line number Diff line number Diff line
@@ -74,7 +74,8 @@ class MetricsDaemonTest : public testing::Test {
                 kFakeCpuinfoMaxFreqPath,
                 1800,
                 kMetricsServer,
                 kMetricsFilePath);
                 kMetricsFilePath,
                 "/");

    // Replace original persistent values with mock ones.
    daily_active_use_mock_ =
+48 −5
Original line number Diff line number Diff line
@@ -11,20 +11,35 @@
#include "base/files/file_util.h"
#include "base/guid.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
#include "base/sys_info.h"
#include "components/metrics/metrics_log_base.h"
#include "components/metrics/proto/chrome_user_metrics_extension.pb.h"
#include "metrics/persistent_integer.h"
#include "vboot/crossystem.h"

const char* SystemProfileCache::kPersistentGUIDFile =
    "/var/lib/metrics/Sysinfo.GUID";
const char* SystemProfileCache::kPersistentSessionIdFilename =
    "Sysinfo.SessionId";
namespace {

SystemProfileCache::SystemProfileCache(bool testing)
const char kPersistentGUIDFile[] = "/var/lib/metrics/Sysinfo.GUID";
const char kPersistentSessionIdFilename[] = "Sysinfo.SessionId";
const char kProductIdFieldName[] = "GOOGLE_METRICS_PRODUCT_ID";

}  // namespace


SystemProfileCache::SystemProfileCache()
    : initialized_(false),
    testing_(false),
    config_root_("/"),
    session_id_(new chromeos_metrics::PersistentInteger(
        kPersistentSessionIdFilename)) {
}

SystemProfileCache::SystemProfileCache(bool testing,
                                       const std::string& config_root)
    : initialized_(false),
      testing_(testing),
      config_root_(config_root),
      session_id_(new chromeos_metrics::PersistentInteger(
          kPersistentSessionIdFilename)) {
}
@@ -48,6 +63,12 @@ bool SystemProfileCache::Initialize() {
  base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_TRACK", &channel_string);
  profile_.channel = ProtoChannelFromString(channel_string);

  // If the product id is not defined, use the default one from the protobuf.
  profile_.product_id = metrics::ChromeUserMetricsExtension::CHROME;
  if (GetProductId(&profile_.product_id)) {
    DLOG(INFO) << "Set the product id to " << profile_.product_id;
  }

  profile_.client_id =
      testing_ ? "client_id_test" : GetPersistentGUID(kPersistentGUIDFile);

@@ -78,6 +99,9 @@ void SystemProfileCache::Populate(
      metrics::MetricsLogBase::Hash(profile_.client_id));
  metrics_proto->set_session_id(profile_.session_id);

  // Sets the product id.
  metrics_proto->set_product(profile_.product_id);

  metrics::SystemProfileProto* profile_proto =
      metrics_proto->mutable_system_profile();
  profile_proto->mutable_hardware()->set_hardware_class(
@@ -122,6 +146,25 @@ bool SystemProfileCache::GetHardwareId(std::string* hwid) {
  return true;
}

bool SystemProfileCache::GetProductId(int* product_id) const {
  chromeos::OsReleaseReader reader;
  if (testing_) {
    base::FilePath root(config_root_);
    CHECK(reader.LoadTestingOnly(root)) << "Failed to load os-release fields "
                                        "from" << root.value();
  } else {
    CHECK(reader.Load()) << "Failed to load os-release fields.";
  }

  std::string id;
  if (reader.GetString(kProductIdFieldName, &id)) {
    CHECK(base::StringToInt(id, product_id)) << "Failed to convert product_id "
                                             << id << " to int.";
    return true;
  }
  return false;
}

metrics::SystemProfileProto_Channel SystemProfileCache::ProtoChannelFromString(
    const std::string& channel) {

Loading