Skip to content

Commit

Permalink
chore(metrics): move example to examples/
Browse files Browse the repository at this point in the history
Related: #3111.

Pull-Request: #3661.
  • Loading branch information
thomaseizinger authored Apr 11, 2023
1 parent 7261856 commit f7c3db9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 37 deletions.
21 changes: 13 additions & 8 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"examples/identify",
"examples/ipfs-kad",
"examples/ipfs-private",
"examples/metrics",
"examples/ping-example",
"examples/relay-server",
"examples/rendezvous",
Expand Down
15 changes: 15 additions & 0 deletions examples/metrics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "metrics-example"
version = "0.1.0"
edition = "2021"
publish = false
license = "MIT"

[dependencies]
env_logger = "0.10.0"
futures = "0.3.27"
hyper = { version = "0.14", features = ["server", "tcp", "http1"] }
libp2p = { path = "../../libp2p", features = ["async-std", "metrics", "ping", "noise", "identify", "tcp", "yamux", "macros"] }
log = "0.4.0"
tokio = { version = "1", features = ["rt-multi-thread"] }
prometheus-client = "0.19.0"
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
//! In one terminal run:
//!
//! ```
//! cargo run --example metrics
//! cargo run
//! ```
//!
//! In a second terminal run:
//!
//! ```
//! cargo run --example metrics -- <listen-addr-of-first-node>
//! cargo run -- <listen-addr-of-first-node>
//! ```
//!
//! Where `<listen-addr-of-first-node>` is replaced by the listen address of the
Expand All @@ -51,16 +51,11 @@
use env_logger::Env;
use futures::executor::block_on;
use futures::stream::StreamExt;
use libp2p_core::{upgrade::Version, Multiaddr, Transport};
use libp2p_identify as identify;
use libp2p_identity as identity;
use libp2p_identity::PeerId;
use libp2p_metrics::{Metrics, Recorder};
use libp2p_noise as noise;
use libp2p_ping as ping;
use libp2p_swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p_tcp as tcp;
use libp2p_yamux as yamux;
use libp2p::core::{upgrade::Version, Multiaddr, Transport};
use libp2p::identity::PeerId;
use libp2p::metrics::{Metrics, Recorder};
use libp2p::swarm::{keep_alive, NetworkBehaviour, SwarmBuilder, SwarmEvent};
use libp2p::{identify, identity, noise, ping, tcp, yamux};
use log::info;
use prometheus_client::registry::Registry;
use std::error::Error;
Expand Down Expand Up @@ -125,7 +120,6 @@ fn main() -> Result<(), Box<dyn Error>> {
/// For illustrative purposes, this includes the [`keep_alive::Behaviour`]) behaviour so the ping actually happen
/// and can be observed via the metrics.
#[derive(NetworkBehaviour)]
#[behaviour(prelude = "libp2p_swarm::derive_prelude")]
struct Behaviour {
identify: identify::Behaviour,
keep_alive: keep_alive::Behaviour,
Expand Down
16 changes: 0 additions & 16 deletions misc/metrics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,9 @@ prometheus-client = "0.19.0"
[target.'cfg(not(target_os = "unknown"))'.dependencies]
libp2p-gossipsub = { version = "0.44.0", path = "../../protocols/gossipsub", optional = true }

[dev-dependencies]
env_logger = "0.10.0"
futures = "0.3.28"
hyper = { version="0.14", features = ["server", "tcp", "http1"] }
libp2p-noise = { path = "../../transports/noise" }
libp2p-ping = { path = "../../protocols/ping" }
libp2p-swarm = { path = "../../swarm", features = ["macros"] }
libp2p-tcp = { path = "../../transports/tcp", features = ["async-io"] }
libp2p-yamux = { path = "../../muxers/yamux" }
log = "0.4.0"
tokio = { version = "1", features = ["rt-multi-thread"] }

# Passing arguments to the docsrs builder in order to properly document cfg's.
# More information: https://docs.rs/about/builds#cross-compiling
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]
rustc-args = ["--cfg", "docsrs"]

[[example]]
name = "metrics"
required-features = ["ping", "identify"]

0 comments on commit f7c3db9

Please sign in to comment.