diff options
Diffstat (limited to 'src/api')
| -rw-r--r-- | src/api/mod.rs | 1 | ||||
| -rw-r--r-- | src/api/peers.rs | 4 | ||||
| -rw-r--r-- | src/api/stats.rs | 11 |
3 files changed, 14 insertions, 2 deletions
diff --git a/src/api/mod.rs b/src/api/mod.rs index d7f14b3..95d63aa 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -158,6 +158,7 @@ fn response_for_value( crate::transport::traffic::PeerTraffic, crate::transport::traffic::ByKind, crate::transport::traffic::Counter, + crate::state::Incidents, ) ), tags( diff --git a/src/api/peers.rs b/src/api/peers.rs index 9ed11c5..5b7d576 100644 --- a/src/api/peers.rs +++ b/src/api/peers.rs @@ -16,7 +16,7 @@ use utoipa::ToSchema; use super::store_status; use crate::document::replica::Epoch; use crate::document::store; -use crate::state::{AppState, HelloState, Liveness, PeerState, unix_millis}; +use crate::state::{AppState, HelloState, Incidents, Liveness, PeerState, unix_millis}; use crate::swarm::peer::forgotten_path; use crate::transport::traffic::PeerTraffic; @@ -69,6 +69,7 @@ pub(crate) struct PeerStatus { /// Messages and payload bytes exchanged with it, by kind, since we started (or /// since it was last listed). traffic: PeerTraffic, + incidents: Incidents, } #[derive(Debug, Serialize, ToSchema)] @@ -147,6 +148,7 @@ pub(crate) async fn list_peers( neighbour, rtt_ms, traffic, + incidents: ps.incidents, }); } diff --git a/src/api/stats.rs b/src/api/stats.rs index f4a368b..e426c7a 100644 --- a/src/api/stats.rs +++ b/src/api/stats.rs @@ -4,7 +4,7 @@ use axum::{Json, extract::State}; use serde::Serialize; use super::peers::EpochInfo; -use crate::state::AppState; +use crate::state::{AppState, Incidents}; use crate::swarm::{members, stability, topology}; use crate::transport::traffic::PeerTraffic; @@ -22,6 +22,8 @@ pub(crate) struct StatsResponse { stale_hello_replies: u64, /// All peers together, including ones no longer listed in /peers. traffic: PeerTraffic, + /// The peers listed in /peers together (a forgotten peer's are gone). + incidents: Incidents, } #[derive(Debug, Serialize)] @@ -96,6 +98,12 @@ pub(crate) async fn get_stats(State(state): State<AppState>) -> Json<StatsRespon let (connected_fraction, observed) = stability::measured(&state); + let mut incidents = Incidents::default(); + let peers: Vec<_> = state.peer_states.read().await.values().cloned().collect(); + for peer_state in peers { + incidents.add(&peer_state.lock().await.incidents); + } + Json(StatsResponse { uptime_secs: node.uptime.as_secs(), ready: state.is_ready().await, @@ -130,5 +138,6 @@ pub(crate) async fn get_stats(State(state): State<AppState>) -> Json<StatsRespon }, stale_hello_replies: node.stale_hello_replies, traffic: state.traffic.total(), + incidents, }) } |
