blob: 85ffb850233881c8d36b5793ef629863014e8aaa [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
17#ifndef UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_
18#define UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_
19
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"
27#include "update_engine/metrics_constants.h"
28#include "update_engine/system_state.h"
29
30namespace chromeos_update_engine {
31
Tianjie Xu1b661142017-09-28 14:03:42 -070032enum class ServerToCheck;
33enum class CertificateCheckResult;
34
Tianjie Xud4c5deb2017-10-24 11:17:03 -070035namespace metrics {
36
37std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter();
38
39} // namespace metrics
40
Tianjie Xu282aa1f2017-09-05 13:42:45 -070041class MetricsReporterInterface {
42 public:
43 virtual ~MetricsReporterInterface() = default;
44
45 virtual void Initialize() = 0;
46
Marton Hunyadya0302682018-05-16 18:52:13 +020047 // Helper function to report metrics related to user-initiated rollback. The
Tianjie Xu282aa1f2017-09-05 13:42:45 -070048 // following metrics are reported:
49 //
50 // |kMetricRollbackResult|
51 virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0;
52
Marton Hunyadya0302682018-05-16 18:52:13 +020053 // Helper function to report metrics related to enterprise (admin-initiated)
54 // rollback:
55 //
56 // |kMetricEnterpriseRollbackSuccess|
57 // |kMetricEnterpriseRollbackFailure|
58 virtual void ReportEnterpriseRollbackMetrics(
59 bool success, const std::string& rollback_version) = 0;
60
Tianjie Xu282aa1f2017-09-05 13:42:45 -070061 // Helper function to report metrics reported once a day. The
62 // following metrics are reported:
63 //
64 // |kMetricDailyOSAgeDays|
65 virtual void ReportDailyMetrics(base::TimeDelta os_age) = 0;
66
67 // Helper function to report metrics after completing an update check
68 // with the ChromeOS update server ("Omaha"). The following metrics
69 // are reported:
70 //
71 // |kMetricCheckResult|
72 // |kMetricCheckReaction|
73 // |kMetricCheckDownloadErrorCode|
74 // |kMetricCheckTimeSinceLastCheckMinutes|
75 // |kMetricCheckTimeSinceLastCheckUptimeMinutes|
Marton Hunyadya0302682018-05-16 18:52:13 +020076 // |kMetricCheckTargetVersion|
77 // |kMetricCheckRollbackTargetVersion|
Tianjie Xu282aa1f2017-09-05 13:42:45 -070078 //
79 // The |kMetricCheckResult| metric will only be reported if |result|
80 // is not |kUnset|.
81 //
82 // The |kMetricCheckReaction| metric will only be reported if
83 // |reaction| is not |kUnset|.
84 //
85 // The |kMetricCheckDownloadErrorCode| will only be reported if
86 // |download_error_code| is not |kUnset|.
87 //
88 // The values for the |kMetricCheckTimeSinceLastCheckMinutes| and
89 // |kMetricCheckTimeSinceLastCheckUptimeMinutes| metrics are
90 // automatically reported and calculated by maintaining persistent
91 // and process-local state variables.
Marton Hunyadya0302682018-05-16 18:52:13 +020092 //
93 // |kMetricCheckTargetVersion| reports the first section of the target version
94 // if it's set, |kMetricCheckRollbackTargetVersion| reports the same, but only
95 // if rollback is also allowed using enterprise policy.
Tianjie Xu282aa1f2017-09-05 13:42:45 -070096 virtual void ReportUpdateCheckMetrics(
97 SystemState* system_state,
98 metrics::CheckResult result,
99 metrics::CheckReaction reaction,
100 metrics::DownloadErrorCode download_error_code) = 0;
101
102 // Helper function to report metrics after the completion of each
103 // update attempt. The following metrics are reported:
104 //
105 // |kMetricAttemptNumber|
106 // |kMetricAttemptPayloadType|
107 // |kMetricAttemptPayloadSizeMiB|
Tianjie Xu1b661142017-09-28 14:03:42 -0700108 // |kMetricAttemptDurationMinutes|
109 // |kMetricAttemptDurationUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700110 // |kMetricAttemptTimeSinceLastAttemptMinutes|
111 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700112 // |kMetricAttemptResult|
113 // |kMetricAttemptInternalErrorCode|
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700114 //
115 // The |kMetricAttemptInternalErrorCode| metric will only be reported
116 // if |internal_error_code| is not |kErrorSuccess|.
117 //
118 // The |kMetricAttemptDownloadErrorCode| metric will only be
119 // reported if |payload_download_error_code| is not |kUnset|.
120 //
121 // The values for the |kMetricAttemptTimeSinceLastAttemptMinutes| and
122 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| metrics are
123 // automatically calculated and reported by maintaining persistent and
124 // process-local state variables.
Tianjie Xu1f93d092017-10-09 12:13:29 -0700125 virtual void ReportUpdateAttemptMetrics(SystemState* system_state,
126 int attempt_number,
127 PayloadType payload_type,
128 base::TimeDelta duration,
129 base::TimeDelta duration_uptime,
130 int64_t payload_size,
131 metrics::AttemptResult attempt_result,
132 ErrorCode internal_error_code) = 0;
133
134 // Helper function to report download metrics after the completion of each
135 // update attempt. The following metrics are reported:
136 //
137 // |kMetricAttemptPayloadBytesDownloadedMiB|
138 // |kMetricAttemptPayloadDownloadSpeedKBps|
139 // |kMetricAttemptDownloadSource|
140 // |kMetricAttemptDownloadErrorCode|
141 // |kMetricAttemptConnectionType|
142 virtual void ReportUpdateAttemptDownloadMetrics(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700143 int64_t payload_bytes_downloaded,
144 int64_t payload_download_speed_bps,
145 DownloadSource download_source,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700146 metrics::DownloadErrorCode payload_download_error_code,
147 metrics::ConnectionType connection_type) = 0;
148
149 // Reports the |kAbnormalTermination| for the |kMetricAttemptResult|
150 // metric. No other metrics in the UpdateEngine.Attempt.* namespace
151 // will be reported.
152 virtual void ReportAbnormallyTerminatedUpdateAttemptMetrics() = 0;
153
154 // Helper function to report the after the completion of a successful
155 // update attempt. The following metrics are reported:
156 //
157 // |kMetricSuccessfulUpdateAttemptCount|
158 // |kMetricSuccessfulUpdateUpdatesAbandonedCount|
159 // |kMetricSuccessfulUpdatePayloadType|
160 // |kMetricSuccessfulUpdatePayloadSizeMiB|
161 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpsServer|
162 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpServer|
163 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpPeer|
164 // |kMetricSuccessfulUpdateBytesDownloadedMiB|
165 // |kMetricSuccessfulUpdateDownloadSourcesUsed|
166 // |kMetricSuccessfulUpdateDownloadOverheadPercentage|
167 // |kMetricSuccessfulUpdateTotalDurationMinutes|
168 // |kMetricSuccessfulUpdateRebootCount|
169 // |kMetricSuccessfulUpdateUrlSwitchCount|
170 //
171 // The values for the |kMetricSuccessfulUpdateDownloadSourcesUsed| are
172 // |kMetricSuccessfulUpdateBytesDownloadedMiB| metrics automatically
173 // calculated from examining the |num_bytes_downloaded| array.
174 virtual void ReportSuccessfulUpdateMetrics(
175 int attempt_count,
176 int updates_abandoned_count,
177 PayloadType payload_type,
178 int64_t payload_size,
179 int64_t num_bytes_downloaded[kNumDownloadSources],
180 int download_overhead_percentage,
181 base::TimeDelta total_duration,
182 int reboot_count,
183 int url_switch_count) = 0;
184
185 // Helper function to report the after the completion of a SSL certificate
186 // check. One of the following metrics is reported:
187 //
188 // |kMetricCertificateCheckUpdateCheck|
189 // |kMetricCertificateCheckDownload|
190 virtual void ReportCertificateCheckMetrics(ServerToCheck server_to_check,
191 CertificateCheckResult result) = 0;
192
193 // Helper function to report the number failed update attempts. The following
194 // metrics are reported:
195 //
196 // |kMetricFailedUpdateCount|
197 virtual void ReportFailedUpdateCount(int target_attempt) = 0;
198
199 // Helper function to report the time interval in minutes between a
200 // successful update and the reboot into the updated system. The following
201 // metrics are reported:
202 //
203 // |kMetricTimeToRebootMinutes|
204 virtual void ReportTimeToReboot(int time_to_reboot_minutes) = 0;
205
206 // Helper function to report the source of installation data. The following
207 // metrics are reported:
208 //
209 // |kMetricInstallDateProvisioningSource|
210 virtual void ReportInstallDateProvisioningSource(int source, int max) = 0;
Amin Hassani80f4d4c2018-05-16 13:34:00 -0700211
212 // Helper function to report an internal error code. The following metrics are
213 // reported:
214 //
215 // |kMetricAttemptInternalErrorCode|
216 virtual void ReportInternalErrorCode(ErrorCode error_code) = 0;
Marton Hunyadyffbfdfb2018-05-30 13:03:29 +0200217
218 // Helper function to report metrics related to the verified boot key
219 // versions:
220 //
221 // |kMetricKernelMinVersion|
222 // |kMetricKernelMaxRollforwardVersion|
223 // |kMetricKernelMaxRollforwardSetSuccess|
224 virtual void ReportKeyVersionMetrics(int kernel_min_version,
225 int kernel_max_rollforward_version,
226 bool kernel_max_rollforward_success) = 0;
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700227};
228
229} // namespace chromeos_update_engine
230
231#endif // UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_