Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

backend: Provide extensive statistics bounded to 1k #561

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 15 additions & 10 deletions backend/telemetry_core/src/state/chain_stats.rs
Expand Up @@ -23,6 +23,11 @@ const REFERENCE_MEMORY_SCORE: u64 = 14899;
const REFERENCE_DISK_SEQUENTIAL_WRITE_SCORE: u64 = 485;
const REFERENCE_DISK_RANDOM_WRITE_SCORE: u64 = 222;

/// The maximum number of statistics sent to the frontend for one entry.
const MAXIMUM_STATS_COUNT: usize = 1024;
/// Top k statistics reported for one entry.
const TOP_K_STATS: usize = 10;

macro_rules! buckets {
(@try $value:expr, $bucket_min:expr, $bucket_max:expr,) => {
if $value < $bucket_max {
Expand Down Expand Up @@ -184,7 +189,7 @@ impl ChainStatsCollator {
self.linux_kernel.modify(
sysinfo
.and_then(|sysinfo| sysinfo.linux_kernel.as_ref())
.map(kernel_version_number),
.map(|value| &**value),
op,
);

Expand Down Expand Up @@ -246,22 +251,22 @@ impl ChainStatsCollator {

pub fn generate(&self) -> ChainStats {
ChainStats {
version: self.version.generate_ranking_top(10),
target_os: self.target_os.generate_ranking_top(10),
target_arch: self.target_arch.generate_ranking_top(10),
cpu: self.cpu.generate_ranking_top(10),
version: self.version.generate_ranking_top(MAXIMUM_STATS_COUNT),
Copy link
Member

@niklasad1 niklasad1 Nov 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add a few comments why 10 vs 1024 is used for certain metrics?

FYI, I have some troubles to understand the rationale behind by looking at the code, so I would like
to have either some kind of grouping by two different structs in ChainStats or add a few comments.

For example:

struct Chainstats {
   // This contains full stats for the metrics 
   full_stats: FullStats
   // This contains the top k stats for the metrics 
   top_k_stats: TopStats,
   other: Other,
}

Thoughts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, staging does not propagate a meaningful number of statistics back to the frontend due to a limited variety of testing nodes with similar kernels and cpus.

I believe we'll end up taking a similar approach to this, but that decision still needs to be data-driven. In the meanwhile, will refactor the ChainStats to make it clear for which statistics we'd want more granular control in the frontend, good suggestion! Thanks!

target_os: self.target_os.generate_ranking_top(TOP_K_STATS),
target_arch: self.target_arch.generate_ranking_top(TOP_K_STATS),
cpu: self.cpu.generate_ranking_top(MAXIMUM_STATS_COUNT),
memory: self.memory.generate_ranking_ordered(),
core_count: self.core_count.generate_ranking_top(10),
linux_kernel: self.linux_kernel.generate_ranking_top(10),
linux_distro: self.linux_distro.generate_ranking_top(10),
core_count: self.core_count.generate_ranking_top(TOP_K_STATS),
linux_kernel: self.linux_kernel.generate_ranking_top(MAXIMUM_STATS_COUNT),
linux_distro: self.linux_distro.generate_ranking_top(TOP_K_STATS),
is_virtual_machine: self.is_virtual_machine.generate_ranking_ordered(),
cpu_hashrate_score: self.cpu_hashrate_score.generate_ranking_top(10),
cpu_hashrate_score: self.cpu_hashrate_score.generate_ranking_top(TOP_K_STATS),
memory_memcpy_score: self.memory_memcpy_score.generate_ranking_ordered(),
disk_sequential_write_score: self
.disk_sequential_write_score
.generate_ranking_ordered(),
disk_random_write_score: self.disk_random_write_score.generate_ranking_ordered(),
cpu_vendor: self.cpu_vendor.generate_ranking_top(10),
cpu_vendor: self.cpu_vendor.generate_ranking_top(TOP_K_STATS),
}
}
}