Skip to content

remove unrelated keys from link stats #1945

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions io/zenoh-transport/src/common/stats.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,3 +378,8 @@ stats_struct! {
pub tx_low_pass_dropped_msgs,
}
}

pub fn is_link_stats(key: &str) -> bool {
let starts_with = |k: &str, prefixes: &[&str]| prefixes.iter().any(|p| k.starts_with(p));
starts_with(key, &["rx_", "tx_"]) && starts_with(&key[3..], &["bytes, t_, n_"])
}
32 changes: 20 additions & 12 deletions zenoh/src/net/runtime/adminspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ use zenoh_protocol::{
use zenoh_result::ZResult;
#[cfg(feature = "stats")]
use zenoh_transport::stats::TransportStats;
use zenoh_transport::unicast::TransportUnicast;
use zenoh_transport::{stats::is_link_stats, unicast::TransportUnicast};

use super::{routing::dispatcher::face::Face, Runtime};
#[cfg(all(feature = "plugins", feature = "runtime_plugins"))]
Expand Down Expand Up @@ -574,14 +574,22 @@ fn local_data(context: &AdminContext, query: Query) {
.iter()
.any(|(k, v)| k == "_stats" && v != "false");
#[cfg(feature = "stats")]
let insert_stats = |mut json: serde_json::Value, stats: Option<&Arc<TransportStats>>| {
if export_stats {
json.as_object_mut()
.unwrap()
.insert("stats".into(), json!(stats.map(|s| s.report())));
}
json
};
let insert_stats =
|mut json: serde_json::Value, stats: Option<&Arc<TransportStats>>, is_link: bool| {
if export_stats {
let mut stats_json = stats.map_or_else(|| json!({}), |s| json!(s.report()));
if is_link {
stats_json
.as_object_mut()
.unwrap()
.retain(|key, _| is_link_stats(key));
}
json.as_object_mut()
.unwrap()
.insert("stats".into(), stats_json);
}
json
};

// plugins info
#[cfg(feature = "plugins")]
Expand Down Expand Up @@ -623,7 +631,7 @@ fn local_data(context: &AdminContext, query: Query) {
.get_link_stats()
.unwrap_or_default()
.iter()
.map(|(link, stats)| insert_stats(link_to_json(link), Some(stats)))
.map(|(link, stats)| insert_stats(link_to_json(link), Some(stats), true))
.collect_vec();
let json = json!({
"peer": transport.get_zid().map_or_else(|_| "unknown".to_string(), |p| p.to_string()),
Expand All @@ -632,7 +640,7 @@ fn local_data(context: &AdminContext, query: Query) {
"weight": transport.get_zid().ok().and_then(|zid| links_info.get(&zid))
});
#[cfg(feature = "stats")]
let json = insert_stats(json, transport.get_stats().ok().as_ref());
let json = insert_stats(json, transport.get_stats().ok().as_ref(), false);
json
};
let transports: Vec<serde_json::Value> = zenoh_runtime::ZRuntime::Net
Expand All @@ -650,7 +658,7 @@ fn local_data(context: &AdminContext, query: Query) {
"plugins": plugins,
});
#[cfg(feature = "stats")]
let json = insert_stats(json, Some(&transport_mgr.get_stats()));
let json = insert_stats(json, Some(&transport_mgr.get_stats()), false);

tracing::trace!("AdminSpace router_data: {:?}", json);
let payload = match serde_json::to_vec(&json) {
Expand Down
Loading