Skip to content

Commit

Permalink
Add database information to telemetry data
Browse files Browse the repository at this point in the history
  • Loading branch information
RickiNano committed Jul 8, 2024
1 parent 39d2c65 commit 0ced680
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 0 deletions.
94 changes: 94 additions & 0 deletions nano/core_test/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<nano::telemetry_data> 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<nano::telemetry_data> 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");
}
1 change: 1 addition & 0 deletions nano/node/messages.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::chrono::milliseconds> (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)
{
Expand Down
1 change: 1 addition & 0 deletions nano/node/messages.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ class telemetry_data
uint8_t maker{ static_cast<std::underlying_type_t<telemetry_maker>> (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<uint8_t> unknown_data;

void serialize (nano::stream &) const;
Expand Down
1 change: 1 addition & 0 deletions nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,7 @@ nano::telemetry_data nano::node::local_telemetry () const
telemetry_data.maker = static_cast<std::underlying_type_t<telemetry_maker>> (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;
Expand Down
3 changes: 3 additions & 0 deletions nano/node/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ nano::telemetry_data nano::consolidate_telemetry_data (std::vector<nano::telemet

std::unordered_map<uint8_t, int> protocol_versions;
std::unordered_map<std::string, int> vendor_versions;
std::unordered_map<std::string, int> database_backends;
std::unordered_map<uint64_t, int> bandwidth_caps;
std::unordered_map<nano::block_hash, int> genesis_blocks;

Expand Down Expand Up @@ -349,6 +350,7 @@ nano::telemetry_data nano::consolidate_telemetry_data (std::vector<nano::telemet
++bandwidth_caps[telemetry_data.bandwidth_cap];
++genesis_blocks[telemetry_data.genesis_block];
active_difficulties.insert (telemetry_data.active_difficulty);
++database_backends[telemetry_data.database_backend];
}

// Remove 10% of the results from the lower and upper bounds to catch any outliers. Need at least 10 responses before any are removed.
Expand Down Expand Up @@ -424,6 +426,7 @@ nano::telemetry_data nano::consolidate_telemetry_data (std::vector<nano::telemet
set_mode_or_average (bandwidth_caps, consolidated_data.bandwidth_cap, bandwidth_sum, size);
set_mode (protocol_versions, consolidated_data.protocol_version, size);
set_mode (genesis_blocks, consolidated_data.genesis_block, size);
set_mode (database_backends, consolidated_data.database_backend, size);

// Vendor version, needs to be parsed out of the string
std::string version;
Expand Down

0 comments on commit 0ced680

Please sign in to comment.