From 34d918ac714ca3b9d555e7ec0846642e79fc909a Mon Sep 17 00:00:00 2001 From: Ed Hennis Date: Thu, 14 Nov 2024 16:41:54 -0500 Subject: [PATCH] Include endpoint info in retry messages --- src/test/jtx/impl/JSONRPCClient.cpp | 60 ++++++++++++++++------------- src/test/jtx/impl/WSClient.cpp | 60 ++++++++++++++++------------- 2 files changed, 66 insertions(+), 54 deletions(-) diff --git a/src/test/jtx/impl/JSONRPCClient.cpp b/src/test/jtx/impl/JSONRPCClient.cpp index 8dddaaf01b3..a8119ff9749 100644 --- a/src/test/jtx/impl/JSONRPCClient.cpp +++ b/src/test/jtx/impl/JSONRPCClient.cpp @@ -36,30 +36,6 @@ namespace test { class JSONRPCClient : public AbstractClient { - static boost::asio::ip::tcp::endpoint - getEndpoint(BasicConfig const& cfg) - { - auto& log = std::cerr; - ParsedPort common; - parse_Port(common, cfg["server"], log); - for (auto const& name : cfg.section("server").values()) - { - if (!cfg.exists(name)) - continue; - ParsedPort pp; - parse_Port(pp, cfg[name], log); - if (pp.protocol.count("http") == 0) - continue; - using namespace boost::asio::ip; - if (pp.ip && pp.ip->is_unspecified()) - *pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} - : address{address_v4::loopback()}; - return {*pp.ip, *pp.port}; - } - Throw("Missing HTTP port"); - return {}; // Silence compiler control paths return value warning - } - template static std::string buffer_string(ConstBufferSequence const& b) @@ -72,6 +48,7 @@ class JSONRPCClient : public AbstractClient } boost::asio::ip::tcp::endpoint ep_; + std::string endpointLabel_; boost::asio::io_service ios_; boost::asio::ip::tcp::socket stream_; boost::beast::multi_buffer bin_; @@ -83,6 +60,9 @@ class JSONRPCClient : public AbstractClient : ep_(getEndpoint(cfg)), stream_(ios_), rpc_version_(rpc_version) { stream_.connect(ep_); + std::stringstream ss; + ss << ep_; + endpointLabel_ = ss.str(); } ~JSONRPCClient() override @@ -91,6 +71,30 @@ class JSONRPCClient : public AbstractClient // stream_.close(); } + static boost::asio::ip::tcp::endpoint + getEndpoint(BasicConfig const& cfg) + { + auto& log = std::cerr; + ParsedPort common; + parse_Port(common, cfg["server"], log); + for (auto const& name : cfg.section("server").values()) + { + if (!cfg.exists(name)) + continue; + ParsedPort pp; + parse_Port(pp, cfg[name], log); + if (pp.protocol.count("http") == 0) + continue; + using namespace boost::asio::ip; + if (pp.ip && pp.ip->is_unspecified()) + *pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} + : address{address_v4::loopback()}; + return {*pp.ip, *pp.port}; + } + Throw("Missing HTTP port"); + return {}; // Silence compiler control paths return value warning + } + /* Return value is an Object type with up to three keys: status @@ -137,13 +141,13 @@ class JSONRPCClient : public AbstractClient Env::retry( [&]() { write(stream_, req); }, - "JSONRPCClient::invoke write", + "JSONRPCClient::invoke write " + endpointLabel_, 10ms); response res; Env::retry( [&]() { read(stream_, bin_, res); }, - "JSONRPCClient::invoke read", + "JSONRPCClient::invoke read " + endpointLabel_, 10ms); Json::Reader jr; @@ -170,9 +174,11 @@ makeJSONRPCClient(Config const& cfg, unsigned rpc_version) using namespace ripple::test::jtx; std::unique_ptr ret; + std::stringstream endpoint; + endpoint << JSONRPCClient::getEndpoint(cfg); Env::retry( [&]() { ret = std::make_unique(cfg, rpc_version); }, - "makeJSONRPCClient", + "makeJSONRPCClient " + endpoint.str(), 250ms); return ret; } diff --git a/src/test/jtx/impl/WSClient.cpp b/src/test/jtx/impl/WSClient.cpp index 97e97185021..6ff5d3aba61 100644 --- a/src/test/jtx/impl/WSClient.cpp +++ b/src/test/jtx/impl/WSClient.cpp @@ -50,31 +50,6 @@ class WSClientImpl : public WSClient } }; - static boost::asio::ip::tcp::endpoint - getEndpoint(BasicConfig const& cfg, bool v2) - { - auto& log = std::cerr; - ParsedPort common; - parse_Port(common, cfg["server"], log); - auto const ps = v2 ? "ws2" : "ws"; - for (auto const& name : cfg.section("server").values()) - { - if (!cfg.exists(name)) - continue; - ParsedPort pp; - parse_Port(pp, cfg[name], log); - if (pp.protocol.count(ps) == 0) - continue; - using namespace boost::asio::ip; - if (pp.ip && pp.ip->is_unspecified()) - *pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} - : address{address_v4::loopback()}; - return {*pp.ip, *pp.port}; - } - Throw("Missing WebSocket port"); - return {}; // Silence compiler control paths return value warning - } - template static std::string buffer_string(ConstBuffers const& b) @@ -94,6 +69,7 @@ class WSClientImpl : public WSClient boost::asio::ip::tcp::socket stream_; boost::beast::websocket::stream ws_; boost::beast::multi_buffer rb_; + std::string endpointLabel_; bool peerClosed_ = false; @@ -153,6 +129,9 @@ class WSClientImpl : public WSClient rb_, strand_.wrap(std::bind( &WSClientImpl::on_read_msg, this, std::placeholders::_1))); + std::stringstream ss; + ss << ep; + endpointLabel_ = ss.str(); } catch (std::exception&) { @@ -166,6 +145,31 @@ class WSClientImpl : public WSClient cleanup(); } + static boost::asio::ip::tcp::endpoint + getEndpoint(BasicConfig const& cfg, bool v2) + { + auto& log = std::cerr; + ParsedPort common; + parse_Port(common, cfg["server"], log); + auto const ps = v2 ? "ws2" : "ws"; + for (auto const& name : cfg.section("server").values()) + { + if (!cfg.exists(name)) + continue; + ParsedPort pp; + parse_Port(pp, cfg[name], log); + if (pp.protocol.count(ps) == 0) + continue; + using namespace boost::asio::ip; + if (pp.ip && pp.ip->is_unspecified()) + *pp.ip = pp.ip->is_v6() ? address{address_v6::loopback()} + : address{address_v4::loopback()}; + return {*pp.ip, *pp.port}; + } + Throw("Missing WebSocket port"); + return {}; // Silence compiler control paths return value warning + } + Json::Value invoke(std::string const& cmd, Json::Value const& params) override { @@ -190,7 +194,7 @@ class WSClientImpl : public WSClient auto const s = to_string(jp); Env::retry( [&]() { ws_.write_some(true, buffer(s)); }, - "WSClient::invoke write_some", + "WSClient::invoke write_some " + endpointLabel_, 100ms); } @@ -312,12 +316,14 @@ makeWSClient( using namespace ripple::test::jtx; std::unique_ptr ret; + std::stringstream endpoint; + endpoint << WSClientImpl::getEndpoint(cfg, v2); Env::retry( [&]() { ret = std::make_unique(cfg, v2, rpc_version, headers); }, - "makeWSClient", + "makeWSClient " + endpoint.str(), 250ms); return ret; }