diff --git a/backend/src/models/api.rs b/backend/src/models/api.rs index 3a75f3b8..57a28abe 100644 --- a/backend/src/models/api.rs +++ b/backend/src/models/api.rs @@ -313,6 +313,38 @@ pub type NodeCount = TypedMap; // #[cfg(not(all(feature = "swagger", debug_assertions)))] pub type DiskCount = TypedMap; +impl RPS { + #[must_use] + pub fn from_metrics(metrics: &TypedMetrics) -> Self { + let mut rps = Self::new(); + rps[Operation::Get] += metrics[RawMetricEntry::ClusterGrinderGetCountRate].value; + rps[Operation::Delete] += metrics[RawMetricEntry::ClusterGrinderDeleteCountRate].value; + rps[Operation::Exist] += metrics[RawMetricEntry::ClusterGrinderExistCountRate].value; + rps[Operation::Put] += metrics[RawMetricEntry::ClusterGrinderPutCountRate].value; + + rps + } +} + +impl AddAssign for RPS { + fn add_assign(&mut self, rhs: Self) { + self[Operation::Get] += rhs[Operation::Get]; + self[Operation::Delete] += rhs[Operation::Delete]; + self[Operation::Exist] += rhs[Operation::Exist]; + self[Operation::Put] += rhs[Operation::Put]; + } +} + +impl Add for RPS { + type Output = Self; + + fn add(mut self, rhs: Self) -> Self::Output { + self += rhs; + + self + } +} + #[derive(Debug, Serialize, Clone)] // #[cfg_attr(all(feature = "swagger", debug_assertions), derive(ToSchema))] // #[cfg_attr(all(feature = "swagger", debug_assertions), diff --git a/backend/src/models/mod.rs b/backend/src/models/mod.rs index c24f8acb..0fd0a0dc 100644 --- a/backend/src/models/mod.rs +++ b/backend/src/models/mod.rs @@ -5,7 +5,11 @@ pub mod shared; pub mod prelude { pub use crate::prelude::*; pub use hyper::Uri; - pub use std::{net::SocketAddr, time::Duration}; + pub use std::{ + net::SocketAddr, + ops::{Add, AddAssign}, + time::Duration, + }; pub use strum::{EnumIter, IntoEnumIterator}; #[cfg(all(feature = "swagger", debug_assertions))] pub use utoipa::openapi::{Object, ObjectBuilder}; diff --git a/backend/src/services/api.rs b/backend/src/services/api.rs index e4d82d1d..ebe7c5a8 100644 --- a/backend/src/services/api.rs +++ b/backend/src/services/api.rs @@ -1,7 +1,6 @@ use super::prelude::*; /// Returns count of Physical Disks per status -/// #[cfg_attr(all(feature = "swagger", debug_assertions), utoipa::path( get, @@ -31,31 +30,16 @@ pub async fn get_disks_count(Extension(client): Extension) -> Jso let mut count = DiskCount::new(); while let Some(res) = space.next().await { - let mut disks_visited = HashSet::new(); - let (disks, space) = match res { - Ok(d) => d, - Err(err) => { - tracing::warn!("couldn't finish request: tokio task failed. Err: {err}"); - continue; - } + let Ok((disks, space)) = res else { + tracing::warn!("couldn't finish request: tokio task failed. Err: {res:?}"); + continue; }; - let space = match space { - Ok(GetSpaceInfoResponse::SpaceInfo(space)) => space, - Err(err) => { - tracing::warn!("couldn't finish getSpace request. Err: {err}"); - continue; - } + let Ok(GetSpaceInfoResponse::SpaceInfo(space)) = space else { + tracing::warn!("couldn't finish getSpace request. {space:?}"); + continue; }; let disks = match disks { - Ok(GetDisksResponse::AJSONArrayWithDisksAndTheirStates(disks)) => { - let mut res = vec![]; - for disk in disks { - if disks_visited.insert(disk.name.clone()) { - res.push(disk); - } - } - res - } + Ok(GetDisksResponse::AJSONArrayWithDisksAndTheirStates(disks)) => disks, Ok(GetDisksResponse::PermissionDenied(err)) => { count[DiskStatusName::Offline] += 1; tracing::warn!("Permission Denied. Err: {err:?}"); @@ -67,14 +51,16 @@ pub async fn get_disks_count(Extension(client): Extension) -> Jso continue; } }; - let active_disks = disks.iter().filter(|disk| disk.is_active); - for disk in active_disks { + let mut active = 0; + disks.iter().filter(|disk| disk.is_active).for_each(|disk| { + active += 1; match DiskStatus::from_space_info(&space, &disk.name) { DiskStatus::Good => count[DiskStatusName::Good] += 1, DiskStatus::Offline => count[DiskStatusName::Offline] += 1, DiskStatus::Bad(_) => count[DiskStatusName::Bad] += 1, } - } + }); + count[DiskStatusName::Offline] = (disks.len() - active) as u64; } tracing::info!("total disks count: {count:?}"); @@ -82,7 +68,6 @@ pub async fn get_disks_count(Extension(client): Extension) -> Jso } /// Get Nodes count per Status -/// #[cfg_attr(all(feature = "swagger", debug_assertions), utoipa::path( get, @@ -111,20 +96,18 @@ pub async fn get_nodes_count(Extension(client): Extension) -> Jso let mut count = NodeCount::new(); - let mut counter = 0; while let Some(res) = metrics.next().await { if let Ok(Ok(GetMetricsResponse::Metrics(metrics))) = res { - tracing::trace!("#{counter}: metrics received successfully"); + tracing::trace!("metrics received successfully"); if Into::::into(metrics).is_bad_node() { count[NodeStatusName::Bad] += 1; } else { count[NodeStatusName::Good] += 1; } } else { - tracing::warn!("#{counter}: couldn't receive metrics from node"); + tracing::warn!("couldn't receive metrics from node"); // TODO: Some better message count[NodeStatusName::Offline] += 1; } - counter += 1; } tracing::info!("total nodes per status count: {count:?}"); @@ -132,7 +115,6 @@ pub async fn get_nodes_count(Extension(client): Extension) -> Jso } /// Returns Total RPS on cluster -/// #[cfg_attr(all(feature = "swagger", debug_assertions), utoipa::path( get, @@ -160,20 +142,14 @@ pub async fn get_rps(Extension(client): Extension) -> Json { .collect(); let mut rps = RPS::new(); - let mut counter = 0; while let Some(res) = metrics.next().await { if let Ok(Ok(metrics)) = res { - tracing::info!("#{counter}: metrics received successfully"); + tracing::info!("metrics received successfully"); let GetMetricsResponse::Metrics(metrics) = metrics; - let metrics = Into::::into(metrics); - rps[Operation::Get] += metrics[RawMetricEntry::ClusterGrinderGetCountRate].value; - rps[Operation::Delete] += metrics[RawMetricEntry::ClusterGrinderDeleteCountRate].value; - rps[Operation::Exist] += metrics[RawMetricEntry::ClusterGrinderExistCountRate].value; - rps[Operation::Put] += metrics[RawMetricEntry::ClusterGrinderPutCountRate].value; + rps += RPS::from_metrics(&metrics.into()); } else { - tracing::warn!("#{counter}: couldn't receive metrics from node"); + tracing::warn!("couldn't receive metrics from node"); // TODO: Some better message } - counter += 1; } tracing::info!("total rps: {rps:?}"); @@ -181,7 +157,6 @@ pub async fn get_rps(Extension(client): Extension) -> Json { } /// Return inforamtion about space on cluster -/// #[cfg_attr(all(feature = "swagger", debug_assertions), utoipa::path( get, @@ -204,20 +179,17 @@ pub async fn get_space(Extension(client): Extension) -> Json>::{closure#0} + 5: 0x7f5d7ed8e448 - as core::ops::function::Fn>::call::h8cf755461602ae5f + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/alloc/src/boxed.rs:2021:9 + 6: 0x7f5d7ed8e448 - std::panicking::rust_panic_with_hook::hd6d6d27f780820d4 + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/std/src/panicking.rs:783:13 + 7: 0x7f5d7ed8e19e - std::panicking::begin_panic_handler::{{closure}}::hd4060d64e210cb3a + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/std/src/panicking.rs:657:13 + 8: 0x7f5d7ed8b756 - std::sys_common::backtrace::__rust_end_short_backtrace::ha66ce0a9f9c9dad7 + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/std/src/sys_common/backtrace.rs:171:18 + 9: 0x7f5d7ed8df02 - rust_begin_unwind + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/std/src/panicking.rs:645:5 + 10: 0x7f5d7edda995 - core::panicking::panic_fmt::hd947f6a92fdda8ae + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/core/src/panicking.rs:72:14 + 11: 0x7f5d83449877 - rustc_query_system[af220a1bd8af13ec]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[b37841d848f64cdf]::plumbing::QueryCtxt, true> + 12: 0x7f5d83c5bcf9 - rustc_query_impl[b37841d848f64cdf]::plumbing::force_from_dep_node::>, false, false, false>> + 13: 0x7f5d83c5bbad - ::{closure#0} as core[b2733e91e945b882]::ops::function::FnOnce<(rustc_middle[587c9a249fda5b49]::ty::context::TyCtxt, rustc_query_system[af220a1bd8af13ec]::dep_graph::dep_node::DepNode)>>::call_once + 14: 0x7f5d82e3e1ad - >::try_mark_previous_green:: + 15: 0x7f5d82e3e128 - >::try_mark_previous_green:: + 16: 0x7f5d82e3e128 - >::try_mark_previous_green:: + 17: 0x7f5d82e3e128 - >::try_mark_previous_green:: + 18: 0x7f5d82e3e128 - >::try_mark_previous_green:: + 19: 0x7f5d82e3e128 - >::try_mark_previous_green:: + 20: 0x7f5d82e3d440 - rustc_query_system[af220a1bd8af13ec]::query::plumbing::ensure_must_run::>, false, false, false>, rustc_query_impl[b37841d848f64cdf]::plumbing::QueryCtxt> + 21: 0x7f5d8399995a - rustc_query_impl[b37841d848f64cdf]::query_impl::mir_borrowck::get_query_incr::__rust_end_short_backtrace + 22: 0x7f5d81e2aae9 - ::par_body_owners::::{closure#0} + 23: 0x7f5d81e2246d - rayon[a2aa17054b6ea8d6]::iter::plumbing::bridge_producer_consumer::helper::, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>> + 24: 0x7f5d81e2bb7f - rayon_core[922b9bd49971f9fc]::join::join_context::, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>>::{closure#0}, rayon[a2aa17054b6ea8d6]::iter::plumbing::bridge_producer_consumer::helper, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}, (), ()>::{closure#0} + 25: 0x7f5d81e2260c - rayon[a2aa17054b6ea8d6]::iter::plumbing::bridge_producer_consumer::helper::, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>> + 26: 0x7f5d81e2bb7f - rayon_core[922b9bd49971f9fc]::join::join_context::, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>>::{closure#0}, rayon[a2aa17054b6ea8d6]::iter::plumbing::bridge_producer_consumer::helper, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}, (), ()>::{closure#0} + 27: 0x7f5d81e2260c - rayon[a2aa17054b6ea8d6]::iter::plumbing::bridge_producer_consumer::helper::, rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>> + 28: 0x7f5d81e3f252 - , rayon[a2aa17054b6ea8d6]::iter::for_each::ForEachConsumer::par_body_owners::{closure#0}>::{closure#0}::{closure#0}>>::{closure#1}>::{closure#0}, ()> as rayon_core[922b9bd49971f9fc]::job::Job>::execute + 29: 0x7f5d816e59a5 - ::wait_until_cold + 30: 0x7f5d816e2873 - ::run + 31: 0x7f5d81af15a7 - <::spawn<::build_scoped, rustc_driver_impl[dfc14170d5281fe1]::run_compiler::{closure#0}>::{closure#0}, core[b2733e91e945b882]::result::Result<(), rustc_span[40779671df086173]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#0}, rustc_interface[2476be00daa2eb92]::util::run_in_thread_pool_with_globals, rustc_driver_impl[dfc14170d5281fe1]::run_compiler::{closure#0}>::{closure#0}, core[b2733e91e945b882]::result::Result<(), rustc_span[40779671df086173]::ErrorGuaranteed>>::{closure#3}::{closure#0}::{closure#1}, core[b2733e91e945b882]::result::Result<(), rustc_span[40779671df086173]::ErrorGuaranteed>>::{closure#0}::{closure#0}::{closure#0}, ()>::{closure#0} as core[b2733e91e945b882]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 32: 0x7f5d81ae74de - std[b5ddf2b2f6b911a9]::sys_common::backtrace::__rust_begin_short_backtrace:: + core[b2733e91e945b882]::marker::Send>, ()> + 33: 0x7f5d81af1233 - <::spawn_unchecked_ + core[b2733e91e945b882]::marker::Send>, ()>::{closure#1} as core[b2733e91e945b882]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 34: 0x7f5d7ed982d5 - as core::ops::function::FnOnce>::call_once::h5b2143c8cf15af4e + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/alloc/src/boxed.rs:2007:9 + 35: 0x7f5d7ed982d5 - as core::ops::function::FnOnce>::call_once::hdf15d86cee824b1d + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/alloc/src/boxed.rs:2007:9 + 36: 0x7f5d7ed982d5 - std::sys::unix::thread::Thread::new::thread_start::hd84c427d4e56e20f + at /rustc/87e1447aadaa2899ff6ccabe1fa669eb50fb60a1/library/std/src/sys/unix/thread.rs:108:17 + 37: 0x7f5d7ea519eb - + 38: 0x7f5d7ead57cc - + 39: 0x0 - + + +rustc version: 1.76.0-nightly (87e1447aa 2023-11-30) +platform: x86_64-unknown-linux-gnu + +query stack during panic: +#0 [thir_body] building THIR for `main::{closure#0}::{closure#0}` +#1 [analysis] running analysis passes on this crate +end of query stack