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

impl: libp2p metrics #705

Merged
merged 5 commits into from Sep 12, 2023
Merged

impl: libp2p metrics #705

merged 5 commits into from Sep 12, 2023

Conversation

RolandSherwin
Copy link
Member

@RolandSherwin RolandSherwin commented Sep 4, 2023

Depends on #706

Description

Summary generated by Reviewpad on 04 Sep 23 14:47 UTC

This pull request includes changes to multiple files. Here is an overview of the changes:

  1. SwarmDriver in sn_networking crate:
    The implementation of the SwarmDriver struct and its associated methods have been modified. Changes include:
  • Importing and using the driver::SwarmDriver trait.
  • Importing and using the libp2p_metrics::Recorder trait.
  • Removing the NodeBehaviour struct.
  • Updating the NodeEvent enum to include additional events.
  • Updating the SwarmDriver struct to include a network_metrics field of type Recorder.
  • Updating the handle_msg method to handle request/response messages using the request_response crate.
  • Updating the handle_kad_event method to handle Kademlia events.
  1. Addition of metrics_service.rs:
    A new file called metrics_service.rs has been added. This file implements a metrics service for the SAFE Network Software. It defines a MetricService struct and a MakeMetricService struct. The MetricService struct implements the Service trait from the hyper crate and provides functions for handling HTTP requests. The MakeMetricService struct is responsible for creating instances of the MetricService struct. The file also contains a metrics_server function that runs the metrics service on localhost.

  2. Changes to Cargo.toml:
    The Cargo.toml file has been modified to include new dependencies and update existing ones. Changes include:

  • Adding the dependency libp2p-metrics with version 0.13.1 and features identify and kad.
  • Adding the dependency prometheus-client with version 0.21.2.
  • Updating the dependency hyper to version 0.14 and adding features server, tcp, and http1.
  1. Changes to cmd.rs:
    The cmd.rs file has been modified to include changes related to imports and function removal. Changes include:
  • Adding the import statement use crate::driver::SwarmDriver.
  • Removing the import statement use libp2p::swarm::dial_opts::DialOpts.
  • Removing the functions dial and dial_with_opts.
  • Removing some code related to dialing with a peer ID.
  1. Other changes:
  • In a certain file, changes include removing the import of the rand::Rng module, removing the definitions of specific constants, adjusting the implementation of the Default trait for a struct, removing unused imports, and removing some comments.
  • Additionally, the file sn_networking/src/msg/mod.rs has been deleted.

Please review these changes to ensure they are correct and meet the requirements of the codebase. Let me know if you need any further clarification!

@reviewpad reviewpad bot added the Large Large sized PR label Sep 4, 2023
@RolandSherwin RolandSherwin changed the title libp2p metrics impl: libp2p metrics Sep 4, 2023
sn_networking/src/metrics_service.rs Fixed Show fixed Hide fixed

tokio::spawn(async move {
let server = Server::bind(&addr).serve(MakeMetricService::new(registry));
info!("Metrics server on http://{}/metrics", server.local_addr());

Check warning

Code scanning / devskim

An HTTP-based URL without TLS was detected. Warning

Insecure URL
const METRICS_CONTENT_TYPE: &str = "application/openmetrics-text;charset=utf-8;version=1.0.0";

pub(crate) fn metrics_server(registry: Registry) {
// Serve on localhost.

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
});
}
NodeRecordStoreConfig {
max_value_bytes: MAX_PACKET_SIZE, // TODO, does this need to be _less_ than MAX_PACKET_SIZE

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment

/// What is the largest packet to send over the network.
/// Records larger than this will be rejected.
// TODO: revisit once utxo is in

Check notice

Code scanning / devskim

A "TODO" or similar was left in source code, possibly indicating incomplete functionality Note

Suspicious comment
@reviewpad
Copy link

reviewpad bot commented Sep 4, 2023

Reviewpad Report

‼️ Errors

  • Unconventional commit detected: 'feat(network): feature gate libp2p metrics
  • this is enabled by default for a node though' (c1e7941)
  • Unconventional title detected: 'impl: libp2p metrics' illegal 'i' character in commit message type: col=00

fn respond_with_404_not_found(&mut self) -> Response<String> {
let mut resp = Response::default();
*resp.status_mut() = StatusCode::NOT_FOUND;
*resp.body_mut() = "Not found try localhost:[port]/metrics".to_string();

Check notice

Code scanning / devskim

Accessing localhost could indicate debug code, or could hinder scaling. Note

Do not leave debug code in production
sn_networking/src/metrics_server.rs Fixed Show fixed Hide fixed
sn_networking/src/metrics_server.rs Fixed Show fixed Hide fixed
@RolandSherwin RolandSherwin force-pushed the network_metrics branch 2 times, most recently from 4a3dacb to 9079f6d Compare September 5, 2023 11:31
@reviewpad reviewpad bot added Medium Medium sized PR and removed Large Large sized PR labels Sep 5, 2023
@RolandSherwin RolandSherwin force-pushed the network_metrics branch 2 times, most recently from d80cf29 to 9207811 Compare September 6, 2023 10:17
@joshuef
Copy link
Contributor

joshuef commented Sep 8, 2023

How do we access these metrics? Do we need tostart a custom server for this? does each node run a server to access metrics?

Copy link
Contributor

@joshuef joshuef left a comment

Choose a reason for hiding this comment

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

I think metrics here confuses with out logging metrics output. I'd say we want a clearer name for this feature.

libp2p-metrics, network-metrics ? something-else ?

@joshuef
Copy link
Contributor

joshuef commented Sep 9, 2023

I'm also torn on this being on by default atm...

@RolandSherwin
Copy link
Member Author

How do we access these metrics? Do we need tostart a custom server for this? does each node run a server to access metrics?

Yes, each node runs a separate hyper server on a random port. This returns the OpenMetrics response type that can be fed into grafana / other tools.

Also, I will push a change to update the feature name and remove it from the default features list.

@joshuef joshuef added this pull request to the merge queue Sep 12, 2023
Merged via the queue into maidsafe:main with commit dc58921 Sep 12, 2023
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Medium Medium sized PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants