Skip to content

Commit

Permalink
Stats
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev committed Jan 4, 2025
1 parent b7d782f commit 5e47b80
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 11 deletions.
16 changes: 15 additions & 1 deletion nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ enum class type
election,
election_cleanup,
election_vote,
http_callback,
http_callbacks,
http_callbacks_notified,
http_callbacks_ec,
ipc,
tcp,
tcp_server,
Expand Down Expand Up @@ -166,6 +168,8 @@ enum class detail
other,
drop,
queued,
error,
failed,

// processing queue
queue,
Expand Down Expand Up @@ -625,6 +629,16 @@ enum class detail
host_unreachable,
not_supported,

// http
error_resolving,
error_connecting,
error_sending,
error_completing,
bad_status,

// http_callbacks
block_confirmed,

_last // Must be the last enum
};

Expand Down
28 changes: 20 additions & 8 deletions nano/node/rpc_callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ void nano::http_callbacks::setup_callbacks ()
// Only process blocks that have achieved quorum or confirmation height
if ((status_a.type == nano::election_status_type::active_confirmed_quorum || status_a.type == nano::election_status_type::active_confirmation_height))
{
stats.inc (nano::stat::type::http_callbacks_notified, nano::stat::detail::block_confirmed);

// Post callback processing to worker thread
// Safe to capture 'this' by reference as workers are stopped before node destruction
node.workers.post ([this, block_a, account_a, amount_a, is_state_send_a, is_state_epoch_a] () {
Expand Down Expand Up @@ -93,8 +95,10 @@ void nano::http_callbacks::setup_callbacks ()
}
else
{
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::error_resolving);
stats.inc (nano::stat::type::http_callbacks_ec, to_stat_detail (ec));

logger.error (nano::log::type::http_callbacks, "Error resolving callback: {}:{} ({})", address, port, ec.message ());
stats.inc (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out);
}
});
});
Expand All @@ -117,6 +121,8 @@ std::shared_ptr<boost::asio::ip::tcp::resolver> const & resolver)
// Check if we have more endpoints to try
if (i_a != boost::asio::ip::tcp::resolver::iterator{})
{
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::initiate);

// Create socket and attempt connection
auto sock = std::make_shared<boost::asio::ip::tcp::socket> (node.io_ctx);
sock->async_connect (i_a->endpoint (),
Expand Down Expand Up @@ -152,36 +158,42 @@ std::shared_ptr<boost::asio::ip::tcp::resolver> const & resolver)
// Check response status
if (boost::beast::http::to_status_class (resp->result ()) == boost::beast::http::status_class::successful)
{
stats.inc (nano::stat::type::http_callback, nano::stat::detail::initiate, nano::stat::dir::out);
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::success);
}
else
{
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::bad_status);

logger.error (nano::log::type::http_callbacks, "Callback to {}:{} failed [status: {}]",
address, port, nano::util::to_str (resp->result ()));
stats.inc (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out);
}
}
else
{
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::error_completing);
stats.inc (nano::stat::type::http_callbacks_ec, to_stat_detail (ec));

logger.error (nano::log::type::http_callbacks, "Unable to complete callback: {}:{} ({})",
address, port, ec.message ());
stats.inc (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out);
}
});
}
else
{
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::error_sending);
stats.inc (nano::stat::type::http_callbacks_ec, to_stat_detail (ec));

logger.error (nano::log::type::http_callbacks, "Unable to send callback: {}:{} ({})", address, port, ec.message ());
stats.inc (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out);
}
});
}
else
else // Connection failed, try next endpoint if available
{
// Connection failed, try next endpoint if available
stats.inc (nano::stat::type::http_callbacks, nano::stat::detail::error_connecting);
stats.inc (nano::stat::type::http_callbacks_ec, to_stat_detail (ec));

logger.error (nano::log::type::http_callbacks, "Unable to connect to callback address({}): {}:{} ({})",
address, i_a->endpoint ().address ().to_string (), port, ec.message ());
stats.inc (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out);

++i_a;
do_rpc_callback (i_a, address, port, target, body, resolver);
Expand Down
4 changes: 2 additions & 2 deletions nano/rpc_test/rpc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5252,7 +5252,7 @@ TEST (rpc, block_confirm_confirmed)
auto transaction = node->ledger.tx_begin_read ();
ASSERT_TRUE (node->ledger.confirmed.block_exists_or_pruned (transaction, nano::dev::genesis->hash ()));
}
ASSERT_EQ (0, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out));
ASSERT_EQ (0, node->stats.count (nano::stat::type::http_callbacks_ec));
auto const rpc_ctx = add_rpc (system, node);
boost::property_tree::ptree request;
request.put ("action", "block_confirm");
Expand All @@ -5266,7 +5266,7 @@ TEST (rpc, block_confirm_confirmed)
// Check callback
// Callback result is error because callback target port isn't listening
// Check for error count greater than zero as the address goes through DNS resolution and may make multiple attempts for multiple IPs per DNS
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::error, nano::stat::detail::http_callback, nano::stat::dir::out) != 0);
ASSERT_TIMELY (5s, node->stats.count (nano::stat::type::http_callbacks_ec) != 0);
}

TEST (rpc, node_id)
Expand Down

0 comments on commit 5e47b80

Please sign in to comment.