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

Feat: Map Node Stats (Version, Operating System etc) to each Node in Feed #587

Closed
wants to merge 10 commits into from

Conversation

CyndieKamau
Copy link
Contributor

Hello, this PR is focused on providing a more detailed view of node metrics on the telemetry platform, by mapping the extra node info aggregated as a summary in ChainStats to specific nodes in the nodes' list table.

Some of the key changes implemented include:

Backend

  • Modified NodeDetails struct to include the extra information (target_os, target_arch, target_env, sysinfo) in common/src/node_types.rs
  • Updated the AddedNode payload to always expose the sysinfo details by default to get the additional stats (cpu, memory, core_count, linux_kernel, linux_distro, is_virtual_machine) found in NodeSysInfo

Frontend

  • Updated the Node constructor to handle the extra details within NodeDetails
  • Added new columns and components to display the newly available information

The objective is to provide telemetry users with deeper insights into the operational aspects of nodes. By exposing more detailed system information, users can better understand and track node operations.

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Apr 30, 2024

User @CyndieKamau, please sign the CLA here.

(&None, &None, &None)
};
let ip = if *expose_node_details { &details.ip } else { &None };
let sys_info = &details.sysinfo;
Copy link
Collaborator

@jsdw jsdw Aug 7, 2024

Choose a reason for hiding this comment

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

I'm not sure how I feel about sys_info no longer respecting the --expose-node-details flag. I think the point of this flag is to provide some privacy for nodes on the default telemetry instance, since they will connect to it by default (ie they aren't explicitly opting in to having their details shared). Then, on eg the 1kv telemetry instance we allow node details to be exposed since nodes must opt in to sharing telemetry there anyway.

It's debatable whether this privacy is required or not for the system info though. Perhaps there is a case for hiding IPs but exposing the hardware details, but I'd want to ask around a bit on this and gather some thoughts.

@@ -16,7 +16,7 @@

use super::counter::{Counter, CounterValue};
use crate::feed_message::ChainStats;

//use arrayvec::ArrayString;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: remove?

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

Choose a reason for hiding this comment

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

Suggested change
use std::{collections::HashMap, /*str::FromStr*/};
use std::collections::HashMap;

@@ -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>>, //starts here
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
pub target_os: Option<Box<str>>, //starts here
pub target_os: Option<Box<str>>,

@@ -19,5 +19,5 @@
mod hash;
mod node_message;

pub use hash::Hash;
//pub use hash::Hash;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
//pub use hash::Hash;

Comment on lines 226 to 228
/// 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
Copy link
Collaborator

Choose a reason for hiding this comment

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

This comment doesn't make sense to me :)

@@ -44,5 +44,5 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
}

.Row:hover {
background-color: #1e1e1e;
background-color: #1e1e1e; /*remember to change to #1e1e1e*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
background-color: #1e1e1e; /*remember to change to #1e1e1e*/
background-color: #1e1e1e;

@@ -86,6 +104,9 @@ export class Row extends React.Component<RowProps, RowState> {
public render() {
const { node, columns } = this.props;

console.log('node details:',node );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove?

@@ -71,6 +72,20 @@ export default class App extends React.Component {
blockpropagation: true,
blocklasttime: false,
uptime: false,
version: true, //starts here
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
version: true, //starts here
version: true,

@@ -133,7 +133,7 @@ export class Connection {
this.bindSocket();
}

public subscribe(chain: Types.GenesisHash) {
public subscribe(chain: Types.GenesisHash) { //It has subscribed to the telemetry core
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove or add proper comment above?

@@ -255,6 +291,22 @@ export interface StateSettings {
blockpropagation: boolean;
blocklasttime: boolean;
uptime: boolean;

version: boolean; //starts here
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
version: boolean; //starts here
version: boolean;

@@ -98,7 +98,8 @@ interface AddedNodeMessage extends MessageBase {
NodeHardware,
BlockDetails,
Maybe<NodeLocation>,
Maybe<Timestamp>
Maybe<Timestamp>,

Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove empty line?


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

Choose a reason for hiding this comment

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

What's the reasoning behind adding this?

As far as I understand, the relevant properties are exposed in NodeDetails, and then they are sent to the UI already (some depending on --expose-node-details). So I wonder whether you can avoid modifying all of this chain stats/counter/ranking stuff? Offhand I can't see it being used anywhere in the frontend changes.

@jsdw
Copy link
Collaborator

jsdw commented Aug 7, 2024

Overall I'm happy to expose node system info for each node. Whether or not it should only be when --expose-node-details is set is still a question in my mind though.

There are also changes to the Counter type and related which look to be adding node details per network ID, but these details are already exposed and sent to the UI via AddedNode by the looks of it, so would be good to justify or scrap those changes (especially since they involve more HashMaps and cloning of things that would be best to avoid if we can.

@CyndieKamau
Copy link
Contributor Author

CyndieKamau commented Aug 7, 2024

Hey @jsdw thank you for the reviews!!!

Yeah actually we first tried mapping each node ID to the extra set of details needed (cpu, cpuarch etc), that was before we had understood the entire codebase and the specific payloads !!! :)

Yeah in hindsight I should have just scraped off those changes and left the latest ones. Let me do just that and get back to you! ^^

@jsdw
Copy link
Collaborator

jsdw commented Aug 8, 2024

That sounds great to me; thank you!

@CyndieKamau
Copy link
Contributor Author

Hey @jsdw I have made the changes requested! ^^
I've scraped off the unnecessary code and the personal comments I missed out

Comment on lines 20 to 21


Copy link
Collaborator

@jsdw jsdw Aug 9, 2024

Choose a reason for hiding this comment

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

Nit; remove extra lines

Suggested change

@@ -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>>,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: remove unnecessary space?

Suggested change
pub target_os: Option<Box<str>>,
pub target_os: Option<Box<str>>,

@@ -16,7 +16,6 @@

use super::counter::{Counter, CounterValue};
use crate::feed_message::ChainStats;

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add back newline between imports and constants?

Comment on lines 221 to 225

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


Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: Unnecessary newlines?

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

@@ -162,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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
.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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

@@ -179,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);
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

@jsdw
Copy link
Collaborator

jsdw commented Aug 9, 2024

Thanks!

I haven't looked through it all yet but would run cargo fmt on the rust codebase to clear up a bunch of spacing and indentation nits / make CI pass :)

@CyndieKamau
Copy link
Contributor Author

Hey @jsdw apologies I was held up abit. So I've formatted both frontend and backend, what's left is actually some e2e tests which are failing:

test e2e_max_nodes_per_connection_is_enforced
test e2e_feeds_told_about_chain_rename_and_stay_subscribed
test e2e_feed_can_subscribe_and_unsubscribe_from_chain

Upon quick introspection I can see its because there's a mismatch between the expected and actual data structure when decoding the JSON message, since we altered it to fit the new inputs.

The solution would be to update the tests to handle this new structure, but otherwise it would be great to hear your opinion on this! Thanks :)

@jsdw
Copy link
Collaborator

jsdw commented Aug 23, 2024

Hey @CyndieKamau, no worries!

Having a quick look at the tests, I think it's just that this enum needs updating to match the feed message updates you did:

(I can't remember why it's a separate struct now, but hopefully it's pretty straightforward to tweak to match the new expected structure!)

MrishoLukamba and others added 2 commits August 26, 2024 14:37
Added new item in Ranking
node_map, mapping node id to node detail

Co-authored-by: Cyndie Kamau <[email protected]>
@MrishoLukamba
Copy link
Contributor

Hey @CyndieKamau, no worries!

Having a quick look at the tests, I think it's just that this enum needs updating to match the feed message updates you did:

(I can't remember why it's a separate struct now, but hopefully it's pretty straightforward to tweak to match the new expected structure!)

@jsdw fixed it, ready to be merged

@MrishoLukamba
Copy link
Contributor

@jsdw any pendings that needs to be addressed for the PR to be merged?

@jsdw
Copy link
Collaborator

jsdw commented Aug 29, 2024

Hey! I'll have to have another proper look over the code, but great to see the tests passing now, nice one!

I do see a .idea folder now added and wonder whether that's best removed?

@MrishoLukamba
Copy link
Contributor

Hey! I'll have to have another proper look over the code, but great to see the tests passing now, nice one!

I do see a .idea folder now added and wonder whether that's best removed?

removed it

@jsdw
Copy link
Collaborator

jsdw commented Aug 29, 2024

I opened #591 to address a few nits with this. Feel free to merge that into here (I can't easily do this) or we can continue from there!

One thing I noticed is that when I run a polkadot --dev node locally and point it to this telemetry server, I don't see any data for most of the new columns. Do you? I'm not sure what data nodes send by default, but need to check that we actually get data from nodes before we can merge this.

@niklasad1
Copy link
Member

#591 is merged so closing this one, thanks

@niklasad1 niklasad1 closed this Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants