Report usage of StopAutoUpdate policy in borgmon charts
Omaha already has an event result for reporting UpdateDeferred (9)
which shows up in the borgman charts. In order to use that we should
perform a normal updatecheck without the updatedisabled set to true and
then discard the response with event type UpdateComplete (3) but with
event result UpdateDeferred (9).
BUG=28645: Report StopAutoUpdate enforcement in Borgmon charts for Omaha
TEST=Tested success, error and deferred cases on my zgb.
Change-Id: I27cb4465ea9876b39edaff3b747ada44a4f875d4
Reviewed-on: https://gerrit.chromium.org/gerrit/19112
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Ready: Jay Srinivasan <jaysri@chromium.org>
Tested-by: Jay Srinivasan <jaysri@chromium.org>
diff --git a/action_processor.h b/action_processor.h
index c45c3c8..256648d 100644
--- a/action_processor.h
+++ b/action_processor.h
@@ -23,6 +23,7 @@
// Action exit codes.
enum ActionExitCode {
+ // use the 0xx and 1xx ranges for client errors.
kActionCodeSuccess = 0,
kActionCodeError = 1,
kActionCodeOmahaRequestError = 2,
@@ -43,14 +44,23 @@
kActionCodeSignedDeltaPayloadExpectedError = 17,
kActionCodeDownloadPayloadPubKeyVerificationError = 18,
kActionCodePostinstallBootedFromFirmwareB = 19,
- kActionCodeOmahaUpdateIgnoredPerPolicy = 20,
+
+ // use the 2xx range for errors in Omaha response.
kActionCodeOmahaRequestEmptyResponseError = 200,
kActionCodeOmahaRequestXMLParseError = 201,
kActionCodeOmahaRequestNoUpdateCheckNode = 202,
kActionCodeOmahaRequestNoUpdateCheckStatus = 203,
kActionCodeOmahaRequestBadUpdateCheckStatus = 204,
+
+ // use the 2xxx range to encode HTTP errors.
kActionCodeOmahaRequestHTTPResponseBase = 2000, // + HTTP response code
+ // use the 5xxx range for return codes that are not really errors,
+ // but deferred updates. these have to be logged with a different
+ // result in Omaha so that they don't show up as errors in borgmon charts.
+ kActionCodeOmahaUpdateIgnoredPerPolicy = 5000,
+ kActionCodeOmahaUpdateDeferredPerPolicy = 5001,
+
// Bit flags.
kActionCodeResumedFlag = 1 << 30, // Set if resuming an interruped update.
kActionCodeBootModeFlag = 1 << 31, // Set if boot mode not normal.
diff --git a/omaha_request_action.cc b/omaha_request_action.cc
index c97a9a7..8329c56 100644
--- a/omaha_request_action.cc
+++ b/omaha_request_action.cc
@@ -100,12 +100,15 @@
if (event == NULL) {
body = GetPingBody(ping_active_days, ping_roll_call_days);
if (!ping_only) {
+ // not passing update_disabled to Omaha because we want to
+ // get the update and report with UpdateDeferred result so that
+ // borgmon charts show up updates that are deferred. This is also
+ // the expected behavior when we move to Omaha v3.0 protocol, so it'll
+ // be consistent.
body += StringPrintf(
" <o:updatecheck"
- " updatedisabled=\"%s\""
" targetversionprefix=\"%s\""
"></o:updatecheck>\n",
- params.update_disabled ? "true" : "false",
XmlEncode(params.target_version_prefix).c_str());
// If this is the first update check after a reboot following a previous
@@ -460,7 +463,7 @@
}
if (params_.update_disabled) {
- LOG(ERROR) << "Ignoring Omaha updates as updates are disabled by policy.";
+ LOG(INFO) << "Ignoring Omaha updates as updates are disabled by policy.";
completer.set_code(kActionCodeOmahaUpdateIgnoredPerPolicy);
return;
}
diff --git a/omaha_request_action.h b/omaha_request_action.h
index b32a3af..b3df207 100644
--- a/omaha_request_action.h
+++ b/omaha_request_action.h
@@ -57,6 +57,7 @@
// complete list of defined event types and results, see
// http://code.google.com/p/omaha/wiki/ServerProtocol#event
struct OmahaEvent {
+ // The Type values correspond to EVENT_TYPE values of Omaha.
enum Type {
kTypeUnknown = 0,
kTypeDownloadComplete = 1,
@@ -66,10 +67,12 @@
kTypeUpdateDownloadFinished = 14,
};
+ // The Result values correspond to EVENT_RESULT values of Omaha.
enum Result {
kResultError = 0,
kResultSuccess = 1,
kResultSuccessReboot = 2,
+ kResultUpdateDeferred = 9, // When we ignore/defer updates due to policy.
};
OmahaEvent()
diff --git a/omaha_request_action_unittest.cc b/omaha_request_action_unittest.cc
index e92fb03..26e808c 100644
--- a/omaha_request_action_unittest.cc
+++ b/omaha_request_action_unittest.cc
@@ -601,7 +601,6 @@
EXPECT_NE(post_str.find(
" <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
" <o:updatecheck"
- " updatedisabled=\"false\""
" targetversionprefix=\"\""
"></o:updatecheck>\n"),
string::npos);
@@ -611,7 +610,7 @@
}
-TEST(OmahaRequestActionTest, FormatUpdateDisabledTest) {
+TEST(OmahaRequestActionTest, FormatTargetVersionPrefixTest) {
vector<char> post_data;
NiceMock<PrefsMock> prefs;
EXPECT_CALL(prefs, GetString(kPrefsPreviousVersion, _))
@@ -632,7 +631,6 @@
EXPECT_NE(post_str.find(
" <o:ping active=\"1\" a=\"-1\" r=\"-1\"></o:ping>\n"
" <o:updatecheck"
- " updatedisabled=\"true\""
" targetversionprefix=\"\""
"></o:updatecheck>\n"),
string::npos);
diff --git a/update_attempter.cc b/update_attempter.cc
index c23135b..214f21a 100644
--- a/update_attempter.cc
+++ b/update_attempter.cc
@@ -602,6 +602,22 @@
return;
}
+ // Classify the code to generate the appropriate result so that
+ // the Borgmon charts show up the results correctly.
+ // Do this before calling GetErrorCodeForAction which could potentially
+ // augment the bit representation of code and thus cause no matches for
+ // the switch cases below.
+ OmahaEvent::Result event_result;
+ switch (code) {
+ case kActionCodeOmahaUpdateIgnoredPerPolicy:
+ case kActionCodeOmahaUpdateDeferredPerPolicy:
+ event_result = OmahaEvent::kResultUpdateDeferred;
+ break;
+ default:
+ event_result = OmahaEvent::kResultError;
+ break;
+ }
+
code = GetErrorCodeForAction(action, code);
fake_update_success_ = code == kActionCodePostinstallBootedFromFirmwareB;
@@ -613,8 +629,9 @@
response_handler_action_->install_plan().is_resume) {
code = static_cast<ActionExitCode>(code | kActionCodeResumedFlag);
}
+
error_event_.reset(new OmahaEvent(OmahaEvent::kTypeUpdateComplete,
- OmahaEvent::kResultError,
+ event_result,
code));
}