Skip to content

Commit

Permalink
[Metrics] latest fix
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan 'kuvaldini' Kuvaldin <[email protected]>
  • Loading branch information
kuvaldini committed Apr 29, 2021
1 parent f925cec commit ea62d16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
3 changes: 1 addition & 2 deletions irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,7 @@ Irohad::RunResult Irohad::run() {
std::shared_ptr<const shared_model::interface::Block> sh_block{
std::move(block)};
ordering_init.commit_notifier.get_subscriber().on_next(sh_block);
getSubscription()->notify(EventTypes::kOnBlock, // kOnInitialBlock
sh_block);
getSubscription()->notify(EventTypes::kOnInitialBlock, sh_block);

ordering_init.sync_event_notifier.get_subscriber().on_next(
synchronizer::SynchronizationEvent{
Expand Down
30 changes: 14 additions & 16 deletions irohad/maintenance/metrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,35 +101,33 @@ Metrics::Metrics(std::string const &listen_addr,
.Register(*registry_);
auto &number_of_signatures_in_last_block =
number_of_signatures_in_last_block_gauge.Add({});

auto calc_diffs = [](shared_model::interface::Block const &block) {
int domains_diff = 0, peers_diff = 0;
using namespace shared_model::interface;
for (Transaction const &trx : block.transactions()) {
for (Command const &cmd : trx.commands()) {
domains_diff += cmd.is<CreateDomain>() ? 1 : 0;
peers_diff += cmd.is<AddPeer>() ? 1 : 0;
peers_diff -= cmd.is<RemovePeer>() ? 1 : 0;
}
}
return std::tuple{domains_diff, peers_diff};
};
auto ptopblock =
storage_->getBlockQuery()
->getBlock(storage_->getBlockQuery()->getTopBlockHeight())
.assumeValue();
number_of_signatures_in_last_block.Set(boost::size(ptopblock->signatures()));

block_subscriber_ =
SubscriberCreator<bool, BlockPtr>::template create<EventTypes::kOnBlock>(
SubscriptionEngineHandlers::kMetrics,
[&, wregistry = std::weak_ptr<Registry>(registry_)](auto &,
BlockPtr pblock) {
std::shared_ptr<Registry> registry{wregistry}; // throw if expired
// block_height is captured by reference because it is stored inside
// registry_, which is shared_ptr
assert(pblock);
block_height.Set(pblock->height());
number_of_signatures_in_last_block.Set(
boost::size(pblock->signatures()));
total_number_of_transactions.Increment(
boost::size(pblock->transactions()));
auto [domains_diff, peers_diff] = calc_diffs(*pblock);
int domains_diff = 0, peers_diff = 0;
using namespace shared_model::interface;
for (Transaction const &trx : pblock->transactions()) {
for (Command const &cmd : trx.commands()) {
domains_diff += cmd.is<CreateDomain>() ? 1 : 0;
peers_diff += cmd.is<AddPeer>() ? 1 : 0;
peers_diff -= cmd.is<RemovePeer>() ? 1 : 0;
}
}
number_of_peers.Increment(peers_diff);
domains_number.Increment(domains_diff);
});
Expand Down

0 comments on commit ea62d16

Please sign in to comment.