• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
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_COMMON_METRICS_REPORTER_INTERFACE_H_
18 #define UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_
19 
20 #include <memory>
21 #include <string>
22 
23 #include <base/time/time.h>
24 
25 #include "update_engine/common/constants.h"
26 #include "update_engine/common/dynamic_partition_control_interface.h"
27 #include "update_engine/common/error_code.h"
28 #include "update_engine/common/metrics_constants.h"
29 #include "update_engine/payload_consumer/install_plan.h"
30 
31 namespace chromeos_update_engine {
32 
33 enum class ServerToCheck;
34 enum class CertificateCheckResult;
35 
36 class MetricsReporterInterface {
37  public:
38   virtual ~MetricsReporterInterface() = default;
39 
40   // Helper function to report metrics related to user-initiated rollback. The
41   // following metrics are reported:
42   //
43   //  |kMetricRollbackResult|
44   virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0;
45 
46   // 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 
54   // 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|
69   //  |kMetricCheckTargetVersion|
70   //  |kMetricCheckRollbackTargetVersion|
71   //
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.
85   //
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.
89   virtual void ReportUpdateCheckMetrics(
90       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|
100   //  |kMetricAttemptDurationMinutes|
101   //  |kMetricAttemptDurationUptimeMinutes|
102   //  |kMetricAttemptTimeSinceLastAttemptMinutes|
103   //  |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
104   //  |kMetricAttemptResult|
105   //  |kMetricAttemptInternalErrorCode|
106   //
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.
117   virtual void ReportUpdateAttemptMetrics(int attempt_number,
118                                           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(
134       int64_t payload_bytes_downloaded,
135       int64_t payload_download_speed_bps,
136       DownloadSource download_source,
137       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|
159   //  |kMetricSuccessfulUpdateTotalDurationUptimeMinutes|
160   //  |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,
174       base::TimeDelta total_duration_uptime,
175       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;
204 
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;
210 
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;
220 
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;
236 };
237 
238 namespace metrics {
239 
240 std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter(
241     DynamicPartitionControlInterface* dynamic_partition_control,
242     const InstallPlan* install_plan);
243 
244 }  // namespace metrics
245 
246 }  // namespace chromeos_update_engine
247 
248 #endif  // UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_
249