| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 17 | #ifndef UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_ | 
 | 18 | #define UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_ | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 19 |  | 
| Tianjie Xu | d4c5deb | 2017-10-24 11:17:03 -0700 | [diff] [blame] | 20 | #include <memory> | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 21 | #include <string> | 
| Tianjie Xu | d4c5deb | 2017-10-24 11:17:03 -0700 | [diff] [blame] | 22 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 23 | #include <base/time/time.h> | 
 | 24 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 25 | #include "update_engine/common/constants.h" | 
 | 26 | #include "update_engine/common/error_code.h" | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 27 | #include "update_engine/common/metrics_constants.h" | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 28 |  | 
 | 29 | namespace chromeos_update_engine { | 
 | 30 |  | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 31 | enum class ServerToCheck; | 
 | 32 | enum class CertificateCheckResult; | 
 | 33 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 34 | class MetricsReporterInterface { | 
 | 35 |  public: | 
 | 36 |   virtual ~MetricsReporterInterface() = default; | 
 | 37 |  | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 38 |   // Helper function to report metrics related to user-initiated rollback. The | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 39 |   // following metrics are reported: | 
 | 40 |   // | 
 | 41 |   //  |kMetricRollbackResult| | 
 | 42 |   virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0; | 
 | 43 |  | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 44 |   // 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 Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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| | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 67 |   //  |kMetricCheckTargetVersion| | 
 | 68 |   //  |kMetricCheckRollbackTargetVersion| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 69 |   // | 
 | 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 Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 83 |   // | 
 | 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 Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 87 |   virtual void ReportUpdateCheckMetrics( | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 88 |       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 Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 98 |   //  |kMetricAttemptDurationMinutes| | 
 | 99 |   //  |kMetricAttemptDurationUptimeMinutes| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 100 |   //  |kMetricAttemptTimeSinceLastAttemptMinutes| | 
 | 101 |   //  |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 102 |   //  |kMetricAttemptResult| | 
 | 103 |   //  |kMetricAttemptInternalErrorCode| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 104 |   // | 
 | 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 Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 115 |   virtual void ReportUpdateAttemptMetrics(int attempt_number, | 
| Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 116 |                                           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 Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 132 |       int64_t payload_bytes_downloaded, | 
 | 133 |       int64_t payload_download_speed_bps, | 
 | 134 |       DownloadSource download_source, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 135 |       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 Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 157 |   //  |kMetricSuccessfulUpdateTotalDurationUptimeMinutes| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 158 |   //  |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 Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 172 |       base::TimeDelta total_duration_uptime, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 173 |       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 Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 202 |  | 
 | 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 Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 208 |  | 
 | 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 Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 218 |  | 
 | 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 Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 234 | }; | 
 | 235 |  | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 236 | namespace metrics { | 
 | 237 |  | 
 | 238 | std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter(); | 
 | 239 |  | 
 | 240 | }  // namespace metrics | 
 | 241 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 242 | }  // namespace chromeos_update_engine | 
 | 243 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 244 | #endif  // UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_ |