queue_tracker: use info_once on new fields

Modern linuxes add fields all the time. On a kernel upgrade we
shouldn't crash just because there's a new json field.

Also there are some further optimizations to represent the kernel
structures themselves. Some fields can overflow which would lead
to some surprizing behaviors in polling the json over time.

FIXME - always check for overflow elsewhere, in packets, overlimits
etc. Could that be a trait?
This commit is contained in:
Dave Taht
2023-01-20 18:37:23 +00:00
parent 1742232eaf
commit 3c6f438e06
6 changed files with 42 additions and 27 deletions

10
src/rust/Cargo.lock generated
View File

@@ -1256,6 +1256,15 @@ dependencies = [
"cfg-if 1.0.0",
]
[[package]]
name = "log-once"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1ae8737764ac12e9cfc5ab42a9ec2bdb7e2b376ce9694a4dffc92b7adee09cb5"
dependencies = [
"log",
]
[[package]]
name = "loom"
version = "0.5.6"
@@ -1335,6 +1344,7 @@ dependencies = [
"criterion",
"lazy_static",
"log",
"log-once",
"lqos_bus",
"lqos_config",
"lqos_sys",

View File

@@ -12,6 +12,7 @@ lqos_config = { path = "../lqos_config" }
lqos_sys = { path = "../lqos_sys" }
lqos_utils = { path = "../lqos_utils" }
log = "0"
log-once = "0.4.0"
lazy_static = "1.4"
parking_lot = "0"
notify = { version = "5.0.0", default-features = false, feature=["macos_kqueue"] } # Not using crossbeam because of Tokio

View File

@@ -3,6 +3,7 @@ use lqos_bus::TcHandle;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use lqos_utils::{string_table_enum, dashy_table_enum};
use log_once::info_once;
string_table_enum!(DiffServ, besteffort, diffserv3, diffserv4, diffserv8, precedence);
dashy_table_enum!(AckFilter, none, ack_filter, ack_filter_aggressive);
@@ -133,7 +134,7 @@ impl TcCakeOptions {
"overhead" => result.overhead = value.as_u64().unwrap() as u16,
"fwmark" => result.fwmark = value.as_str().unwrap().to_string(),
_ => {
log::error!("Unknown entry in Tc-cake-options: {key}");
info_once!("Unknown entry in tc-cake-options json decoder: {key}");
}
}
}
@@ -176,7 +177,7 @@ impl TcCakeTin {
"max_pkt_len" => result.max_pkt_len = value.as_u64().unwrap() as u16,
"flow_quantum" => result.flow_quantum = value.as_u64().unwrap() as u16,
_ => {
log::error!("Unknown entry in Tc-cake-tin: {key}");
info_once!("Unknown entry in tc-cake-tin json decoder: {key}");
}
}
}

View File

@@ -9,6 +9,7 @@ use anyhow::{Error, Result};
use lqos_bus::TcHandle;
use serde::Serialize;
use serde_json::Value;
use log_once::info_once;
#[derive(Default, Clone, Debug, Serialize)]
pub struct TcFqCodel {
@@ -65,7 +66,7 @@ impl TcFqCodel {
"options" => result.options = TcFqCodelOptions::from_json(value)?,
"kind" => {}
_ => {
log::error!("Unknown entry in Tc-codel: {key}");
info_once!("Unknown entry in tc-codel json decoder: {key}");
}
}
}
@@ -89,7 +90,7 @@ impl TcFqCodelOptions {
"ecn" => result.ecn = value.as_bool().unwrap(),
"drop_batch" => result.drop_batch = value.as_u64().unwrap() as u16,
_ => {
log::error!("Unknown entry in Tc-codel-options: {key}");
info_once!("Unknown entry in tc-codel-options json decoder: {key}");
}
}
}

View File

@@ -7,16 +7,17 @@ use anyhow::{Error, Result};
use lqos_bus::TcHandle;
use serde::Serialize;
use serde_json::Value;
use log_once::info_once;
#[derive(Default, Clone, Debug, Serialize)]
pub struct TcHtb {
handle: TcHandle,
parent: TcHandle,
bytes: u64,
packets: u64,
drops: u64,
overlimits: u64,
requeues: u64,
packets: u32,
drops: u32,
overlimits: u32,
requeues: u32,
backlog: u32,
qlen: u32,
options: TcHtbOptions,
@@ -38,16 +39,16 @@ impl TcHtb {
"handle" => result.handle = TcHandle::from_string(value.as_str().unwrap())?,
"parent" => result.parent = TcHandle::from_string(value.as_str().unwrap())?,
"bytes" => result.bytes = value.as_u64().unwrap(),
"packets" => result.packets = value.as_u64().unwrap(),
"drops" => result.drops = value.as_u64().unwrap(),
"overlimits" => result.overlimits = value.as_u64().unwrap(),
"requeues" => result.requeues = value.as_u64().unwrap(),
"packets" => result.packets = value.as_u64().unwrap() as u32,
"drops" => result.drops = value.as_u64().unwrap() as u32,
"overlimits" => result.overlimits = value.as_u64().unwrap() as u32,
"requeues" => result.requeues = value.as_u64().unwrap() as u32,
"backlog" => result.backlog = value.as_u64().unwrap() as u32,
"qlen" => result.qlen = value.as_u64().unwrap() as u32,
"options" => result.options = TcHtbOptions::from_json(value)?,
"kind" => {}
_ => {
log::error!("Unknown entry in Tc-HTB: {key}");
info_once!("Unknown entry in tc-HTB json decoder: {key}");
}
}
}
@@ -71,7 +72,7 @@ impl TcHtbOptions {
}
"direct_qlen" => result.direct_qlen = value.as_u64().unwrap() as u32,
_ => {
log::error!("Unknown entry in Tc-HTB: {key}");
info_once!("Unknown entry in tc-HTB json decoder: {key}");
}
}
}

View File

@@ -6,18 +6,19 @@ use anyhow::Result;
use lqos_bus::TcHandle;
use serde::Serialize;
use serde_json::Value;
use log_once::info_once;
#[derive(Default, Clone, Debug, Serialize)]
pub struct TcMultiQueue {
handle: TcHandle,
root: bool,
bytes: u64,
packets: u64,
drops: u64,
overlimits: u64,
requeues: u64,
backlog: u64,
qlen: u64,
packets: u32, // FIXME These can overflow in older linuxes
drops: u32,
overlimits: u32,
requeues: u32, // what does requeues really mean?
backlog: u32,
qlen: u32,
}
impl TcMultiQueue {
@@ -28,16 +29,16 @@ impl TcMultiQueue {
"handle" => result.handle = TcHandle::from_string(value.as_str().unwrap())?,
"root" => result.root = value.as_bool().unwrap(),
"bytes" => result.bytes = value.as_u64().unwrap(),
"packets" => result.packets = value.as_u64().unwrap(),
"drops" => result.drops = value.as_u64().unwrap(),
"overlimits" => result.overlimits = value.as_u64().unwrap(),
"requeues" => result.requeues = value.as_u64().unwrap(),
"backlog" => result.backlog = value.as_u64().unwrap(),
"qlen" => result.qlen = value.as_u64().unwrap(),
"packets" => result.packets = value.as_u64().unwrap() as u32,
"drops" => result.drops = value.as_u64().unwrap() as u32,
"overlimits" => result.overlimits = value.as_u64().unwrap() as u32,
"requeues" => result.requeues = value.as_u64().unwrap() as u32,
"backlog" => result.backlog = value.as_u64().unwrap() as u32,
"qlen" => result.qlen = value.as_u64().unwrap() as u32,
"kind" => {}
"options" => {}
_ => {
log::error!("Unknown entry in Tc-MQ: {key}");
info_once!("Unknown entry in tc-MQ json decoder: {key}");
}
}
}