Skip to content

Commit 44f154a

Browse files
committed
Factor out the metrics transmission logic
This new file will be the home of related metrics transmission logic from `host/libs/metrics/send`. Bug: 452136634
1 parent 874801f commit 44f154a

File tree

4 files changed

+81
-13
lines changed

4 files changed

+81
-13
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ cf_cc_library(
7979
"//cuttlefish/common/libs/utils:result",
8080
"//cuttlefish/host/commands/cvd/instances",
8181
"//cuttlefish/host/commands/cvd/metrics:is_enabled",
82-
"//cuttlefish/host/commands/metrics:send",
8382
"//cuttlefish/host/libs/metrics:event_type",
8483
"//cuttlefish/host/libs/metrics:metrics_conversion",
85-
"//cuttlefish/host/libs/metrics:metrics_headers",
84+
"//cuttlefish/host/libs/metrics:metrics_transmitter",
8685
"//cuttlefish/host/libs/metrics:metrics_writer",
8786
"//cuttlefish/host/libs/metrics:session_id",
8887
"//external_proto:clientanalytics_cc_proto",
@@ -91,6 +90,22 @@ cf_cc_library(
9190
],
9291
)
9392

93+
cf_cc_library(
94+
name = "metrics_transmitter",
95+
srcs = [
96+
"metrics_transmitter.cc",
97+
],
98+
hdrs = [
99+
"metrics_transmitter.h",
100+
],
101+
deps = [
102+
"//cuttlefish/common/libs/utils:result",
103+
"//cuttlefish/host/commands/metrics:send",
104+
"//cuttlefish/host/libs/metrics:metrics_headers",
105+
"//external_proto:clientanalytics_cc_proto",
106+
],
107+
)
108+
94109
cf_cc_library(
95110
name = "metrics_writer",
96111
srcs = [

base/cvd/cuttlefish/host/libs/metrics/metrics_orchestration.cc

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,9 @@
2626
#include "cuttlefish/common/libs/utils/result.h"
2727
#include "cuttlefish/host/commands/cvd/instances/instance_group_record.h"
2828
#include "cuttlefish/host/commands/cvd/metrics/is_enabled.h"
29-
#include "cuttlefish/host/commands/metrics/send.h"
3029
#include "cuttlefish/host/libs/metrics/event_type.h"
3130
#include "cuttlefish/host/libs/metrics/metrics_conversion.h"
32-
#include "cuttlefish/host/libs/metrics/metrics_defs.h"
31+
#include "cuttlefish/host/libs/metrics/metrics_transmitter.h"
3332
#include "cuttlefish/host/libs/metrics/metrics_writer.h"
3433
#include "cuttlefish/host/libs/metrics/session_id.h"
3534
#include "external_proto/clientanalytics.pb.h"
@@ -59,14 +58,6 @@ Result<void> SetUpMetrics(const std::string& metrics_directory) {
5958
return {};
6059
}
6160

62-
Result<void> TransmitMetrics(const LogRequest& log_request) {
63-
int reporting_outcome = metrics::PostRequest(log_request.SerializeAsString(),
64-
metrics::ClearcutServer::kProd);
65-
CF_EXPECTF(reporting_outcome != MetricsExitCodes::kSuccess,
66-
"Issue reporting metrics: {}", reporting_outcome);
67-
return {};
68-
}
69-
7061
Result<void> GatherAndWriteMetrics(EventType event_type,
7162
const std::string& metrics_directory) {
7263
const std::string session_id =
@@ -81,7 +72,7 @@ Result<void> GatherAndWriteMetrics(EventType event_type,
8172
LOG(INFO) << "This will automatically send diagnostic information to "
8273
"Google, such as crash reports and usage data from the host "
8374
"machine managing the Android Virtual Device.";
84-
CF_EXPECT(TransmitMetrics(log_request));
75+
CF_EXPECT(TransmitMetricsEvent(log_request));
8576
}
8677
return {};
8778
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#include "cuttlefish/host/libs/metrics/metrics_transmitter.h"
18+
19+
#include "cuttlefish/common/libs/utils/result.h"
20+
#include "cuttlefish/host/commands/metrics/send.h"
21+
#include "cuttlefish/host/libs/metrics/metrics_defs.h"
22+
#include "external_proto/clientanalytics.pb.h"
23+
24+
namespace cuttlefish {
25+
26+
Result<void> TransmitMetricsEvent(
27+
const wireless_android_play_playlog::LogRequest& log_request) {
28+
int reporting_outcome = metrics::PostRequest(log_request.SerializeAsString(),
29+
metrics::ClearcutServer::kProd);
30+
CF_EXPECTF(reporting_outcome != MetricsExitCodes::kSuccess,
31+
"Issue reporting metrics: {}", reporting_outcome);
32+
return {};
33+
}
34+
35+
} // namespace cuttlefish
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2025 The Android Open Source Project
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#pragma once
18+
19+
#include "cuttlefish/common/libs/utils/result.h"
20+
#include "external_proto/clientanalytics.pb.h"
21+
22+
namespace cuttlefish {
23+
24+
Result<void> TransmitMetricsEvent(
25+
const wireless_android_play_playlog::LogRequest& log_request);
26+
27+
} // namespace cuttlefish

0 commit comments

Comments
 (0)