From 0ced6809396dec8df9de7ec5ea44433b5ce84f68 Mon Sep 17 00:00:00 2001 From: RickiNano <81099017+RickiNano@users.noreply.github.com> Date: Mon, 8 Jul 2024 19:15:37 +0200 Subject: [PATCH] Add database information to telemetry data --- nano/core_test/telemetry.cpp | 94 ++++++++++++++++++++++++++++++++++++ nano/node/messages.cpp | 1 + nano/node/messages.hpp | 1 + nano/node/node.cpp | 1 + nano/node/telemetry.cpp | 3 ++ 5 files changed, 100 insertions(+) diff --git a/nano/core_test/telemetry.cpp b/nano/core_test/telemetry.cpp index 73e91acaa0..99c86084b7 100644 --- a/nano/core_test/telemetry.cpp +++ b/nano/core_test/telemetry.cpp @@ -536,3 +536,97 @@ TEST (telemetry, DISABLED_mismatched_genesis) // Ensure node with different genesis gets disconnected ASSERT_TIMELY (5s, !node1.network.find_node_id (node2.get_node_id ())); } + +TEST (telemetry, majority_database_backend_information_missing) +{ + // Majority of nodes reporting no database info (Version 26.1 and earlier). One node reporting RocksDb backend + nano::telemetry_data data1; + data1.account_count = 2; + data1.block_count = 1; + data1.cemented_count = 1; + data1.protocol_version = 12; + data1.peer_count = 2; + data1.bandwidth_cap = 0; + data1.unchecked_count = 3; + data1.uptime = 6; + data1.genesis_block = nano::block_hash (3); + data1.major_version = 27; + data1.minor_version = 0; + data1.patch_version = 0; + data1.pre_release_version = 1; + data1.maker = 1; + data1.timestamp = std::chrono::system_clock::time_point (100ms); + data1.active_difficulty = 10; + std::vector all_data (100, data1); + + nano::telemetry_data data2; + data2.account_count = 2; + data2.block_count = 1; + data2.cemented_count = 1; + data2.protocol_version = 12; + data2.peer_count = 2; + data2.bandwidth_cap = 100; + data2.unchecked_count = 3; + data2.uptime = 6; + data2.genesis_block = nano::block_hash (3); + data2.major_version = 27; + data2.minor_version = 0; + data2.patch_version = 0; + data2.pre_release_version = 2; + data2.maker = 1; + data2.timestamp = std::chrono::system_clock::time_point (100ms); + data2.active_difficulty = 10; + data1.database_backend = "RocksDb"; + + all_data.push_back (data2); + + auto consolidated_telemetry_data2 = nano::consolidate_telemetry_data (all_data); + ASSERT_EQ (consolidated_telemetry_data2.database_backend, "Unknown"); +} + +TEST (telemetry, majority_database_backend_information_included) +{ + // Majority of nodes with LMDB database. One node with no information + nano::telemetry_data data1; + data1.account_count = 2; + data1.block_count = 1; + data1.cemented_count = 1; + data1.protocol_version = 12; + data1.peer_count = 2; + data1.bandwidth_cap = 0; + data1.unchecked_count = 3; + data1.uptime = 6; + data1.genesis_block = nano::block_hash (3); + data1.major_version = 27; + data1.minor_version = 0; + data1.patch_version = 0; + data1.pre_release_version = 1; + data1.maker = 1; + data1.timestamp = std::chrono::system_clock::time_point (100ms); + data1.active_difficulty = 10; + data1.database_backend = "LMDB"; + std::vector all_data (100, data1); + + nano::telemetry_data data2; + data2.account_count = 2; + data2.block_count = 1; + data2.cemented_count = 1; + data2.protocol_version = 12; + data2.peer_count = 2; + data2.bandwidth_cap = 100; + data2.unchecked_count = 3; + data2.uptime = 6; + data2.genesis_block = nano::block_hash (3); + data2.major_version = 27; + data2.minor_version = 0; + data2.patch_version = 0; + data2.pre_release_version = 2; + data2.maker = 1; + data2.timestamp = std::chrono::system_clock::time_point (100ms); + data2.active_difficulty = 10; + + all_data.push_back (data2); + + auto consolidated_telemetry_data2 = nano::consolidate_telemetry_data (all_data); + ASSERT_EQ (consolidated_telemetry_data2.database_backend, "LMDB"); +} \ No newline at end of file diff --git a/nano/node/messages.cpp b/nano/node/messages.cpp index ac82d67b27..8d9b8cdb24 100644 --- a/nano/node/messages.cpp +++ b/nano/node/messages.cpp @@ -1158,6 +1158,7 @@ nano::error nano::telemetry_data::serialize_json (nano::jsonconfig & json, bool json.put ("maker", maker); json.put ("timestamp", std::chrono::duration_cast (timestamp.time_since_epoch ()).count ()); json.put ("active_difficulty", nano::to_string_hex (active_difficulty)); + json.put ("database_backend", database_backend); // Keep these last for UI purposes if (!ignore_identification_metrics_a) { diff --git a/nano/node/messages.hpp b/nano/node/messages.hpp index 5046eae812..12ca18cf72 100644 --- a/nano/node/messages.hpp +++ b/nano/node/messages.hpp @@ -324,6 +324,7 @@ class telemetry_data uint8_t maker{ static_cast> (telemetry_maker::nf_node) }; // Where this telemetry information originated std::chrono::system_clock::time_point timestamp; uint64_t active_difficulty{ 0 }; + std::string database_backend{ "Unknown" }; std::vector unknown_data; void serialize (nano::stream &) const; diff --git a/nano/node/node.cpp b/nano/node/node.cpp index 2bc1bbf513..fdea3cf63f 100644 --- a/nano/node/node.cpp +++ b/nano/node/node.cpp @@ -1346,6 +1346,7 @@ nano::telemetry_data nano::node::local_telemetry () const telemetry_data.maker = static_cast> (ledger.pruning ? telemetry_maker::nf_pruned_node : telemetry_maker::nf_node); telemetry_data.timestamp = std::chrono::system_clock::now (); telemetry_data.active_difficulty = default_difficulty (nano::work_version::work_1); + telemetry_data.database_backend = config.rocksdb_config.enable ? "RocksDb" : "LMDB"; // Make sure this is the final operation! telemetry_data.sign (node_id); return telemetry_data; diff --git a/nano/node/telemetry.cpp b/nano/node/telemetry.cpp index 5e5b15fd2f..b62617a482 100644 --- a/nano/node/telemetry.cpp +++ b/nano/node/telemetry.cpp @@ -312,6 +312,7 @@ nano::telemetry_data nano::consolidate_telemetry_data (std::vector protocol_versions; std::unordered_map vendor_versions; + std::unordered_map database_backends; std::unordered_map bandwidth_caps; std::unordered_map genesis_blocks; @@ -349,6 +350,7 @@ nano::telemetry_data nano::consolidate_telemetry_data (std::vector