Skip to content

Commit

Permalink
[DO NOT SUBMIT] Saving logging for debugging eg sideloading
Browse files Browse the repository at this point in the history
b/325626249

Change-Id: I3eb78ad4d51288a447aaf81a08f4f3c91ba03e24
  • Loading branch information
TyHolc authored and niranjanyardi committed Apr 24, 2024
1 parent 620f6c9 commit ec819cb
Show file tree
Hide file tree
Showing 8 changed files with 158 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cobalt/updater/configurator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ std::vector<GURL> Configurator::UpdateUrl() const {
if (base::CommandLine::ForCurrentProcess()->HasSwitch(
browser::switches::kUseQAUpdateServer)) {
return std::vector<GURL>{GURL(kUpdaterJSONDefaultUrlQA)};
// } else if (base::CommandLine::ForCurrentProcess()->HasSwitch(
// browser::switches::kUseCustomUpdateServer)) {
// return base::CommandLine::ForCurrentProcess()->GetSwitch(
// browser::switches::kUseCustomUpdateServer);
} else {
return std::vector<GURL>{GURL(kUpdaterJSONDefaultUrl)};
}
Expand Down
2 changes: 1 addition & 1 deletion cobalt/updater/updater_constants.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const char kLoggingModuleSwitch[] = "vmodule";
const char kUpdaterJSONDefaultUrlQA[] =
"https://omaha-qa.sandbox.google.com/service/update2/json";
const char kUpdaterJSONDefaultUrl[] =
"https://tools.google.com/service/update2/json";
"http://127.0.0.1:5000/test/omaha/fake";
const char kCrashUploadURL[] = "https://clients2.google.com/cr/report";
const char kCrashStagingUploadURL[] =
"https://clients2.google.com/cr/staging_report";
Expand Down
13 changes: 12 additions & 1 deletion cobalt/updater/updater_module.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,30 +104,41 @@ void Observer::OnEvent(Events event, const std::string& id) {
if (update_client_->GetCrxUpdateState(id, &crx_update_item_)) {
auto status_iterator =
component_to_updater_status_map.find(crx_update_item_.state);
LOG(INFO) << "==============================component_to_updater_status_map";
for (auto item : component_to_updater_status_map) {
LOG(INFO) << "first: " << item.first;
LOG(INFO) << "second: " << item.second;
}
LOG(INFO) << "==============================";
if (status_iterator == component_to_updater_status_map.end()) {
LOG(INFO) << "==============================DEBUG 1";
status = "Status is unknown.";
} else if (crx_update_item_.state == ComponentState::kUpToDate &&
updater_configurator_->GetPreviousUpdaterStatus().compare(
updater_status_string_map.find(UpdaterStatus::kUpdated)
->second) == 0) {
LOG(INFO) << "==============================DEBUG 2";
status = std::string(
updater_status_string_map.find(UpdaterStatus::kUpdated)->second);
} else {
LOG(INFO) << "==============================DEBUG 3";
status = std::string(
updater_status_string_map.find(status_iterator->second)->second);
}
if (crx_update_item_.state == ComponentState::kUpdateError) {
LOG(INFO) << "==============================DEBUG 4";
status +=
", error code is " + std::to_string(crx_update_item_.error_code);
}
if (updater_notification_ext_ != nullptr) {
LOG(INFO) << "==============================DEBUG 5";
updater_notification_ext_->UpdaterState(
ComponentStateToCobaltExtensionUpdaterNotificationState(
crx_update_item_.state),
GetCurrentEvergreenVersion().c_str());
}
} else {
status = "No status available";
status = "Yoohooooo!";
}
updater_configurator_->SetUpdaterStatus(status);
LOG(INFO) << "Updater status is " << status;
Expand Down
10 changes: 10 additions & 0 deletions components/update_client/request_sender.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ void RequestSender::SendInternal() {
static_cast<int>(ProtocolError::URL_FETCHER_FAILED),
std::string(), std::string(), 0));
}
LOG(INFO) << "==============================================================";
LOG(INFO) << "POST REQUEST:";
LOG(INFO) << "URL: " << url;
LOG(INFO) << "request_body: " << request_body_;
for (auto header : request_extra_headers_) {
LOG(INFO) << "header: " << header.first << " -> " << header.second;
}
network_fetcher_->PostRequest(
url, request_body_, request_extra_headers_,
base::BindOnce(&RequestSender::OnResponseStarted, base::Unretained(this)),
Expand Down Expand Up @@ -187,6 +194,9 @@ void RequestSender::OnNetworkFetcherComplete(
if (original_url.SchemeIsCryptographic() && error > 0)
retry_after_sec = base::saturated_cast<int>(xheader_retry_after_sec);

LOG(INFO) << "=============================================================";
LOG(INFO) << "Response body: " << *response_body;

base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::BindOnce(&RequestSender::SendInternalComplete,
base::Unretained(this), error,
Expand Down
Empty file.
110 changes: 110 additions & 0 deletions components/update_client/test_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# server.py

from flask import Flask, jsonify

app = Flask(__name__)

first_req = True

update = {
"server": "prod",
"protocol": "3.1",
"daystart": {
"elapsed_seconds": 51861,
"elapsed_days": 6316
},
"app": [
{
"cohorthint": "SB16",
"appid": "{A9557415-DDCD-4948-8113-C643EFCF710C}",
"cohort": "1:3f/3i/3j:",
"status": "ok",
"cohortname": "SB16.qa.COBALT",
"ping": {
"status": "ok"
},
"updatecheck": {
"status": "ok",
"urls": {
"url": [
{
"codebase": "https://edgedl.me.gvt1.com/edgedl/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "https://redirector.gvt1.com/edgedl/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "http://edgedl.me.gvt1.com/edgedl/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "http://redirector.gvt1.com/edgedl/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "https://dl.google.com/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "http://dl.google.com/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "https://www.google.com/dl/cobalt/COBALT/99.99.1030/"
},
{
"codebase": "http://www.google.com/dl/cobalt/COBALT/99.99.1030/"
}
]
},
"manifest": {
"version": "99.99.1030",
"packages": {
"package": [
{
"hash_sha256": "b43f8d0294ea48c3df44a19f78a354b025a2ab58163c44c1f56ab49327f557db",
"size": 16770294,
"name": "cobalt_x64_sbversion-16_qa_20240417120115.crx",
"fp": "1.b43f8d0294ea48c3df44a19f78a354b025a2ab58163c44c1f56ab49327f557db",
"required": True,
"hash": "iNAb+q7RCoOGPR5FnoInfXIGSFM\u003d"
}
]
}
}
}
}
]
}

noupdate = {
"server": "prod",
"protocol": "3.1",
"daystart": {
"elapsed_seconds": 51881,
"elapsed_days": 6316
},
"app": [
{
"cohorthint": "SB16.qa.COBALT",
"appid": "{A9557415-DDCD-4948-8113-C643EFCF710C}",
"cohort": "1:3f/3i/3j:",
"status": "ok",
"cohortname": "SB16.qa.COBALT",
"ping": {
"status": "ok"
},
"updatecheck": {
"status": "noupdate"
}
}
]
}


@app.route('/test/omaha/fake', methods=['POST'])
def get_tasks():
if first_req:
return jsonify({'response': update})
else:
return jsonify({'response': noupdate})


if __name__ == '__main__':
app.run(debug=True)
22 changes: 20 additions & 2 deletions components/update_client/update_checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,22 @@ void UpdateCheckerImpl::CheckForUpdatesHelper(
#endif

auto urls(config_->UpdateUrl());
if (IsEncryptionRequired(components))
RemoveUnsecureUrls(&urls);
LOG(INFO) << "URLS BEFORE==============================================================";
for (auto url : urls) {
LOG(INFO) << url;
}
LOG(INFO) << "==============================================================";
// if (IsEncryptionRequired(components)) {
// LOG(INFO) << "==============================================================";
// LOG(INFO) << "Encryption is required";
// RemoveUnsecureUrls(&urls);
// }

LOG(INFO) << "URLS AFTER==============================================================";
for (auto url : urls) {
LOG(INFO) << url;
}
LOG(INFO) << "==============================================================";

// Components in this update check are either all foreground, or all
// background since this member is inherited from the component's update
Expand Down Expand Up @@ -249,6 +263,8 @@ void UpdateCheckerImpl::CheckForUpdatesHelper(
// update_check_callback_, indicates a throttling by the update server.
// Only non-negative values are valid. Negative values are not trusted
// and are ignored.
LOG(INFO) << "==============================================================";
LOG(INFO) << "COBALT QUICK UPDATE";
UpdateCheckFailed(ErrorCategory::kUpdateCheck,
static_cast<int>(UpdateCheckError::QUICK_ROLL_FORWARD),
-1);
Expand Down Expand Up @@ -287,6 +303,8 @@ void UpdateCheckerImpl::CheckForUpdatesHelper(
updater_state_attributes_.get(), std::move(apps));

request_sender_ = std::make_unique<RequestSender>(config_);
LOG(INFO) << "==============================================================";
LOG(INFO) << "SENDING REQUEST";
request_sender_->Send(
urls,
BuildUpdateCheckExtraRequestHeaders(config_->GetProdId(),
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ Brotli==1.0.9
six<2
pytest-pythonpath<0.8
parameterized>=0.9.0
flask

0 comments on commit ec819cb

Please sign in to comment.