blob: a7a91a546539842830f018565c65ea4fbc939a33 [file] [log] [blame]
Tianjie Xu282aa1f2017-09-05 13:42:45 -07001//
2// Copyright (C) 2017 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
Amin Hassaniec7bc112020-10-29 16:47:58 -070017#ifndef UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_
18#define UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_
Tianjie Xu282aa1f2017-09-05 13:42:45 -070019
Tianjie Xud4c5deb2017-10-24 11:17:03 -070020#include <memory>
Marton Hunyadya0302682018-05-16 18:52:13 +020021#include <string>
Tianjie Xud4c5deb2017-10-24 11:17:03 -070022
Tianjie Xu282aa1f2017-09-05 13:42:45 -070023#include <base/time/time.h>
24
Tianjie Xu282aa1f2017-09-05 13:42:45 -070025#include "update_engine/common/constants.h"
Yifan Hongc514f662021-02-04 11:18:43 -080026#include "update_engine/common/dynamic_partition_control_interface.h"
Tianjie Xu282aa1f2017-09-05 13:42:45 -070027#include "update_engine/common/error_code.h"
Amin Hassaniec7bc112020-10-29 16:47:58 -070028#include "update_engine/common/metrics_constants.h"
Kelvin Zhang9a5e3682021-03-29 12:58:48 -040029#include "update_engine/payload_consumer/install_plan.h"
Tianjie Xu282aa1f2017-09-05 13:42:45 -070030
31namespace chromeos_update_engine {
32
Tianjie Xu1b661142017-09-28 14:03:42 -070033enum class ServerToCheck;
34enum class CertificateCheckResult;
35
Tianjie Xu282aa1f2017-09-05 13:42:45 -070036class MetricsReporterInterface {
37 public:
38 virtual ~MetricsReporterInterface() = default;
39
Marton Hunyadya0302682018-05-16 18:52:13 +020040 // Helper function to report metrics related to user-initiated rollback. The
Tianjie Xu282aa1f2017-09-05 13:42:45 -070041 // following metrics are reported:
42 //
43 // |kMetricRollbackResult|
44 virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0;
45
Marton Hunyadya0302682018-05-16 18:52:13 +020046 // Helper function to report metrics related to enterprise (admin-initiated)
47 // rollback:
48 //
49 // |kMetricEnterpriseRollbackSuccess|
50 // |kMetricEnterpriseRollbackFailure|
51 virtual void ReportEnterpriseRollbackMetrics(
52 bool success, const std::string& rollback_version) = 0;
53
Tianjie Xu282aa1f2017-09-05 13:42:45 -070054 // Helper function to report metrics reported once a day. The
55 // following metrics are reported:
56 //
57 // |kMetricDailyOSAgeDays|
58 virtual void ReportDailyMetrics(base::TimeDelta os_age) = 0;
59
60 // Helper function to report metrics after completing an update check
61 // with the ChromeOS update server ("Omaha"). The following metrics
62 // are reported:
63 //
64 // |kMetricCheckResult|
65 // |kMetricCheckReaction|
66 // |kMetricCheckDownloadErrorCode|
67 // |kMetricCheckTimeSinceLastCheckMinutes|
68 // |kMetricCheckTimeSinceLastCheckUptimeMinutes|
Marton Hunyadya0302682018-05-16 18:52:13 +020069 // |kMetricCheckTargetVersion|
70 // |kMetricCheckRollbackTargetVersion|
Tianjie Xu282aa1f2017-09-05 13:42:45 -070071 //
72 // The |kMetricCheckResult| metric will only be reported if |result|
73 // is not |kUnset|.
74 //
75 // The |kMetricCheckReaction| metric will only be reported if
76 // |reaction| is not |kUnset|.
77 //
78 // The |kMetricCheckDownloadErrorCode| will only be reported if
79 // |download_error_code| is not |kUnset|.
80 //
81 // The values for the |kMetricCheckTimeSinceLastCheckMinutes| and
82 // |kMetricCheckTimeSinceLastCheckUptimeMinutes| metrics are
83 // automatically reported and calculated by maintaining persistent
84 // and process-local state variables.
Marton Hunyadya0302682018-05-16 18:52:13 +020085 //
86 // |kMetricCheckTargetVersion| reports the first section of the target version
87 // if it's set, |kMetricCheckRollbackTargetVersion| reports the same, but only
88 // if rollback is also allowed using enterprise policy.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070089 virtual void ReportUpdateCheckMetrics(
Tianjie Xu282aa1f2017-09-05 13:42:45 -070090 metrics::CheckResult result,
91 metrics::CheckReaction reaction,
92 metrics::DownloadErrorCode download_error_code) = 0;
93
94 // Helper function to report metrics after the completion of each
95 // update attempt. The following metrics are reported:
96 //
97 // |kMetricAttemptNumber|
98 // |kMetricAttemptPayloadType|
99 // |kMetricAttemptPayloadSizeMiB|
Tianjie Xu1b661142017-09-28 14:03:42 -0700100 // |kMetricAttemptDurationMinutes|
101 // |kMetricAttemptDurationUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700102 // |kMetricAttemptTimeSinceLastAttemptMinutes|
103 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700104 // |kMetricAttemptResult|
105 // |kMetricAttemptInternalErrorCode|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700106 //
107 // The |kMetricAttemptInternalErrorCode| metric will only be reported
108 // if |internal_error_code| is not |kErrorSuccess|.
109 //
110 // The |kMetricAttemptDownloadErrorCode| metric will only be
111 // reported if |payload_download_error_code| is not |kUnset|.
112 //
113 // The values for the |kMetricAttemptTimeSinceLastAttemptMinutes| and
114 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| metrics are
115 // automatically calculated and reported by maintaining persistent and
116 // process-local state variables.
Amin Hassani538bd592020-11-04 20:46:08 -0800117 virtual void ReportUpdateAttemptMetrics(int attempt_number,
Tianjie Xu1f93d092017-10-09 12:13:29 -0700118 PayloadType payload_type,
119 base::TimeDelta duration,
120 base::TimeDelta duration_uptime,
121 int64_t payload_size,
122 metrics::AttemptResult attempt_result,
123 ErrorCode internal_error_code) = 0;
124
125 // Helper function to report download metrics after the completion of each
126 // update attempt. The following metrics are reported:
127 //
128 // |kMetricAttemptPayloadBytesDownloadedMiB|
129 // |kMetricAttemptPayloadDownloadSpeedKBps|
130 // |kMetricAttemptDownloadSource|
131 // |kMetricAttemptDownloadErrorCode|
132 // |kMetricAttemptConnectionType|
133 virtual void ReportUpdateAttemptDownloadMetrics(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700134 int64_t payload_bytes_downloaded,
135 int64_t payload_download_speed_bps,
136 DownloadSource download_source,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700137 metrics::DownloadErrorCode payload_download_error_code,
138 metrics::ConnectionType connection_type) = 0;
139
140 // Reports the |kAbnormalTermination| for the |kMetricAttemptResult|
141 // metric. No other metrics in the UpdateEngine.Attempt.* namespace
142 // will be reported.
143 virtual void ReportAbnormallyTerminatedUpdateAttemptMetrics() = 0;
144
145 // Helper function to report the after the completion of a successful
146 // update attempt. The following metrics are reported:
147 //
148 // |kMetricSuccessfulUpdateAttemptCount|
149 // |kMetricSuccessfulUpdateUpdatesAbandonedCount|
150 // |kMetricSuccessfulUpdatePayloadType|
151 // |kMetricSuccessfulUpdatePayloadSizeMiB|
152 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpsServer|
153 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpServer|
154 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpPeer|
155 // |kMetricSuccessfulUpdateBytesDownloadedMiB|
156 // |kMetricSuccessfulUpdateDownloadSourcesUsed|
157 // |kMetricSuccessfulUpdateDownloadOverheadPercentage|
158 // |kMetricSuccessfulUpdateTotalDurationMinutes|
Sen Jiang8712e962018-05-08 12:12:28 -0700159 // |kMetricSuccessfulUpdateTotalDurationUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700160 // |kMetricSuccessfulUpdateRebootCount|
161 // |kMetricSuccessfulUpdateUrlSwitchCount|
162 //
163 // The values for the |kMetricSuccessfulUpdateDownloadSourcesUsed| are
164 // |kMetricSuccessfulUpdateBytesDownloadedMiB| metrics automatically
165 // calculated from examining the |num_bytes_downloaded| array.
166 virtual void ReportSuccessfulUpdateMetrics(
167 int attempt_count,
168 int updates_abandoned_count,
169 PayloadType payload_type,
170 int64_t payload_size,
171 int64_t num_bytes_downloaded[kNumDownloadSources],
172 int download_overhead_percentage,
173 base::TimeDelta total_duration,
Sen Jiang8712e962018-05-08 12:12:28 -0700174 base::TimeDelta total_duration_uptime,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700175 int reboot_count,
176 int url_switch_count) = 0;
177
178 // Helper function to report the after the completion of a SSL certificate
179 // check. One of the following metrics is reported:
180 //
181 // |kMetricCertificateCheckUpdateCheck|
182 // |kMetricCertificateCheckDownload|
183 virtual void ReportCertificateCheckMetrics(ServerToCheck server_to_check,
184 CertificateCheckResult result) = 0;
185
186 // Helper function to report the number failed update attempts. The following
187 // metrics are reported:
188 //
189 // |kMetricFailedUpdateCount|
190 virtual void ReportFailedUpdateCount(int target_attempt) = 0;
191
192 // Helper function to report the time interval in minutes between a
193 // successful update and the reboot into the updated system. The following
194 // metrics are reported:
195 //
196 // |kMetricTimeToRebootMinutes|
197 virtual void ReportTimeToReboot(int time_to_reboot_minutes) = 0;
198
199 // Helper function to report the source of installation data. The following
200 // metrics are reported:
201 //
202 // |kMetricInstallDateProvisioningSource|
203 virtual void ReportInstallDateProvisioningSource(int source, int max) = 0;
Amin Hassani80f4d4c2018-05-16 13:34:00 -0700204
205 // Helper function to report an internal error code. The following metrics are
206 // reported:
207 //
208 // |kMetricAttemptInternalErrorCode|
209 virtual void ReportInternalErrorCode(ErrorCode error_code) = 0;
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +0200210
211 // Helper function to report metrics related to the verified boot key
212 // versions:
213 //
214 // |kMetricKernelMinVersion|
215 // |kMetricKernelMaxRollforwardVersion|
216 // |kMetricKernelMaxRollforwardSetSuccess|
217 virtual void ReportKeyVersionMetrics(int kernel_min_version,
218 int kernel_max_rollforward_version,
219 bool kernel_max_rollforward_success) = 0;
May Lippert60aa3ca2018-08-15 16:55:29 -0700220
221 // Helper function to report the duration between an update being seen by the
222 // client to the update being applied. Updates are not always immediately
223 // applied when seen, several enterprise policies can affect when an update
224 // would actually be downloaded and applied.
225 //
226 // This metric should only be reported for enterprise enrolled devices.
227 //
228 // The following metrics are reported from this function:
229 // If |has_time_restriction_policy| is false:
230 // |kMetricSuccessfulUpdateDurationFromSeenDays|
231 // If |has_time_restriction_policy| is true:
232 // |kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays|
233 //
234 virtual void ReportEnterpriseUpdateSeenToDownloadDays(
235 bool has_time_restriction_policy, int time_to_update_days) = 0;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700236};
237
Amin Hassani538bd592020-11-04 20:46:08 -0800238namespace metrics {
239
Yifan Hongc514f662021-02-04 11:18:43 -0800240std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter(
Kelvin Zhang9a5e3682021-03-29 12:58:48 -0400241 DynamicPartitionControlInterface* dynamic_partition_control,
242 const InstallPlan* install_plan);
Amin Hassani538bd592020-11-04 20:46:08 -0800243
244} // namespace metrics
245
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700246} // namespace chromeos_update_engine
247
Amin Hassaniec7bc112020-10-29 16:47:58 -0700248#endif // UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_