diff options
-rw-r--r-- | constants.h | 13 | ||||
-rw-r--r-- | payload_state.cc | 23 | ||||
-rw-r--r-- | payload_state.h | 3 | ||||
-rw-r--r-- | payload_state_unittest.cc | 78 | ||||
-rw-r--r-- | utils.cc | 15 | ||||
-rw-r--r-- | utils.h | 3 |
6 files changed, 134 insertions, 1 deletions
diff --git a/constants.h b/constants.h index dc39d5a3..c6ffb746 100644 --- a/constants.h +++ b/constants.h @@ -71,6 +71,19 @@ typedef enum { kNumDownloadSources } DownloadSource; +// A payload can be a Full or Delta payload. In some cases, a Full payload is +// used even when a Delta payload was available for the update, called here +// ForcedFull. The PayloadType enum is only used to send UMA metrics about the +// successfully applied payload. +typedef enum { + kPayloadTypeFull, + kPayloadTypeDelta, + kPayloadTypeForcedFull, + + // Note: Add new payload types only above this line. + kNumPayloadTypes +} PayloadType; + // The default number of UMA buckets for metrics. const int kNumDefaultUmaBuckets = 50; diff --git a/payload_state.cc b/payload_state.cc index 20e2cacb..a933ea53 100644 --- a/payload_state.cc +++ b/payload_state.cc @@ -156,6 +156,7 @@ void PayloadState::UpdateSucceeded() { ReportRebootMetrics(); ReportDurationMetrics(); ReportUpdatesAbandonedCountMetric(); + ReportPayloadTypeMetric(); // Reset the number of responses seen since it counts from the last // successful update, e.g. now. @@ -877,6 +878,28 @@ void PayloadState::ReportDurationMetrics() { prefs_->Delete(kPrefsUpdateDurationUptime); } +void PayloadState::ReportPayloadTypeMetric() { + string metric; + PayloadType uma_payload_type; + OmahaRequestParams* params = system_state_->request_params(); + + if (response_.is_delta_payload) { + uma_payload_type = kPayloadTypeDelta; + } else if (params->delta_okay()) { + uma_payload_type = kPayloadTypeFull; + } else { // Full payload, delta was not allowed by request. + uma_payload_type = kPayloadTypeForcedFull; + } + + metric = "Installer.PayloadFormat"; + system_state_->metrics_lib()->SendEnumToUMA( + metric, + uma_payload_type, + kNumPayloadTypes); + LOG(INFO) << "Uploading " << utils::ToString(uma_payload_type) + << " for metric " << metric; +} + string PayloadState::GetPrefsKey(const string& prefix, DownloadSource source) { return prefix + "-from-" + utils::ToString(source); } diff --git a/payload_state.h b/payload_state.h index 3c88622a..c4651e91 100644 --- a/payload_state.h +++ b/payload_state.h @@ -134,6 +134,9 @@ class PayloadState : public PayloadStateInterface { // Reports the various metrics related to update duration. void ReportDurationMetrics(); + // Reports the metric related to the applied payload type. + void ReportPayloadTypeMetric(); + // Resets all the persisted state values which are maintained relative to the // current response signature. The response signature itself is not reset. void ResetPersistedState(); diff --git a/payload_state_unittest.cc b/payload_state_unittest.cc index dcdcd113..9bd4c08c 100644 --- a/payload_state_unittest.cc +++ b/payload_state_unittest.cc @@ -714,6 +714,8 @@ TEST(PayloadStateTest, BytesDownloadedMetricsGetAddedToCorrectSources) { "Installer.DownloadSourcesUsed", 3, _, _, _)); EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendToUMA( "Installer.DownloadOverheadPercentage", 542, _, _, _)); + EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendEnumToUMA( + "Installer.PayloadFormat", kPayloadTypeFull, kNumPayloadTypes)); payload_state.UpdateSucceeded(); @@ -989,4 +991,80 @@ TEST(PayloadStateTest, CandidateUrlsComputedCorrectly) { EXPECT_EQ(0, payload_state.GetUrlFailureCount()); } +TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsDelta) { + OmahaResponse response; + response.is_delta_payload = true; + PayloadState payload_state; + MockSystemState mock_system_state; + + EXPECT_TRUE(payload_state.Initialize(&mock_system_state)); + SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response); + + // Simulate a successful download and update. + payload_state.DownloadComplete(); + + EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendEnumToUMA( + "Installer.PayloadFormat", kPayloadTypeDelta, kNumPayloadTypes)); + payload_state.UpdateSucceeded(); + + // Mock the request to a request where the delta was disabled but Omaha sends + // a delta anyway and test again. + OmahaRequestParams params(&mock_system_state); + params.set_delta_okay(false); + mock_system_state.set_request_params(¶ms); + + EXPECT_TRUE(payload_state.Initialize(&mock_system_state)); + SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response); + + payload_state.DownloadComplete(); + + EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendEnumToUMA( + "Installer.PayloadFormat", kPayloadTypeDelta, kNumPayloadTypes)); + payload_state.UpdateSucceeded(); +} + +TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsForcedFull) { + OmahaResponse response; + response.is_delta_payload = false; + PayloadState payload_state; + MockSystemState mock_system_state; + + EXPECT_TRUE(payload_state.Initialize(&mock_system_state)); + SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response); + + // Mock the request to a request where the delta was disabled. + OmahaRequestParams params(&mock_system_state); + params.set_delta_okay(false); + mock_system_state.set_request_params(¶ms); + + // Simulate a successful download and update. + payload_state.DownloadComplete(); + + EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendEnumToUMA( + "Installer.PayloadFormat", kPayloadTypeForcedFull, kNumPayloadTypes)); + payload_state.UpdateSucceeded(); +} + +TEST(PayloadStateTest, PayloadTypeMetricWhenTypeIsFull) { + OmahaResponse response; + response.is_delta_payload = false; + PayloadState payload_state; + MockSystemState mock_system_state; + + EXPECT_TRUE(payload_state.Initialize(&mock_system_state)); + SetupPayloadStateWith2Urls("Hash6437", true, &payload_state, &response); + + // Mock the request to a request where the delta was disabled. + OmahaRequestParams params(&mock_system_state); + params.set_delta_okay(true); + mock_system_state.set_request_params(¶ms); + + // Simulate a successful download and update. + payload_state.DownloadComplete(); + + EXPECT_CALL(*mock_system_state.mock_metrics_lib(), SendEnumToUMA( + "Installer.PayloadFormat", kPayloadTypeFull, kNumPayloadTypes)); + payload_state.UpdateSucceeded(); +} + } @@ -802,7 +802,7 @@ string ToString(bool b) { return (b ? "true" : "false"); } -std::string ToString(DownloadSource source) { +string ToString(DownloadSource source) { switch (source) { case kDownloadSourceHttpsServer: return "HttpsServer"; case kDownloadSourceHttpServer: return "HttpServer"; @@ -814,6 +814,19 @@ std::string ToString(DownloadSource source) { return "Unknown"; } +string ToString(PayloadType payload_type) { + switch (payload_type) { + case kPayloadTypeDelta: return "Delta"; + case kPayloadTypeFull: return "Full"; + case kPayloadTypeForcedFull: return "ForcedFull"; + case kNumPayloadTypes: return "Unknown"; + // Don't add a default case to let the compiler warn about newly added + // payload types which should be added here. + } + + return "Unknown"; +} + ErrorCode GetBaseErrorCode(ErrorCode code) { // Ignore the higher order bits in the code by applying the mask as // we want the enumerations to be in the small contiguous range @@ -168,6 +168,9 @@ std::string ToString(bool b); // Returns a string representation of the given enum. std::string ToString(DownloadSource source); +// Returns a string representation of the given enum. +std::string ToString(PayloadType payload_type); + enum BootLoader { BootLoader_SYSLINUX = 0, BootLoader_CHROME_FIRMWARE = 1 |