| 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" | 
| Yifan Hong | c514f66 | 2021-02-04 11:18:43 -0800 | [diff] [blame] | 26 | #include "update_engine/common/dynamic_partition_control_interface.h" | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 27 | #include "update_engine/common/error_code.h" | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 28 | #include "update_engine/common/metrics_constants.h" | 
| Kelvin Zhang | 9a5e368 | 2021-03-29 12:58:48 -0400 | [diff] [blame] | 29 | #include "update_engine/payload_consumer/install_plan.h" | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 30 |  | 
|  | 31 | namespace chromeos_update_engine { | 
|  | 32 |  | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 33 | enum class ServerToCheck; | 
|  | 34 | enum class CertificateCheckResult; | 
|  | 35 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 36 | class MetricsReporterInterface { | 
|  | 37 | public: | 
|  | 38 | virtual ~MetricsReporterInterface() = default; | 
|  | 39 |  | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 40 | // Helper function to report metrics related to user-initiated rollback. The | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 41 | // following metrics are reported: | 
|  | 42 | // | 
|  | 43 | //  |kMetricRollbackResult| | 
|  | 44 | virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0; | 
|  | 45 |  | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 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 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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| | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 69 | //  |kMetricCheckTargetVersion| | 
|  | 70 | //  |kMetricCheckRollbackTargetVersion| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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. | 
| Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame] | 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. | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 89 | virtual void ReportUpdateCheckMetrics( | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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| | 
| Tianjie Xu | 1b66114 | 2017-09-28 14:03:42 -0700 | [diff] [blame] | 100 | //  |kMetricAttemptDurationMinutes| | 
|  | 101 | //  |kMetricAttemptDurationUptimeMinutes| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 102 | //  |kMetricAttemptTimeSinceLastAttemptMinutes| | 
|  | 103 | //  |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 104 | //  |kMetricAttemptResult| | 
|  | 105 | //  |kMetricAttemptInternalErrorCode| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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. | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 117 | virtual void ReportUpdateAttemptMetrics(int attempt_number, | 
| Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 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( | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 134 | int64_t payload_bytes_downloaded, | 
|  | 135 | int64_t payload_download_speed_bps, | 
|  | 136 | DownloadSource download_source, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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| | 
| Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 159 | //  |kMetricSuccessfulUpdateTotalDurationUptimeMinutes| | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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, | 
| Sen Jiang | 8712e96 | 2018-05-08 12:12:28 -0700 | [diff] [blame] | 174 | base::TimeDelta total_duration_uptime, | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 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; | 
| Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 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; | 
| Marton Hunyady | ffbfdfb | 2018-05-30 13:03:29 +0200 | [diff] [blame] | 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; | 
| May Lippert | 60aa3ca | 2018-08-15 16:55:29 -0700 | [diff] [blame] | 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; | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 236 | }; | 
|  | 237 |  | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 238 | namespace metrics { | 
|  | 239 |  | 
| Yifan Hong | c514f66 | 2021-02-04 11:18:43 -0800 | [diff] [blame] | 240 | std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter( | 
| Kelvin Zhang | 9a5e368 | 2021-03-29 12:58:48 -0400 | [diff] [blame] | 241 | DynamicPartitionControlInterface* dynamic_partition_control, | 
|  | 242 | const InstallPlan* install_plan); | 
| Amin Hassani | 538bd59 | 2020-11-04 20:46:08 -0800 | [diff] [blame] | 243 |  | 
|  | 244 | }  // namespace metrics | 
|  | 245 |  | 
| Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 246 | }  // namespace chromeos_update_engine | 
|  | 247 |  | 
| Amin Hassani | ec7bc11 | 2020-10-29 16:47:58 -0700 | [diff] [blame] | 248 | #endif  // UPDATE_ENGINE_COMMON_METRICS_REPORTER_INTERFACE_H_ |