metrics_reporter_interface.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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. #ifndef UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_
  17. #define UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_
  18. #include <memory>
  19. #include <string>
  20. #include <base/time/time.h>
  21. #include "update_engine/common/constants.h"
  22. #include "update_engine/common/error_code.h"
  23. #include "update_engine/metrics_constants.h"
  24. #include "update_engine/system_state.h"
  25. namespace chromeos_update_engine {
  26. enum class ServerToCheck;
  27. enum class CertificateCheckResult;
  28. namespace metrics {
  29. std::unique_ptr<MetricsReporterInterface> CreateMetricsReporter();
  30. } // namespace metrics
  31. class MetricsReporterInterface {
  32. public:
  33. virtual ~MetricsReporterInterface() = default;
  34. virtual void Initialize() = 0;
  35. // Helper function to report metrics related to user-initiated rollback. The
  36. // following metrics are reported:
  37. //
  38. // |kMetricRollbackResult|
  39. virtual void ReportRollbackMetrics(metrics::RollbackResult result) = 0;
  40. // Helper function to report metrics related to enterprise (admin-initiated)
  41. // rollback:
  42. //
  43. // |kMetricEnterpriseRollbackSuccess|
  44. // |kMetricEnterpriseRollbackFailure|
  45. virtual void ReportEnterpriseRollbackMetrics(
  46. bool success, const std::string& rollback_version) = 0;
  47. // Helper function to report metrics reported once a day. The
  48. // following metrics are reported:
  49. //
  50. // |kMetricDailyOSAgeDays|
  51. virtual void ReportDailyMetrics(base::TimeDelta os_age) = 0;
  52. // Helper function to report metrics after completing an update check
  53. // with the ChromeOS update server ("Omaha"). The following metrics
  54. // are reported:
  55. //
  56. // |kMetricCheckResult|
  57. // |kMetricCheckReaction|
  58. // |kMetricCheckDownloadErrorCode|
  59. // |kMetricCheckTimeSinceLastCheckMinutes|
  60. // |kMetricCheckTimeSinceLastCheckUptimeMinutes|
  61. // |kMetricCheckTargetVersion|
  62. // |kMetricCheckRollbackTargetVersion|
  63. //
  64. // The |kMetricCheckResult| metric will only be reported if |result|
  65. // is not |kUnset|.
  66. //
  67. // The |kMetricCheckReaction| metric will only be reported if
  68. // |reaction| is not |kUnset|.
  69. //
  70. // The |kMetricCheckDownloadErrorCode| will only be reported if
  71. // |download_error_code| is not |kUnset|.
  72. //
  73. // The values for the |kMetricCheckTimeSinceLastCheckMinutes| and
  74. // |kMetricCheckTimeSinceLastCheckUptimeMinutes| metrics are
  75. // automatically reported and calculated by maintaining persistent
  76. // and process-local state variables.
  77. //
  78. // |kMetricCheckTargetVersion| reports the first section of the target version
  79. // if it's set, |kMetricCheckRollbackTargetVersion| reports the same, but only
  80. // if rollback is also allowed using enterprise policy.
  81. virtual void ReportUpdateCheckMetrics(
  82. SystemState* system_state,
  83. metrics::CheckResult result,
  84. metrics::CheckReaction reaction,
  85. metrics::DownloadErrorCode download_error_code) = 0;
  86. // Helper function to report metrics after the completion of each
  87. // update attempt. The following metrics are reported:
  88. //
  89. // |kMetricAttemptNumber|
  90. // |kMetricAttemptPayloadType|
  91. // |kMetricAttemptPayloadSizeMiB|
  92. // |kMetricAttemptDurationMinutes|
  93. // |kMetricAttemptDurationUptimeMinutes|
  94. // |kMetricAttemptTimeSinceLastAttemptMinutes|
  95. // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes|
  96. // |kMetricAttemptResult|
  97. // |kMetricAttemptInternalErrorCode|
  98. //
  99. // The |kMetricAttemptInternalErrorCode| metric will only be reported
  100. // if |internal_error_code| is not |kErrorSuccess|.
  101. //
  102. // The |kMetricAttemptDownloadErrorCode| metric will only be
  103. // reported if |payload_download_error_code| is not |kUnset|.
  104. //
  105. // The values for the |kMetricAttemptTimeSinceLastAttemptMinutes| and
  106. // |kMetricAttemptTimeSinceLastAttemptUptimeMinutes| metrics are
  107. // automatically calculated and reported by maintaining persistent and
  108. // process-local state variables.
  109. virtual void ReportUpdateAttemptMetrics(SystemState* system_state,
  110. int attempt_number,
  111. PayloadType payload_type,
  112. base::TimeDelta duration,
  113. base::TimeDelta duration_uptime,
  114. int64_t payload_size,
  115. metrics::AttemptResult attempt_result,
  116. ErrorCode internal_error_code) = 0;
  117. // Helper function to report download metrics after the completion of each
  118. // update attempt. The following metrics are reported:
  119. //
  120. // |kMetricAttemptPayloadBytesDownloadedMiB|
  121. // |kMetricAttemptPayloadDownloadSpeedKBps|
  122. // |kMetricAttemptDownloadSource|
  123. // |kMetricAttemptDownloadErrorCode|
  124. // |kMetricAttemptConnectionType|
  125. virtual void ReportUpdateAttemptDownloadMetrics(
  126. int64_t payload_bytes_downloaded,
  127. int64_t payload_download_speed_bps,
  128. DownloadSource download_source,
  129. metrics::DownloadErrorCode payload_download_error_code,
  130. metrics::ConnectionType connection_type) = 0;
  131. // Reports the |kAbnormalTermination| for the |kMetricAttemptResult|
  132. // metric. No other metrics in the UpdateEngine.Attempt.* namespace
  133. // will be reported.
  134. virtual void ReportAbnormallyTerminatedUpdateAttemptMetrics() = 0;
  135. // Helper function to report the after the completion of a successful
  136. // update attempt. The following metrics are reported:
  137. //
  138. // |kMetricSuccessfulUpdateAttemptCount|
  139. // |kMetricSuccessfulUpdateUpdatesAbandonedCount|
  140. // |kMetricSuccessfulUpdatePayloadType|
  141. // |kMetricSuccessfulUpdatePayloadSizeMiB|
  142. // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpsServer|
  143. // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpServer|
  144. // |kMetricSuccessfulUpdateBytesDownloadedMiBHttpPeer|
  145. // |kMetricSuccessfulUpdateBytesDownloadedMiB|
  146. // |kMetricSuccessfulUpdateDownloadSourcesUsed|
  147. // |kMetricSuccessfulUpdateDownloadOverheadPercentage|
  148. // |kMetricSuccessfulUpdateTotalDurationMinutes|
  149. // |kMetricSuccessfulUpdateTotalDurationUptimeMinutes|
  150. // |kMetricSuccessfulUpdateRebootCount|
  151. // |kMetricSuccessfulUpdateUrlSwitchCount|
  152. //
  153. // The values for the |kMetricSuccessfulUpdateDownloadSourcesUsed| are
  154. // |kMetricSuccessfulUpdateBytesDownloadedMiB| metrics automatically
  155. // calculated from examining the |num_bytes_downloaded| array.
  156. virtual void ReportSuccessfulUpdateMetrics(
  157. int attempt_count,
  158. int updates_abandoned_count,
  159. PayloadType payload_type,
  160. int64_t payload_size,
  161. int64_t num_bytes_downloaded[kNumDownloadSources],
  162. int download_overhead_percentage,
  163. base::TimeDelta total_duration,
  164. base::TimeDelta total_duration_uptime,
  165. int reboot_count,
  166. int url_switch_count) = 0;
  167. // Helper function to report the after the completion of a SSL certificate
  168. // check. One of the following metrics is reported:
  169. //
  170. // |kMetricCertificateCheckUpdateCheck|
  171. // |kMetricCertificateCheckDownload|
  172. virtual void ReportCertificateCheckMetrics(ServerToCheck server_to_check,
  173. CertificateCheckResult result) = 0;
  174. // Helper function to report the number failed update attempts. The following
  175. // metrics are reported:
  176. //
  177. // |kMetricFailedUpdateCount|
  178. virtual void ReportFailedUpdateCount(int target_attempt) = 0;
  179. // Helper function to report the time interval in minutes between a
  180. // successful update and the reboot into the updated system. The following
  181. // metrics are reported:
  182. //
  183. // |kMetricTimeToRebootMinutes|
  184. virtual void ReportTimeToReboot(int time_to_reboot_minutes) = 0;
  185. // Helper function to report the source of installation data. The following
  186. // metrics are reported:
  187. //
  188. // |kMetricInstallDateProvisioningSource|
  189. virtual void ReportInstallDateProvisioningSource(int source, int max) = 0;
  190. // Helper function to report an internal error code. The following metrics are
  191. // reported:
  192. //
  193. // |kMetricAttemptInternalErrorCode|
  194. virtual void ReportInternalErrorCode(ErrorCode error_code) = 0;
  195. // Helper function to report metrics related to the verified boot key
  196. // versions:
  197. //
  198. // |kMetricKernelMinVersion|
  199. // |kMetricKernelMaxRollforwardVersion|
  200. // |kMetricKernelMaxRollforwardSetSuccess|
  201. virtual void ReportKeyVersionMetrics(int kernel_min_version,
  202. int kernel_max_rollforward_version,
  203. bool kernel_max_rollforward_success) = 0;
  204. // Helper function to report the duration between an update being seen by the
  205. // client to the update being applied. Updates are not always immediately
  206. // applied when seen, several enterprise policies can affect when an update
  207. // would actually be downloaded and applied.
  208. //
  209. // This metric should only be reported for enterprise enrolled devices.
  210. //
  211. // The following metrics are reported from this function:
  212. // If |has_time_restriction_policy| is false:
  213. // |kMetricSuccessfulUpdateDurationFromSeenDays|
  214. // If |has_time_restriction_policy| is true:
  215. // |kMetricSuccessfulUpdateDurationFromSeenTimeRestrictedDays|
  216. //
  217. virtual void ReportEnterpriseUpdateSeenToDownloadDays(
  218. bool has_time_restriction_policy, int time_to_update_days) = 0;
  219. };
  220. } // namespace chromeos_update_engine
  221. #endif // UPDATE_ENGINE_METRICS_REPORTER_INTERFACE_H_