Skip to content

Commit

Permalink
chore: remove unnecessary code
Browse files Browse the repository at this point in the history
  • Loading branch information
CyndieKamau committed Aug 8, 2024
1 parent 64c606d commit dc3a986
Show file tree
Hide file tree
Showing 14 changed files with 17 additions and 53 deletions.
1 change: 0 additions & 1 deletion backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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>>, //starts here
pub target_os: Option<Box<str>>,
pub target_arch: Option<Box<str>>,
pub target_env: Option<Box<str>>,
pub sysinfo: Option<NodeSysInfo>,
Expand Down
1 change: 0 additions & 1 deletion backend/telemetry_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ maxminddb = "0.23.0"
num_cpus = "1.13.0"
once_cell = "1.8.0"
parking_lot = "0.12.1"
arrayvec = { version = "0.7.1", features = ["serde"] }
primitive-types = { version = "0.12.1", features = ["serde"] }
rayon = "1.5.1"
reqwest = { version = "0.11.4", features = ["json"] }
Expand Down
8 changes: 2 additions & 6 deletions backend/telemetry_core/src/feed_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@
//! This module provides a way of encoding the various messages that we'll
//! send to subscribed feeds (browsers).

use std::collections::HashMap;

use arrayvec::ArrayString;

use serde::Serialize;

use crate::state::Node;
Expand Down Expand Up @@ -223,15 +222,12 @@ impl FeedMessageWrite for AddedNode<'_> {
#[derive(Serialize)]
pub struct ChainStatsUpdate<'a>(pub &'a ChainStats);

/// Ranking list out node details elements per node id and counts per elements
/// `list`: List of node detail element per its count [( item, count )]
/// `node_map`: A map

#[derive(Serialize, PartialEq, Eq, Default)]
pub struct Ranking<K> {
pub list: Vec<(K, u64)>,
pub other: u64,
pub unknown: u64,
pub node_map: HashMap<ArrayString<64>,K>
}

#[derive(Serialize, PartialEq, Eq, Default)]
Expand Down
4 changes: 2 additions & 2 deletions backend/telemetry_core/src/state/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,9 +227,9 @@ impl Chain {
}

self.stats_collator
.update_hwbench(node.details(),old_hwbench.as_ref(), CounterValue::Decrement);
.update_hwbench(old_hwbench.as_ref(), CounterValue::Decrement);
self.stats_collator
.update_hwbench(node.details(),node.hwbench(), CounterValue::Increment);
.update_hwbench(node.hwbench(), CounterValue::Increment);
}
_ => {}
}
Expand Down
23 changes: 6 additions & 17 deletions backend/telemetry_core/src/state/chain_stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

use super::counter::{Counter, CounterValue};
use crate::feed_message::ChainStats;
//use arrayvec::ArrayString;
// These are the benchmark scores generated on our reference hardware.
const REFERENCE_CPU_SCORE: u64 = 1028;
const REFERENCE_MEMORY_SCORE: u64 = 14899;
Expand Down Expand Up @@ -159,84 +158,75 @@ impl ChainStatsCollator {
hwbench: Option<&common::node_types::NodeHwBench>,
op: CounterValue,
) {
self.version.modify(details.network_id,Some(&*details.version), op);
self.version.modify(Some(&*details.version), op);

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

self.target_arch
.modify(details.network_id,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(
details.network_id,
sysinfo
.and_then(|sysinfo| sysinfo.cpu.as_ref())
.map(|value| &**value),
op,
);

let memory = sysinfo.and_then(|sysinfo| sysinfo.memory.map(bucket_memory));
self.memory.modify(details.network_id,memory.as_ref(), op);
self.memory.modify(memory.as_ref(), op);

self.core_count
.modify(details.network_id,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(
details.network_id,
sysinfo
.and_then(|sysinfo| sysinfo.linux_kernel.as_ref())
.map(kernel_version_number),
op,
);

self.linux_distro.modify(
details.network_id,
sysinfo
.and_then(|sysinfo| sysinfo.linux_distro.as_ref())
.map(|value| &**value),
op,
);

self.is_virtual_machine.modify(
details.network_id,
sysinfo.and_then(|sysinfo| sysinfo.is_virtual_machine.as_ref()),
op,
);

self.cpu_vendor.modify(
details.network_id,
sysinfo.and_then(|sysinfo| sysinfo.cpu.as_ref().map(cpu_vendor)),
op,
);

self.update_hwbench(details,hwbench, op);
self.update_hwbench(hwbench, op);
}

pub fn update_hwbench(
&mut self,
details: &common::node_types::NodeDetails,
hwbench: Option<&common::node_types::NodeHwBench>,
op: CounterValue,
) {
self.cpu_hashrate_score.modify(
details.network_id,
hwbench
.map(|hwbench| bucket_score(hwbench.cpu_hashrate_score, REFERENCE_CPU_SCORE))
.as_ref(),
op,
);

self.memory_memcpy_score.modify(
details.network_id,
hwbench
.map(|hwbench| bucket_score(hwbench.memory_memcpy_score, REFERENCE_MEMORY_SCORE))
.as_ref(),
op,
);

self.disk_sequential_write_score.modify(
details.network_id,
hwbench
.and_then(|hwbench| hwbench.disk_sequential_write_score)
.map(|score| bucket_score(score, REFERENCE_DISK_SEQUENTIAL_WRITE_SCORE))
Expand All @@ -245,7 +235,6 @@ impl ChainStatsCollator {
);

self.disk_random_write_score.modify(
details.network_id,
hwbench
.and_then(|hwbench| hwbench.disk_random_write_score)
.map(|score| bucket_score(score, REFERENCE_DISK_RANDOM_WRITE_SCORE))
Expand Down
18 changes: 2 additions & 16 deletions backend/telemetry_core/src/state/counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

use arrayvec::ArrayString;

use crate::feed_message::Ranking;
use std::{collections::HashMap, /*str::FromStr*/};
use std::collections::HashMap;


/// A data structure which counts how many occurrences of a given key we've seen.
Expand All @@ -31,9 +29,6 @@ pub struct Counter<K> {
/// The number of occurrences where the key is `None`.
empty: u64,

/// The map of Node Id ( Network Id) to the node detail element
/// i.e {"123DE": "aarch64"}
node_map: HashMap<ArrayString<64>,K>
}

#[derive(Copy, Clone, PartialEq, Eq, Debug)]
Expand All @@ -48,7 +43,7 @@ where

{
/// Either adds or removes a single occurence of a given `key`.
pub fn modify<'a, Q>(&mut self,node_id: ArrayString<64>, key: Option<&'a Q>, op: CounterValue)
pub fn modify<'a, Q>(&mut self, key: Option<&'a Q>, op: CounterValue)
where
Q: ?Sized + std::hash::Hash + Eq,
K: std::borrow::Borrow<Q>,
Expand All @@ -59,8 +54,6 @@ where
match op {
CounterValue::Increment => {
*entry += 1;
// add the node Id and the value ( key ) to the node_map
self.node_map.insert(node_id, key.to_owned());

}
CounterValue::Decrement => {
Expand All @@ -69,20 +62,15 @@ where
// Don't keep entries for which there are no hits.
self.map.remove(key);
}
// remove the node Id and the value ( key ) to the node_map
self.node_map.remove(&node_id);
}
}
} else {
assert_eq!(op, CounterValue::Increment);
self.map.insert(key.to_owned(), 1);
// add the node Id and the value ( key ) to the node_map
self.node_map.insert(node_id, key.to_owned());

}

} else {
// The key is None, no need to update the map (nodeId -> key)
match op {
CounterValue::Increment => {
self.empty += 1;
Expand Down Expand Up @@ -117,7 +105,6 @@ where
list,
other,
unknown: self.empty,
node_map: self.node_map.clone(),
}
}

Expand All @@ -133,7 +120,6 @@ where
list,
other: 0,
unknown: self.empty,
node_map: self.node_map.clone(),
}
}
}
1 change: 0 additions & 1 deletion backend/telemetry_shard/src/json_message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@
mod hash;
mod node_message;

//pub use hash::Hash;
pub use node_message::*;
2 changes: 1 addition & 1 deletion frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export default class App extends React.Component {
blockpropagation: true,
blocklasttime: false,
uptime: false,
version: true, //starts here
version: true,
target_os: true,
target_arch: true,
core_count: true,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/Connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ export class Connection {
this.bindSocket();
}

public subscribe(chain: Types.GenesisHash) { //It has subscribed to the telemetry core
public subscribe(chain: Types.GenesisHash) {
if (
this.appState.subscribed != null &&
this.appState.subscribed !== chain
Expand Down
1 change: 0 additions & 1 deletion frontend/src/common/feed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ interface AddedNodeMessage extends MessageBase {
BlockDetails,
Maybe<NodeLocation>,
Maybe<Timestamp>,

];
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/List/Row.css
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
}

.Row:hover {
background-color: #1e1e1e; /*remember to change to #1e1e1e*/
background-color: #1e1e1e;
}
2 changes: 0 additions & 2 deletions frontend/src/components/List/Row.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ export class Row extends React.Component<RowProps, RowState> {
public render() {
const { node, columns } = this.props;

console.log('node details:',node );


this.renderedChangeRef = node.changeRef;

Expand Down
3 changes: 1 addition & 2 deletions frontend/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,7 @@ export interface StateSettings {
blockpropagation: boolean;
blocklasttime: boolean;
uptime: boolean;

version: boolean; //starts here
version: boolean;
target_os: boolean;
target_arch: boolean;
cpu: boolean;
Expand Down

0 comments on commit dc3a986

Please sign in to comment.