blob: 2c7ce5b52f8d520c1cdd19251b7d59344d3ad10e [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>
21
Tianjie Xu282aa1f2017-09-05 13:42:45 -070022#include <base/time/time.h>
23
Tianjie Xu282aa1f2017-09-05 13:42:45 -070024#include "update_engine/common/constants.h"
25#include "update_engine/common/error_code.h"
26#include "update_engine/metrics_constants.h"
27#include "update_engine/system_state.h"
28
29namespace chromeos_update_engine {
30
Tianjie Xu1b661142017-09-28 14:03:42 -070031enum class ServerToCheck;
32enum class CertificateCheckResult;
33
Tianjie Xud4c5deb2017-10-24 11:17:03 -070034namespace metrics {
35
36std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter();
37
38} // namespace metrics
39
Tianjie Xu282aa1f2017-09-05 13:42:45 -070040class MetricsReporterInterface {
41 public:
42 virtual ~MetricsReporterInterface() = default;
43
44 virtual void Initialize() = 0;
45
46 // Helper function to report metrics related to rollback. The
47 // following metrics are reported:
48 //
49 // |kMetricRollbackResult|
50 virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0;
51
52 // 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|
67 //
68 // The |kMetricCheckResult| metric will only be reported if |result|
69 // is not |kUnset|.
70 //
71 // The |kMetricCheckReaction| metric will only be reported if
72 // |reaction| is not |kUnset|.
73 //
74 // The |kMetricCheckDownloadErrorCode| will only be reported if
75 // |download_error_code| is not |kUnset|.
76 //
77 // The values for the |kMetricCheckTimeSinceLastCheckMinutes| and
78 // |kMetricCheckTimeSinceLastCheckUptimeMinutes| metrics are
79 // automatically reported and calculated by maintaining persistent
80 // and process-local state variables.
81 virtual void ReportUpdateCheckMetrics(
82 SystemState* system_state,
83 metrics::CheckResult result,
84 metrics::CheckReaction reaction,
85 metrics::DownloadErrorCode download_error_code) = 0;
86
87 // Helper function to report metrics after the completion of each
88 // update attempt. The following metrics are reported:
89 //
90 // |kMetricAttemptNumber|
91 // |kMetricAttemptPayloadType|
92 // |kMetricAttemptPayloadSizeMiB|
Tianjie Xu1b661142017-09-28 14:03:42 -070093 // |kMetricAttemptDurationMinutes|
94 // |kMetricAttemptDurationUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -070095 // |kMetricAttemptTimeSinceLastAttemptMinutes|
96 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
Tianjie Xu282aa1f2017-09-05 13:42:45 -070097 // |kMetricAttemptResult|
98 // |kMetricAttemptInternalErrorCode|
Tianjie Xu282aa1f2017-09-05 13:42:45 -070099 //
100 // The |kMetricAttemptInternalErrorCode| metric will only be reported
101 // if |internal_error_code| is not |kErrorSuccess|.
102 //
103 // The |kMetricAttemptDownloadErrorCode| metric will only be
104 // reported if |payload_download_error_code| is not |kUnset|.
105 //
106 // The values for the |kMetricAttemptTimeSinceLastAttemptMinutes| and
107 // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| metrics are
108 // automatically calculated and reported by maintaining persistent and
109 // process-local state variables.
Tianjie Xu1f93d092017-10-09 12:13:29 -0700110 virtual void ReportUpdateAttemptMetrics(SystemState* system_state,
111 int attempt_number,
112 PayloadType payload_type,
113 base::TimeDelta duration,
114 base::TimeDelta duration_uptime,
115 int64_t payload_size,
116 metrics::AttemptResult attempt_result,
117 ErrorCode internal_error_code) = 0;
118
119 // Helper function to report download metrics after the completion of each
120 // update attempt. The following metrics are reported:
121 //
122 // |kMetricAttemptPayloadBytesDownloadedMiB|
123 // |kMetricAttemptPayloadDownloadSpeedKBps|
124 // |kMetricAttemptDownloadSource|
125 // |kMetricAttemptDownloadErrorCode|
126 // |kMetricAttemptConnectionType|
127 virtual void ReportUpdateAttemptDownloadMetrics(
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700128 int64_t payload_bytes_downloaded,
129 int64_t payload_download_speed_bps,
130 DownloadSource download_source,
Tianjie Xu282aa1f2017-09-05 13:42:45 -0700131 metrics::DownloadErrorCode payload_download_error_code,
132 metrics::ConnectionType connection_type) = 0;
133
134 // Reports the |kAbnormalTermination| for the |kMetricAttemptResult|
135 // metric. No other metrics in the UpdateEngine.Attempt.* namespace
136 // will be reported.
137 virtual void ReportAbnormallyTerminatedUpdateAttemptMetrics() = 0;
138
139 // Helper function to report the after the completion of a successful
140 // update attempt. The following metrics are reported:
141 //
142 // |kMetricSuccessfulUpdateAttemptCount|
143 // |kMetricSuccessfulUpdateUpdatesAbandonedCount|
144 // |kMetricSuccessfulUpdatePayloadType|
145 // |kMetricSuccessfulUpdatePayloadSizeMiB|
146 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpsServer|
147 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpServer|
148 // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpPeer|
149 // |kMetricSuccessfulUpdateBytesDownloadedMiB|
150 // |kMetricSuccessfulUpdateDownloadSourcesUsed|
151 // |kMetricSuccessfulUpdateDownloadOverheadPercentage|
152 // |kMetricSuccessfulUpdateTotalDurationMinutes|
153 // |kMetricSuccessfulUpdateRebootCount|
154 // |kMetricSuccessfulUpdateUrlSwitchCount|
155 //
156 // The values for the |kMetricSuccessfulUpdateDownloadSourcesUsed| are
157 // |kMetricSuccessfulUpdateBytesDownloadedMiB| metrics automatically
158 // calculated from examining the |num_bytes_downloaded| array.
159 virtual void ReportSuccessfulUpdateMetrics(
160 int attempt_count,
161 int updates_abandoned_count,
162 PayloadType payload_type,
163 int64_t payload_size,
164 int64_t num_bytes_downloaded[kNumDownloadSources],
165 int download_overhead_percentage,
166 base::TimeDelta total_duration,
167 int reboot_count,
168 int url_switch_count) = 0;
169
170 // Helper function to report the after the completion of a SSL certificate
171 // check. One of the following metrics is reported:
172 //
173 // |kMetricCertificateCheckUpdateCheck|
174 // |kMetricCertificateCheckDownload|
175 virtual void ReportCertificateCheckMetrics(ServerToCheck server_to_check,
176 CertificateCheckResult result) = 0;
177
178 // Helper function to report the number failed update attempts. The following
179 // metrics are reported:
180 //
181 // |kMetricFailedUpdateCount|
182 virtual void ReportFailedUpdateCount(int target_attempt) = 0;
183
184 // Helper function to report the time interval in minutes between a
185 // successful update and the reboot into the updated system. The following
186 // metrics are reported:
187 //
188 // |kMetricTimeToRebootMinutes|
189 virtual void ReportTimeToReboot(int time_to_reboot_minutes) = 0;
190
191 // Helper function to report the source of installation data. The following
192 // metrics are reported:
193 //
194 // |kMetricInstallDateProvisioningSource|
195 virtual void ReportInstallDateProvisioningSource(int source, int max) = 0;
196};
197
198} // namespace chromeos_update_engine
199
200#endif // UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_