add etl info to server_info response

This commit is contained in:
CJ Cobb
2022-03-17 12:39:14 -04:00
committed by CJ Cobb
parent bcd59ddf73
commit b1add848f4
12 changed files with 80 additions and 22 deletions

View File

@@ -130,10 +130,10 @@ private:
/// server_info
std::chrono::time_point<std::chrono::system_clock> lastPublish_;
std::mutex publishTimeMtx_;
mutable std::mutex publishTimeMtx_;
std::chrono::time_point<std::chrono::system_clock>
getLastPublish()
getLastPublish() const
{
std::unique_lock<std::mutex> lck(publishTimeMtx_);
return lastPublish_;
@@ -261,24 +261,6 @@ private:
return numMarkers_;
}
boost::json::object
getInfo()
{
boost::json::object result;
result["etl_sources"] = loadBalancer_->toJson();
result["is_writer"] = writing_.load();
result["read_only"] = readOnly_;
auto last = getLastPublish();
if (last.time_since_epoch().count() != 0)
result["last_publish_time"] = std::to_string(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - getLastPublish())
.count());
return result;
}
/// start all of the necessary components and begin ETL
void
run()
@@ -329,6 +311,24 @@ public:
BOOST_LOG_TRIVIAL(debug) << "Joined ReportingETL worker thread";
}
boost::json::object
getInfo() const
{
boost::json::object result;
result["etl_sources"] = loadBalancer_->toJson();
result["is_writer"] = writing_.load();
result["read_only"] = readOnly_;
auto last = getLastPublish();
if (last.time_since_epoch().count() != 0)
result["last_publish_time"] = std::to_string(
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::system_clock::now() - getLastPublish())
.count());
return result;
}
};
#endif

View File

@@ -230,7 +230,7 @@ main(int argc, char* argv[])
// The server handles incoming RPCs
auto httpServer = Server::make_HttpServer(
*config, ioc, ctxRef, backend, subscriptions, balancer, dosGuard);
*config, ioc, ctxRef, backend, subscriptions, balancer, etl, dosGuard);
// Blocks until stopped.
// When stopped, shared_ptrs fall out of scope

View File

@@ -12,6 +12,7 @@ make_WsContext(
std::shared_ptr<BackendInterface const> const& backend,
std::shared_ptr<SubscriptionManager> const& subscriptions,
std::shared_ptr<ETLLoadBalancer> const& balancer,
std::shared_ptr<ReportingETL const> const& etl,
std::shared_ptr<WsBase> const& session,
Backend::LedgerRange const& range,
Counters& counters,
@@ -30,6 +31,7 @@ make_WsContext(
backend,
subscriptions,
balancer,
etl,
session,
range,
counters,
@@ -43,6 +45,7 @@ make_HttpContext(
std::shared_ptr<BackendInterface const> const& backend,
std::shared_ptr<SubscriptionManager> const& subscriptions,
std::shared_ptr<ETLLoadBalancer> const& balancer,
std::shared_ptr<ReportingETL const> const& etl,
Backend::LedgerRange const& range,
RPC::Counters& counters,
std::string const& clientIp)
@@ -74,6 +77,7 @@ make_HttpContext(
backend,
subscriptions,
balancer,
etl,
nullptr,
range,
counters,

View File

@@ -23,6 +23,7 @@
class WsBase;
class SubscriptionManager;
class ETLLoadBalancer;
class ReportingETL;
namespace RPC {
@@ -38,6 +39,7 @@ struct Context
// SubscriptionManager as a weak_ptr, to prevent a shared_ptr cycle.
std::shared_ptr<SubscriptionManager> subscriptions;
std::shared_ptr<ETLLoadBalancer> const& balancer;
std::shared_ptr<ReportingETL const> const& etl;
std::shared_ptr<WsBase> session;
Backend::LedgerRange const& range;
Counters& counters;
@@ -51,6 +53,7 @@ struct Context
std::shared_ptr<BackendInterface const> const& backend_,
std::shared_ptr<SubscriptionManager> const& subscriptions_,
std::shared_ptr<ETLLoadBalancer> const& balancer_,
std::shared_ptr<ReportingETL const> const& etl_,
std::shared_ptr<WsBase> const& session_,
Backend::LedgerRange const& range_,
Counters& counters_,
@@ -62,6 +65,7 @@ struct Context
, backend(backend_)
, subscriptions(subscriptions_)
, balancer(balancer_)
, etl(etl_)
, session(session_)
, range(range_)
, counters(counters_)
@@ -144,6 +148,7 @@ make_WsContext(
std::shared_ptr<BackendInterface const> const& backend,
std::shared_ptr<SubscriptionManager> const& subscriptions,
std::shared_ptr<ETLLoadBalancer> const& balancer,
std::shared_ptr<ReportingETL const> const& etl,
std::shared_ptr<WsBase> const& session,
Backend::LedgerRange const& range,
Counters& counters,
@@ -156,6 +161,7 @@ make_HttpContext(
std::shared_ptr<BackendInterface const> const& backend,
std::shared_ptr<SubscriptionManager> const& subscriptions,
std::shared_ptr<ETLLoadBalancer> const& balancer,
std::shared_ptr<ReportingETL const> const& etl,
Backend::LedgerRange const& range,
Counters& counters,
std::string const& clientIp);

View File

@@ -1,6 +1,7 @@
#include <backend/BackendInterface.h>
#include <etl/ETLSource.h>
#include <etl/ReportingETL.h>
#include <rpc/RPCHelpers.h>
namespace RPC {
@@ -35,6 +36,8 @@ doServerInfo(Context const& context)
cache["latest_ledger_seq"] =
context.backend->cache().latestLedgerSequence();
response["etl"] = context.etl->getInfo();
auto serverInfoRippled = context.balancer->forwardToRippled(
context.params, context.clientIp, context.yield);

View File

@@ -111,6 +111,7 @@ class HttpBase
std::shared_ptr<BackendInterface const> backend_;
std::shared_ptr<SubscriptionManager> subscriptions_;
std::shared_ptr<ETLLoadBalancer> balancer_;
std::shared_ptr<ReportingETL const> etl_;
DOSGuard& dosGuard_;
RPC::Counters& counters_;
send_lambda lambda_;
@@ -124,6 +125,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer buffer)
@@ -131,6 +133,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
, lambda_(*this)
@@ -183,6 +186,7 @@ public:
backend_,
subscriptions_,
balancer_,
etl_,
dosGuard_,
counters_);
}
@@ -201,6 +205,7 @@ public:
lambda_,
backend_,
balancer_,
etl_,
dosGuard_,
counters_,
ip,
@@ -247,6 +252,7 @@ handle_request(
Send&& send,
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
std::string const& ip,
@@ -319,7 +325,7 @@ handle_request(
RPC::make_error(RPC::Error::rpcNOT_READY))));
std::optional<RPC::Context> context = RPC::make_HttpContext(
yc, request, backend, nullptr, balancer, *range, counters, ip);
yc, request, backend, nullptr, balancer, etl, *range, counters, ip);
if (!context)
return send(httpResponse(

View File

@@ -22,6 +22,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer buffer)
@@ -30,6 +31,7 @@ public:
backend,
subscriptions,
balancer,
etl,
dosGuard,
counters,
std::move(buffer))

View File

@@ -27,6 +27,7 @@ class Detector
std::shared_ptr<BackendInterface const> backend_;
std::shared_ptr<SubscriptionManager> subscriptions_;
std::shared_ptr<ETLLoadBalancer> balancer_;
std::shared_ptr<ReportingETL const> etl_;
DOSGuard& dosGuard_;
RPC::Counters& counters_;
boost::beast::flat_buffer buffer_;
@@ -39,6 +40,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters)
: ioc_(ioc)
@@ -47,6 +49,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
{
@@ -85,6 +88,7 @@ public:
backend_,
subscriptions_,
balancer_,
etl_,
dosGuard_,
counters_,
std::move(buffer_))
@@ -99,6 +103,7 @@ public:
backend_,
subscriptions_,
balancer_,
etl_,
dosGuard_,
counters_,
std::move(buffer_))
@@ -115,6 +120,7 @@ make_websocket_session(
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters)
{
@@ -124,6 +130,7 @@ make_websocket_session(
backend,
subscriptions,
balancer,
etl,
dosGuard,
counters,
std::move(buffer),
@@ -140,6 +147,7 @@ make_websocket_session(
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters)
{
@@ -149,6 +157,7 @@ make_websocket_session(
backend,
subscriptions,
balancer,
etl,
dosGuard,
counters,
std::move(buffer),
@@ -169,6 +178,7 @@ class Listener
std::shared_ptr<BackendInterface const> backend_;
std::shared_ptr<SubscriptionManager> subscriptions_;
std::shared_ptr<ETLLoadBalancer> balancer_;
std::shared_ptr<ReportingETL const> etl_;
DOSGuard& dosGuard_;
RPC::Counters counters_;
@@ -180,6 +190,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard)
: ioc_(ioc)
, ctx_(ctx)
@@ -187,6 +198,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
{
boost::beast::error_code ec;
@@ -263,6 +275,7 @@ private:
backend_,
subscriptions_,
balancer_,
etl_,
dosGuard_,
counters_)
->run();
@@ -286,6 +299,7 @@ make_HttpServer(
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard)
{
if (!config.contains("server"))
@@ -305,6 +319,7 @@ make_HttpServer(
backend,
subscriptions,
balancer,
etl,
dosGuard);
server->run();

View File

@@ -35,6 +35,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& buffer)
@@ -43,6 +44,7 @@ public:
backend,
subscriptions,
balancer,
etl,
dosGuard,
counters,
std::move(buffer))
@@ -79,6 +81,7 @@ class WsUpgrader : public std::enable_shared_from_this<WsUpgrader>
std::shared_ptr<BackendInterface const> backend_;
std::shared_ptr<SubscriptionManager> subscriptions_;
std::shared_ptr<ETLLoadBalancer> balancer_;
std::shared_ptr<ReportingETL const> etl_;
DOSGuard& dosGuard_;
RPC::Counters& counters_;
http::request<http::string_body> req_;
@@ -90,6 +93,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& b)
@@ -99,6 +103,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
{
@@ -109,6 +114,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& b,
@@ -119,6 +125,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
, req_(std::move(req))
@@ -173,6 +180,7 @@ private:
backend_,
subscriptions_,
balancer_,
etl_,
dosGuard_,
counters_,
std::move(buffer_))

View File

@@ -23,6 +23,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer buffer)
@@ -31,6 +32,7 @@ public:
backend,
subscriptions,
balancer,
etl,
dosGuard,
counters,
std::move(buffer))

View File

@@ -33,6 +33,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& b)
@@ -41,6 +42,7 @@ public:
backend,
subscriptions,
balancer,
etl,
dosGuard,
counters,
std::move(b))
@@ -75,6 +77,7 @@ class SslWsUpgrader : public std::enable_shared_from_this<SslWsUpgrader>
std::shared_ptr<BackendInterface const> backend_;
std::shared_ptr<SubscriptionManager> subscriptions_;
std::shared_ptr<ETLLoadBalancer> balancer_;
std::shared_ptr<ReportingETL const> etl_;
DOSGuard& dosGuard_;
RPC::Counters& counters_;
http::request<http::string_body> req_;
@@ -87,6 +90,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& b)
@@ -96,6 +100,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
{
@@ -106,6 +111,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& b,
@@ -116,6 +122,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
, req_(std::move(req))
@@ -185,6 +192,7 @@ private:
backend_,
subscriptions_,
balancer_,
etl_,
dosGuard_,
counters_,
std::move(buffer_))

View File

@@ -87,6 +87,7 @@ class WsSession : public WsBase,
// a cyclical dependency that would block destruction
std::weak_ptr<SubscriptionManager> subscriptions_;
std::shared_ptr<ETLLoadBalancer> balancer_;
std::shared_ptr<ReportingETL const> etl_;
DOSGuard& dosGuard_;
RPC::Counters& counters_;
std::mutex mtx_;
@@ -98,6 +99,7 @@ public:
std::shared_ptr<BackendInterface const> backend,
std::shared_ptr<SubscriptionManager> subscriptions,
std::shared_ptr<ETLLoadBalancer> balancer,
std::shared_ptr<ReportingETL const> etl,
DOSGuard& dosGuard,
RPC::Counters& counters,
boost::beast::flat_buffer&& buffer)
@@ -106,6 +108,7 @@ public:
, backend_(backend)
, subscriptions_(subscriptions)
, balancer_(balancer)
, etl_(etl)
, dosGuard_(dosGuard)
, counters_(counters)
{
@@ -231,6 +234,7 @@ public:
backend_,
subscriptions_.lock(),
balancer_,
etl_,
shared_from_this(),
*range,
counters_,