diff --git a/nano/lib/stats.cpp b/nano/lib/stats.cpp index 5ead07d069..57a5a5823b 100644 --- a/nano/lib/stats.cpp +++ b/nano/lib/stats.cpp @@ -126,10 +126,10 @@ auto nano::stats::count (stat::type type, stat::detail detail, stat::dir dir) co return 0; } -void nano::stats::sample (stat::sample sample, nano::stats::sampler_value_t value) +void nano::stats::sample (stat::sample sample, std::pair expected_min_max, nano::stats::sampler_value_t value) { // Updates need to happen while holding the mutex - auto update_sampler = [this] (nano::stats::sampler_key key, auto && updater) { + auto update_sampler = [this, expected_min_max] (nano::stats::sampler_key key, auto && updater) { // This is a two-step process to avoid exclusively locking the mutex in the common case { std::shared_lock lock{ mutex }; @@ -145,7 +145,7 @@ void nano::stats::sample (stat::sample sample, nano::stats::sampler_value_t valu std::unique_lock lock{ mutex }; // Insertions will be ignored if the key already exists - auto [it, inserted] = samplers.emplace (key, std::make_unique (config.max_samples)); + auto [it, inserted] = samplers.emplace (key, std::make_unique (config.max_samples, expected_min_max)); updater (*it->second); } }; diff --git a/nano/lib/stats.hpp b/nano/lib/stats.hpp index db46384223..5403470b2b 100644 --- a/nano/lib/stats.hpp +++ b/nano/lib/stats.hpp @@ -117,7 +117,7 @@ class stats final counter_value_t count (stat::type type, stat::detail detail, stat::dir dir = stat::dir::in) const; /** Adds a sample to the given sampler */ - void sample (stat::sample sample, sampler_value_t value); + void sample (stat::sample sample, std::pair expected_min_max, sampler_value_t value); /** Returns a potentially empty list of the last N samples, where N is determined by the 'max_samples' configuration. Samples are reset after each lookup. */ std::vector samples (stat::sample sample); @@ -174,8 +174,11 @@ class stats final class sampler_entry { public: - explicit sampler_entry (size_t max_samples) : - samples{ max_samples } {}; + std::pair const expected_min_max; + + sampler_entry (size_t max_samples, std::pair expected_min_max) : + samples{ max_samples }, + expected_min_max{ expected_min_max } {}; // Prevent copying sampler_entry (sampler_entry const &) = delete; diff --git a/nano/node/active_transactions.cpp b/nano/node/active_transactions.cpp index d9552b94c5..17ff10ccfb 100644 --- a/nano/node/active_transactions.cpp +++ b/nano/node/active_transactions.cpp @@ -340,7 +340,7 @@ void nano::active_transactions::cleanup_election (nano::unique_lock lock_a.unlock (); - node.stats.sample (nano::stat::sample::active_election_duration, election->duration ().count ()); + node.stats.sample (nano::stat::sample::active_election_duration, { 0, 1000 * 60 * 10 /* 0-10 minutes range */ }, election->duration ().count ()); vacancy_update (); diff --git a/nano/node/bootstrap_ascending/service.cpp b/nano/node/bootstrap_ascending/service.cpp index 83ebbd1d03..126bd096ea 100644 --- a/nano/node/bootstrap_ascending/service.cpp +++ b/nano/node/bootstrap_ascending/service.cpp @@ -362,7 +362,7 @@ void nano::bootstrap_ascending::service::process (nano::asc_pull_ack const & mes tags_by_id.erase (iterator); stats.inc (nano::stat::type::bootstrap_ascending, nano::stat::detail::reply); - stats.sample (nano::stat::sample::bootstrap_tag_duration, nano::milliseconds_since_epoch () - tag.time); + stats.sample (nano::stat::sample::bootstrap_tag_duration, { 0, config.bootstrap_ascending.timeout }, nano::milliseconds_since_epoch () - tag.time); scoring.received_message (channel); diff --git a/nano/rpc_test/rpc.cpp b/nano/rpc_test/rpc.cpp index 8941747db3..cad3711d72 100644 --- a/nano/rpc_test/rpc.cpp +++ b/nano/rpc_test/rpc.cpp @@ -5827,13 +5827,13 @@ TEST (rpc, stats_counters) auto node = add_ipc_enabled_node (system); auto const rpc_ctx = add_rpc (system, node); - node->stats.sample (nano::stat::sample::active_election_duration, 1); - node->stats.sample (nano::stat::sample::active_election_duration, 2); - node->stats.sample (nano::stat::sample::active_election_duration, 3); - node->stats.sample (nano::stat::sample::active_election_duration, 4); + node->stats.sample (nano::stat::sample::active_election_duration, { 0, 10 }, 1); + node->stats.sample (nano::stat::sample::active_election_duration, { 0, 10 }, 2); + node->stats.sample (nano::stat::sample::active_election_duration, { 0, 10 }, 3); + node->stats.sample (nano::stat::sample::active_election_duration, { 0, 10 }, 4); - node->stats.sample (nano::stat::sample::bootstrap_tag_duration, 5); - node->stats.sample (nano::stat::sample::bootstrap_tag_duration, 5); + node->stats.sample (nano::stat::sample::bootstrap_tag_duration, { 0, 10 }, 5); + node->stats.sample (nano::stat::sample::bootstrap_tag_duration, { 0, 10 }, 5); boost::property_tree::ptree request; request.put ("action", "stats"); @@ -5847,6 +5847,7 @@ TEST (rpc, stats_counters) std::cout << ss.str () << std::endl; } + // TODO: Assert the response // ASSERT_EQ (response.get_child ("node").get_child ("vote_uniquer").get_child ("cache").get ("count"), "1"); }