Skip to content

Commit

Permalink
Use channel as telemetry data key (#4697)
Browse files Browse the repository at this point in the history
* Use channel as telemetry data key

* Erase dead channels
  • Loading branch information
pwojcikdev authored Oct 15, 2024
1 parent c22851b commit 885447f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions nano/lib/stats_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ enum class detail
failed_send_telemetry_req,
empty_payload,
cleanup_outdated,
erase_stale,

// vote generator
generator_broadcasts,
Expand Down
19 changes: 10 additions & 9 deletions nano/node/telemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,19 @@ void nano::telemetry::process (const nano::telemetry_ack & telemetry, const std:

nano::unique_lock<nano::mutex> lock{ mutex };

const auto endpoint = channel->get_endpoint ();

if (auto it = telemetries.get<tag_endpoint> ().find (endpoint); it != telemetries.get<tag_endpoint> ().end ())
if (auto it = telemetries.get<tag_channel> ().find (channel); it != telemetries.get<tag_channel> ().end ())
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::update);

telemetries.get<tag_endpoint> ().modify (it, [&telemetry, &endpoint] (auto & entry) {
debug_assert (entry.endpoint == endpoint);
telemetries.get<tag_channel> ().modify (it, [&telemetry, &channel] (auto & entry) {
entry.data = telemetry.data;
entry.last_updated = std::chrono::steady_clock::now ();
});
}
else
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::insert);
telemetries.get<tag_endpoint> ().insert ({ endpoint, telemetry.data, std::chrono::steady_clock::now (), channel });
telemetries.get<tag_channel> ().insert ({ channel, telemetry.data, std::chrono::steady_clock::now () });

if (telemetries.size () > max_size)
{
Expand Down Expand Up @@ -247,10 +244,14 @@ void nano::telemetry::cleanup ()
// Remove if telemetry data is stale
if (!check_timeout (entry))
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::cleanup_outdated);
stats.inc (nano::stat::type::telemetry, nano::stat::detail::erase_stale);
return true; // Erase
}
if (!entry.channel->alive ())
{
stats.inc (nano::stat::type::telemetry, nano::stat::detail::erase_dead);
return true; // Erase
}

return false; // Do not erase
});
}
Expand Down Expand Up @@ -283,7 +284,7 @@ std::unordered_map<nano::endpoint, nano::telemetry_data> nano::telemetry::get_al
{
if (check_timeout (entry))
{
result[entry.endpoint] = entry.data;
result[entry.endpoint ()] = entry.data;
}
}
return result;
Expand Down
15 changes: 11 additions & 4 deletions nano/node/telemetry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ class telemetry
private:
struct entry
{
nano::endpoint endpoint;
std::shared_ptr<nano::transport::channel> channel;
nano::telemetry_data data;
std::chrono::steady_clock::time_point last_updated;
std::shared_ptr<nano::transport::channel> channel;

nano::endpoint endpoint () const
{
return channel->get_endpoint ();
}
};

private:
Expand All @@ -110,13 +114,16 @@ class telemetry
private:
// clang-format off
class tag_sequenced {};
class tag_channel {};
class tag_endpoint {};

using ordered_telemetries = boost::multi_index_container<entry,
mi::indexed_by<
mi::sequenced<mi::tag<tag_sequenced>>,
mi::hashed_unique<mi::tag<tag_endpoint>,
mi::member<entry, nano::endpoint, &entry::endpoint>>
mi::ordered_unique<mi::tag<tag_channel>,
mi::member<entry, std::shared_ptr<nano::transport::channel>, &entry::channel>>,
mi::hashed_non_unique<mi::tag<tag_endpoint>,
mi::const_mem_fun<entry, nano::endpoint, &entry::endpoint>>
>>;
// clang-format on

Expand Down

0 comments on commit 885447f

Please sign in to comment.