Skip to content

Commit

Permalink
Merge pull request #513 from AntelopeIO/GH-227-rm-nodeos_block_votes
Browse files Browse the repository at this point in the history
Prometheus: Remove vote metrics that are not useful
  • Loading branch information
heifner authored Aug 9, 2024
2 parents 1911d72 + d84df0b commit 75769d3
Show file tree
Hide file tree
Showing 5 changed files with 2 additions and 79 deletions.
5 changes: 0 additions & 5 deletions plugins/chain_plugin/chain_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2735,11 +2735,6 @@ const controller::config& chain_plugin::chain_config() const {
return *my->chain_config;
}

void chain_plugin::register_update_vote_block_metrics(std::function<void(chain_apis::tracked_votes::vote_block_metrics&&)>&& m) {
assert(my->_last_tracked_votes);
my->_last_tracked_votes->register_update_vote_block_metrics(std::move(m));
}

} // namespace eosio

FC_REFLECT( eosio::chain_apis::detail::ram_market_exchange_state_t, (ignore1)(ignore2)(ignore3)(core_symbol)(ignore4) )
Original file line number Diff line number Diff line change
Expand Up @@ -1027,8 +1027,6 @@ class chain_plugin : public plugin<chain_plugin> {

const controller::config& chain_config() const;

void register_update_vote_block_metrics(std::function<void(chain_apis::tracked_votes::vote_block_metrics&&)>&&);

private:

unique_ptr<class chain_plugin_impl> my;
Expand Down
10 changes: 0 additions & 10 deletions plugins/chain_plugin/include/eosio/chain_plugin/tracked_votes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ namespace eosio::chain_apis {
class tracked_votes {
public:

struct vote_block_metrics {
uint32_t block_num = 0;
std::vector<std::string> strong_votes;
std::vector<std::string> weak_votes;
std::vector<std::string> no_votes;
};

/**
* Instantiate a new tracked votes cache from the given chain controller
* The caller is expected to manage lifetimes such that this controller reference does not go stale
Expand Down Expand Up @@ -49,9 +42,6 @@ namespace eosio::chain_apis {
// Returns last vote information by a given finalizer
std::optional<vote_info> get_last_vote_info(const fc::crypto::blslib::bls_public_key& finalizer_pub_key) const;

// register prometheus callback
void register_update_vote_block_metrics(std::function<void(chain_apis::tracked_votes::vote_block_metrics&&)>&&);

private:
std::unique_ptr<struct tracked_votes_impl> _impl;
};
Expand Down
28 changes: 2 additions & 26 deletions plugins/chain_plugin/tracked_votes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,11 @@ namespace eosio::chain_apis {
// A handle to the controller.
const chain::controller& controller;

// prometheus support
std::function<void(tracked_votes::vote_block_metrics&&)> _update_vote_block_metrics;

// Called on accepted_block signal. Retrieve vote information from
// QC in the block and store it in last_votes.
void on_accepted_block( const chain::signed_block_ptr& block, const chain::block_id_type& id ) {
try {
if (!_update_vote_block_metrics && !tracking_enabled && !chain::vote_logger.is_enabled(fc::log_level::info))
if (!tracking_enabled && !chain::vote_logger.is_enabled(fc::log_level::info))
return;

// do not bother tracking/logging when syncing or replaying
Expand All @@ -46,7 +43,7 @@ namespace eosio::chain_apis {
return;
}

if (tracking_enabled || _update_vote_block_metrics) {
if (tracking_enabled) {
// Retrieve vote information from QC
const auto& qc_ext = block->extract_extension<chain::quorum_certificate_extension>();
chain::qc_vote_metrics_t vm = controller.vote_metrics(id, qc_ext.qc);
Expand All @@ -73,9 +70,6 @@ namespace eosio::chain_apis {
track_votes(vm.strong_votes, true);
track_votes(vm.weak_votes, false);
}
if (_update_vote_block_metrics) {
update_vote_block_metrics(block->block_num(), vm);
}
log_missing_votes(block, id, vm.missing_votes, qc_ext.qc.block_num);
} else if (chain::vote_logger.is_enabled(fc::log_level::info)) {
const auto& qc_ext = block->extract_extension<chain::quorum_certificate_extension>();
Expand Down Expand Up @@ -118,20 +112,6 @@ namespace eosio::chain_apis {
}
}

// update prometheus metrics
void update_vote_block_metrics(chain::block_num_type block_num, const chain::qc_vote_metrics_t& vm) {
tracked_votes::vote_block_metrics m;
m.block_num = block_num;
m.strong_votes.resize(vm.strong_votes.size());
m.weak_votes.resize(vm.weak_votes.size());
m.no_votes.resize(vm.missing_votes.size());

std::ranges::transform(vm.strong_votes, m.strong_votes.begin(), [](const auto& f) { return f.fin_auth->description; });
std::ranges::transform(vm.weak_votes, m.weak_votes.begin(), [](const auto& f) { return f.fin_auth->description; });
std::ranges::transform(vm.missing_votes, m.no_votes.begin(), [](const auto& f) { return f.fin_auth->description; });
_update_vote_block_metrics(std::move(m));
}

}; // tracked_votes_impl

tracked_votes::tracked_votes( const chain::controller& controller, bool tracking_enabled )
Expand All @@ -149,8 +129,4 @@ namespace eosio::chain_apis {
return _impl->get_last_vote_info(finalizer_pub_key);
}

void tracked_votes::register_update_vote_block_metrics(std::function<void(chain_apis::tracked_votes::vote_block_metrics&&)>&& m) {
_impl->_update_vote_block_metrics = std::move(m);
}

} // namespace eosio::chain_apis
36 changes: 0 additions & 36 deletions plugins/prometheus_plugin/metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,6 @@ struct catalog_type {
};
p2p_connection_metrics p2p_metrics;

// producer plugin
struct vote_metrics {
Gauge& block_num;
prometheus::Family<Gauge>& voted;
};
vote_metrics block_votes;

prometheus::Family<Counter>& cpu_usage_us;
prometheus::Family<Counter>& net_usage_us;

Expand Down Expand Up @@ -147,10 +140,6 @@ struct catalog_type {
, .connection_start_time{family<Gauge>("nodeos_p2p_connection_start_time", "time of last connection to peer")}
, .peer_addr{family<Gauge>("nodeos_p2p_peer_addr", "peer address")}
}
, block_votes{
.block_num{build<Gauge>("nodeos_block_num", "current block number")}
, .voted{family<Gauge>("nodeos_block_votes", "votes incorporated into a block, -1 weak, 1 strong, 0 no vote")}
}
, cpu_usage_us(family<Counter>("nodeos_cpu_usage_us_total", "total cpu usage in microseconds for blocks"))
, net_usage_us(family<Counter>("nodeos_net_usage_us_total", "total net usage in microseconds for blocks"))
, last_irreversible(build<Gauge>("nodeos_last_irreversible", "last irreversible block number"))
Expand Down Expand Up @@ -245,25 +234,6 @@ struct catalog_type {
}
}

void update(const chain_apis::tracked_votes::vote_block_metrics&& metrics) {
block_votes.block_num.Set(metrics.block_num);

auto add_and_set_gauge = [&](auto& fam, const auto& prod, const auto& value) {
auto& gauge = fam.Add({{"producer", prod}});
gauge.Set(value);
};

for (const auto& v : metrics.strong_votes) {
add_and_set_gauge(block_votes.voted, v, 1);
}
for (const auto& v : metrics.weak_votes) {
add_and_set_gauge(block_votes.voted, v, -1);
}
for (const auto& v : metrics.no_votes) {
add_and_set_gauge(block_votes.voted, v, 0);
}
}

void update(block_metrics& blk_metrics, const producer_plugin::speculative_block_metrics& metrics) {
blk_metrics.num_blocks_created.Increment(1);
blk_metrics.current_block_num.Set(metrics.block_num);
Expand Down Expand Up @@ -353,12 +323,6 @@ struct catalog_type {
[&strand, this](const producer_plugin::incoming_block_metrics& metrics) {
strand.post([metrics, this]() { update(metrics); });
});

auto& chain = app().get_plugin<chain_plugin>();
chain.register_update_vote_block_metrics(
[&strand, this](const chain_apis::tracked_votes::vote_block_metrics&& metrics) {
strand.post([metrics{std::move(metrics)}, this]() mutable { update(std::move(metrics)); });
});
}
};

Expand Down

0 comments on commit 75769d3

Please sign in to comment.