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 20 #include <memory> 21 #include <string> 22 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 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[]; 46 extern const char kMetricCheckTargetVersion[]; 47 extern const char kMetricCheckRollbackTargetVersion[]; 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 kMetricSuccessfulUpdateDurationFromSeenDays[]; 73 extern const char kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays[]; 74 extern const char kMetricSuccessfulUpdatePayloadType[]; 75 extern const char kMetricSuccessfulUpdatePayloadSizeMiB[]; 76 extern const char kMetricSuccessfulUpdateRebootCount[]; 77 extern const char kMetricSuccessfulUpdateTotalDurationMinutes[]; 78 extern const char kMetricSuccessfulUpdateTotalDurationUptimeMinutes[]; 79 extern const char kMetricSuccessfulUpdateUpdatesAbandonedCount[]; 80 extern const char kMetricSuccessfulUpdateUrlSwitchCount[]; 81 82 // UpdateEngine.Rollback.* metric. 83 extern const char kMetricRollbackResult[]; 84 85 // UpdateEngine.EnterpriseRollback.* metrics. 86 extern const char kMetricEnterpriseRollbackFailure[]; 87 extern const char kMetricEnterpriseRollbackSuccess[]; 88 89 // UpdateEngine.CertificateCheck.* metrics. 90 extern const char kMetricCertificateCheckUpdateCheck[]; 91 extern const char kMetricCertificateCheckDownload[]; 92 93 // UpdateEngine.KernelKey.* metrics. 94 extern const char kMetricKernelMinVersion[]; 95 extern const char kMetricKernelMaxRollforwardVersion[]; 96 extern const char kMetricKernelMaxRollforwardSetSuccess[]; 97 98 // UpdateEngine.* metrics. 99 extern const char kMetricFailedUpdateCount[]; 100 extern const char kMetricInstallDateProvisioningSource[]; 101 extern const char kMetricTimeToRebootMinutes[]; 102 103 } // namespace metrics 104 105 class MetricsReporterOmaha : public MetricsReporterInterface { 106 public: 107 MetricsReporterOmaha(); 108 109 ~MetricsReporterOmaha() override = default; 110 111 void Initialize() override; 112 113 void ReportRollbackMetrics(metrics::RollbackResult result) override; 114 115 void ReportEnterpriseRollbackMetrics( 116 bool success, const std::string& rollback_version) override; 117 118 void ReportDailyMetrics(base::TimeDelta os_age) override; 119 120 void ReportUpdateCheckMetrics( 121 SystemState* system_state, 122 metrics::CheckResult result, 123 metrics::CheckReaction reaction, 124 metrics::DownloadErrorCode download_error_code) override; 125 126 void ReportUpdateAttemptMetrics(SystemState* system_state, 127 int attempt_number, 128 PayloadType payload_type, 129 base::TimeDelta duration, 130 base::TimeDelta duration_uptime, 131 int64_t payload_size, 132 metrics::AttemptResult attempt_result, 133 ErrorCode internal_error_code) override; 134 135 void ReportUpdateAttemptDownloadMetrics( 136 int64_t payload_bytes_downloaded, 137 int64_t payload_download_speed_bps, 138 DownloadSource download_source, 139 metrics::DownloadErrorCode payload_download_error_code, 140 metrics::ConnectionType connection_type) override; 141 142 void ReportAbnormallyTerminatedUpdateAttemptMetrics() override; 143 144 void ReportSuccessfulUpdateMetrics( 145 int attempt_count, 146 int updates_abandoned_count, 147 PayloadType payload_type, 148 int64_t payload_size, 149 int64_t num_bytes_downloaded[kNumDownloadSources], 150 int download_overhead_percentage, 151 base::TimeDelta total_duration, 152 base::TimeDelta total_duration_uptime, 153 int reboot_count, 154 int url_switch_count) override; 155 156 void ReportCertificateCheckMetrics(ServerToCheck server_to_check, 157 CertificateCheckResult result) override; 158 159 void ReportFailedUpdateCount(int target_attempt) override; 160 161 void ReportTimeToReboot(int time_to_reboot_minutes) override; 162 163 void ReportInstallDateProvisioningSource(int source, int max) override; 164 165 void ReportInternalErrorCode(ErrorCode error_code) override; 166 167 void ReportKeyVersionMetrics(int kernel_min_version, 168 int kernel_max_rollforward_version, 169 bool kernel_max_rollforward_success) override; 170 171 void ReportEnterpriseUpdateSeenToDownloadDays( 172 bool has_time_restriction_policy, int time_to_update_days) override; 173 174 private: 175 friend class MetricsReporterOmahaTest; 176 177 std::unique_ptr<MetricsLibraryInterface> metrics_lib_; 178 179 DISALLOW_COPY_AND_ASSIGN(MetricsReporterOmaha); 180 }; // class metrics 181 182 } // namespace chromeos_update_engine 183 184 #endif // UPDATE_ENGINE_METRICS_REPORTER_OMAHA_H_ 185