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 | |
| 17 | #ifndef UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ |
| 18 | #define UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ |
| 19 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 20 | #include <memory> |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame^] | 21 | #include <string> |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 22 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 23 | #include <base/time/time.h> |
| 24 | #include <metrics/metrics_library.h> |
| 25 | |
| 26 | #include "update_engine/certificate_checker.h" |
| 27 | #include "update_engine/common/constants.h" |
| 28 | #include "update_engine/common/error_code.h" |
| 29 | #include "update_engine/metrics_constants.h" |
| 30 | #include "update_engine/metrics_reporter_interface.h" |
| 31 | #include "update_engine/system_state.h" |
| 32 | |
| 33 | namespace chromeos_update_engine { |
| 34 | |
| 35 | class SystemState; |
| 36 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 37 | namespace metrics { |
| 38 | |
| 39 | // UpdateEngine.Daily.* metrics. |
| 40 | extern const char kMetricDailyOSAgeDays[]; |
| 41 | |
| 42 | // UpdateEngine.Check.* metrics. |
| 43 | extern const char kMetricCheckDownloadErrorCode[]; |
| 44 | extern const char kMetricCheckReaction[]; |
| 45 | extern const char kMetricCheckResult[]; |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame^] | 46 | extern const char kMetricCheckTargetVersion[]; |
| 47 | extern const char kMetricCheckRollbackTargetVersion[]; |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 48 | extern const char kMetricCheckTimeSinceLastCheckMinutes[]; |
| 49 | extern const char kMetricCheckTimeSinceLastCheckUptimeMinutes[]; |
| 50 | |
| 51 | // UpdateEngine.Attempt.* metrics. |
| 52 | extern const char kMetricAttemptNumber[]; |
| 53 | extern const char kMetricAttemptPayloadType[]; |
| 54 | extern const char kMetricAttemptPayloadSizeMiB[]; |
| 55 | extern const char kMetricAttemptConnectionType[]; |
| 56 | extern const char kMetricAttemptDurationMinutes[]; |
| 57 | extern const char kMetricAttemptDurationUptimeMinutes[]; |
| 58 | extern const char kMetricAttemptTimeSinceLastAttemptMinutes[]; |
| 59 | extern const char kMetricAttemptTimeSinceLastAttemptUptimeMinutes[]; |
| 60 | extern const char kMetricAttemptPayloadBytesDownloadedMiB[]; |
| 61 | extern const char kMetricAttemptPayloadDownloadSpeedKBps[]; |
| 62 | extern const char kMetricAttemptDownloadSource[]; |
| 63 | extern const char kMetricAttemptResult[]; |
| 64 | extern const char kMetricAttemptInternalErrorCode[]; |
| 65 | extern const char kMetricAttemptDownloadErrorCode[]; |
| 66 | |
| 67 | // UpdateEngine.SuccessfulUpdate.* metrics. |
| 68 | extern const char kMetricSuccessfulUpdateAttemptCount[]; |
| 69 | extern const char kMetricSuccessfulUpdateBytesDownloadedMiB[]; |
| 70 | extern const char kMetricSuccessfulUpdateDownloadOverheadPercentage[]; |
| 71 | extern const char kMetricSuccessfulUpdateDownloadSourcesUsed[]; |
| 72 | extern const char kMetricSuccessfulUpdatePayloadType[]; |
| 73 | extern const char kMetricSuccessfulUpdatePayloadSizeMiB[]; |
| 74 | extern const char kMetricSuccessfulUpdateRebootCount[]; |
| 75 | extern const char kMetricSuccessfulUpdateTotalDurationMinutes[]; |
| 76 | extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[]; |
| 77 | extern const char kMetricSuccessfulUpdateUrlSwitchCount[]; |
| 78 | |
| 79 | // UpdateEngine.Rollback.* metric. |
| 80 | extern const char kMetricRollbackResult[]; |
| 81 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame^] | 82 | // UpdateEngine.EnterpriseRollback.* metrics. |
| 83 | extern const char kMetricEnterpriseRollbackFailure[]; |
| 84 | extern const char kMetricEnterpriseRollbackSuccess[]; |
| 85 | |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 86 | // UpdateEngine.CertificateCheck.* metrics. |
| 87 | extern const char kMetricCertificateCheckUpdateCheck[]; |
| 88 | extern const char kMetricCertificateCheckDownload[]; |
| 89 | |
| 90 | // UpdateEngine.* metrics. |
| 91 | extern const char kMetricFailedUpdateCount[]; |
| 92 | extern const char kMetricInstallDateProvisioningSource[]; |
| 93 | extern const char kMetricTimeToRebootMinutes[]; |
| 94 | |
| 95 | } // namespace metrics |
| 96 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 97 | class MetricsReporterOmaha : public MetricsReporterInterface { |
| 98 | public: |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 99 | MetricsReporterOmaha(); |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 100 | |
| 101 | ~MetricsReporterOmaha() override = default; |
| 102 | |
| 103 | void Initialize() override; |
| 104 | |
| 105 | void ReportRollbackMetrics(metrics::RollbackResult result) override; |
| 106 | |
Marton Hunyady | a030268 | 2018-05-16 18:52:13 +0200 | [diff] [blame^] | 107 | void ReportEnterpriseRollbackMetrics( |
| 108 | bool success, const std::string& rollback_version) override; |
| 109 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 110 | void ReportDailyMetrics(base::TimeDelta os_age) override; |
| 111 | |
| 112 | void ReportUpdateCheckMetrics( |
| 113 | SystemState* system_state, |
| 114 | metrics::CheckResult result, |
| 115 | metrics::CheckReaction reaction, |
| 116 | metrics::DownloadErrorCode download_error_code) override; |
| 117 | |
Tianjie Xu | 1f93d09 | 2017-10-09 12:13:29 -0700 | [diff] [blame] | 118 | void ReportUpdateAttemptMetrics(SystemState* system_state, |
| 119 | int attempt_number, |
| 120 | PayloadType payload_type, |
| 121 | base::TimeDelta duration, |
| 122 | base::TimeDelta duration_uptime, |
| 123 | int64_t payload_size, |
| 124 | metrics::AttemptResult attempt_result, |
| 125 | ErrorCode internal_error_code) override; |
| 126 | |
| 127 | void ReportUpdateAttemptDownloadMetrics( |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 128 | int64_t payload_bytes_downloaded, |
| 129 | int64_t payload_download_speed_bps, |
| 130 | DownloadSource download_source, |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 131 | metrics::DownloadErrorCode payload_download_error_code, |
| 132 | metrics::ConnectionType connection_type) override; |
| 133 | |
| 134 | void ReportAbnormallyTerminatedUpdateAttemptMetrics() override; |
| 135 | |
| 136 | void ReportSuccessfulUpdateMetrics( |
| 137 | int attempt_count, |
| 138 | int updates_abandoned_count, |
| 139 | PayloadType payload_type, |
| 140 | int64_t payload_size, |
| 141 | int64_t num_bytes_downloaded[kNumDownloadSources], |
| 142 | int download_overhead_percentage, |
| 143 | base::TimeDelta total_duration, |
| 144 | int reboot_count, |
| 145 | int url_switch_count) override; |
| 146 | |
| 147 | void ReportCertificateCheckMetrics(ServerToCheck server_to_check, |
| 148 | CertificateCheckResult result) override; |
| 149 | |
| 150 | void ReportFailedUpdateCount(int target_attempt) override; |
| 151 | |
| 152 | void ReportTimeToReboot(int time_to_reboot_minutes) override; |
| 153 | |
| 154 | void ReportInstallDateProvisioningSource(int source, int max) override; |
| 155 | |
Amin Hassani | 80f4d4c | 2018-05-16 13:34:00 -0700 | [diff] [blame] | 156 | void ReportInternalErrorCode(ErrorCode error_code) override; |
| 157 | |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 158 | private: |
Tianjie Xu | 98333a8 | 2017-09-22 21:29:29 -0700 | [diff] [blame] | 159 | friend class MetricsReporterOmahaTest; |
| 160 | |
| 161 | std::unique_ptr<MetricsLibraryInterface> metrics_lib_; |
Tianjie Xu | 282aa1f | 2017-09-05 13:42:45 -0700 | [diff] [blame] | 162 | |
| 163 | DISALLOW_COPY_AND_ASSIGN(MetricsReporterOmaha); |
| 164 | }; // class metrics |
| 165 | |
| 166 | } // namespace chromeos_update_engine |
| 167 | |
| 168 | #endif // UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ |