Skip to content

Commit

Permalink
Remove telemetry data aggregation (#4684)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwojcikdev authored Jul 19, 2024
1 parent 43746c3 commit d6f140b
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 411 deletions.
248 changes: 0 additions & 248 deletions nano/core_test/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,230 +10,6 @@

using namespace std::chrono_literals;

TEST (telemetry, consolidate_data)
{
auto time = 1582117035109;

// Pick specific values so that we can check both mode and average are working correctly
nano::telemetry_data data;
data.account_count = 2;
data.block_count = 1;
data.cemented_count = 1;
data.protocol_version = 12;
data.peer_count = 2;
data.bandwidth_cap = 100;
data.unchecked_count = 3;
data.uptime = 6;
data.genesis_block = nano::block_hash (3);
data.major_version = 20;
data.minor_version = 1;
data.patch_version = 4;
data.pre_release_version = 6;
data.maker = 2;
data.timestamp = std::chrono::system_clock::time_point (std::chrono::milliseconds (time));
data.active_difficulty = 2;

nano::telemetry_data data1;
data1.account_count = 5;
data1.block_count = 7;
data1.cemented_count = 4;
data1.protocol_version = 11;
data1.peer_count = 5;
data1.bandwidth_cap = 0;
data1.unchecked_count = 1;
data1.uptime = 10;
data1.genesis_block = nano::block_hash (4);
data1.major_version = 10;
data1.minor_version = 2;
data1.patch_version = 3;
data1.pre_release_version = 6;
data1.maker = 2;
data1.timestamp = std::chrono::system_clock::time_point (std::chrono::milliseconds (time + 1));
data1.active_difficulty = 3;

nano::telemetry_data data2;
data2.account_count = 3;
data2.block_count = 3;
data2.cemented_count = 2;
data2.protocol_version = 11;
data2.peer_count = 4;
data2.bandwidth_cap = 0;
data2.unchecked_count = 2;
data2.uptime = 3;
data2.genesis_block = nano::block_hash (4);
data2.major_version = 20;
data2.minor_version = 1;
data2.patch_version = 4;
data2.pre_release_version = 6;
data2.maker = 2;
data2.timestamp = std::chrono::system_clock::time_point (std::chrono::milliseconds (time));
data2.active_difficulty = 2;

std::vector<nano::telemetry_data> all_data{ data, data1, data2 };

auto consolidated_telemetry_data = nano::consolidate_telemetry_data (all_data);
ASSERT_EQ (consolidated_telemetry_data.account_count, 3);
ASSERT_EQ (consolidated_telemetry_data.block_count, 3);
ASSERT_EQ (consolidated_telemetry_data.cemented_count, 2);
ASSERT_EQ (consolidated_telemetry_data.protocol_version, 11);
ASSERT_EQ (consolidated_telemetry_data.peer_count, 3);
ASSERT_EQ (consolidated_telemetry_data.bandwidth_cap, 0);
ASSERT_EQ (consolidated_telemetry_data.unchecked_count, 2);
ASSERT_EQ (consolidated_telemetry_data.uptime, 6);
ASSERT_EQ (consolidated_telemetry_data.genesis_block, nano::block_hash (4));
ASSERT_EQ (consolidated_telemetry_data.major_version, 20);
ASSERT_EQ (consolidated_telemetry_data.minor_version, 1);
ASSERT_EQ (consolidated_telemetry_data.patch_version, 4);
ASSERT_EQ (consolidated_telemetry_data.pre_release_version, 6);
ASSERT_EQ (consolidated_telemetry_data.maker, 2);
ASSERT_EQ (consolidated_telemetry_data.timestamp, std::chrono::system_clock::time_point (std::chrono::milliseconds (time)));
ASSERT_EQ (consolidated_telemetry_data.active_difficulty, 2);

// Modify the metrics which may be either the mode or averages to ensure all are tested.
all_data[2].bandwidth_cap = 53;
all_data[2].protocol_version = 13;
all_data[2].genesis_block = nano::block_hash (3);
all_data[2].major_version = 10;
all_data[2].minor_version = 2;
all_data[2].patch_version = 3;
all_data[2].pre_release_version = 6;
all_data[2].maker = 2;

auto consolidated_telemetry_data1 = nano::consolidate_telemetry_data (all_data);
ASSERT_EQ (consolidated_telemetry_data1.major_version, 10);
ASSERT_EQ (consolidated_telemetry_data1.minor_version, 2);
ASSERT_EQ (consolidated_telemetry_data1.patch_version, 3);
ASSERT_EQ (consolidated_telemetry_data1.pre_release_version, 6);
ASSERT_EQ (consolidated_telemetry_data1.maker, 2);
ASSERT_TRUE (consolidated_telemetry_data1.protocol_version == 11 || consolidated_telemetry_data1.protocol_version == 12 || consolidated_telemetry_data1.protocol_version == 13);
ASSERT_EQ (consolidated_telemetry_data1.bandwidth_cap, 51);
ASSERT_EQ (consolidated_telemetry_data1.genesis_block, nano::block_hash (3));

// Test equality operator
ASSERT_FALSE (consolidated_telemetry_data == consolidated_telemetry_data1);
ASSERT_EQ (consolidated_telemetry_data, consolidated_telemetry_data);
}

TEST (telemetry, consolidate_data_remove_outliers)
{
nano::telemetry_data data;
data.account_count = 2;
data.block_count = 1;
data.cemented_count = 1;
data.protocol_version = 12;
data.peer_count = 2;
data.bandwidth_cap = 100;
data.unchecked_count = 3;
data.uptime = 6;
data.genesis_block = nano::block_hash (3);
data.major_version = 20;
data.minor_version = 1;
data.patch_version = 5;
data.pre_release_version = 2;
data.maker = 1;
data.timestamp = std::chrono::system_clock::time_point (100ms);
data.active_difficulty = 10;

// Insert 20 of these, and 2 outliers at the lower and upper bounds which should get removed
std::vector<nano::telemetry_data> all_data (20, data);

// Insert some outliers
nano::telemetry_data lower_bound_outlier_data;
lower_bound_outlier_data.account_count = 1;
lower_bound_outlier_data.block_count = 0;
lower_bound_outlier_data.cemented_count = 0;
lower_bound_outlier_data.protocol_version = 11;
lower_bound_outlier_data.peer_count = 0;
lower_bound_outlier_data.bandwidth_cap = 8;
lower_bound_outlier_data.unchecked_count = 1;
lower_bound_outlier_data.uptime = 2;
lower_bound_outlier_data.genesis_block = nano::block_hash (2);
lower_bound_outlier_data.major_version = 11;
lower_bound_outlier_data.minor_version = 1;
lower_bound_outlier_data.patch_version = 1;
lower_bound_outlier_data.pre_release_version = 1;
lower_bound_outlier_data.maker = 1;
lower_bound_outlier_data.timestamp = std::chrono::system_clock::time_point (1ms);
lower_bound_outlier_data.active_difficulty = 1;
all_data.push_back (lower_bound_outlier_data);
all_data.push_back (lower_bound_outlier_data);

nano::telemetry_data upper_bound_outlier_data;
upper_bound_outlier_data.account_count = 99;
upper_bound_outlier_data.block_count = 99;
upper_bound_outlier_data.cemented_count = 99;
upper_bound_outlier_data.protocol_version = 99;
upper_bound_outlier_data.peer_count = 99;
upper_bound_outlier_data.bandwidth_cap = 999;
upper_bound_outlier_data.unchecked_count = 99;
upper_bound_outlier_data.uptime = 999;
upper_bound_outlier_data.genesis_block = nano::block_hash (99);
upper_bound_outlier_data.major_version = 99;
upper_bound_outlier_data.minor_version = 9;
upper_bound_outlier_data.patch_version = 9;
upper_bound_outlier_data.pre_release_version = 9;
upper_bound_outlier_data.maker = 9;
upper_bound_outlier_data.timestamp = std::chrono::system_clock::time_point (999ms);
upper_bound_outlier_data.active_difficulty = 99;
all_data.push_back (upper_bound_outlier_data);
all_data.push_back (upper_bound_outlier_data);

auto consolidated_telemetry_data = nano::consolidate_telemetry_data (all_data);
ASSERT_EQ (data, consolidated_telemetry_data);
}

TEST (telemetry, consolidate_data_remove_outliers_with_zero_bandwidth)
{
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 = 20;
data1.minor_version = 1;
data1.patch_version = 5;
data1.pre_release_version = 2;
data1.maker = 1;
data1.timestamp = std::chrono::system_clock::time_point (100ms);
data1.active_difficulty = 10;

// Add a majority of nodes with bandwidth set to 0
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 = 20;
data2.minor_version = 1;
data2.patch_version = 5;
data2.pre_release_version = 2;
data2.maker = 1;
data2.timestamp = std::chrono::system_clock::time_point (100ms);
data2.active_difficulty = 10;

auto consolidated_telemetry_data1 = nano::consolidate_telemetry_data (all_data);
ASSERT_EQ (consolidated_telemetry_data1.bandwidth_cap, 0);

// And a few nodes with non-zero bandwidth
all_data.push_back (data2);
all_data.push_back (data2);

auto consolidated_telemetry_data2 = nano::consolidate_telemetry_data (all_data);
ASSERT_EQ (consolidated_telemetry_data2.bandwidth_cap, 0);
}

TEST (telemetry, signatures)
{
nano::keypair node_id;
Expand Down Expand Up @@ -512,27 +288,3 @@ TEST (telemetry, ongoing_broadcasts)
ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::telemetry, nano::stat::detail::process) >= 3);
ASSERT_TIMELY (5s, node2.stats.count (nano::stat::type::telemetry, nano::stat::detail::process) >= 3)
}

// TODO: With handshake V2, nodes with mismatched genesis will refuse to connect while setting up the system
TEST (telemetry, DISABLED_mismatched_genesis)
{
// Only second node will broadcast telemetry
nano::test::system system;
nano::node_flags node_flags;
node_flags.disable_ongoing_telemetry_requests = true;
node_flags.disable_providing_telemetry_metrics = true;
auto & node1 = *system.add_node (node_flags);

// Set up a node with different genesis
nano::network_params network_params{ nano::networks::nano_dev_network };
network_params.ledger.genesis = network_params.ledger.nano_live_genesis;
nano::node_config node_config{ network_params };
node_flags.disable_providing_telemetry_metrics = false;
auto & node2 = *system.add_node (node_config, node_flags);

ASSERT_TIMELY (5s, node1.stats.count (nano::stat::type::telemetry, nano::stat::detail::genesis_mismatch) > 0);
ASSERT_ALWAYS (1s, node1.stats.count (nano::stat::type::telemetry, nano::stat::detail::process) == 0)

// Ensure node with different genesis gets disconnected
ASSERT_TIMELY (5s, !node1.network.find_node_id (node2.get_node_id ()));
}
22 changes: 8 additions & 14 deletions nano/node/json_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4145,27 +4145,21 @@ void nano::json_handler::telemetry ()
}
else
{
// Default case without any parameters, requesting telemetry metrics locally
auto telemetry_data = node.local_telemetry ();

nano::jsonconfig config_l;
std::vector<nano::telemetry_data> telemetry_datas;
telemetry_datas.reserve (telemetry_responses.size ());
std::transform (telemetry_responses.begin (), telemetry_responses.end (), std::back_inserter (telemetry_datas), [] (auto const & endpoint_telemetry_data) {
return endpoint_telemetry_data.second;
});

auto average_telemetry_metrics = nano::consolidate_telemetry_data (telemetry_datas);
// Don't add node_id/signature in consolidated metrics
auto const should_ignore_identification_metrics = true;
auto err = average_telemetry_metrics.serialize_json (config_l, should_ignore_identification_metrics);
auto const should_ignore_identification_metrics = false;
auto err = telemetry_data.serialize_json (config_l, should_ignore_identification_metrics);
auto const & ptree = config_l.get_tree ();

if (!err)
{
response_l.insert (response_l.begin (), ptree.begin (), ptree.end ());
}
else
{
ec = nano::error_rpc::generic;
}

response_errors ();
return;
}

response_errors ();
Expand Down
Loading

0 comments on commit d6f140b

Please sign in to comment.