Skip to content

Commit

Permalink
chore: run cargo fmt for formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
CyndieKamau committed Aug 12, 2024
1 parent dc3a986 commit fd85c46
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 19 deletions.
2 changes: 1 addition & 1 deletion backend/common/src/node_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub struct NodeDetails {
pub validator: Option<Box<str>>,
pub network_id: NetworkId,
pub startup_time: Option<Box<str>>,
pub target_os: Option<Box<str>>,
pub target_os: Option<Box<str>>,
pub target_arch: Option<Box<str>>,
pub target_env: Option<Box<str>>,
pub sysinfo: Option<NodeSysInfo>,
Expand Down
16 changes: 10 additions & 6 deletions backend/telemetry_core/src/feed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
//! This module provides a way of encoding the various messages that we'll
//! send to subscribed feeds (browsers).



use serde::Serialize;

use crate::state::Node;
Expand Down Expand Up @@ -187,9 +185,17 @@ impl FeedMessageWrite for AddedNode<'_> {
let details = node.details();
// Always include sysinfo, conditionally include ip and hwbench based on expose_node_details.
let node_hwbench = node.hwbench();
let ip = if *expose_node_details { &details.ip } else { &None };
let ip = if *expose_node_details {
&details.ip
} else {
&None
};
let sys_info = &details.sysinfo;
let hwbench = if *expose_node_details { &node_hwbench } else { &None };
let hwbench = if *expose_node_details {
&node_hwbench
} else {
&None
};

let details = (
&details.name,
Expand Down Expand Up @@ -218,11 +224,9 @@ impl FeedMessageWrite for AddedNode<'_> {
}
}


#[derive(Serialize)]
pub struct ChainStatsUpdate<'a>(pub &'a ChainStats);


#[derive(Serialize, PartialEq, Eq, Default)]
pub struct Ranking<K> {
pub list: Vec<(K, u64)>,
Expand Down
8 changes: 4 additions & 4 deletions backend/telemetry_core/src/state/chain_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ pub struct ChainStatsCollator {
linux_kernel: Counter<String>,
linux_distro: Counter<String>,
is_virtual_machine: Counter<bool>,
cpu_hashrate_score: Counter<(u32, Option<u32>),>,
cpu_hashrate_score: Counter<(u32, Option<u32>)>,
memory_memcpy_score: Counter<(u32, Option<u32>)>,
disk_sequential_write_score: Counter<(u32, Option<u32>)>,
disk_random_write_score: Counter<(u32, Option<u32>)>,
Expand All @@ -161,10 +161,10 @@ impl ChainStatsCollator {
self.version.modify(Some(&*details.version), op);

self.target_os
.modify(details.target_os.as_ref().map(|value| &**value), op);
.modify(details.target_os.as_ref().map(|value| &**value), op);

self.target_arch
.modify(details.target_arch.as_ref().map(|value| &**value), op);
.modify(details.target_arch.as_ref().map(|value| &**value), op);

let sysinfo = details.sysinfo.as_ref();
self.cpu.modify(
Expand All @@ -178,7 +178,7 @@ impl ChainStatsCollator {
self.memory.modify(memory.as_ref(), op);

self.core_count
.modify(sysinfo.and_then(|sysinfo| sysinfo.core_count.as_ref()), op);
.modify(sysinfo.and_then(|sysinfo| sysinfo.core_count.as_ref()), op);

self.linux_kernel.modify(
sysinfo
Expand Down
10 changes: 2 additions & 8 deletions backend/telemetry_core/src/state/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use crate::feed_message::Ranking;
use std::collections::HashMap;


/// A data structure which counts how many occurrences of a given key we've seen.
#[derive(Default)]
pub struct Counter<K> {
Expand All @@ -28,7 +27,6 @@ pub struct Counter<K> {

/// The number of occurrences where the key is `None`.
empty: u64,

}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand All @@ -39,8 +37,7 @@ pub enum CounterValue {

impl<K> Counter<K>
where
K: Sized + std::hash::Hash + Eq

K: Sized + std::hash::Hash + Eq,
{
/// Either adds or removes a single occurence of a given `key`.
pub fn modify<'a, Q>(&mut self, key: Option<&'a Q>, op: CounterValue)
Expand All @@ -54,7 +51,6 @@ where
match op {
CounterValue::Increment => {
*entry += 1;

}
CounterValue::Decrement => {
*entry -= 1;
Expand All @@ -67,9 +63,7 @@ where
} else {
assert_eq!(op, CounterValue::Increment);
self.map.insert(key.to_owned(), 1);

}

} else {
match op {
CounterValue::Increment => {
Expand Down Expand Up @@ -111,7 +105,7 @@ where
/// Generates a sorted table of all of the keys.
pub fn generate_ranking_ordered(&self) -> Ranking<K>
where
K: Copy + Clone + Ord
K: Copy + Clone + Ord,
{
let mut list: Vec<(K, u64)> = self.map.iter().map(|(key, count)| (*key, *count)).collect();
list.sort_unstable_by_key(|&(key, count)| (key, !count));
Expand Down

0 comments on commit fd85c46

Please sign in to comment.