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

Log ID for each RPC call #951

Merged
merged 1 commit into from
Jul 13, 2018
Merged
Show file tree
Hide file tree
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
14 changes: 8 additions & 6 deletions rai/node/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,12 @@ void rai::rpc::stop ()
acceptor.close ();
}

rai::rpc_handler::rpc_handler (rai::node & node_a, rai::rpc & rpc_a, std::string const & body_a, std::function<void(boost::property_tree::ptree const &)> const & response_a) :
rai::rpc_handler::rpc_handler (rai::node & node_a, rai::rpc & rpc_a, std::string const & body_a, std::string const & request_id_a, std::function<void(boost::property_tree::ptree const &)> const & response_a) :
body (body_a),
node (node_a),
rpc (rpc_a),
response (response_a)
response (response_a),
request_id (request_id_a)
{
}

Expand Down Expand Up @@ -4532,7 +4533,8 @@ void rai::rpc_connection::read ()
this_l->node->background ([this_l]() {
auto start (std::chrono::steady_clock::now ());
auto version (this_l->request.version ());
auto response_handler ([this_l, version, start](boost::property_tree::ptree const & tree_a) {
std::string request_id (boost::str (boost::format ("%1%") % boost::io::group (std::hex, std::showbase, reinterpret_cast<uintptr_t> (this_l.get ()))));
auto response_handler ([this_l, version, start, request_id](boost::property_tree::ptree const & tree_a) {

std::stringstream ostream;
boost::property_tree::write_json (ostream, tree_a);
Expand All @@ -4544,12 +4546,12 @@ void rai::rpc_connection::read ()

if (this_l->node->config.logging.log_rpc ())
{
BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast<std::chrono::microseconds> (std::chrono::steady_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast<uintptr_t> (this_l.get ())));
BOOST_LOG (this_l->node->log) << boost::str (boost::format ("RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast<std::chrono::microseconds> (std::chrono::steady_clock::now () - start).count () % request_id);
}
});
if (this_l->request.method () == boost::beast::http::verb::post)
{
auto handler (std::make_shared<rai::rpc_handler> (*this_l->node, this_l->rpc, this_l->request.body (), response_handler));
auto handler (std::make_shared<rai::rpc_handler> (*this_l->node, this_l->rpc, this_l->request.body (), request_id, response_handler));
handler->process_request ();
}
else
Expand Down Expand Up @@ -4602,7 +4604,7 @@ void rai::rpc_handler::process_request ()
}
if (node.config.logging.log_rpc ())
{
BOOST_LOG (node.log) << body;
BOOST_LOG (node.log) << boost::str (boost::format ("%1% ") % request_id) << body;
}
if (action == "account_balance")
{
Expand Down
3 changes: 2 additions & 1 deletion rai/node/rpc.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ class payment_observer : public std::enable_shared_from_this<rai::payment_observ
class rpc_handler : public std::enable_shared_from_this<rai::rpc_handler>
{
public:
rpc_handler (rai::node &, rai::rpc &, std::string const &, std::function<void(boost::property_tree::ptree const &)> const &);
rpc_handler (rai::node &, rai::rpc &, std::string const &, std::string const &, std::function<void(boost::property_tree::ptree const &)> const &);
void process_request ();
void account_balance ();
void account_block_count ();
Expand Down Expand Up @@ -217,6 +217,7 @@ class rpc_handler : public std::enable_shared_from_this<rai::rpc_handler>
void work_peers ();
void work_peers_clear ();
std::string body;
std::string request_id;
rai::node & node;
rai::rpc & rpc;
boost::property_tree::ptree request;
Expand Down
7 changes: 4 additions & 3 deletions rai/node/rpc_secure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,8 @@ void rai::rpc_connection_secure::read ()
this_l->node->background ([this_l]() {
auto start (std::chrono::steady_clock::now ());
auto version (this_l->request.version ());
auto response_handler ([this_l, version, start](boost::property_tree::ptree const & tree_a) {
std::string request_id (boost::str (boost::format ("%1%") % boost::io::group (std::hex, std::showbase, reinterpret_cast<uintptr_t> (this_l.get ()))));
auto response_handler ([this_l, version, start, request_id](boost::property_tree::ptree const & tree_a) {
std::stringstream ostream;
boost::property_tree::write_json (ostream, tree_a);
ostream.flush ();
Expand All @@ -171,13 +172,13 @@ void rai::rpc_connection_secure::read ()

if (this_l->node->config.logging.log_rpc ())
{
BOOST_LOG (this_l->node->log) << boost::str (boost::format ("TLS: RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast<std::chrono::microseconds> (std::chrono::steady_clock::now () - start).count () % boost::io::group (std::hex, std::showbase, reinterpret_cast<uintptr_t> (this_l.get ())));
BOOST_LOG (this_l->node->log) << boost::str (boost::format ("TLS: RPC request %2% completed in: %1% microseconds") % std::chrono::duration_cast<std::chrono::microseconds> (std::chrono::steady_clock::now () - start).count () % request_id);
}
});

if (this_l->request.method () == boost::beast::http::verb::post)
{
auto handler (std::make_shared<rai::rpc_handler> (*this_l->node, this_l->rpc, this_l->request.body (), response_handler));
auto handler (std::make_shared<rai::rpc_handler> (*this_l->node, this_l->rpc, this_l->request.body (), request_id, response_handler));
handler->process_request ();
}
else
Expand Down