-
Notifications
You must be signed in to change notification settings - Fork 58
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
Drop rpc replace metrics #2670
base: main
Are you sure you want to change the base?
Drop rpc replace metrics #2670
Conversation
3786eb7
to
cb994a9
Compare
let service = NodeService::new(node, Box::new(rpc_client)); | ||
// TODO: remove this as we have no way to know the reward balance of nodes since EVM payments! | ||
let metric_client = MetricClient::new(node.metrics_port.unwrap()); | ||
let service = NodeService::new(node, Box::new(metric_client)); // TODO: remove this as we have no way to know the reward balance of nodes since EVM payments! |
Check notice
Code scanning / devskim
A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note
63cd487
to
b0761aa
Compare
b0761aa
to
35433fc
Compare
@@ -438,6 +438,7 @@ impl NetworkBuilder { | |||
is_client: bool, | |||
req_res_protocol: ProtocolSupport, | |||
upnp: bool, | |||
root_dir: Option<PathBuf> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is optional, maybe should this be a method inside the NetworkBuilder
?
// Run the node | ||
let runing_node_metrics = running_node.clone(); | ||
let _return_value = tokio::spawn(async move { | ||
sleep(Duration::from_millis(200)).await; | ||
let state = runing_node_metrics.get_swarm_local_state().await.expect("Failed to get swarm local state"); | ||
let connected_peers = state.connected_peers.iter().map(|p| p.to_string()).collect(); | ||
let listeners = state.listeners.iter().map(|m| m.to_string()).collect(); | ||
let network_info = NetworkInfoMetrics::new(connected_peers, listeners); | ||
|
||
write_network_metrics_to_file( | ||
runing_node_metrics.root_dir_path.clone(), | ||
network_info, | ||
runing_node_metrics.network.peer_id().to_string() | ||
); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things here:
- It would be better if we don't import things from
service_management
inside ant_node. They should be isolated. - The listeners can be added or removed, and it can happen throughout the lifetime of the program (for private nodes), it would be better if you could move the logic inside the
NetworkEvent::NewListenAddr
event, which is handled insideantnode
to write the listen addr to the file.- Since we also have to deal with removal of the listen addr (for private nodes), we should also create a new
NetworkEvent::ListenerClosed
event which will be emitted fromSwarmEvent::ListenerClosed
. This newly created event has to be then handled inside antnode and you should remove that particular listenaddr from the file.
- Since we also have to deal with removal of the listen addr (for private nodes), we should also create a new
ant-service-management/src/metric.rs
Outdated
for sample in scrape.samples.iter() { | ||
for (key, value) in sample.labels.iter() { | ||
match key.as_str() { | ||
"peer_id" => node_info.peer_id = value.parse().unwrap(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use unwrap
or expect
in our code as it may cause the program to crash instantly, we should return error types here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All the unwraps have to be removed.
ant-service-management/src/metric.rs
Outdated
} | ||
} | ||
|
||
pub async fn get_endpoint_metrics(&self, endpoint_name: &str) -> Result<prometheus_parse::Scrape, Box<dyn std::error::Error>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should probalby create a new error.rs
or if one already exists, add new enums for the errors returned from these functions. Box<dyn std::error::Error>
is a dynamic object and we cannot easily downcast it back to the actual error.
We use something called as thiserror
for error management, it is a good read.
@@ -13,6 +13,7 @@ pub mod error; | |||
pub mod faucet; | |||
pub mod node; | |||
pub mod rpc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think all the references to rpc
should be removed from our codebase.
impl RpcActions for MetricClient { | ||
async fn node_info(&self) -> Result<NodeInfo> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the Action
here:
- We must rename
RpcActions
->MetricActions
- remove the unused methods
- Also the
expect
has to be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was also puzzled about the use of RpcActions
. We shouldn't have references to RPC any more.
ant-service-management/src/metric.rs
Outdated
self.get_node_info_from_metadata_extended(&scrape, &mut node_info); | ||
let scrape = self.get_endpoint_metrics("metrics").await.expect("Failed to get endpoint metrics"); | ||
self.get_node_info_from_metrics(&scrape, &mut node_info); | ||
println!("node_info: {:?}", node_info); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume these println
are for debugging? It would be great if these can be tidied up.
df91d89
to
cb8c46f
Compare
cb8c46f
to
db7c11b
Compare
Description
ant-node-manager currently uses rpc server to collect node_information and network_information, replace the rpc server with metric server.
Related Issue
Fixes #<issue_number> (if applicable).
Type of Change
Please mark the types of changes made in this pull request.
Checklist
Please ensure all of the following tasks have been completed: