chore(metrics): move example to examples/

Related: #3111.

Pull-Request: #3661.
This commit is contained in:
Thomas Eizinger 2023-04-11 22:47:43 +02:00 committed by GitHub
parent 7261856e7a
commit f7c3db9d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 36 additions and 37 deletions

21
Cargo.lock generated
View File

@ -2580,24 +2580,16 @@ dependencies = [
name = "libp2p-metrics"
version = "0.12.0"
dependencies = [
"env_logger 0.10.0",
"futures",
"hyper",
"libp2p-core",
"libp2p-dcutr",
"libp2p-gossipsub",
"libp2p-identify",
"libp2p-identity",
"libp2p-kad",
"libp2p-noise",
"libp2p-ping",
"libp2p-relay",
"libp2p-swarm",
"libp2p-tcp",
"libp2p-yamux",
"log",
"prometheus-client",
"tokio",
]
[[package]]
@ -3194,6 +3186,19 @@ dependencies = [
"autocfg",
]
[[package]]
name = "metrics-example"
version = "0.1.0"
dependencies = [
"env_logger 0.10.0",
"futures",
"hyper",
"libp2p",
"log",
"prometheus-client",
"tokio",
]
[[package]]
name = "minimal-lexical"
version = "0.2.1"

View File

@ -9,6 +9,7 @@ members = [
"examples/identify",
"examples/ipfs-kad",
"examples/ipfs-private",
"examples/metrics",
"examples/ping-example",
"examples/relay-server",
"examples/rendezvous",

View File

@ -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"

View File

@ -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
@ -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;
@ -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,

View File

@ -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"]