blob: 29d13faf93c72d54dfce1dc426978439608a1364 [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"
Tianjie Xu282aa1f2017-09-05 13:42:45 -070029
30namespace chromeos_update_engine {
31
Tianjie Xu1b661142017-09-28 14:03:42 -070032enum class ServerToCheck;
33enum class CertificateCheckResult;
34
Tianjie Xu282aa1f2017-09-05 13:42:45 -070035class MetricsReporterInterface {
36 public:
37 virtual ~MetricsReporterInterface() = default;
38
Marton Hunyadya0302682018-05-16 18:52:13 +020039 // Helper function to report metrics related to user-initiated rollback. The
Tianjie Xu282aa1f2017-09-05 13:42:45 -070040 // following metrics are reported:
41 //
42 // |kMetricRollbackResult|
43 virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0;
44
Marton Hunyadya0302682018-05-16 18:52:13 +020045 // Helper function to report metrics related to enterprise (admin-initiated)
46 // rollback:
47 //
48 // |kMetricEnterpriseRollbackSuccess|
49 // |kMetricEnterpriseRollbackFailure|
50 virtual void ReportEnterpriseRollbackMetrics(
51 bool success, const std::string& rollback_version) = 0;
52
Tianjie Xu282aa1f2017-09-05 13:42:45 -070053 // Helper function to report metrics reported once a day. The
54 // following metrics are reported:
55 //
56 // |kMetricDailyOSAgeDays|
57 virtual void ReportDailyMetrics(base::TimeDelta os_age) = 0;
58
59 // Helper function to report metrics after completing an update check
60 // with the ChromeOS update server ("Omaha"). The following metrics
61 // are reported:
62 //
63 // |kMetricCheckResult|
64 // |kMetricCheckReaction|
65 // |kMetricCheckDownloadErrorCode|
66 // |kMetricCheckTimeSinceLastCheckMinutes|
67 // |kMetricCheckTimeSinceLastCheckUptimeMinutes|
Marton Hunyadya0302682018-05-16 18:52:13 +020068 // |kMetricCheckTargetVersion|
69 // |kMetricCheckRollbackTargetVersion|
Tianjie Xu282aa1f2017-09-05 13:42:45 -070070 //
71 // The |kMetricCheckResult| metric will only be reported if |result|
72 // is not |kUnset|.
73 //
74 // The |kMetricCheckReaction| metric will only be reported if
75 // |reaction| is not |kUnset|.
76 //
77 // The |kMetricCheckDownloadErrorCode| will only be reported if
78 // |download_error_code| is not |kUnset|.
79 //
80 // The values for the |kMetricCheckTimeSinceLastCheckMinutes| and
81 // |kMetricCheckTimeSinceLastCheckUptimeMinutes| metrics are
82 // automatically reported and calculated by maintaining persistent
83 // and process-local state variables.
Marton Hunyadya0302682018-05-16 18:52:13 +020084 //
85 // |kMetricCheckTargetVersion| reports the first section of the target version
86 // if it's set, |kMetricCheckRollbackTargetVersion| reports the same, but only
87 // if rollback is also allowed using enterprise policy.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070088 virtual void ReportUpdateCheckMetrics(
Tianjie Xu282aa1f2017-09-05 13:42:45 -070089 metrics::CheckResult result,
90 metrics::CheckReaction reaction,
91 metrics::DownloadErrorCode download_error_code) = 0;
92
93 // Helper function to report metrics after the completion of each
94 // update attempt. The following metrics are reported:
95 //
96 // |kMetricAttemptNumber|
97 // |kMetricAttemptPayloadType|
98 // |kMetricAttemptPayloadSizeMiB|
Tianjie Xu1b661142017-09-28 14:03:42 -070099 // |kMetricAttemptDurationMinutes|
100 // |kMetricAttemptDurationUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700101 // |kMetricAttemptTimeSinceLastAttemptMinutes|
102 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700103 // |kMetricAttemptResult|
104 // |kMetricAttemptInternalErrorCode|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700105 //
106 // The |kMetricAttemptInternalErrorCode| metric will only be reported
107 // if |internal_error_code| is not |kErrorSuccess|.
108 //
109 // The |kMetricAttemptDownloadErrorCode| metric will only be
110 // reported if |payload_download_error_code| is not |kUnset|.
111 //
112 // The values for the |kMetricAttemptTimeSinceLastAttemptMinutes| and
113 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| metrics are
114 // automatically calculated and reported by maintaining persistent and
115 // process-local state variables.
Amin Hassani538bd592020-11-04 20:46:08 -0800116 virtual void ReportUpdateAttemptMetrics(int attempt_number,
Tianjie Xu1f93d092017-10-09 12:13:29 -0700117 PayloadType payload_type,
118 base::TimeDelta duration,
119 base::TimeDelta duration_uptime,
120 int64_t payload_size,
121 metrics::AttemptResult attempt_result,
122 ErrorCode internal_error_code) = 0;
123
124 // Helper function to report download metrics after the completion of each
125 // update attempt. The following metrics are reported:
126 //
127 // |kMetricAttemptPayloadBytesDownloadedMiB|
128 // |kMetricAttemptPayloadDownloadSpeedKBps|
129 // |kMetricAttemptDownloadSource|
130 // |kMetricAttemptDownloadErrorCode|
131 // |kMetricAttemptConnectionType|
132 virtual void ReportUpdateAttemptDownloadMetrics(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700133 int64_t payload_bytes_downloaded,
134 int64_t payload_download_speed_bps,
135 DownloadSource download_source,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700136 metrics::DownloadErrorCode payload_download_error_code,
137 metrics::ConnectionType connection_type) = 0;
138
139 // Reports the |kAbnormalTermination| for the |kMetricAttemptResult|
140 // metric. No other metrics in the UpdateEngine.Attempt.* namespace
141 // will be reported.
142 virtual void ReportAbnormallyTerminatedUpdateAttemptMetrics() = 0;
143
144 // Helper function to report the after the completion of a successful
145 // update attempt. The following metrics are reported:
146 //
147 // |kMetricSuccessfulUpdateAttemptCount|
148 // |kMetricSuccessfulUpdateUpdatesAbandonedCount|
149 // |kMetricSuccessfulUpdatePayloadType|
150 // |kMetricSuccessfulUpdatePayloadSizeMiB|
151 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpsServer|
152 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpServer|
153 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpPeer|
154 // |kMetricSuccessfulUpdateBytesDownloadedMiB|
155 // |kMetricSuccessfulUpdateDownloadSourcesUsed|
156 // |kMetricSuccessfulUpdateDownloadOverheadPercentage|
157 // |kMetricSuccessfulUpdateTotalDurationMinutes|
Sen Jiang8712e962018-05-08 12:12:28 -0700158 // |kMetricSuccessfulUpdateTotalDurationUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700159 // |kMetricSuccessfulUpdateRebootCount|
160 // |kMetricSuccessfulUpdateUrlSwitchCount|
161 //
162 // The values for the |kMetricSuccessfulUpdateDownloadSourcesUsed| are
163 // |kMetricSuccessfulUpdateBytesDownloadedMiB| metrics automatically
164 // calculated from examining the |num_bytes_downloaded| array.
165 virtual void ReportSuccessfulUpdateMetrics(
166 int attempt_count,
167 int updates_abandoned_count,
168 PayloadType payload_type,
169 int64_t payload_size,
170 int64_t num_bytes_downloaded[kNumDownloadSources],
171 int download_overhead_percentage,
172 base::TimeDelta total_duration,
Sen Jiang8712e962018-05-08 12:12:28 -0700173 base::TimeDelta total_duration_uptime,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700174 int reboot_count,
175 int url_switch_count) = 0;
176
177 // Helper function to report the after the completion of a SSL certificate
178 // check. One of the following metrics is reported:
179 //
180 // |kMetricCertificateCheckUpdateCheck|
181 // |kMetricCertificateCheckDownload|
182 virtual void ReportCertificateCheckMetrics(ServerToCheck server_to_check,
183 CertificateCheckResult result) = 0;
184
185 // Helper function to report the number failed update attempts. The following
186 // metrics are reported:
187 //
188 // |kMetricFailedUpdateCount|
189 virtual void ReportFailedUpdateCount(int target_attempt) = 0;
190
191 // Helper function to report the time interval in minutes between a
192 // successful update and the reboot into the updated system. The following
193 // metrics are reported:
194 //
195 // |kMetricTimeToRebootMinutes|
196 virtual void ReportTimeToReboot(int time_to_reboot_minutes) = 0;
197
198 // Helper function to report the source of installation data. The following
199 // metrics are reported:
200 //
201 // |kMetricInstallDateProvisioningSource|
202 virtual void ReportInstallDateProvisioningSource(int source, int max) = 0;
Amin Hassani80f4d4c2018-05-16 13:34:00 -0700203
204 // Helper function to report an internal error code. The following metrics are
205 // reported:
206 //
207 // |kMetricAttemptInternalErrorCode|
208 virtual void ReportInternalErrorCode(ErrorCode error_code) = 0;
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +0200209
210 // Helper function to report metrics related to the verified boot key
211 // versions:
212 //
213 // |kMetricKernelMinVersion|
214 // |kMetricKernelMaxRollforwardVersion|
215 // |kMetricKernelMaxRollforwardSetSuccess|
216 virtual void ReportKeyVersionMetrics(int kernel_min_version,
217 int kernel_max_rollforward_version,
218 bool kernel_max_rollforward_success) = 0;
May Lippert60aa3ca2018-08-15 16:55:29 -0700219
220 // Helper function to report the duration between an update being seen by the
221 // client to the update being applied. Updates are not always immediately
222 // applied when seen, several enterprise policies can affect when an update
223 // would actually be downloaded and applied.
224 //
225 // This metric should only be reported for enterprise enrolled devices.
226 //
227 // The following metrics are reported from this function:
228 // If |has_time_restriction_policy| is false:
229 // |kMetricSuccessfulUpdateDurationFromSeenDays|
230 // If |has_time_restriction_policy| is true:
231 // |kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays|
232 //
233 virtual void ReportEnterpriseUpdateSeenToDownloadDays(
234 bool has_time_restriction_policy, int time_to_update_days) = 0;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700235};
236
Amin Hassani538bd592020-11-04 20:46:08 -0800237namespace metrics {
238
Yifan Hongc514f662021-02-04 11:18:43 -0800239std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter(
240 DynamicPartitionControlInterface* dynamic_partition_control);
Amin Hassani538bd592020-11-04 20:46:08 -0800241
242} // namespace metrics
243
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700244} // namespace chromeos_update_engine
245
Amin Hassaniec7bc112020-10-29 16:47:58 -0700246#endif // UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_