Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trivial] Modify health check API #3491

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions src/ripple/overlay/impl/OverlayImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,15 +1094,16 @@ OverlayImpl::processHealth(http_request_type const& req, Handoff& handoff)

auto info = getServerInfo();

int last_validated_ledger_age = std::numeric_limits<int>::max();
int last_validated_ledger_age = -1;
if (info.isMember("validated_ledger"))
last_validated_ledger_age = info["validated_ledger"]["age"].asInt();
bool amendment_blocked = false;
if (info.isMember("amendment_blocked"))
amendment_blocked = true;
int number_peers = info["peers"].asInt();
std::string server_state = info["server_state"].asString();
auto load_factor = info["load_factor"].asDouble();
auto load_factor =
info["load_factor"].asDouble() / info["load_base"].asDouble();

enum { healthy, warning, critical };
int health = healthy;
Expand All @@ -1111,7 +1112,8 @@ OverlayImpl::processHealth(http_request_type const& req, Handoff& handoff)
health = state;
};

if (last_validated_ledger_age >= 7)
msg.body()[jss::info] = Json::objectValue;
if (last_validated_ledger_age >= 7 || last_validated_ledger_age < 0)
{
msg.body()[jss::info]["validated_ledger"] = last_validated_ledger_age;
if (last_validated_ledger_age < 20)
Expand Down Expand Up @@ -1157,10 +1159,18 @@ OverlayImpl::processHealth(http_request_type const& req, Handoff& handoff)
set_health(critical);
}

if (health != critical)
msg.result(boost::beast::http::status::ok);
else
msg.result(boost::beast::http::status::service_unavailable);
switch (health)
{
case healthy:
msg.result(boost::beast::http::status::ok);
break;
case warning:
msg.result(boost::beast::http::status::service_unavailable);
break;
case critical:
msg.result(boost::beast::http::status::internal_server_error);
break;
}

msg.prepare_payload();
handoff.response = std::make_shared<SimpleWriter>(msg);
Expand Down