Skip to content

Commit

Permalink
[Metrics] #837 #883 #919 #896 #835
Browse files Browse the repository at this point in the history
Integrate kOnBlock to storage_impl.cpp
Closes #837 Add total number of blocks
Closes #883 Number of domains
Closes #919 Number of signatures in the last block
Closes #896 Measure total number of transactions
Closes #835 Total nodes/peers updated when kOnBlock
Should close #835 no online/connected peers parameter in this commit.
Add CMake files to .clang-format-ignore
Disable prometheus-cpp logs
Extend WSV to countDomains(), countTransactions(), countPeers()
-fno-lto to link GCC-10 and clang with civetweb which was built with
GCC-9
Tests dependant on ametsuchi are linked against sync_subscription, not
async
Closes #966 Disable prometheus-cpp self-metrics

Signed-off-by: Ivan 'kuvaldini' Kuvaldin <[email protected]>
  • Loading branch information
kuvaldini committed Jun 4, 2021
1 parent 8a843bf commit de47f01
Show file tree
Hide file tree
Showing 27 changed files with 565 additions and 134 deletions.
2 changes: 2 additions & 0 deletions .clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CMakeLists.txt
*.cmake
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ if(CMAKE_BUILD_TYPE MATCHES "Release")
endif()
endif()

## FIXME revert this after change CI to GitHub actions.
## Temporal fix for 'bytecode stream version incompatible' between gcc-9 and gcc-10 and clang
## when dependancies were build via vcpkg with default GCC9 could not be linked with iroha built with GCC-10
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION FALSE)

if(WIN32)
# We have to set _WIN32_WINNT for gRPC
if(${CMAKE_SYSTEM_VERSION} EQUAL 10) # Windows 10
Expand Down
27 changes: 27 additions & 0 deletions irohad/ametsuchi/impl/postgres_wsv_query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ametsuchi/impl/postgres_wsv_query.hpp"

#include <soci/boost-tuple.h>

#include "ametsuchi/impl/soci_std_optional.hpp"
#include "ametsuchi/impl/soci_utils.hpp"
#include "ametsuchi/ledger_state.hpp"
Expand Down Expand Up @@ -79,6 +80,32 @@ namespace iroha {
return getPeersFromSociRowSet(result);
}

iroha::expected::Result<size_t, std::string> PostgresWsvQuery::count(
std::string_view what) try {
int count;
sql_ << "SELECT count(*) FROM " << what, soci::into(count);
return count;
} catch (const std::exception &e) {
auto msg = fmt::format("Failed to count {}, query: {}", what, e.what());
log_->error(msg);
return iroha::expected::makeError(msg);
}

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countPeers() {
return count("peer");
}

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countDomains() {
return count("domain");
}

iroha::expected::Result<size_t, std::string>
PostgresWsvQuery::countTransactions() {
return count("tx_positions");
}

boost::optional<std::shared_ptr<shared_model::interface::Peer>>
PostgresWsvQuery::getPeerByPublicKey(
shared_model::interface::types::PublicKeyHexStringView public_key) {
Expand Down
10 changes: 8 additions & 2 deletions irohad/ametsuchi/impl/postgres_wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifndef IROHA_POSTGRES_WSV_QUERY_HPP
#define IROHA_POSTGRES_WSV_QUERY_HPP

#include "ametsuchi/wsv_query.hpp"

#include <soci/soci.h>

#include "ametsuchi/wsv_query.hpp"
#include "logger/logger_fwd.hpp"

namespace iroha {
Expand All @@ -28,6 +28,10 @@ namespace iroha {
std::vector<std::shared_ptr<shared_model::interface::Peer>>>
getPeers() override;

iroha::expected::Result<size_t, std::string> countPeers() override;
iroha::expected::Result<size_t, std::string> countDomains() override;
iroha::expected::Result<size_t, std::string> countTransactions() override;

boost::optional<std::shared_ptr<shared_model::interface::Peer>>
getPeerByPublicKey(shared_model::interface::types::PublicKeyHexStringView
public_key) override;
Expand All @@ -43,6 +47,8 @@ namespace iroha {
template <typename T, typename F>
auto execute(F &&f) -> boost::optional<soci::rowset<T>>;

iroha::expected::Result<size_t, std::string> count(std::string_view);

// TODO andrei 24.09.2018: IR-1718 Consistent soci::session fields in
// storage classes
std::unique_ptr<soci::session> psql_;
Expand Down
16 changes: 13 additions & 3 deletions irohad/ametsuchi/impl/storage_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@

#include "ametsuchi/impl/storage_impl.hpp"

#include <utility>

#include <soci/callbacks.h>
#include <soci/postgresql/soci-postgresql.h>

#include <boost/algorithm/string.hpp>
#include <boost/format.hpp>
#include <boost/range/algorithm/replace_if.hpp>
Expand Down Expand Up @@ -36,6 +35,7 @@
#include "logger/logger.hpp"
#include "logger/logger_manager.hpp"
#include "main/impl/pg_connection_init.hpp"
#include "main/subscription.hpp"

namespace iroha {
namespace ametsuchi {
Expand Down Expand Up @@ -307,7 +307,11 @@ namespace iroha {
if (not maybe_block) {
return fmt::format("Failed to fetch block {}", height);
}
notifier_.get_subscriber().on_next(*std::move(maybe_block));

std::shared_ptr<const shared_model::interface::Block> block_ptr =
std::move(maybe_block.get());
notifier_.get_subscriber().on_next(block_ptr);
getSubscription()->notify(EventTypes::kOnBlock, block_ptr);
}
return expected::makeValue(std::move(commit_result.ledger_state));
};
Expand Down Expand Up @@ -357,6 +361,9 @@ namespace iroha {
}

notifier_.get_subscriber().on_next(block);
getSubscription()->notify(
EventTypes::kOnBlock,
std::shared_ptr<const shared_model::interface::Block>(block));

decltype(std::declval<PostgresWsvQuery>().getPeers()) opt_ledger_peers;
{
Expand Down Expand Up @@ -455,6 +462,9 @@ namespace iroha {
std::shared_ptr<const shared_model::interface::Block> block) {
if (block_store_->insert(block)) {
notifier_.get_subscriber().on_next(block);
getSubscription()->notify(
EventTypes::kOnBlock,
std::shared_ptr<const shared_model::interface::Block>(block));
return {};
}
return expected::makeError("Block insertion to storage failed");
Expand Down
31 changes: 30 additions & 1 deletion irohad/ametsuchi/wsv_query.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
#ifndef IROHA_WSV_QUERY_HPP
#define IROHA_WSV_QUERY_HPP

#include <boost/optional.hpp>
#include <vector>

#include <boost/optional.hpp>
#include "common/result.hpp"
#include "interfaces/common_objects/peer.hpp"
#include "interfaces/common_objects/string_view_types.hpp"
Expand Down Expand Up @@ -40,6 +40,35 @@ namespace iroha {
std::vector<std::shared_ptr<shared_model::interface::Peer>>>
getPeers() = 0;

// ToDo?(kuvaldini,iceseer) #997
// /**
// * @brief Fetch domains stored in ledger
// * @return list of domains in insertion to ledger order
// */
// virtual iroha::expected::Result<
// std::vector<std::shared_ptr<shared_model::interface::Domain>>,
// std::string>
// getDomains() = 0;

/**
* @brief Fetch number of domains in ledger
* @return number of domains in ledger
*/
virtual iroha::expected::Result<size_t, std::string> countPeers() = 0;

/**
* @brief Fetch number of domains in ledger
* @return number of domains in ledger
*/
virtual iroha::expected::Result<size_t, std::string> countDomains() = 0;

/**
* @brief Fetch number of valid transactions in ledger
* @return number of transactions in ledger
*/
virtual iroha::expected::Result<size_t, std::string>
countTransactions() = 0;

/**
* Fetch peer with given public key from ledger
* @return the peer if found, none otherwise
Expand Down
3 changes: 2 additions & 1 deletion irohad/main/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ Irohad::Irohad(
const boost::optional<GossipPropagationStrategyParams>
&opt_mst_gossip_params,
boost::optional<IrohadConfig::InterPeerTls> inter_peer_tls_config)
: config_(config),
: se_(getSubscription()),
config_(config),
listen_ip_(listen_ip),
keypair_(keypair),
startup_wsv_sync_policy_(startup_wsv_sync_policy),
Expand Down
1 change: 1 addition & 0 deletions irohad/main/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ class Irohad {
virtual RunResult initWsvRestorer();

// constructor dependencies
std::shared_ptr<iroha::Subscription> se_;
IrohadConfig config_;
const std::string listen_ip_;
boost::optional<shared_model::crypto::Keypair> keypair_;
Expand Down
65 changes: 44 additions & 21 deletions irohad/main/irohad.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,6 @@ int main(int argc, char *argv[]) {
log_manager);
}

if (FLAGS_metrics_port.size()) {
maintenance_metrics_init(FLAGS_metrics_addr + ":" + FLAGS_metrics_port);
} else if (config.metrics_addr_port.size()) {
maintenance_metrics_init(config.metrics_addr_port);
}

daemon_status_notifier->notify(
::iroha::utility_service::Status::kInitialization);

Expand Down Expand Up @@ -374,10 +368,18 @@ int main(int argc, char *argv[]) {

// clear previous storage if any
irohad->dropStorage();
// Check if iroha daemon storage was successfully re-initialized
if (not irohad->storage) {
// Abort execution if not
log->error("Failed to re-initialize storage");
daemon_status_notifier->notify(
::iroha::utility_service::Status::kFailed);
return EXIT_FAILURE;
}

const auto txs_num = block->transactions().size();
if (auto e = iroha::expected::resultToOptionalError(
irohad->storage->insertBlock(std::move(block)))) {
auto inserted = irohad->storage->insertBlock(std::move(block));
if (auto e = iroha::expected::resultToOptionalError(inserted)) {
log->critical("Could not apply genesis block: {}", e.value());
return EXIT_FAILURE;
}
Expand All @@ -391,19 +393,17 @@ int main(int argc, char *argv[]) {
"genesis block is provided. Please pecify new genesis block using "
"--genesis_block parameter.");
return EXIT_FAILURE;
} else {
if (overwrite) {
// no genesis, blockstore present, overwrite specified -> new block
// store, world state should be reset
irohad->resetWsv();
if (not FLAGS_reuse_state) {
log->warn(
"No new genesis block is specified - blockstore will not be "
"overwritten. If you want overwrite ledger state, please "
"specify new genesis block using --genesis_block parameter. "
"If you want to reuse existing state data (WSV), consider the "
"--reuse_state flag.");
}
} else if (overwrite) {
// no genesis, blockstore present, overwrite specified -> new block
// store, world state should be reset
irohad->resetWsv();
if (not FLAGS_reuse_state) {
log->warn(
"No new genesis block is specified - blockstore will not be "
"overwritten. If you want overwrite ledger state, please "
"specify new genesis block using --genesis_block parameter. "
"If you want to reuse existing state data (WSV), consider the "
"--reuse_state flag.");
}
}
}
Expand Down Expand Up @@ -446,6 +446,29 @@ int main(int argc, char *argv[]) {
std::signal(SIGQUIT, handler);
#endif

// start metrics
std::shared_ptr<Metrics> metrics; // Must be a pointer because 'this' is
// captured to lambdas in constructor.
std::string metrics_addr;
if (FLAGS_metrics_port.size()) {
metrics_addr = FLAGS_metrics_addr + ":" + FLAGS_metrics_port;
} else if (config.metrics_addr_port.size()) {
metrics_addr = config.metrics_addr_port;
}
if (metrics_addr.empty()) {
log->info("Skiping Metrics initialization.");
} else {
try {
metrics =
Metrics::create(metrics_addr,
irohad->storage,
log_manager->getChild("Metrics")->getLogger());
log->info("Metrics listens on {}", metrics->getListenAddress());
} catch (std::exception const &ex) {
log->warn("Failed to initialize Metrics: {}", ex.what());
}
}

// runs iroha
log->info("Running iroha");
auto run_result = irohad->run();
Expand Down
Loading

0 comments on commit de47f01

Please sign in to comment.