Skip to content

Commit 686693a

Browse files
committed
Add disabled code for minimal metrics reporting in cvd start
This is disabled by a compile-time constant. It uses the same `CuttlefishLogEvent` type as the `host/commands/metrics` code. The metrics messages sent are currently empty. Bug: b/445773158
1 parent 14127bc commit 686693a

File tree

5 files changed

+76
-4
lines changed

5 files changed

+76
-4
lines changed

base/cvd/cuttlefish/host/commands/cvd/cli/commands/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,13 @@ cf_cc_library(
398398
"//cuttlefish/host/commands/cvd/instances:cvd_persistent_data",
399399
"//cuttlefish/host/commands/cvd/instances:reset_client_utils",
400400
"//cuttlefish/host/commands/cvd/instances/lock",
401+
"//cuttlefish/host/commands/cvd/metrics:is_enabled",
401402
"//cuttlefish/host/commands/cvd/utils",
403+
"//cuttlefish/host/commands/metrics:libmetrics_utils",
404+
"//cuttlefish/host/commands/metrics/proto:metrics_protos",
402405
"//cuttlefish/host/libs/config:config_constants",
403406
"//cuttlefish/host/libs/config:cuttlefish_config",
407+
"//cuttlefish/host/libs/metrics:metrics_headers",
404408
"//libbase",
405409
"@fmt",
406410
],

base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,15 @@
6161
#include "cuttlefish/host/commands/cvd/instances/lock/instance_lock.h"
6262
#include "cuttlefish/host/commands/cvd/instances/operator_client.h"
6363
#include "cuttlefish/host/commands/cvd/instances/reset_client_utils.h"
64+
#include "cuttlefish/host/commands/cvd/metrics/is_enabled.h"
6465
#include "cuttlefish/host/commands/cvd/utils/common.h"
6566
#include "cuttlefish/host/commands/cvd/utils/interrupt_listener.h"
6667
#include "cuttlefish/host/commands/cvd/utils/subprocess_waiter.h"
68+
#include "cuttlefish/host/commands/metrics/proto/cf_metrics_protos.h"
69+
#include "cuttlefish/host/commands/metrics/utils.h"
6770
#include "cuttlefish/host/libs/config/config_constants.h"
6871
#include "cuttlefish/host/libs/config/cuttlefish_config.h"
72+
#include "cuttlefish/host/libs/metrics/metrics_defs.h"
6973

7074
namespace cuttlefish {
7175
namespace {
@@ -617,6 +621,43 @@ Result<void> CvdStartCommandHandler::LaunchDevice(
617621

618622
CF_EXPECT(subprocess_waiter_.Setup(launch_command));
619623

624+
LOG(INFO)
625+
<< "By using this Android Virtual Device, you agree to Google Terms of "
626+
"Service (https://policies.google.com/terms). The Google Privacy "
627+
"Policy (https://policies.google.com/privacy) describes how Google "
628+
"handles information generated as you use Google services.";
629+
if (kEnableCvdMetrics) {
630+
static constexpr int kLogSourceId = 1753;
631+
static constexpr char kLogSourceStr[] = "CUTTLEFISH_METRICS";
632+
static constexpr int kCppClientType =
633+
19; // C++ native client type (clientanalytics.proto)
634+
//
635+
LOG(INFO) << "This will automatically send diagnostic information to "
636+
"Google, such as crash reports and usage data from the host "
637+
"machine managing the Android Virtual Device.";
638+
CuttlefishLogEvent cf_log_event;
639+
640+
cf_log_event.set_session_id("cvd-todo-session");
641+
642+
LogRequest request_proto;
643+
request_proto.set_log_source(kLogSourceId);
644+
request_proto.set_log_source_name(kLogSourceStr);
645+
646+
ClientInfo& client_info = *request_proto.mutable_client_info();
647+
client_info.set_client_type(kCppClientType);
648+
649+
LogEvent& log_event = *request_proto.add_log_event();
650+
log_event.set_event_time_ms(metrics::GetEpochTimeMs());
651+
log_event.set_source_extension(cf_log_event.SerializeAsString());
652+
653+
std::string request_string = request_proto.SerializeAsString();
654+
MetricsExitCodes reporting_outcome =
655+
metrics::PostRequest(request_string, metrics::ClearcutServer::kProd);
656+
if (reporting_outcome != MetricsExitCodes::kSuccess) {
657+
LOG(ERROR) << "Issue reporting metrics: " << reporting_outcome;
658+
}
659+
}
660+
620661
auto acloud_compat_action_result = AcloudCompatActions(group, envs, request);
621662
if (!acloud_compat_action_result.ok()) {
622663
LOG(ERROR) << acloud_compat_action_result.error().FormatForEnv();

base/cvd/cuttlefish/host/commands/cvd/metrics/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ package(
44
default_visibility = ["//:android_cuttlefish"],
55
)
66

7+
cf_cc_library(
8+
name = "is_enabled",
9+
hdrs = ["is_enabled.h"],
10+
)
11+
712
cf_cc_library(
813
name = "metrics",
914
srcs = [
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
#pragma once
17+
18+
namespace cuttlefish {
19+
20+
static constexpr bool kEnableCvdMetrics = false;
21+
22+
} // namespace cuttlefish

base/cvd/cuttlefish/host/commands/metrics/proto/cf_metrics_protos.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
#pragma GCC system_header
2424

25-
#include "cuttlefish/host/commands/metrics/proto/cf_log.pb.h"
26-
#include "cuttlefish/host/commands/metrics/proto/cf_metrics_event.pb.h"
27-
#include "cuttlefish/host/commands/metrics/proto/clientanalytics.pb.h"
28-
#include "cuttlefish/host/commands/metrics/proto/common.pb.h"
25+
#include "cuttlefish/host/commands/metrics/proto/cf_log.pb.h" // IWYU pragma: export
26+
#include "cuttlefish/host/commands/metrics/proto/cf_metrics_event.pb.h" // IWYU pragma: export
27+
#include "cuttlefish/host/commands/metrics/proto/clientanalytics.pb.h" // IWYU pragma: export
28+
#include "cuttlefish/host/commands/metrics/proto/common.pb.h" // IWYU pragma: export

0 commit comments

Comments
 (0)