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