From b28b65ba28b94ab90ebabd568dcc9e0fa4ed00ad Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Thu, 9 Jul 2026 15:53:46 -0700 Subject: [PATCH 1/5] Delete v1 metrics in host/commands/metrics_launcher Bug: 463443661 --- .../commands/metrics_launcher/BUILD.bazel | 22 ------ .../metrics_launcher/metrics_launcher.cpp | 74 ------------------- base/cvd/cuttlefish/package/BUILD.bazel | 1 - 3 files changed, 97 deletions(-) delete mode 100644 base/cvd/cuttlefish/host/commands/metrics_launcher/BUILD.bazel delete mode 100644 base/cvd/cuttlefish/host/commands/metrics_launcher/metrics_launcher.cpp diff --git a/base/cvd/cuttlefish/host/commands/metrics_launcher/BUILD.bazel b/base/cvd/cuttlefish/host/commands/metrics_launcher/BUILD.bazel deleted file mode 100644 index f441d27147f..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics_launcher/BUILD.bazel +++ /dev/null @@ -1,22 +0,0 @@ -load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary") - -package( - default_visibility = ["//:android_cuttlefish"], -) - -cf_cc_binary( - name = "metrics_launcher", - srcs = [ - "metrics_launcher.cpp", - ], - depend_on_what_you_use_enabled = False, - deps = [ - "//cuttlefish/common/libs/utils:tee_logging", - "//cuttlefish/host/libs/metrics", - "//cuttlefish/host/libs/msg_queue", - "//cuttlefish/result", - "//libbase", - "@abseil-cpp//absl/log", - "@gflags", - ], -) diff --git a/base/cvd/cuttlefish/host/commands/metrics_launcher/metrics_launcher.cpp b/base/cvd/cuttlefish/host/commands/metrics_launcher/metrics_launcher.cpp deleted file mode 100644 index b1ff329979b..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics_launcher/metrics_launcher.cpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include - -#include "absl/log/log.h" -#include "gflags/gflags.h" - -#include "cuttlefish/common/libs/utils/tee_logging.h" -#include "cuttlefish/host/libs/metrics/metrics_receiver.h" -#include "cuttlefish/result/result.h" - -namespace cuttlefish { -namespace { - -Result MetricsLauncherMain() { - while (true) { - std::cout << "Please choose an action: \n"; - std::cout << " start - send start event to cuttlefish metrics client \n"; - std::cout << " stop - send stop event to cuttlefish metrics client \n"; - std::cout << " boot - send boot event to cuttlefish metrics client\n"; - std::cout << " lock - send lock event to cuttlefish metrics client\n"; - std::cout << " atest - send launch command to atest metrics client \n"; - std::cout << " exit - exit the program \n"; - - std::string command; - std::getline(std::cin, command); - - if (command == "start") { - cuttlefish::MetricsReceiver::LogMetricsVMStart(); - } else if (command == "stop") { - cuttlefish::MetricsReceiver::LogMetricsVMStop(); - } else if (command == "boot") { - cuttlefish::MetricsReceiver::LogMetricsDeviceBoot(); - } else if (command == "lock") { - cuttlefish::MetricsReceiver::LogMetricsLockScreen(); - } else if (command == "exit") { - break; - } else { - LOG(ERROR) << "Unknown command: " << command; - } - } - return {}; -} - -} // namespace -} // namespace cuttlefish - -int main(int argc, char** argv) { - cuttlefish::LogToStderr(); - google::ParseCommandLineFlags(&argc, &argv, true); - - cuttlefish::Result result = cuttlefish::MetricsLauncherMain(); - if (!result.ok()) { - LOG(ERROR) << result.error(); - return EXIT_FAILURE; - } - return EXIT_SUCCESS; -} diff --git a/base/cvd/cuttlefish/package/BUILD.bazel b/base/cvd/cuttlefish/package/BUILD.bazel index b237a0a7ba2..27e806c8e6b 100644 --- a/base/cvd/cuttlefish/package/BUILD.bazel +++ b/base/cvd/cuttlefish/package/BUILD.bazel @@ -64,7 +64,6 @@ package_files( "cuttlefish-common/bin/lpmake": "@android_system_extras//:lpmake", "cuttlefish-common/bin/lz4": "@lz4//programs:lz4", "cuttlefish-common/bin/make_f2fs": "@f2fs_tools//:make_f2fs", - "cuttlefish-common/bin/metrics_launcher": "//cuttlefish/host/commands/metrics_launcher", "cuttlefish-common/bin/metrics": "//cuttlefish/host/commands/metrics", "cuttlefish-common/bin/mkbootfs": "//mkbootfs", "cuttlefish-common/bin/mkbootimg.py": "@mkbootimg//:mkbootimg.py", From 1b2444130722d319adf0ab5f8a4dddec2656e2e0 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Thu, 9 Jul 2026 15:54:37 -0700 Subject: [PATCH 2/5] Delete v1 metrics from host/commands/metrics Bug: 463443661 --- .../host/commands/metrics/BUILD.bazel | 95 +---------- .../commands/metrics/clearcut_log_parser.sh | 60 ------- .../host/commands/metrics/clearcut_protos.cc | 70 -------- .../host/commands/metrics/clearcut_protos.h | 36 ---- .../host/commands/metrics/events.cc | 161 ------------------ .../cuttlefish/host/commands/metrics/events.h | 33 ---- .../host/commands/metrics/host_receiver.cc | 102 ----------- .../host/commands/metrics/host_receiver.h | 40 ----- .../host/commands/metrics/metrics.cc | 61 ------- .../cuttlefish/host/commands/metrics/send.cc | 80 --------- .../cuttlefish/host/commands/metrics/send.h | 33 ---- .../cuttlefish/host/commands/metrics/utils.cc | 127 -------------- .../cuttlefish/host/commands/metrics/utils.h | 33 ---- .../host/commands/metrics/utils_tests.cpp | 41 ----- base/cvd/cuttlefish/package/BUILD.bazel | 1 - 15 files changed, 1 insertion(+), 972 deletions(-) delete mode 100755 base/cvd/cuttlefish/host/commands/metrics/clearcut_log_parser.sh delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.cc delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.h delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/events.cc delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/events.h delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/host_receiver.cc delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/host_receiver.h delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/metrics.cc delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/send.cc delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/send.h delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/utils.cc delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/utils.h delete mode 100644 base/cvd/cuttlefish/host/commands/metrics/utils_tests.cpp diff --git a/base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel index 09dfbbe3ea7..136a1f964c1 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel @@ -1,20 +1,9 @@ -load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary", "cf_cc_library", "cf_cc_test") +load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary", "cf_cc_library") package( default_visibility = ["//:android_cuttlefish"], ) -cf_cc_library( - name = "clearcut_protos", - srcs = ["clearcut_protos.cc"], - hdrs = ["clearcut_protos.h"], - deps = [ - "//external_proto:cf_log_cc_proto", - "//external_proto:clientanalytics_cc_proto", - "//external_proto:log_source_enum_cc_proto", - ], -) - cf_cc_library( name = "debug_reader", srcs = ["debug_reader.cc"], @@ -28,54 +17,6 @@ cf_cc_library( ], ) -cf_cc_library( - name = "events", - srcs = ["events.cc"], - hdrs = ["events.h"], - deps = [ - "//cuttlefish/host/commands/metrics:clearcut_protos", - "//cuttlefish/host/commands/metrics:send", - "//cuttlefish/host/commands/metrics:utils", - "//cuttlefish/host/libs/config:vmm_mode", - "//external_proto:cf_log_cc_proto", - "//external_proto:cf_metrics_event_cc_proto", - "//external_proto:clientanalytics_cc_proto", - "@abseil-cpp//absl/log", - "@protobuf//:timestamp_cc_proto", - ], -) - -cf_cc_binary( - name = "metrics", - srcs = [ - "host_receiver.cc", - "host_receiver.h", - "metrics.cc", - ], - depend_on_what_you_use_enabled = False, - deps = [ - "//cuttlefish/common/libs/fs", - "//cuttlefish/common/libs/utils:files", - "//cuttlefish/common/libs/utils:tee_logging", - "//cuttlefish/host/commands/metrics:events", - "//cuttlefish/host/commands/metrics:utils", - "//cuttlefish/host/libs/config:cuttlefish_config", - "//cuttlefish/host/libs/config:vmm_mode", - "//cuttlefish/host/libs/log_names", - "//cuttlefish/host/libs/metrics", - "//cuttlefish/host/libs/metrics:metrics_headers", - "//cuttlefish/host/libs/msg_queue", - "//external_proto:cf_log_cc_proto", - "//libbase", - "@abseil-cpp//absl/log", - "@abseil-cpp//absl/log:check", - "@fruit", - "@gflags", - "@jsoncpp", - "@protobuf", - ], -) - cf_cc_library( name = "metrics_conversion", srcs = [ @@ -143,37 +84,3 @@ cf_cc_binary( "@abseil-cpp//absl/log", ], ) - -cf_cc_library( - name = "send", - srcs = ["send.cc"], - hdrs = ["send.h"], - depend_on_what_you_use_enabled = False, - deps = [ - "//cuttlefish/host/libs/metrics:metrics_headers", - "//cuttlefish/host/libs/web/http_client", - "//cuttlefish/host/libs/web/http_client:curl_global_init", - "//cuttlefish/host/libs/web/http_client:curl_http_client", - "//cuttlefish/host/libs/web/http_client:http_string", - "//cuttlefish/result", - "//libbase", - "@abseil-cpp//absl/log", - ], -) - -cf_cc_library( - name = "utils", - srcs = ["utils.cc"], - hdrs = ["utils.h"], - depend_on_what_you_use_enabled = False, - deps = [ - "//libbase", - "@abseil-cpp//absl/log", - ], -) - -cf_cc_test( - name = "utils_test", - srcs = ["utils_tests.cpp"], - deps = ["//cuttlefish/host/commands/metrics:utils"], -) diff --git a/base/cvd/cuttlefish/host/commands/metrics/clearcut_log_parser.sh b/base/cvd/cuttlefish/host/commands/metrics/clearcut_log_parser.sh deleted file mode 100755 index b7a0c7822e5..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/clearcut_log_parser.sh +++ /dev/null @@ -1,60 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2023 The Android Open Source Project -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -# - -# This function searches for log files within the specified directory -# that contain the given string in their filenames. -# It returns a list of matching log file paths. -FindLogFiles() { - # Check for the correct number of arguments - if [[ "$#" -ne 2 ]]; then - echo "Usage: ${FUNCNAME} " - return 1 - fi - - # Get the directory and string from the arguments - local directory="$1" - local string="$2" - - # Ensure the directory exists - if [[ ! -d "$directory" ]]; then - echo "Error: Directory $directory does not exist." - return 1 - fi - - # Use the find command to search for files with names containing the given string - find "$directory" -type f -name "*$string*" -} - -# /tmp/clearcut-logwriter is the default directory where clearcut logs are stored -logs_directory="/tmp/clearcut-logwriter" - -# Find log files for "cuttlefish" metrics -cuttlefish_logs=$(FindLogFiles "$logs_directory" "cuttlefish") -echo "$cuttlefish_logs" - -# Find log files for "atest" internal metrics -atest_internal_logs=$(FindLogFiles "$logs_directory" "atest_internal") -echo "$atest_internal_logs" - -# Find log files for "atest" external metrics -atest_external_logs=$(FindLogFiles "$logs_directory" "atest_external") -echo "$atest_external_logs" - -# gqui is a tool to parse clearcut logs -gqui from "$cuttlefish_logs" proto GWSLogEntryProto > clearcut_cf.txt 2> clearcut_cf_error.txt -gqui from "$atest_internal_logs" proto GWSLogEntryProto > clearcut_atest_internal.txt 2> clearcut_atest_internal_error.txt -gqui from "$atest_external_logs" proto GWSLogEntryProto > clearcut_atest_external.txt 2> clearcut_atest_external_error.txt diff --git a/base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.cc b/base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.cc deleted file mode 100644 index c8f580c5c47..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.cc +++ /dev/null @@ -1,70 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/metrics/clearcut_protos.h" - -#include - -#include "external_proto/cf_log.pb.h" -#include "external_proto/clientanalytics.pb.h" -#include "external_proto/log_source_enum.pb.h" - -namespace cuttlefish::metrics { - -namespace { - -using logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent; -using wireless_android_play_playlog::ClientInfo; -using wireless_android_play_playlog::LogEvent; -using wireless_android_play_playlog::LogRequest; -using wireless_android_play_playlog::LogSourceEnum::LogSource; - -static constexpr LogSource kLogSourceId = LogSource::CUTTLEFISH_METRICS; - -static constexpr char kLogSourceStr[] = "CUTTLEFISH_METRICS"; -static constexpr ClientInfo::ClientType kCppClientType = ClientInfo::CPLUSPLUS; - -} // namespace - -LogEvent BuildLogEvent(uint64_t now_ms, const CuttlefishLogEvent& cf_event) { - LogEvent log_event; - log_event.set_event_time_ms(now_ms); - log_event.set_source_extension(cf_event.SerializeAsString()); - return log_event; -} - -LogRequest BuildLogRequest(uint64_t now_ms, LogEvent event) { - std::vector events; - events.emplace_back(std::move(event)); - return BuildLogRequest(now_ms, events); -} - -LogRequest BuildLogRequest(uint64_t now_ms, std::vector events) { - LogRequest log_request; - log_request.set_request_time_ms(now_ms); - log_request.set_log_source(kLogSourceId); - log_request.set_log_source_name(kLogSourceStr); - - ClientInfo& client_info = *log_request.mutable_client_info(); - client_info.set_client_type(kCppClientType); - - for (LogEvent event : events) { - *log_request.add_log_event() = std::move(event); - } - - return log_request; -} - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.h b/base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.h deleted file mode 100644 index a15aa88ac0f..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/clearcut_protos.h +++ /dev/null @@ -1,36 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once - -#include - -#include "external_proto/cf_log.pb.h" -#include "external_proto/clientanalytics.pb.h" - -namespace cuttlefish::metrics { - -wireless_android_play_playlog::LogEvent BuildLogEvent( - uint64_t now_ms, - const logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent& - cf_event); - -wireless_android_play_playlog::LogRequest BuildLogRequest( - uint64_t now_ms, wireless_android_play_playlog::LogEvent event); - -wireless_android_play_playlog::LogRequest BuildLogRequest( - uint64_t now_ms, - std::vector events); - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/events.cc b/base/cvd/cuttlefish/host/commands/metrics/events.cc deleted file mode 100644 index 9a1ed3b8e4a..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/events.cc +++ /dev/null @@ -1,161 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/metrics/events.h" - -#include - -#include "absl/log/log.h" -#include "google/protobuf/timestamp.pb.h" - -#include "cuttlefish/host/commands/metrics/clearcut_protos.h" -#include "cuttlefish/host/commands/metrics/send.h" -#include "cuttlefish/host/commands/metrics/utils.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" -#include "external_proto/cf_log.pb.h" -#include "external_proto/cf_metrics_event.pb.h" -#include "external_proto/clientanalytics.pb.h" - -namespace cuttlefish::metrics { - -namespace { - -using google::protobuf::Timestamp; -using logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent; -using logs::proto::wireless::android::cuttlefish::events::MetricsEvent; -using wireless_android_play_playlog::LogEvent; -using wireless_android_play_playlog::LogRequest; - -// TODO: 403646742 - this value previously came from the build, need to revisit -static constexpr int PRODUCT_SHIPPING_API_LEVEL = 37; - -Timestamp MillisToTimestamp(uint64_t millis) { - Timestamp timestamp; - timestamp.set_nanos((millis % 1000) * 1000000); - timestamp.set_seconds(millis / 1000); - - return timestamp; -} - -MetricsEvent::OsType GetOsType() { - struct utsname buf; - if (uname(&buf) != 0) { - LOG(ERROR) << "failed to retrieve system information"; - return MetricsEvent::CUTTLEFISH_OS_TYPE_UNSPECIFIED; - } - std::string sysname(buf.sysname); - std::string machine(buf.machine); - - if (sysname != "Linux") { - return MetricsEvent::CUTTLEFISH_OS_TYPE_UNSPECIFIED; - } - if (machine == "x86_64") { - return MetricsEvent::CUTTLEFISH_OS_TYPE_LINUX_X86_64; - } - if (machine == "x86") { - return MetricsEvent::CUTTLEFISH_OS_TYPE_LINUX_X86; - } - if (machine == "aarch64" || machine == "arm64") { - return MetricsEvent::CUTTLEFISH_OS_TYPE_LINUX_AARCH64; - } - if (machine[0] == 'a') { - return MetricsEvent::CUTTLEFISH_OS_TYPE_LINUX_AARCH32; - } - return MetricsEvent::CUTTLEFISH_OS_TYPE_UNSPECIFIED; -} - -MetricsEvent::VmmType GetVmm(VmmMode vmm_mode) { - switch (vmm_mode) { - case VmmMode::kCrosvm: - return MetricsEvent::CUTTLEFISH_VMM_TYPE_CROSVM; - case VmmMode::kQemu: - return MetricsEvent::CUTTLEFISH_VMM_TYPE_QEMU; - default: - return MetricsEvent::CUTTLEFISH_VMM_TYPE_UNSPECIFIED; - } -} - -// Builds the 2nd level MetricsEvent. -MetricsEvent BuildMetricsEvent(uint64_t now_ms, VmmMode vmm_mode, - MetricsEvent::EventType event_type) { - // "metrics_event" is the 2nd level MetricsEvent - MetricsEvent metrics_event; - metrics_event.set_event_type(event_type); - metrics_event.set_os_type(GetOsType()); - metrics_event.set_os_version(GetOsVersion()); - metrics_event.set_vmm_type(GetVmm(vmm_mode)); - - if (!GetVmmVersion().empty()) { - metrics_event.set_vmm_version(GetVmmVersion()); - } - - metrics_event.set_company(GetCompany()); - metrics_event.set_api_level(PRODUCT_SHIPPING_API_LEVEL); - - *metrics_event.mutable_event_time() = MillisToTimestamp(now_ms); - - return metrics_event; -} - -int SendEvent(MetricsEvent::EventType event_type, VmmMode vmm_mode) { - uint64_t now_ms = GetEpochTimeMs(); - - CuttlefishLogEvent cf_event = BuildCfLogEvent(now_ms); - *cf_event.mutable_metrics_event() = - BuildMetricsEvent(now_ms, vmm_mode, event_type); - - LogEvent log_event = BuildLogEvent(now_ms, cf_event); - - LogRequest log_request = BuildLogRequest(now_ms, log_event); - std::string log_request_str = log_request.SerializeAsString(); - - return PostRequest(log_request_str, ClearcutServer::kProd); -} - -} // namespace - -CuttlefishLogEvent BuildCfLogEvent(uint64_t now_ms) { - CuttlefishLogEvent cf_event; - cf_event.set_device_type(CuttlefishLogEvent::CUTTLEFISH_DEVICE_TYPE_HOST); - cf_event.set_session_id(GenerateSessionId(now_ms)); - - if (!GetCfVersion().empty()) { - cf_event.set_cuttlefish_version(GetCfVersion()); - } - - *cf_event.mutable_timestamp_ms() = MillisToTimestamp(now_ms); - - return cf_event; -} - -int SendVMStart(VmmMode vmm_mode) { - return SendEvent(MetricsEvent::CUTTLEFISH_EVENT_TYPE_VM_INSTANTIATION, - vmm_mode); -} - -int SendVMStop(VmmMode vmm_mode) { - return SendEvent(MetricsEvent::CUTTLEFISH_EVENT_TYPE_VM_STOP, vmm_mode); -} - -int SendDeviceBoot(VmmMode vmm_mode) { - return SendEvent(MetricsEvent::CUTTLEFISH_EVENT_TYPE_DEVICE_BOOT, vmm_mode); -} - -int SendLockScreen(VmmMode vmm_mode) { - return SendEvent(MetricsEvent::CUTTLEFISH_EVENT_TYPE_LOCK_SCREEN_AVAILABLE, - vmm_mode); -} - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/events.h b/base/cvd/cuttlefish/host/commands/metrics/events.h deleted file mode 100644 index 5fd9b37d0c8..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/events.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include "cuttlefish/host/libs/config/vmm_mode.h" -#include "external_proto/cf_log.pb.h" - -namespace cuttlefish::metrics { - -logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent BuildCfLogEvent( - uint64_t now_ms); - -int SendVMStart(VmmMode); -int SendVMStop(VmmMode); -int SendDeviceBoot(VmmMode); -int SendLockScreen(VmmMode); - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/host_receiver.cc b/base/cvd/cuttlefish/host/commands/metrics/host_receiver.cc deleted file mode 100644 index 9dfcdc70864..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/host_receiver.cc +++ /dev/null @@ -1,102 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/metrics/host_receiver.h" - -#include - -#include "absl/log/check.h" -#include "absl/log/log.h" - -#include "cuttlefish/host/commands/metrics/events.h" -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" -#include "cuttlefish/host/libs/metrics/metrics_configs.h" -#include "cuttlefish/host/libs/metrics/metrics_defs.h" -#include "cuttlefish/host/libs/msg_queue/msg_queue.h" -#include "external_proto/cf_log.pb.h" - -namespace cuttlefish { - -using logs::proto::wireless::android::cuttlefish::CuttlefishLogEvent; - -MetricsHostReceiver::MetricsHostReceiver(bool is_metrics_enabled) - : is_metrics_enabled_(is_metrics_enabled) {} - -MetricsHostReceiver::~MetricsHostReceiver() {} - -void MetricsHostReceiver::ServerLoop() { - auto msg_queue = SysVMessageQueue::Create(metrics_queue_name_); - if (msg_queue == NULL) { - LOG(FATAL) << "create: failed to create" << metrics_queue_name_; - } - - struct msg_buffer msg = {0, {0}}; - while (true) { - int rc = msg_queue->Receive(&msg, MAX_MSG_SIZE, 1, true); - if (rc == -1) { - LOG(FATAL) << "receive: failed to receive any messages"; - } - - std::string text(msg.mesg_text); - LOG(INFO) << "Metrics host received: " << text; - - // Process the received message - ProcessMessage(text); - - sleep(1); - } -} - -void MetricsHostReceiver::Join() { thread_.join(); } - -bool MetricsHostReceiver::Initialize(const std::string& metrics_queue_name) { - metrics_queue_name_ = metrics_queue_name; - if (!is_metrics_enabled_) { - LOG(ERROR) << "init: metrics not enabled"; - return false; - } - - // Start the server loop in a separate thread - thread_ = std::thread(&MetricsHostReceiver::ServerLoop, this); - return true; -} - -void MetricsHostReceiver::ProcessMessage(const std::string& text) { - int rc = MetricsExitCodes::kSuccess; - - const CuttlefishConfig* config = CuttlefishConfig::Get(); - CHECK(config) << "Could not open cuttlefish config"; - VmmMode vmm_mode = config->vm_manager(); - - if (text == "VMStart") { - rc = metrics::SendVMStart(vmm_mode); - } else if (text == "VMStop") { - rc = metrics::SendVMStop(vmm_mode); - } else if (text == "DeviceBoot") { - rc = metrics::SendDeviceBoot(vmm_mode); - } else if (text == "LockScreen") { - rc = metrics::SendLockScreen(vmm_mode); - } else { - LOG(ERROR) << "Message not recognized: " << text; - rc = MetricsExitCodes::kMetricsError; - } - - if (rc != MetricsExitCodes::kSuccess) { - LOG(ERROR) << "Message failed to send to ClearCut: " << text; - } -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/metrics/host_receiver.h b/base/cvd/cuttlefish/host/commands/metrics/host_receiver.h deleted file mode 100644 index b677312c0c9..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/host_receiver.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include - -namespace cuttlefish { - -class MetricsHostReceiver { - private: - bool is_metrics_enabled_; - std::thread thread_; - std::string metrics_queue_name_; - - void ServerLoop(); - // Send different Clearcut events based on the received message - void ProcessMessage(const std::string& text); - - public: - MetricsHostReceiver(bool is_metrics_enabled); - ~MetricsHostReceiver(); - bool Initialize(const std::string& metrics_queue_name); - void Join(); -}; - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics.cc b/base/cvd/cuttlefish/host/commands/metrics/metrics.cc deleted file mode 100644 index 52bbe65a23f..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/metrics.cc +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright (C) 2020 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "absl/log/check.h" -#include "absl/log/log.h" -#include "gflags/gflags.h" - -#include "cuttlefish/common/libs/utils/tee_logging.h" -#include "cuttlefish/host/commands/metrics/host_receiver.h" -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/log_names/log_names.h" -#include "cuttlefish/host/libs/metrics/metrics_configs.h" -#include "cuttlefish/host/libs/metrics/metrics_defs.h" - -namespace cuttlefish { -namespace { - -int MetricsMain(int argc, char** argv) { - google::ParseCommandLineFlags(&argc, &argv, true); - auto config = CuttlefishConfig::Get(); - CHECK(config) << "Could not open cuttlefish config"; - auto instance = config->ForDefaultInstance(); - auto metrics_log_path = instance.PerInstanceLogPath(kLogNameMetrics); - if (instance.run_as_daemon()) { - LogToFiles({metrics_log_path, instance.launcher_log_path()}); - } else { - LogToStderrAndFiles({metrics_log_path, instance.launcher_log_path()}); - } - if (config->enable_metrics() != CuttlefishConfig::Answer::kYes) { - LOG(ERROR) << "metrics not enabled, but metrics were launched."; - return MetricsExitCodes::kInvalidHostConfiguration; - } - - bool is_metrics_enabled = - CuttlefishConfig::Answer::kYes == config->enable_metrics(); - MetricsHostReceiver host_receiver(is_metrics_enabled); - if (!host_receiver.Initialize(kCfMetricsQueueName)) { - LOG(ERROR) << "metrics host_receiver failed to init"; - return MetricsExitCodes::kMetricsError; - } - LOG(INFO) << "Metrics started"; - host_receiver.Join(); - return MetricsExitCodes::kMetricsError; -} - -} // namespace -} // namespace cuttlefish - -int main(int argc, char** argv) { return cuttlefish::MetricsMain(argc, argv); } diff --git a/base/cvd/cuttlefish/host/commands/metrics/send.cc b/base/cvd/cuttlefish/host/commands/metrics/send.cc deleted file mode 100644 index aea85a02f30..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/send.cc +++ /dev/null @@ -1,80 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/metrics/send.h" - -#include - -#include "absl/log/log.h" - -#include "cuttlefish/host/libs/metrics/metrics_defs.h" -#include "cuttlefish/host/libs/web/http_client/curl_global_init.h" -#include "cuttlefish/host/libs/web/http_client/curl_http_client.h" -#include "cuttlefish/host/libs/web/http_client/http_client.h" -#include "cuttlefish/host/libs/web/http_client/http_string.h" -#include "cuttlefish/result/result.h" - -namespace cuttlefish::metrics { -namespace { - -std::string ClearcutServerUrl(ClearcutServer server) { - switch (server) { - case ClearcutServer::kLocal: - return "http://localhost:27910/log"; - - case ClearcutServer::kStaging: - return "https://play.googleapis.com:443/staging/log"; - - case ClearcutServer::kProd: - return "https://play.googleapis.com:443/log"; - - default: - LOG(FATAL) << "Invalid host configuration"; - return ""; - } -} - -} // namespace - -MetricsExitCodes PostRequest(const std::string& output, ClearcutServer server) { - CurlGlobalInit curl_global_init; - std::unique_ptr http_client = CurlHttpClient(); - if (!http_client) { - return MetricsExitCodes::kMetricsError; - } - return PostRequest(*http_client, output, server); -} - -MetricsExitCodes PostRequest(HttpClient& http_client, const std::string& output, - ClearcutServer server) { - std::string clearcut_url = ClearcutServerUrl(server); - - Result> http_res = - HttpPostToString(http_client, clearcut_url, output); - if (!http_res.ok()) { - LOG(ERROR) << "HTTP command failed: " << http_res.error(); - return MetricsExitCodes::kMetricsError; - } - - if (!http_res->HttpSuccess()) { - LOG(ERROR) << "Metrics message failed: [" << http_res->data << "]"; - LOG(ERROR) << "http error code: " << http_res->http_code; - return MetricsExitCodes::kMetricsError; - } - LOG(INFO) << "Metrics posted to ClearCut"; - return MetricsExitCodes::kSuccess; -} - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/send.h b/base/cvd/cuttlefish/host/commands/metrics/send.h deleted file mode 100644 index d77ae76fe76..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/send.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include "cuttlefish/host/libs/metrics/metrics_defs.h" -#include "cuttlefish/host/libs/web/http_client/http_client.h" - -namespace cuttlefish::metrics { - -enum class ClearcutServer { - kLocal = 0, - kStaging = 1, - kProd = 2, -}; - -MetricsExitCodes PostRequest(const std::string& output, ClearcutServer server); -MetricsExitCodes PostRequest(HttpClient&, const std::string& output, - ClearcutServer server); - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/utils.cc b/base/cvd/cuttlefish/host/commands/metrics/utils.cc deleted file mode 100644 index 8d7bd0b5a24..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/utils.cc +++ /dev/null @@ -1,127 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/metrics/utils.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "absl/log/log.h" - -namespace cuttlefish::metrics { - -static std::string Hashing(const std::string& input) { - const std::hash hasher; - return std::to_string(hasher(input)); -} - -std::string GetOsName() { - struct utsname buf; - if (uname(&buf) != 0) { - LOG(ERROR) << "failed to retrieve system information"; - return "Error"; - } - return std::string(buf.sysname); -} - -std::string GenerateSessionId(uint64_t now_ms) { - uint64_t now_day = now_ms / 1000 / 60 / 60 / 24; - return Hashing(GetMacAddress() + std::to_string(now_day)); -} - -std::string GetCfVersion() { - // TODO: per ellisr@ leave empty for now - return ""; -} - -std::string GetOsVersion() { - struct utsname buf; - if (uname(&buf) != 0) { - LOG(ERROR) << "failed to retrieve system information"; - } - std::string version = buf.release; - return version; -} - -std::string GetMacAddress() { - int sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP); - if (sock == -1) { - LOG(ERROR) << "couldn't connect to socket"; - return ""; - } - - char buf2[1024]; - struct ifconf ifc; - ifc.ifc_len = sizeof(buf2); - ifc.ifc_buf = buf2; - if (ioctl(sock, SIOCGIFCONF, &ifc) == -1) { - LOG(ERROR) << "couldn't connect to socket"; - return ""; - } - - struct ifreq* it = ifc.ifc_req; - const struct ifreq* const end = it + (ifc.ifc_len / sizeof(struct ifreq)); - - unsigned char mac_address[6] = {0}; - struct ifreq ifr; - for (; it != end; ++it) { - strncpy(ifr.ifr_name, it->ifr_name, strlen(it->ifr_name)); - if (ioctl(sock, SIOCGIFFLAGS, &ifr) != 0) { - LOG(ERROR) << "couldn't connect to socket"; - return ""; - } - if (ifr.ifr_flags & IFF_LOOPBACK) { - continue; - } - if (ioctl(sock, SIOCGIFHWADDR, &ifr) == 0) { - memcpy(mac_address, ifr.ifr_hwaddr.sa_data, 6); - break; - } - } - - char mac[100]; - sprintf(mac, "%02x:%02x:%02x:%02x:%02x:%02x", mac_address[0], mac_address[1], - mac_address[2], mac_address[3], mac_address[4], mac_address[5]); - return mac; -} - -std::string GetCompany() { - // TODO: per ellisr@ leave hard-coded for now - return "GOOGLE"; -} - -std::string GetVmmVersion() { - // TODO: per ellisr@ leave empty for now - return ""; -} - -uint64_t GetEpochTimeMs() { - auto now = std::chrono::system_clock::now().time_since_epoch(); - uint64_t milliseconds_since_epoch = - std::chrono::duration_cast(now).count(); - return milliseconds_since_epoch; -} - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/utils.h b/base/cvd/cuttlefish/host/commands/metrics/utils.h deleted file mode 100644 index 354b6503adf..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/utils.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -#include - -namespace cuttlefish::metrics { - -std::string GetOsName(); -std::string GetOsVersion(); -std::string GenerateSessionId(uint64_t now); -std::string GetCfVersion(); -std::string GetMacAddress(); -std::string GetCompany(); -std::string GetVmmVersion(); -uint64_t GetEpochTimeMs(); - -} // namespace cuttlefish::metrics diff --git a/base/cvd/cuttlefish/host/commands/metrics/utils_tests.cpp b/base/cvd/cuttlefish/host/commands/metrics/utils_tests.cpp deleted file mode 100644 index 2cd73178188..00000000000 --- a/base/cvd/cuttlefish/host/commands/metrics/utils_tests.cpp +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "gtest/gtest.h" - -#include "cuttlefish/host/commands/metrics/utils.h" - -namespace cuttlefish { -TEST(MacAddressTest, ValidMacAddress) { - std::string mac = metrics::GetMacAddress(); - ASSERT_FALSE(mac.empty()); - EXPECT_EQ(mac.size(), 17); // Ensure MAC address has correct length - // Add other assertions as needed -} - -TEST(MacAddressTest, MacAddressFormat) { - std::string mac = metrics::GetMacAddress(); - // Ensure MAC address has the correct format (e.g., XX:XX:XX:XX:XX:XX) - EXPECT_EQ(mac[2], ':'); - EXPECT_EQ(mac[5], ':'); - EXPECT_EQ(mac[8], ':'); - EXPECT_EQ(mac[11], ':'); - EXPECT_EQ(mac[14], ':'); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/package/BUILD.bazel b/base/cvd/cuttlefish/package/BUILD.bazel index 27e806c8e6b..56778267fae 100644 --- a/base/cvd/cuttlefish/package/BUILD.bazel +++ b/base/cvd/cuttlefish/package/BUILD.bazel @@ -64,7 +64,6 @@ package_files( "cuttlefish-common/bin/lpmake": "@android_system_extras//:lpmake", "cuttlefish-common/bin/lz4": "@lz4//programs:lz4", "cuttlefish-common/bin/make_f2fs": "@f2fs_tools//:make_f2fs", - "cuttlefish-common/bin/metrics": "//cuttlefish/host/commands/metrics", "cuttlefish-common/bin/mkbootfs": "//mkbootfs", "cuttlefish-common/bin/mkbootimg.py": "@mkbootimg//:mkbootimg.py", "cuttlefish-common/bin/mke2fs": "@e2fsprogs//:mke2fs", From 84d2690cfaf3e5794dcf5d7c98b89627bd032dae Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Thu, 9 Jul 2026 17:32:32 -0700 Subject: [PATCH 3/5] Rename directory to match remaining code With the v1 metrics code deleted, the only code left is for the `metrics_transmitter` binary. Rename the directory to match that purpose. Bug: 463443661 --- .../commands/{metrics => metrics_transmitter}/BUILD.bazel | 8 ++++---- .../{metrics => metrics_transmitter}/debug_reader.cc | 2 +- .../{metrics => metrics_transmitter}/debug_reader.h | 0 .../metrics_conversion.cc | 2 +- .../{metrics => metrics_transmitter}/metrics_conversion.h | 0 .../{metrics => metrics_transmitter}/metrics_flags.cc | 2 +- .../{metrics => metrics_transmitter}/metrics_flags.h | 0 .../metrics_transmission.cc | 2 +- .../metrics_transmission.h | 0 .../metrics_transmitter.cc | 8 ++++---- base/cvd/cuttlefish/package/BUILD.bazel | 2 +- 11 files changed, 13 insertions(+), 13 deletions(-) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/BUILD.bazel (87%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/debug_reader.cc (95%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/debug_reader.h (100%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_conversion.cc (96%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_conversion.h (100%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_flags.cc (97%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_flags.h (100%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_transmission.cc (96%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_transmission.h (100%) rename base/cvd/cuttlefish/host/commands/{metrics => metrics_transmitter}/metrics_transmitter.cc (86%) diff --git a/base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/commands/metrics_transmitter/BUILD.bazel similarity index 87% rename from base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/BUILD.bazel index 136a1f964c1..f01246b46dd 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/metrics_transmitter/BUILD.bazel @@ -75,10 +75,10 @@ cf_cc_binary( ], deps = [ "//cuttlefish/common/libs/utils:tee_logging", - "//cuttlefish/host/commands/metrics:debug_reader", - "//cuttlefish/host/commands/metrics:metrics_conversion", - "//cuttlefish/host/commands/metrics:metrics_flags", - "//cuttlefish/host/commands/metrics:metrics_transmission", + "//cuttlefish/host/commands/metrics_transmitter:debug_reader", + "//cuttlefish/host/commands/metrics_transmitter:metrics_conversion", + "//cuttlefish/host/commands/metrics_transmitter:metrics_flags", + "//cuttlefish/host/commands/metrics_transmitter:metrics_transmission", "//cuttlefish/result", "//external_proto:clientanalytics_cc_proto", "@abseil-cpp//absl/log", diff --git a/base/cvd/cuttlefish/host/commands/metrics/debug_reader.cc b/base/cvd/cuttlefish/host/commands/metrics_transmitter/debug_reader.cc similarity index 95% rename from base/cvd/cuttlefish/host/commands/metrics/debug_reader.cc rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/debug_reader.cc index f3abb163dbf..11530f2dc4d 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/debug_reader.cc +++ b/base/cvd/cuttlefish/host/commands/metrics_transmitter/debug_reader.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "cuttlefish/host/commands/metrics/debug_reader.h" +#include "cuttlefish/host/commands/metrics_transmitter/debug_reader.h" #include diff --git a/base/cvd/cuttlefish/host/commands/metrics/debug_reader.h b/base/cvd/cuttlefish/host/commands/metrics_transmitter/debug_reader.h similarity index 100% rename from base/cvd/cuttlefish/host/commands/metrics/debug_reader.h rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/debug_reader.h diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_conversion.cc b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_conversion.cc similarity index 96% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_conversion.cc rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_conversion.cc index 278463f24bd..d354ef39ff3 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/metrics_conversion.cc +++ b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_conversion.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "cuttlefish/host/commands/metrics/metrics_conversion.h" +#include "cuttlefish/host/commands/metrics_transmitter/metrics_conversion.h" #include #include diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_conversion.h b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_conversion.h similarity index 100% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_conversion.h rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_conversion.h diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_flags.cc b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_flags.cc similarity index 97% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_flags.cc rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_flags.cc index 8871af2f063..f425370bd81 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/metrics_flags.cc +++ b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_flags.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "cuttlefish/host/commands/metrics/metrics_flags.h" +#include "cuttlefish/host/commands/metrics_transmitter/metrics_flags.h" #include #include diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_flags.h b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_flags.h similarity index 100% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_flags.h rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_flags.h diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_transmission.cc b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmission.cc similarity index 96% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_transmission.cc rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmission.cc index eab8df471fa..db0f55ad3c1 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/metrics_transmission.cc +++ b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmission.cc @@ -14,7 +14,7 @@ * limitations under the License. */ -#include "cuttlefish/host/commands/metrics/metrics_transmission.h" +#include "cuttlefish/host/commands/metrics_transmitter/metrics_transmission.h" #include #include diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_transmission.h b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmission.h similarity index 100% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_transmission.h rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmission.h diff --git a/base/cvd/cuttlefish/host/commands/metrics/metrics_transmitter.cc b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmitter.cc similarity index 86% rename from base/cvd/cuttlefish/host/commands/metrics/metrics_transmitter.cc rename to base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmitter.cc index 22b8757bf31..822afe07034 100644 --- a/base/cvd/cuttlefish/host/commands/metrics/metrics_transmitter.cc +++ b/base/cvd/cuttlefish/host/commands/metrics_transmitter/metrics_transmitter.cc @@ -19,10 +19,10 @@ #include "absl/log/log.h" #include "cuttlefish/common/libs/utils/tee_logging.h" -#include "cuttlefish/host/commands/metrics/debug_reader.h" -#include "cuttlefish/host/commands/metrics/metrics_conversion.h" -#include "cuttlefish/host/commands/metrics/metrics_flags.h" -#include "cuttlefish/host/commands/metrics/metrics_transmission.h" +#include "cuttlefish/host/commands/metrics_transmitter/debug_reader.h" +#include "cuttlefish/host/commands/metrics_transmitter/metrics_conversion.h" +#include "cuttlefish/host/commands/metrics_transmitter/metrics_flags.h" +#include "cuttlefish/host/commands/metrics_transmitter/metrics_transmission.h" #include "cuttlefish/result/result.h" #include "external_proto/clientanalytics.pb.h" diff --git a/base/cvd/cuttlefish/package/BUILD.bazel b/base/cvd/cuttlefish/package/BUILD.bazel index 56778267fae..0e28b1ecf4a 100644 --- a/base/cvd/cuttlefish/package/BUILD.bazel +++ b/base/cvd/cuttlefish/package/BUILD.bazel @@ -150,7 +150,7 @@ package_files( name = "metrics", executable = "cuttlefish-metrics/bin/metrics_transmitter", package_file_to_src = { - "cuttlefish-metrics/bin/metrics_transmitter": "//cuttlefish/host/commands/metrics:metrics_transmitter", + "cuttlefish-metrics/bin/metrics_transmitter": "//cuttlefish/host/commands/metrics_transmitter:metrics_transmitter", }, visibility = ["//:android_cuttlefish"], ) From 9916f843854cab507f8c43e2fec079b13c309e9c Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Thu, 9 Jul 2026 17:39:45 -0700 Subject: [PATCH 4/5] Delete v1 metrics from host/libs/metrics And the transitive deletions that follow from those. Keep the `report_anonymous_usage_stats` flag definitions to avoid breaking compatibility, but no longer use those values. Reserving the deleted proto field number and identifier to avoid backwards incompatible changes with serialization or TextProto/JSON encodings. Bug: 463443661 --- .../assemble_cvd/assemble_cvd_flags.cpp | 5 +- .../host/commands/assemble_cvd/flags.cc | 3 - .../commands/assemble_cvd/flags_defaults.h | 4 - .../host/commands/cvd/cli/commands/create.cpp | 2 + .../host/commands/cvd/cli/commands/start.cpp | 41 ++--- .../host/commands/cvd/cli/commands/start.h | 1 - .../host/commands/run_cvd/BUILD.bazel | 2 - .../host/commands/run_cvd/launch/BUILD.bazel | 12 -- .../host/commands/run_cvd/launch/metrics.cpp | 34 ---- .../host/commands/run_cvd/launch/metrics.h | 27 --- .../cuttlefish/host/commands/run_cvd/main.cc | 7 - .../host/commands/start/BUILD.bazel | 2 - .../cuttlefish/host/commands/start/main.cc | 4 - .../host/commands/start/start_flags.cpp | 5 +- .../start/validate_metrics_confirmation.cpp | 87 ---------- .../start/validate_metrics_confirmation.h | 23 --- .../cuttlefish/host/commands/stop/BUILD.bazel | 1 - .../cvd/cuttlefish/host/commands/stop/main.cc | 7 - .../host/libs/config/cuttlefish_config.cpp | 45 ----- .../host/libs/config/cuttlefish_config.h | 12 -- .../host/libs/config/known_paths.cpp | 2 - .../cuttlefish/host/libs/config/known_paths.h | 1 - .../cuttlefish/host/libs/metrics/BUILD.bazel | 27 --- .../host/libs/metrics/metrics_configs.h | 34 ---- .../host/libs/metrics/metrics_defs.h | 26 --- .../host/libs/metrics/metrics_receiver.cc | 73 -------- .../host/libs/metrics/metrics_receiver.h | 34 ---- .../host/libs/metrics/notification.cc | 32 ---- .../host/libs/metrics/notification.h | 2 - .../host/libs/msg_queue/BUILD.bazel | 21 --- .../cuttlefish/host/libs/msg_queue/README.md | 57 ------- .../host/libs/msg_queue/msg_queue.cc | 120 ------------- .../host/libs/msg_queue/msg_queue.h | 36 ---- base/cvd/external_proto/BUILD.bazel | 15 -- base/cvd/external_proto/cf_log.proto | 9 +- .../cvd/external_proto/cf_metrics_event.proto | 161 ------------------ 36 files changed, 24 insertions(+), 950 deletions(-) delete mode 100644 base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.h delete mode 100644 base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.h delete mode 100644 base/cvd/cuttlefish/host/libs/metrics/metrics_configs.h delete mode 100644 base/cvd/cuttlefish/host/libs/metrics/metrics_defs.h delete mode 100644 base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.cc delete mode 100644 base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.h delete mode 100644 base/cvd/cuttlefish/host/libs/msg_queue/BUILD.bazel delete mode 100644 base/cvd/cuttlefish/host/libs/msg_queue/README.md delete mode 100644 base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.cc delete mode 100644 base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.h delete mode 100644 base/cvd/external_proto/cf_metrics_event.proto diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp index 826ceb7b0e9..37f4125cd97 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.cpp @@ -235,10 +235,7 @@ DEFINE_int32(num_instances, CF_DEFAULTS_NUM_INSTANCES, DEFINE_string(instance_nums, CF_DEFAULTS_INSTANCE_NUMS, "A comma-separated list of instance numbers " "to use. Mutually exclusive with base_instance_num."); -DEFINE_string(report_anonymous_usage_stats, - CF_DEFAULTS_REPORT_ANONYMOUS_USAGE_STATS, - "Report anonymous usage " - "statistics for metrics collection and analysis."); +DEFINE_string(report_anonymous_usage_stats, "", "Deprecated, no usage."); DEFINE_vec(ril_dns, CF_DEFAULTS_RIL_DNS, "DNS address of mobile network (RIL)"); DEFINE_vec(kgdb, fmt::format("{}", CF_DEFAULTS_KGDB), "Configure the virtual device for debugging the kernel " diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc index b9ef55a3c47..0e15881b33f 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc @@ -430,9 +430,6 @@ Result InitializeCuttlefishConfiguration( tmp_config_obj.set_sig_server_address(FLAGS_webrtc_sig_server_addr); - tmp_config_obj.set_enable_metrics(FLAGS_report_anonymous_usage_stats); - // TODO(moelsherif): Handle this flag (set_metrics_binary) in the future - std::optional guest_config_mac80211_hwsim = guest_configs[0].enforce_mac80211_hwsim; if (guest_config_mac80211_hwsim.has_value()) { diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags_defaults.h b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags_defaults.h index 8b47a93d487..1d0192e9554 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags_defaults.h +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags_defaults.h @@ -242,10 +242,6 @@ #define CF_DEFAULTS_FIXED_LOCATION_FILE_PATH CF_DEFAULTS_DYNAMIC_STRING #define CF_DEFAULTS_GNSS_FILE_PATH CF_DEFAULTS_DYNAMIC_STRING -// Metrics default parameters -// TODO: Defined twice , please remove redundant definitions -#define CF_DEFAULTS_REPORT_ANONYMOUS_USAGE_STATS CF_DEFAULTS_DYNAMIC_STRING - // MCU emulator default configuration path #define CF_DEFAULTS_MCU_CONFIG_PATH CF_DEFAULTS_DYNAMIC_STRING diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp index c209d85f9e4..f09e8a947b0 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/create.cpp @@ -208,6 +208,8 @@ Result CreateSymlinks(const LocalInstanceGroup& group) { // dangling. The config file in the home directory is used by // cvd_internal_start to persist the user's choice for // -report_anonymous_usage_stats. + // NOTE: --report_anonymous_usage_stats flag and its value in the config are + // deprecated CF_EXPECT( Copy(group.Instances()[0].InstanceDirectory() + "/cuttlefish_config.json", CF_EXPECT(SystemWideUserHome()) + "/.cuttlefish_config.json"), diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp index 5603969c1bd..7f67a4f55b2 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.cpp @@ -334,10 +334,8 @@ CvdStartCommandHandler::CvdStartCommandHandler( static bool HasUnsafeFlagsForBypass(const std::vector& args) { std::vector args_copy = args; bool daemon = true; - std::string report_anonymous = ""; std::vector safe_flags = { GflagsCompatFlag("daemon", daemon), - GflagsCompatFlag("report_anonymous_usage_stats", report_anonymous), }; auto res = ConsumeFlags(safe_flags, args_copy); if (!res.ok()) { @@ -374,15 +372,6 @@ Result CvdStartCommandHandler::Handle(const CommandRequest& request) { CF_EXPECT(ConsumeFlags(BuildOwnFlags(), subcmd_args)); subcmd_args.push_back("--daemon=true"); - if (own_flags_.report_anonymous_usage_stats) { - subcmd_args.push_back("--report_anonymous_usage_stats=" + - *own_flags_.report_anonymous_usage_stats); - } else if (!own_flags_.daemon) { - // If the user did not specify the anonymous usage stats flag, default it - // to 'n' to ensure that cvd_internal_start does not block waiting for - // input on stdin. - subcmd_args.push_back("--report_anonymous_usage_stats=n"); - } LocalInstanceGroup group = CF_EXPECT(selector::SelectGroup(instance_manager_, request), @@ -572,6 +561,8 @@ Result CvdStartCommandHandler::LaunchDeviceInterruptible( // determine the default value for the -report_anonymous_usage_stats flag so // we symlink that to the group's home directory, this link will be // overwritten later by cvd_internal_start itself. + // NOTE: --report_anonymous_usage_stats flag and its value in the config are + // deprecated auto symlink_config_res = SymlinkPreviousConfig(group.HomeDir()); if (!symlink_config_res.ok()) { LOG(ERROR) << "Failed to symlink the config file at system wide home: " @@ -687,21 +678,19 @@ Result> CvdStartCommandHandler::Flags( } std::vector CvdStartCommandHandler::BuildOwnFlags() { - return {GflagsCompatFlag("host_substitutions", own_flags_.host_substitutions) - .Help("Comma separated list of files to replace in the host " - "artifacts from the android build with artifacts from the " - "cuttlefish-base package. The special value \"all\" causes " - "it to replace everything it can, while with an empty it " - "will replace what the android build specifies in the " - "'debian_substitution_marker' file."), - GflagsCompatFlag("daemon", own_flags_.daemon) - .Help("Run the start command in the background as a daemon. " - "If false, the command runs in the foreground and monitors " - "logs."), - GflagsCompatFlag("report_anonymous_usage_stats", - own_flags_.report_anonymous_usage_stats) - .Help("Report anonymous usage stats. In foreground mode, " - "defaults to 'n' if not specified.")}; + return { + GflagsCompatFlag("host_substitutions", own_flags_.host_substitutions) + .Help("Comma separated list of files to replace in the host " + "artifacts from the android build with artifacts from the " + "cuttlefish-base package. The special value \"all\" causes " + "it to replace everything it can, while with an empty it " + "will replace what the android build specifies in the " + "'debian_substitution_marker' file."), + GflagsCompatFlag("daemon", own_flags_.daemon) + .Help("Run the start command in the background as a daemon. " + "If false, the command runs in the foreground and monitors " + "logs."), + }; } } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.h b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.h index 3f118c65ea4..6e029a7f8ae 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.h +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/commands/start.h @@ -66,7 +66,6 @@ class CvdStartCommandHandler : public CvdCommandHandler { struct { std::vector host_substitutions; bool daemon; - std::optional report_anonymous_usage_stats; } own_flags_; }; diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel b/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel index 33bc4b3acfc..ea39d0499f7 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/run_cvd/BUILD.bazel @@ -80,7 +80,6 @@ cf_cc_binary( "//cuttlefish/host/commands/run_cvd/launch:kernel_log_monitor", "//cuttlefish/host/commands/run_cvd/launch:logcat_receiver", "//cuttlefish/host/commands/run_cvd/launch:mcu", - "//cuttlefish/host/commands/run_cvd/launch:metrics", "//cuttlefish/host/commands/run_cvd/launch:modem", "//cuttlefish/host/commands/run_cvd/launch:netsim_server", "//cuttlefish/host/commands/run_cvd/launch:nfc_connector", @@ -112,7 +111,6 @@ cf_cc_binary( "//cuttlefish/host/libs/feature", "//cuttlefish/host/libs/feature:inject", "//cuttlefish/host/libs/log_names", - "//cuttlefish/host/libs/metrics", "//cuttlefish/host/libs/version", "//cuttlefish/host/libs/vm_manager", "//cuttlefish/result", diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel b/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel index e1a69222c69..269b72e7970 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel @@ -270,18 +270,6 @@ cf_cc_library( ], ) -cf_cc_library( - name = "metrics", - srcs = ["metrics.cpp"], - hdrs = ["metrics.h"], - deps = [ - "//cuttlefish/host/libs/config:cuttlefish_config", - "//cuttlefish/host/libs/config:known_paths", - "//cuttlefish/host/libs/feature", - "//cuttlefish/process:command", - ], -) - cf_cc_library( name = "modem", srcs = ["modem.cpp"], diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.cpp deleted file mode 100644 index 7e01646a7fa..00000000000 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.cpp +++ /dev/null @@ -1,34 +0,0 @@ -// -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/run_cvd/launch/metrics.h" - -#include - -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/config/known_paths.h" -#include "cuttlefish/host/libs/feature/command_source.h" -#include "cuttlefish/process/command.h" - -namespace cuttlefish { - -std::optional MetricsService(const CuttlefishConfig& config) { - if (config.enable_metrics() != cuttlefish::CuttlefishConfig::Answer::kYes) { - return {}; - } - return Command(MetricsBinary()); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.h b/base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.h deleted file mode 100644 index 691147db523..00000000000 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/metrics.h +++ /dev/null @@ -1,27 +0,0 @@ -// -// Copyright (C) 2019 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#pragma once - -#include - -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/feature/command_source.h" - -namespace cuttlefish { - -std::optional MetricsService(const CuttlefishConfig& config); - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/main.cc b/base/cvd/cuttlefish/host/commands/run_cvd/main.cc index dc676f4115a..1f247c344de 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/main.cc +++ b/base/cvd/cuttlefish/host/commands/run_cvd/main.cc @@ -45,7 +45,6 @@ #include "cuttlefish/host/commands/run_cvd/launch/kernel_log_monitor.h" #include "cuttlefish/host/commands/run_cvd/launch/logcat_receiver.h" #include "cuttlefish/host/commands/run_cvd/launch/mcu.h" -#include "cuttlefish/host/commands/run_cvd/launch/metrics.h" #include "cuttlefish/host/commands/run_cvd/launch/modem.h" #include "cuttlefish/host/commands/run_cvd/launch/netsim_server.h" #include "cuttlefish/host/commands/run_cvd/launch/nfc_connector.h" @@ -79,7 +78,6 @@ #include "cuttlefish/host/libs/feature/feature.h" #include "cuttlefish/host/libs/feature/inject.h" #include "cuttlefish/host/libs/log_names/log_names.h" -#include "cuttlefish/host/libs/metrics/metrics_receiver.h" #include "cuttlefish/host/libs/version/version.h" #include "cuttlefish/host/libs/vm_manager/vm_manager.h" #include "cuttlefish/result/result.h" @@ -192,7 +190,6 @@ fruit::Component<> runCvdComponent( .install(AutoCmd::Component) .install(AutoCmd::Component) .install(KernelLogMonitorComponent) - .install(AutoCmd::Component) .install(OpenwrtControlServerComponent) .install(AutoCmd::Component) .install(RootCanalComponent) @@ -262,10 +259,6 @@ Result RunCvdMain(int argc, char** argv) { CF_EXPECT(late_injected->LateInject(injector)); } - if (config->enable_metrics() == cuttlefish::CuttlefishConfig::Answer::kYes) { - MetricsReceiver::LogMetricsVMStart(); - } - auto instance_bindings = injector.getMultibindings(); CF_EXPECT(instance_bindings.size() == 1); CF_EXPECT(instance_bindings[0]->Run()); // Should not return diff --git a/base/cvd/cuttlefish/host/commands/start/BUILD.bazel b/base/cvd/cuttlefish/host/commands/start/BUILD.bazel index d8d71af8857..655ae850af7 100644 --- a/base/cvd/cuttlefish/host/commands/start/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/start/BUILD.bazel @@ -14,8 +14,6 @@ cf_cc_binary( "main.cc", "override_bool_arg.cpp", "override_bool_arg.h", - "validate_metrics_confirmation.cpp", - "validate_metrics_confirmation.h", ], depend_on_what_you_use_enabled = False, # `layering_check` conflicts with the combination of the clang prebuilt and diff --git a/base/cvd/cuttlefish/host/commands/start/main.cc b/base/cvd/cuttlefish/host/commands/start/main.cc index fc9669a9572..637ac820d5a 100644 --- a/base/cvd/cuttlefish/host/commands/start/main.cc +++ b/base/cvd/cuttlefish/host/commands/start/main.cc @@ -38,7 +38,6 @@ #include "cuttlefish/host/commands/start/flag_forwarder.h" #include "cuttlefish/host/commands/start/override_bool_arg.h" #include "cuttlefish/host/commands/start/start_flags.h" -#include "cuttlefish/host/commands/start/validate_metrics_confirmation.h" #include "cuttlefish/host/libs/config/config_constants.h" #include "cuttlefish/host/libs/config/config_utils.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" @@ -296,9 +295,6 @@ int CvdInternalStartMain(int argc, char** argv) { setenv("CF_CONSOLE_SEVERITY", FLAGS_verbosity.c_str(), /* replace */ false); setenv("CF_FILE_SEVERITY", FLAGS_file_verbosity.c_str(), /* replace */ false); - auto use_metrics = FLAGS_report_anonymous_usage_stats; - FLAGS_report_anonymous_usage_stats = ValidateMetricsConfirmation(use_metrics); - if (FLAGS_track_host_tools_crc) { // TODO(b/159068082) Make decisions based on this value in assemble_cvd LOG(INFO) << "Host changed from last run: " << HostToolsUpdated(); diff --git a/base/cvd/cuttlefish/host/commands/start/start_flags.cpp b/base/cvd/cuttlefish/host/commands/start/start_flags.cpp index 8afff7b205d..f76cb75f0aa 100644 --- a/base/cvd/cuttlefish/host/commands/start/start_flags.cpp +++ b/base/cvd/cuttlefish/host/commands/start/start_flags.cpp @@ -22,10 +22,7 @@ DEFINE_int32(num_instances, CF_DEFAULTS_NUM_INSTANCES, "Number of Android guests to launch"); -DEFINE_string(report_anonymous_usage_stats, - CF_DEFAULTS_REPORT_ANONYMOUS_USAGE_STATS, - "Report anonymous usage " - "statistics for metrics collection and analysis."); +DEFINE_string(report_anonymous_usage_stats, "", "Deprecated, no usage."); DEFINE_int32( base_instance_num, CF_DEFAULTS_BASE_INSTANCE_NUM, "The instance number of the device created. When `-num_instances N`" diff --git a/base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.cpp b/base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.cpp deleted file mode 100644 index 08db3a740f0..00000000000 --- a/base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// -// Copyright (C) 2020 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/commands/start/validate_metrics_confirmation.h" - -#include -#include -#include - -#include "android-base/macros.h" - -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/metrics/notification.h" - -namespace cuttlefish { -namespace { - -constexpr std::string_view kFirstAnswerPrompt = - "Automatically send diagnostic information to Google from this Android " - "Virtual Device. (Y/n)?:"; -constexpr std::string_view kMustAnswerPrompt = - "Must accept/reject anonymous usage statistics reporting. "; - -} // namespace - -std::string ValidateMetricsConfirmation(std::string use_metrics) { - if (use_metrics.empty()) { - if (CuttlefishConfig::ConfigExists()) { - auto config = CuttlefishConfig::Get(); - if (config) { - if (config->enable_metrics() == CuttlefishConfig::Answer::kYes) { - use_metrics = "y"; - } else if (config->enable_metrics() == CuttlefishConfig::Answer::kNo) { - use_metrics = "n"; - } - } - } - } - - char ch = !use_metrics.empty() ? tolower(use_metrics.at(0)) : -1; - if (ch != 'n') { - if (use_metrics.empty()) { - std::cout << kFirstAnswerPrompt; - } - } - std::string result; - while (result.empty()) { - switch (ch) { - case 0: - case '\r': - case '\n': - case 'y': - result = "y"; - break; - case 'n': - result = "n"; - break; - default: - std::cout << kMustAnswerPrompt << kFirstAnswerPrompt; - FALLTHROUGH_INTENDED; - case -1: - std::cin.get(ch); - // if there's no tty the EOF flag is set, in which case default to 'n' - if (std::cin.eof()) { - ch = 'n'; - std::cout << "n\n"; // for consistency with user input - } - ch = tolower(ch); - } - } - DisplayAdjustmentNoticeOnce(); - return result; -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.h b/base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.h deleted file mode 100644 index 8976eb6b4e1..00000000000 --- a/base/cvd/cuttlefish/host/commands/start/validate_metrics_confirmation.h +++ /dev/null @@ -1,23 +0,0 @@ -// -// Copyright (C) 2020 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -#pragma once - -#include - -namespace cuttlefish { - -std::string ValidateMetricsConfirmation(std::string use_metrics); - -} diff --git a/base/cvd/cuttlefish/host/commands/stop/BUILD.bazel b/base/cvd/cuttlefish/host/commands/stop/BUILD.bazel index 53ce6ed9de5..c0d3ee9fadb 100644 --- a/base/cvd/cuttlefish/host/commands/stop/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/stop/BUILD.bazel @@ -16,7 +16,6 @@ cf_cc_binary( "//cuttlefish/flag_parser", "//cuttlefish/host/libs/command_util", "//cuttlefish/host/libs/config:cuttlefish_config", - "//cuttlefish/host/libs/metrics", "//cuttlefish/posix:strerror", "//cuttlefish/result", "//libbase", diff --git a/base/cvd/cuttlefish/host/commands/stop/main.cc b/base/cvd/cuttlefish/host/commands/stop/main.cc index dc7f306ffeb..2342b0e9f9c 100644 --- a/base/cvd/cuttlefish/host/commands/stop/main.cc +++ b/base/cvd/cuttlefish/host/commands/stop/main.cc @@ -40,7 +40,6 @@ #include "cuttlefish/host/libs/command_util/runner/defs.h" #include "cuttlefish/host/libs/command_util/util.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/metrics/metrics_receiver.h" #include "cuttlefish/posix/strerror.h" #include "cuttlefish/result/result.h" @@ -271,12 +270,6 @@ int main(int argc, char** argv) { return 134; } - if (cuttlefish::CuttlefishConfig::Get() && - cuttlefish::CuttlefishConfig::Get()->enable_metrics() == - cuttlefish::CuttlefishConfig::Answer::kYes) { - cuttlefish::MetricsReceiver::LogMetricsVMStop(); - } - return cuttlefish::StopCvdMain(wait_for_launcher, clear_instance_dirs, instance_nums); } diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp index a784dad5769..ebb04e9deb3 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp @@ -321,51 +321,6 @@ std::vector CuttlefishConfig::netsim_args() const { return netsim_args; } -static constexpr char kEnableMetrics[] = "enable_metrics"; -void CuttlefishConfig::set_enable_metrics(std::string enable_metrics) { - (*dictionary_)[kEnableMetrics] = - static_cast(cuttlefish::CuttlefishConfig::Answer::kUnknown); - if (!enable_metrics.empty()) { - switch (enable_metrics.at(0)) { - case 'y': - case 'Y': - (*dictionary_)[kEnableMetrics] = - static_cast(cuttlefish::CuttlefishConfig::Answer::kYes); - break; - case 'n': - case 'N': - (*dictionary_)[kEnableMetrics] = - static_cast(cuttlefish::CuttlefishConfig::Answer::kNo); - break; - } - } -} - -// validate the casting and conversion from json configs to -// CuttlefishConfig::Answer class -bool IsValidMetricsConfigs(int value) { - return value == static_cast(CuttlefishConfig::Answer::kUnknown) || - value == static_cast(CuttlefishConfig::Answer::kNo) || - value == static_cast(CuttlefishConfig::Answer::kYes); -} - -CuttlefishConfig::Answer CuttlefishConfig::enable_metrics() const { - int value = (*dictionary_)[kEnableMetrics].asInt(); - if (!IsValidMetricsConfigs(value)) { - LOG(ERROR) << "Invalid integer value for Answer enum"; - return static_cast(CuttlefishConfig::Answer::kUnknown); - } - return static_cast(value); -} - -static constexpr char kMetricsBinary[] = "metrics_binary"; -void CuttlefishConfig::set_metrics_binary(const std::string& metrics_binary) { - (*dictionary_)[kMetricsBinary] = metrics_binary; -} -std::string CuttlefishConfig::metrics_binary() const { - return (*dictionary_)[kMetricsBinary].asString(); -} - static constexpr char kExtraKernelCmdline[] = "extra_kernel_cmdline"; void CuttlefishConfig::set_extra_kernel_cmdline( const std::string& extra_cmdline) { diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h index 0a667ab4473..8bb23142620 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h @@ -178,18 +178,6 @@ class CuttlefishConfig { void set_netsim_args(const std::string& netsim_args); std::vector netsim_args() const; - enum class Answer { - kUnknown = 0, - kYes, - kNo, - }; - - void set_enable_metrics(std::string enable_metrics); - CuttlefishConfig::Answer enable_metrics() const; - - void set_metrics_binary(const std::string& metrics_binary); - std::string metrics_binary() const; - void set_extra_kernel_cmdline(const std::string& extra_cmdline); std::vector extra_kernel_cmdline() const; diff --git a/base/cvd/cuttlefish/host/libs/config/known_paths.cpp b/base/cvd/cuttlefish/host/libs/config/known_paths.cpp index 587f0b912cb..341c0e7db32 100644 --- a/base/cvd/cuttlefish/host/libs/config/known_paths.cpp +++ b/base/cvd/cuttlefish/host/libs/config/known_paths.cpp @@ -109,8 +109,6 @@ std::string LogcatReceiverBinary() { return HostBinaryPath("logcat_receiver"); } std::string McopyBinary() { return HostBinaryPath("mcopy"); } -std::string MetricsBinary() { return HostBinaryPath("metrics"); } - std::string MkfsFat() { return HostBinaryPath("mkfs.fat"); } std::string MkuserimgMke2fsBinary() { diff --git a/base/cvd/cuttlefish/host/libs/config/known_paths.h b/base/cvd/cuttlefish/host/libs/config/known_paths.h index 066e4719510..5095ad58b06 100644 --- a/base/cvd/cuttlefish/host/libs/config/known_paths.h +++ b/base/cvd/cuttlefish/host/libs/config/known_paths.h @@ -42,7 +42,6 @@ std::string GnssGrpcProxyBinary(); std::string KernelLogMonitorBinary(); std::string LogcatReceiverBinary(); std::string McopyBinary(); -std::string MetricsBinary(); std::string MkfsFat(); std::string MkuserimgMke2fsBinary(); std::string MmdBinary(); diff --git a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel index 64e767f31e0..c33927b3189 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/metrics/BUILD.bazel @@ -139,25 +139,6 @@ cf_cc_library( deps = ["//cuttlefish/common/libs/utils:environment"], ) -cf_cc_library( - name = "metrics", - srcs = ["metrics_receiver.cc"], - hdrs = ["metrics_receiver.h"], - depend_on_what_you_use_enabled = False, - deps = [ - ":metrics_headers", - "//cuttlefish/common/libs/fs", - "//cuttlefish/common/libs/utils:tee_logging", - "//cuttlefish/host/libs/config:cuttlefish_config", - "//cuttlefish/host/libs/msg_queue", - "//libbase", - "@abseil-cpp//absl/log", - "@fruit", - "@gflags", - "@jsoncpp", - ], -) - cf_cc_library( name = "metrics_conversion", srcs = ["metrics_conversion.cc"], @@ -200,14 +181,6 @@ cf_cc_library( hdrs = ["metrics_environment.h"], ) -cf_cc_library( - name = "metrics_headers", - hdrs = [ - "metrics_configs.h", - "metrics_defs.h", - ], -) - cf_cc_library( name = "metrics_orchestration", srcs = ["metrics_orchestration.cc"], diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_configs.h b/base/cvd/cuttlefish/host/libs/metrics/metrics_configs.h deleted file mode 100644 index d2ea5646b89..00000000000 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_configs.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2023 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include - -namespace cuttlefish { - -// TODO(moelsherif) :review this value once we have a better idea of the size of -// the messages -const uint32_t MAX_MSG_SIZE = 200; - -typedef struct msg_buffer { - long mesg_type; - char mesg_text[MAX_MSG_SIZE]; -} msg_buffer; - -constexpr char kCfMetricsQueueName[] = "cf_metrics_msg_queue"; - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_defs.h b/base/cvd/cuttlefish/host/libs/metrics/metrics_defs.h deleted file mode 100644 index dc6a362689e..00000000000 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_defs.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -namespace cuttlefish { - -enum MetricsExitCodes : int { - kSuccess = 0, - kMetricsError = 1, - kInvalidHostConfiguration = 2, -}; - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.cc b/base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.cc deleted file mode 100644 index 85b229015f6..00000000000 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.cc +++ /dev/null @@ -1,73 +0,0 @@ -// -// Copyright (C) 2022 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "metrics_receiver.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "absl/log/log.h" -#include "gflags/gflags.h" - -#include "cuttlefish/common/libs/utils/tee_logging.h" -#include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/metrics/metrics_configs.h" -#include "cuttlefish/host/libs/metrics/metrics_defs.h" -#include "cuttlefish/host/libs/msg_queue/msg_queue.h" - -using cuttlefish::MetricsExitCodes; - -namespace cuttlefish { - -void SendHelper(const std::string& queue_name, const std::string& message) { - auto msg_queue = SysVMessageQueue::Create(queue_name, false); - if (msg_queue == NULL) { - LOG(FATAL) << "Create: failed to create" << queue_name; - } - - struct msg_buffer msg; - msg.mesg_type = 1; - strncpy(msg.mesg_text, message.c_str(), message.size()); - int rc = msg_queue->Send(&msg, message.length() + 1, true); - if (rc == -1) { - LOG(FATAL) << "Send: failed to send message to msg_queue"; - } -} - -void MetricsReceiver::LogMetricsVMStart() { - SendHelper(kCfMetricsQueueName, "VMStart"); -} - -void MetricsReceiver::LogMetricsVMStop() { - SendHelper(kCfMetricsQueueName, "VMStop"); -} - -void MetricsReceiver::LogMetricsDeviceBoot() { - SendHelper(kCfMetricsQueueName, "DeviceBoot"); -} - -void MetricsReceiver::LogMetricsLockScreen() { - SendHelper(kCfMetricsQueueName, "LockScreen"); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.h b/base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.h deleted file mode 100644 index d827d1f51e5..00000000000 --- a/base/cvd/cuttlefish/host/libs/metrics/metrics_receiver.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include - -namespace cuttlefish { - -class MetricsReceiver { - public: - MetricsReceiver() = default; - ; - ~MetricsReceiver() = default; - ; - static void LogMetricsVMStart(); - static void LogMetricsVMStop(); - static void LogMetricsDeviceBoot(); - static void LogMetricsLockScreen(); -}; - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/notification.cc b/base/cvd/cuttlefish/host/libs/metrics/notification.cc index b7ce23b2c85..e98379c4d48 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/notification.cc +++ b/base/cvd/cuttlefish/host/libs/metrics/notification.cc @@ -34,7 +34,6 @@ namespace cuttlefish { namespace { constexpr std::string_view kNoticeFilename = "PRIVACY_NOTICE.txt"; -constexpr std::string_view kAdjustmentFilename = "ADJUST_PERMISSIONS.txt"; constexpr std::string_view kTermsAndPrivacyNotice = "By using this Android Virtual Device, you agree to Google Terms of " @@ -47,28 +46,15 @@ constexpr std::string_view kMetricsEnabledNotice = "crash reports and usage data from the host machine managing the Android " "Virtual Device."; -constexpr std::string_view kAdjustmentNotice = - "You can adjust the permission for sending diagnostic information to " - "Google by running \"--report_anonymous_usage_stats=n\""; - Result GetNoticeFilepath() { return fmt::format("{}/{}", CF_EXPECT(CvdDataHome()), kNoticeFilename); } -Result GetAdjustmentFilepath() { - return fmt::format("{}/{}", CF_EXPECT(CvdDataHome()), kAdjustmentFilename); -} - Result WriteNoticeFile(const std::string& contents) { CF_EXPECT(WriteCvdDataFile(kNoticeFilename, contents)); return {}; } -Result WriteAdjustmentFile(const std::string& contents) { - CF_EXPECT(WriteCvdDataFile(kAdjustmentFilename, contents)); - return {}; -} - std::string GetNoticeMessage() { std::stringstream result; result << kTermsAndPrivacyNotice << std::endl; @@ -97,22 +83,4 @@ void DisplayPrivacyNotice() { } } -void DisplayAdjustmentNoticeOnce() { - Result filepath_result = GetAdjustmentFilepath(); - if (!filepath_result.ok()) { - VLOG(0) << "Failed generating adjustment filepath: " - << filepath_result.error(); - } else if (FileExists(*filepath_result)) { - return; - } - - std::cout << kAdjustmentNotice << "\n"; - - Result write_result = - WriteAdjustmentFile(absl::StrCat(kAdjustmentNotice, "\n")); - if (!write_result.ok()) { - VLOG(0) << "Failed writing adjustment file: " << write_result.error(); - } -} - } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/metrics/notification.h b/base/cvd/cuttlefish/host/libs/metrics/notification.h index 0e2fe39602d..a991cba406f 100644 --- a/base/cvd/cuttlefish/host/libs/metrics/notification.h +++ b/base/cvd/cuttlefish/host/libs/metrics/notification.h @@ -22,6 +22,4 @@ namespace cuttlefish { void DisplayPrivacyNotice(); -void DisplayAdjustmentNoticeOnce(); - } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/msg_queue/BUILD.bazel b/base/cvd/cuttlefish/host/libs/msg_queue/BUILD.bazel deleted file mode 100644 index ab91b73aec0..00000000000 --- a/base/cvd/cuttlefish/host/libs/msg_queue/BUILD.bazel +++ /dev/null @@ -1,21 +0,0 @@ -load("//cuttlefish/bazel:rules.bzl", "cf_cc_library") - -package( - default_visibility = ["//:android_cuttlefish"], -) - -cf_cc_library( - name = "msg_queue", - srcs = [ - "msg_queue.cc", - ], - hdrs = [ - "msg_queue.h", - ], - depend_on_what_you_use_enabled = False, - deps = [ - "//cuttlefish/posix:strerror", - "//libbase", - "@abseil-cpp//absl/log", - ], -) diff --git a/base/cvd/cuttlefish/host/libs/msg_queue/README.md b/base/cvd/cuttlefish/host/libs/msg_queue/README.md deleted file mode 100644 index 87e8d05aa0f..00000000000 --- a/base/cvd/cuttlefish/host/libs/msg_queue/README.md +++ /dev/null @@ -1,57 +0,0 @@ -# msg_queue - -This is the Cuttlefish message queue wrapper library, as one of the IPC options available. Below are the example usages running in two separate processes. - -``` -#define MAX_MSG_SIZE 200 -#define NUM_MESSAGES 100 - -typedef struct msg_buffer { - long mesg_type; - char mesg_text[MAX_MSG_SIZE]; -} msg_buffer; - -int example_send() -{ - const std::string message ="Test message" - auto msg_queue = SysVMessageQueue::Create("unique_queue_name", false); - if (msg_queue == NULL) { - LOG(FATAL) << "Create: failed to create" << "unique_queue_name"; - } - - struct msg_buffer msg; - msg.mesg_type = 1; - strcpy(msg.mesg_text, message.c_str()); - int rc = msg_queue->Send(&msg, message.length() + 1, true); - if (rc == -1) { - LOG(FATAL) << "Send: failed to send message to msg_queue"; - } -} -``` - -``` -#define MAX_MSG_SIZE 200 - -typedef struct msg_buffer { - long mesg_type; - char mesg_text[MAX_MSG_SIZE]; -} msg_buffer; - -int example_receive() -{ - auto msg_queue = SysVMessageQueue::Create("unique_queue_name"); - if (msg_queue == NULL) { - LOG(FATAL) << "create: failed to create" << "unique_queue_name"; - } - - struct msg_buffer msg = {0, {0}}; - int rc = msg_queue->Receive(&msg, MAX_MSG_SIZE, 1, true); - if (rc == -1) { - LOG(FATAL) << "receive: failed to receive any messages"; - } - - std::string text(msg.mesg_text); - LOG(INFO) << "Metrics host received: " << text; - return 0; -} -``` diff --git a/base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.cc b/base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.cc deleted file mode 100644 index 98e9ed5e66f..00000000000 --- a/base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.cc +++ /dev/null @@ -1,120 +0,0 @@ -// -// Copyright (C) 2020 The Android Open Source Project -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "cuttlefish/host/libs/msg_queue/msg_queue.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "absl/log/log.h" - -#include "cuttlefish/posix/strerror.h" - -#define DEFAULT_MSGQ_KEY 0x1234 -#define HASH_MULTIPLIER 5381 - -namespace cuttlefish { - -key_t GenerateQueueKey(const char* str) { - if (str == nullptr || *str == '\0') { - LOG(ERROR) << "Invalid queue name provided: " << str; - LOG(ERROR) << "Using default msg queue key: " << DEFAULT_MSGQ_KEY; - return DEFAULT_MSGQ_KEY; - } - - uint64_t hash = HASH_MULTIPLIER; - int c; - - while ((c = *str++)) { - hash = ((hash << 5) + hash) + c; - } - - return static_cast(hash); -} - -// class holds `msgid` returned from msg_queue_create, and match the lifetime of -// the message queue to the lifetime of the object. - -SysVMessageQueue::SysVMessageQueue(int id, bool auto_close) - : msgid_(id), auto_close_(auto_close) {} - -SysVMessageQueue::~SysVMessageQueue(void) { - if (auto_close_ && msgctl(msgid_, IPC_RMID, NULL) < 0) { - LOG(ERROR) << "Could not remove message queue: " << StrError(errno); - } -} - -// SysVMessageQueue::Create would return an empty/null std::unique_ptr if -// initialization failed. -std::unique_ptr SysVMessageQueue::Create( - const std::string& queue_name, bool auto_close) { - key_t key = GenerateQueueKey(queue_name.c_str()); - - int queue_id = msgget(key, 0); - if (queue_id < 0) { - queue_id = msgget(key, IPC_CREAT | IPC_EXCL | 0600); - } - auto msg = std::unique_ptr( - new SysVMessageQueue(queue_id, auto_close)); - return msg; -} - -int SysVMessageQueue::Send(void* data, size_t size, bool block) { - int msgflg = block ? 0 : IPC_NOWAIT; - if (msgsnd(msgid_, data, size, msgflg) < 0) { - int error_num = errno; - if (error_num == EAGAIN) { - // returns EAGAIN if queue is full and non-blocking - return EAGAIN; - } - LOG(ERROR) << "Could not send message: " << StrError(error_num); - return error_num; - } - return 0; -} - -// If msgtyp is 0, then the first message in the queue is read. -// If msgtyp is greater than 0, then the first message in the queue of type -// msgtyp is read. -// If msgtyp is less than 0, then the first message in the queue with the lowest -// type less than or equal to the absolute value of msgtyp will be read. -ssize_t SysVMessageQueue::Receive(void* data, size_t size, long msgtyp, - bool block) { - // Ensure data buffer has space for message type - if (size < sizeof(long)) { - LOG(ERROR) << "receive: buffer size too small"; - return -1; - } - // System call fails with errno set to ENOMSG if queue is empty and - // non-blocking. - int msgflg = block ? 0 : IPC_NOWAIT; - ssize_t result = msgrcv(msgid_, data, size, msgtyp, msgflg); - if (result == -1) { - LOG(ERROR) << "receive: failed to receive any messages. Error: " - << StrError(errno); - } - - return result; -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.h b/base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.h deleted file mode 100644 index cb995aebc62..00000000000 --- a/base/cvd/cuttlefish/host/libs/msg_queue/msg_queue.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#pragma once - -#include -#include - -namespace cuttlefish { -class SysVMessageQueue { - public: - static std::unique_ptr Create(const std::string& queue_name, - bool auto_close = true); - ~SysVMessageQueue(); - - int Send(void* data, size_t size, bool block); - ssize_t Receive(void* data, size_t size, long msgtyp, bool block); - - private: - SysVMessageQueue(int msgid, bool auto_close); - int msgid_; - bool auto_close_; -}; -} // namespace cuttlefish diff --git a/base/cvd/external_proto/BUILD.bazel b/base/cvd/external_proto/BUILD.bazel index 8db9c0ff460..e616962d1aa 100644 --- a/base/cvd/external_proto/BUILD.bazel +++ b/base/cvd/external_proto/BUILD.bazel @@ -138,7 +138,6 @@ proto_library( name = "cf_log_proto", srcs = ["cf_log.proto"], deps = [ - "//external_proto:cf_metrics_event_proto", "//external_proto:cf_metrics_event_v2_proto", "@protobuf//:cpp_features_proto", "@protobuf//:timestamp_proto", @@ -150,20 +149,6 @@ cc_proto_library( deps = ["//external_proto:cf_log_proto"], ) -proto_library( - name = "cf_metrics_event_proto", - srcs = ["cf_metrics_event.proto"], - deps = [ - "@protobuf//:duration_proto", - "@protobuf//:timestamp_proto", - ], -) - -cc_proto_library( - name = "cf_metrics_event_cc_proto", - deps = ["//external_proto:cf_metrics_event_proto"], -) - proto_library( name = "cf_metrics_event_v2_proto", srcs = ["cf_metrics_event_v2.proto"], diff --git a/base/cvd/external_proto/cf_log.proto b/base/cvd/external_proto/cf_log.proto index 6b58bcd3350..39ad1c7c811 100644 --- a/base/cvd/external_proto/cf_log.proto +++ b/base/cvd/external_proto/cf_log.proto @@ -17,7 +17,6 @@ edition = "2023"; package logs.proto.wireless.android.cuttlefish; -import "external_proto/cf_metrics_event.proto"; import "external_proto/cf_metrics_event_v2.proto"; import "google/protobuf/cpp_features.proto"; import "google/protobuf/timestamp.proto"; @@ -59,10 +58,12 @@ message CuttlefishLogEvent { // The version of Cuttlefish that's sending the log event. string cuttlefish_version = 4; + // deprecated v1 metrics event type message + // previously used by launch_cvd go/cf-metrics-prd + reserved 5; + reserved metrics_event; + oneof events { - // Metrics V1, used by launch_cvd: go/cf-metrics-prd - logs.proto.wireless.android.cuttlefish.events.MetricsEvent metrics_event = - 5; // Metrics V2, used by cvd: go/cf-metrics-prd-v2 logs.proto.wireless.android.cuttlefish.events.MetricsEventV2 metrics_event_v2 = 7; diff --git a/base/cvd/external_proto/cf_metrics_event.proto b/base/cvd/external_proto/cf_metrics_event.proto deleted file mode 100644 index 2d696b1ed6e..00000000000 --- a/base/cvd/external_proto/cf_metrics_event.proto +++ /dev/null @@ -1,161 +0,0 @@ -/* - * Copyright (C) 2020 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -syntax = "proto2"; - -import "google/protobuf/duration.proto"; -import "google/protobuf/timestamp.proto"; - -package logs.proto.wireless.android.cuttlefish.events; - -// Wrapper for Cuttlefish Metrics log events. -// Next index: 22 -message MetricsEvent { - // High level event types for this message. This is the broadest - // category identifier for MetricsEvent and should be used to indicate - // which other fields will be populated. Only used in field event_type. - // Next index: 6 - enum EventType { - // An unspecified, unhandled event. - CUTTLEFISH_EVENT_TYPE_UNSPECIFIED = 0; - - // The device experienced an error. - CUTTLEFISH_EVENT_TYPE_ERROR = 1; - - // The event type is the time the VM instance is instantiated. - CUTTLEFISH_EVENT_TYPE_VM_INSTANTIATION = 2; - - // The event type is the time the device boot process is started. - CUTTLEFISH_EVENT_TYPE_DEVICE_BOOT = 3; - - // The event type is the time the device lock screen is available. - CUTTLEFISH_EVENT_TYPE_LOCK_SCREEN_AVAILABLE = 4; - - // The event type is the time the virtual device was stopped. - CUTTLEFISH_EVENT_TYPE_VM_STOP = 5; - } - - // Defines the OS that this log was sourced from. - // This may not be the same OS which uploaded the log event. - // Next index: 5 - enum OsType { - // The log event was sourced from an unspecified os type. - CUTTLEFISH_OS_TYPE_UNSPECIFIED = 0; - - // The log event was sourced from Linux x86 os type. - CUTTLEFISH_OS_TYPE_LINUX_X86 = 1; - - // The log event was sourced from Linux x86_64 os type. - CUTTLEFISH_OS_TYPE_LINUX_X86_64 = 2; - - // The log event was sourced from Linux aarch32 os type. - CUTTLEFISH_OS_TYPE_LINUX_AARCH32 = 3; - - // The log event was sourced from Linux aarch64 os type. - CUTTLEFISH_OS_TYPE_LINUX_AARCH64 = 4; - } - - // Defines the VMM that this log was sourced from. - // This may not be the same VMM which uploaded the log event. - // Next index: 3 - enum VmmType { - // The log event was sourced from an unspecified vmm type. - CUTTLEFISH_VMM_TYPE_UNSPECIFIED = 0; - - // The log event was sourced from a CrOS VM vmm type. - CUTTLEFISH_VMM_TYPE_CROSVM = 1; - - // The log event was sourced from a QEMU vmm type. - CUTTLEFISH_VMM_TYPE_QEMU = 2; - } - - // High level error types for this message. Defines the error - // the device received when it experienced an error. This field - // should only be present when event_type is ERROR. - // Next index: 1 - enum ErrorType { - // An unspecified, unhandled error. - CUTTLEFISH_ERROR_TYPE_UNSPECIFIED = 0; - } - - // Defines the type of device event contained in this message. - // This is the highest level identifier for MetricsEvent messages. - optional EventType event_type = 1; - - // Defines the error the device received when it experienced an error. - // The field should only be present when event_type is ERROR. - optional ErrorType error_type = 2; - - // Time the event occurred in milliseconds since Unix epoch. - optional google.protobuf.Timestamp event_time = 3; - - // Elapsed time for the event in milliseconds. - optional google.protobuf.Duration elapsed_time_ms = 4; - - // The type of OS this log event originated from. - optional OsType os_type = 5; - - // OS version for the host/guest operating system. - // Ex. Android version (9.x, 10.x, etc.) or `uname -r` output - optional string os_version = 6; - - // Android guest API level - optional int32 api_level = 7; - - // The type of VMM this log event originated from. - optional VmmType vmm_type = 8; - - // The version of the VMM that's sending the log event. - optional string vmm_version = 9; - - // The company that's sending the log event. - optional string company = 10; - - // TODO(moelsherif) : The following fields are not yet implemented. - - // The allowlist of launch_cvd flags attached to the launch_cvd command - // associated with this instance - repeated string launch_cvd_flags = 11; - - // Exists a -system_image_dir specified in launch_cvd - optional bool exists_system_image_spec = 12; - - // Exists a -boot_image specified in launch_cvd - optional bool exists_boot_image_spec = 13; - - // Exists a -bootloader specified in launch_cvd - optional bool exists_bootloader_spec = 14; - - // Exists a -composite_disk specified in launch_cvd - optional bool exists_composite_disk_spec = 15; - - // Exists a -data_image specified in launch_cvd - optional bool exists_data_image_spec = 16; - - // Exists a -metadata_image specified in launch_cvd - optional bool exists_metadata_image_spec = 17; - - // Exists a -misc_image specified in launch_cvd - optional bool exists_misc_image_spec = 18; - - // Exists a -qemu_binary specified in launch_cvd - optional bool exists_qemu_binary_spec = 19; - - // Exists a -super_image specified in launch_cvd - optional bool exists_super_image_spec = 20; - - // Exists a -vendor_boot_image specified in launch_cvd - optional bool exists_vendor_boot_image_spec = 21; -} From 1aae572ccedc9b68ee002707bc2599d1a2cd0ee4 Mon Sep 17 00:00:00 2001 From: Chad Reynolds Date: Thu, 9 Jul 2026 18:01:05 -0700 Subject: [PATCH 5/5] Remove v1 metrics processing from config proto The field corresponded to the `report_anonymous_usage_stats` flag, which is now deprecated and unused. Reserving the deleted proto field number and identifier to avoid backwards incompatible changes with serialization or TextProto/JSON encodings. Bug: 463443661 --- .../host/commands/cvd/cli/parser/BUILD.bazel | 24 ---- .../cvd/cli/parser/cf_metrics_configs.cpp | 49 ------- .../cvd/cli/parser/cf_metrics_configs.h | 29 ---- .../cvd/cli/parser/launch_cvd_parser.cpp | 2 - .../commands/cvd/cli/parser/load_config.proto | 14 +- .../cvd/cli/parser/metrics_configs_test.cc | 128 ------------------ 6 files changed, 8 insertions(+), 238 deletions(-) delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.h delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/cli/parser/metrics_configs_test.cc diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/BUILD.bazel b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/BUILD.bazel index 9042531b531..f6432722f11 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/BUILD.bazel @@ -53,16 +53,6 @@ cf_cc_library( ], ) -cf_cc_library( - name = "cf_metrics_configs", - srcs = ["cf_metrics_configs.cpp"], - hdrs = ["cf_metrics_configs.h"], - deps = [ - "//cuttlefish/host/commands/cvd/cli/parser:cf_configs_common", - "//cuttlefish/host/commands/cvd/cli/parser:load_config_cc_proto", - ], -) - cf_cc_test( name = "configs_inheritance_test", srcs = ["configs_inheritance_test.cc"], @@ -108,7 +98,6 @@ cf_cc_library( deps = [ "//cuttlefish/host/commands/cvd/cli/parser:cf_configs_common", "//cuttlefish/host/commands/cvd/cli/parser:cf_configs_instances", - "//cuttlefish/host/commands/cvd/cli/parser:cf_metrics_configs", "//cuttlefish/host/commands/cvd/cli/parser:launch_cvd_templates", "//cuttlefish/host/commands/cvd/cli/parser:load_config_cc_proto", "//cuttlefish/result", @@ -177,19 +166,6 @@ cf_cc_library( ], ) -cf_cc_test( - name = "metrics_configs_test", - srcs = ["metrics_configs_test.cc"], - depend_on_what_you_use_enabled = False, - deps = [ - "//cuttlefish/host/commands/cvd/cli/parser:test_common", - "//cuttlefish/result", - "//cuttlefish/result:result_matchers", - "//libbase", - "@jsoncpp", - ], -) - cf_cc_library( name = "selector_parser", srcs = ["selector_parser.cpp"], diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.cpp deleted file mode 100644 index cb1d1a2b2c7..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#include "cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.h" - -#include -#include - -#include "cuttlefish/host/commands/cvd/cli/parser/cf_configs_common.h" -#include "cuttlefish/host/commands/cvd/cli/parser/load_config.pb.h" - -namespace cuttlefish { - -using cvd::config::EnvironmentSpecification; -using cvd::config::Instance; - -namespace { - -constexpr bool kEnableMetricsDefault = false; - -std::string EnabledToReportAnonUsageStats(const bool enabled) { - return enabled ? "y" : "n"; -} - -} // namespace - -std::vector GenerateMetricsFlags( - const EnvironmentSpecification& config) { - bool enable = kEnableMetricsDefault; - if (config.metrics().has_enable()) { - enable = config.metrics().enable(); - } - auto flag_value = EnabledToReportAnonUsageStats(enable); - return {GenerateFlag("report_anonymous_usage_stats", flag_value)}; -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.h b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.h deleted file mode 100644 index 4f55ea9f222..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#include "cuttlefish/host/commands/cvd/cli/parser/load_config.pb.h" - -namespace cuttlefish { - -std::vector GenerateMetricsFlags( - const cvd::config::EnvironmentSpecification&); - -}; // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/launch_cvd_parser.cpp b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/launch_cvd_parser.cpp index d27aef54467..d0920fa164c 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/launch_cvd_parser.cpp +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/launch_cvd_parser.cpp @@ -25,7 +25,6 @@ #include "cuttlefish/host/commands/cvd/cli/parser/cf_configs_common.h" #include "cuttlefish/host/commands/cvd/cli/parser/cf_configs_instances.h" -#include "cuttlefish/host/commands/cvd/cli/parser/cf_metrics_configs.h" #include "cuttlefish/host/commands/cvd/cli/parser/launch_cvd_templates.h" #include "cuttlefish/host/commands/cvd/cli/parser/load_config.pb.h" #include "cuttlefish/result/result.h" @@ -76,7 +75,6 @@ Result> GenerateCfFlags( GenerateFlag("netsim_args", absl::StrJoin(launch.netsim_args(), " "))); } - flags = MergeResults(std::move(flags), GenerateMetricsFlags(launch)); flags = MergeResults(std::move(flags), CF_EXPECT(GenerateInstancesFlags(launch))); auto flag_op = GenerateUndefOkFlag(flags); diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/load_config.proto b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/load_config.proto index 25ac3c436fb..6c85cb3797b 100644 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/load_config.proto +++ b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/load_config.proto @@ -45,9 +45,12 @@ enum ModemSimulatorSimType { } message EnvironmentSpecification { + // deprecated v1 metrics enabling field, report_anonymous_usage_stats + reserved 3; + reserved "metrics"; + repeated Instance instances = 1; optional Fetch fetch = 2; - optional Metrics metrics = 3; optional Common common = 4; optional bool netsim_bt = 5; optional bool netsim_uwb = 6; @@ -57,8 +60,11 @@ message EnvironmentSpecification { // TODO: chadreynolds - when we can make breaking changes and update, use this // in EnvironmentSpecification instead of individual fields message EnvironmentOptions { + // deprecated v1 metrics enabling field, report_anonymous_usage_stats + reserved 2; + reserved "metrics"; + optional Fetch fetch = 1; - optional Metrics metrics = 2; optional Common common = 3; optional bool netsim_bt = 4; optional bool netsim_uwb = 5; @@ -222,10 +228,6 @@ message DeviceState { optional int32 hinge_angle_value = 2; } -message Metrics { - optional bool enable = 1; -} - message DisplayOverlay { int32 vm_index = 1; int32 display_index = 2; diff --git a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/metrics_configs_test.cc b/base/cvd/cuttlefish/host/commands/cvd/cli/parser/metrics_configs_test.cc deleted file mode 100644 index 5ee56b5a899..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/cli/parser/metrics_configs_test.cc +++ /dev/null @@ -1,128 +0,0 @@ -/* - * Copyright (C) 2015-2022 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include - -#include "gmock/gmock.h" -#include "gtest/gtest.h" -#include "json/value.h" - -#include "cuttlefish/host/commands/cvd/cli/parser/test_common.h" -#include "cuttlefish/result/result.h" -#include "cuttlefish/result/result_matchers.h" - -namespace cuttlefish { - -using ::testing::IsTrue; -using ::testing::Not; - -TEST(MetricsFlagsParserTest, ParseOneInstanceMetricsReportValidValue) { - const char* test_string = R""""( -{ - "instances" : - [ - { - } - ], - "metrics": { - "enable": true - } -} - )""""; - - Json::Value json_configs; - std::string json_text(test_string); - - EXPECT_THAT(ParseJsonString(json_text, json_configs), IsTrue()) - << "Invalid Json string"; - auto serialized_data = LaunchCvdParserTester(json_configs); - EXPECT_THAT(serialized_data, IsOk()) << serialized_data.error().Trace(); -} - -TEST(MetricsFlagsParserTest, ParseOneInstanceMetricsReportInvalidValue) { - const char* test_string = R""""( -{ - "instances" : - [ - { - } - ], - "metrics": { - "enable": "foo" - } -} - )""""; - - Json::Value json_configs; - std::string json_text(test_string); - - EXPECT_THAT(ParseJsonString(json_text, json_configs), IsTrue()) - << "Invalid Json string"; - auto serialized_data = LaunchCvdParserTester(json_configs); - EXPECT_THAT(serialized_data, Not(IsOk())); -} - -TEST(MetricsFlagsParserTest, ParseOneInstancesMetricsReportFlagEmptyJson) { - const char* test_string = R""""( -{ - "instances" : - [ - { - } - ] -} - )""""; - - Json::Value json_configs; - std::string json_text(test_string); - - EXPECT_THAT(ParseJsonString(json_text, json_configs), IsTrue()) - << "Invalid Json string"; - auto serialized_data = LaunchCvdParserTester(json_configs); - EXPECT_THAT(serialized_data, IsOk()) << serialized_data.error().Trace(); - EXPECT_THAT( - FindConfig(*serialized_data, R"(--report_anonymous_usage_stats=n)"), - IsTrue()) - << "report_anonymous_usage_stats flag is missing or wrongly formatted"; -} - -TEST(MetricsFlagsParserTest, ParseTwoInstancesMetricsReportFlagEmptyJson) { - const char* test_string = R""""( -{ - "instances" : - [ - { - }, - { - } - ] -} - )""""; - - Json::Value json_configs; - std::string json_text(test_string); - - EXPECT_THAT(ParseJsonString(json_text, json_configs), IsTrue()) - << "Invalid Json string"; - auto serialized_data = LaunchCvdParserTester(json_configs); - EXPECT_THAT(serialized_data, IsOk()) << serialized_data.error().Trace(); - EXPECT_THAT( - FindConfig(*serialized_data, R"(--report_anonymous_usage_stats=n)"), - IsTrue()) - << "report_anonymous_usage_stats flag is missing or wrongly formatted"; -} - -} // namespace cuttlefish