Skip to content

Commit ae0f152

Browse files
mskrzypkowsgithub-actions[bot]varex83emlautarom1
authored
feat: relay server missing features (#354)
* feat(relay-server): finish relay server implementation - Start Prometheus monitoring server on configured monitoring_addr - Handle relay swarm events: ReservationReqAccepted/Denied, ReservationTimedOut, CircuitReqAccepted/Denied, CircuitClosed — with structured logging - Track connection metrics (connection_total, active_connections) via RELAY_METRICS on SwarmEvent::ConnectionEstablished and ConnectionClosed - Log version, git hash, and build time on startup using pluto_core::version - Make RelayMetrics fields public; add PeerWithPeerClusterLabels::new() constructor - Remove #[allow(missing_docs)] from p2p.rs; add module doc comment - Add vise-exporter to regular (non-dev) dependencies - Update serve_addr_metrics test: remove #[ignore], test monitoring endpoint, check for prometheus output Closes #129 Co-authored-by: Bohdan Ohorodnii <varex83@users.noreply.github.com> * fix(relay-server): fix compilation and formatting errors in p2p.rs - Dereference LazyLock for VERSION in tracing macro: %*VERSION - Use inc_by(1)/dec_by(1) instead of inc()/dec() on vise::Gauge - Add .. to ReservationReqDenied and CircuitReqDenied patterns for missing status field - Merge pluto_p2p imports and reorder metrics imports alphabetically - Reformat ListenerClosed, ReservationReqAccepted, ReservationReqDenied match arms per rustfmt Co-authored-by: Bohdan Ohorodnii <varex83@users.noreply.github.com> * chore: merge main (feat: add bootnode.rs #262) Manually merges changes from main branch commit e41e6d9: - Add crates/p2p/src/bootnode.rs and crates/p2p/src/relay.rs - Add crates/p2p/examples/bootnode.rs - Update p2p peer.rs: add Default for MutablePeer, addr_infos_from_p2p_addrs - Update p2p gater.rs: remove Arc wrapper from relay peers - Update p2p utils.rs: add multi_addrs_via_relay helper - Update p2p lib.rs: export bootnode and relay modules - Update p2p Cargo.toml: add backon, reqwest, url deps - Fix crypto share indexing: use 1-indexed keys throughout - Remove MathError enum, replace with direct DivisionByZero variant - Fix cluster test_cluster.rs: use 1-indexed share lookup - Fix app obolapi: add FailedToConvertShareIndexToU8/MathOverflow errors - Add app/src/utils.rs with archive helpers - Add core/src/parasigdb/memory.rs - Update Cargo.toml and Cargo.lock with flate2, tar deps - Update relay_server example: simplify TCP addr, add docblock Co-authored-by: Bohdan Ohorodnii <varex83@users.noreply.github.com> * chore: merge main (feat(core): implement signeddata #273) Manual merge of 4e68ef9 into this branch (shallow clone prevents git merge). - Add crates/core/src/signeddata.rs and signeddata testdata - Add pub mod signeddata to crates/core/src/lib.rs - Update crates/core/Cargo.toml with signeddata deps - Update crates/crypto/Cargo.toml: remove pluto-core dep (avoids cycle) - Update crates/crypto/src/tblsconv.rs: remove core conversions (avoids cycle) - Add/update crates/eth2api/ spec types for signeddata - Add/update crates/eth2util/src/types.rs - Update Cargo.lock Co-authored-by: Lautaro Emanuel <emlautarom1@users.noreply.github.com> * fixed compilation and clippy * review * retry_get helper for unit tests * better assertions in the serve_addr_metrics test * removed unsed ssz_types.rs * move back multi_addrs_via_relay * Bandwidth metric for the p2p relay server * Unit tests for bandwidth metric * Comments added * fixed clippy * moved metrics into RelayMetrics * review comments --------- Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com> Co-authored-by: Bohdan Ohorodnii <varex83@users.noreply.github.com> Co-authored-by: Lautaro Emanuel <emlautarom1@users.noreply.github.com>
1 parent de45a05 commit ae0f152

15 files changed

Lines changed: 763 additions & 95 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ aes = "0.8.4"
6666
ctr = "0.9.2"
6767
cipher = "0.4.4"
6868
pbkdf2 = "0.12.2"
69+
pin-project = "1"
6970
sha2 = "0.10.9"
7071
scrypt = "0.11.0"
7172
unicode-normalization = "0.1.25"

crates/cli/src/commands/relay.rs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -415,17 +415,29 @@ mod tests {
415415
}
416416

417417
#[tokio::test]
418-
#[ignore = "/metrics endpoint not implemented"]
419418
async fn serve_addr_metrics() {
419+
let monitoring_addr = net::TcpListener::bind("127.0.0.1:0")
420+
.await
421+
.unwrap()
422+
.local_addr()
423+
.unwrap()
424+
.to_string();
425+
let monitoring_url = format!("http://{monitoring_addr}/metrics");
426+
420427
with_relay_server(
421-
|_| {},
422-
async |cfg| {
423-
let response = relay_server_get(cfg, "/metrics").await.unwrap();
428+
move |args| {
429+
args.debug_monitoring.monitor_addr = Some(monitoring_addr);
430+
},
431+
async move |_cfg| {
432+
let response = retry_get(&monitoring_url).await.unwrap();
424433
let body = response.text().await.unwrap();
425434

426-
dbg!(&body);
427-
428-
assert!(body.contains("libp2p_relaysvc_"));
435+
assert!(body.contains("relay_p2p_connection_total"));
436+
assert!(body.contains("relay_p2p_active_connections"));
437+
assert!(body.contains("relay_p2p_ping_latency"));
438+
assert!(body.contains("relay_p2p_network_sent_bytes"));
439+
assert!(body.contains("relay_p2p_network_receive_bytes"));
440+
assert!(body.ends_with("# EOF\n"));
429441
},
430442
)
431443
.await
@@ -523,12 +535,11 @@ mod tests {
523535
path: &str,
524536
) -> Result<reqwest::Response, reqwest::Error> {
525537
let http_address = cfg.http_addr.unwrap();
526-
let request = async || {
527-
reqwest::get(format!("http://{}{}", http_address, path))
528-
.await
529-
.and_then(|r| r.error_for_status())
530-
};
538+
retry_get(&format!("http://{}{}", http_address, path)).await
539+
}
531540

541+
async fn retry_get(url: &str) -> Result<reqwest::Response, reqwest::Error> {
542+
let request = async || reqwest::get(url).await.and_then(|r| r.error_for_status());
532543
let mut backoff = backon::ExponentialBuilder::default()
533544
.with_min_delay(time::Duration::from_millis(200))
534545
.with_max_delay(time::Duration::from_secs(2))

crates/dkg/src/bcast/behaviour.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,6 +701,7 @@ mod tests {
701701
NodeType::TCP,
702702
false,
703703
p2p_context.clone(),
704+
None,
704705
move |builder, _keypair| builder.with_inner(behaviour),
705706
)?;
706707
let addr: Multiaddr = format!("/ip4/127.0.0.1/tcp/{}", ports[index]).parse()?;

crates/dkg/src/exchanger.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ mod tests {
434434
NodeType::TCP,
435435
false,
436436
p2p_context,
437+
None,
437438
move |builder, _key| builder.with_inner(behaviour),
438439
)?;
439440

crates/dkg/src/nodesigs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ mod tests {
570570
NodeType::TCP,
571571
false,
572572
p2p_context,
573+
None,
573574
move |builder, _| builder.with_inner(behaviour),
574575
)?;
575576

crates/p2p/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ serde.workspace = true
2828
serde_json.workspace = true
2929
pluto-core.workspace = true
3030
backon.workspace = true
31+
pin-project.workspace = true
3132
reqwest.workspace = true
3233
unsigned-varint.workspace = true
3334
url.workspace = true

0 commit comments

Comments
 (0)