@mark1russell7/harness 0.16.7 → 0.16.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -0
- package/build/{cell-FMlgjqVq.d.ts → cell-CYOKWfwg.d.ts} +46 -1
- package/build/image-YlflAajQ.js.map +1 -1
- package/build/index.d.ts +62 -2
- package/build/index.js +227 -55
- package/build/index.js.map +1 -1
- package/build/schema.d.ts +1 -1
- package/image/Dockerfile +1 -1
- package/image/native/src/bin/egress.rs +540 -0
- package/image/native/src/bin/ports.rs +33 -1
- package/image/native/src/lib.rs +111 -2
- package/package.json +3 -3
package/image/native/src/lib.rs
CHANGED
|
@@ -1,10 +1,84 @@
|
|
|
1
|
-
//! What the programs of the harness's native side share: their event lines
|
|
2
|
-
//! schedule.
|
|
1
|
+
//! What the programs of the harness's native side share: their event lines, the arrivals of a
|
|
2
|
+
//! schedule and the counters of the network stack.
|
|
3
3
|
|
|
4
4
|
use prober::monotonic_ns;
|
|
5
5
|
use serde_json::{json, Value};
|
|
6
|
+
use std::collections::BTreeMap;
|
|
6
7
|
use std::error::Error;
|
|
7
8
|
|
|
9
|
+
/// The counters of the network stack, each by its name, for example `Tcp.RetransSegs`,
|
|
10
|
+
/// `TcpExt.TCPACKSkippedTimeWait`, `Dev.eth0.rx_drop` or `Softnet.dropped`. The files of snmp,
|
|
11
|
+
/// netstat and dev are of the namespace of the caller. The file softnet_stat is of the host.
|
|
12
|
+
pub fn stack_counters() -> BTreeMap<String, u64> {
|
|
13
|
+
let read = |path: &str| std::fs::read_to_string(path).unwrap_or_default();
|
|
14
|
+
let mut counters = pairs_of(&read("/proc/net/snmp"));
|
|
15
|
+
counters.extend(pairs_of(&read("/proc/net/netstat")));
|
|
16
|
+
counters.extend(devices_of(&read("/proc/net/dev")));
|
|
17
|
+
counters.extend(softnet_of(&read("/proc/net/softnet_stat")));
|
|
18
|
+
counters
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/// Reads the format of /proc/net/snmp and /proc/net/netstat: a line of names, then a line of values
|
|
22
|
+
/// with the same prefix. A value that is not a count, as the -1 of `Tcp.MaxConn`, is skipped.
|
|
23
|
+
pub fn pairs_of(text: &str) -> BTreeMap<String, u64> {
|
|
24
|
+
let lines: Vec<&str> = text.lines().collect();
|
|
25
|
+
let mut counters = BTreeMap::new();
|
|
26
|
+
let mut at = 0;
|
|
27
|
+
while at + 1 < lines.len() {
|
|
28
|
+
let (Some((prefix, names)), Some((other, values))) = (lines[at].split_once(':'), lines[at + 1].split_once(':')) else {
|
|
29
|
+
at += 1;
|
|
30
|
+
continue;
|
|
31
|
+
};
|
|
32
|
+
if prefix != other || values.split_whitespace().next().is_some_and(|first| first.parse::<i64>().is_err()) {
|
|
33
|
+
at += 1;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (name, value) in names.split_whitespace().zip(values.split_whitespace()) {
|
|
37
|
+
if let Ok(value) = value.parse::<u64>() {
|
|
38
|
+
counters.insert(format!("{prefix}.{name}"), value);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
at += 2;
|
|
42
|
+
}
|
|
43
|
+
counters
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// The columns of /proc/net/dev that the counters keep, by their place after the name of the device.
|
|
47
|
+
const DEVICE_COLUMNS: [(usize, &str); 6] =
|
|
48
|
+
[(1, "rx_packets"), (2, "rx_errs"), (3, "rx_drop"), (9, "tx_packets"), (10, "tx_errs"), (11, "tx_drop")];
|
|
49
|
+
|
|
50
|
+
/// Reads /proc/net/dev: one line for each device, after two lines of headings.
|
|
51
|
+
pub fn devices_of(text: &str) -> BTreeMap<String, u64> {
|
|
52
|
+
let mut counters = BTreeMap::new();
|
|
53
|
+
for line in text.lines() {
|
|
54
|
+
let Some((device, values)) = line.split_once(':') else { continue };
|
|
55
|
+
let values: Vec<u64> = values.split_whitespace().filter_map(|value| value.parse().ok()).collect();
|
|
56
|
+
if values.len() < 16 {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
for (column, name) in DEVICE_COLUMNS {
|
|
60
|
+
counters.insert(format!("Dev.{}.{name}", device.trim()), values[column]);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
counters
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/// Reads /proc/net/softnet_stat: one line of hexadecimal columns for each processor. The sums of the
|
|
67
|
+
/// first three columns are the packets processed, the packets dropped at a full backlog, and the
|
|
68
|
+
/// rounds that ended with work left.
|
|
69
|
+
pub fn softnet_of(text: &str) -> BTreeMap<String, u64> {
|
|
70
|
+
let mut sums = [0u64; 3];
|
|
71
|
+
for line in text.lines() {
|
|
72
|
+
for (sum, value) in sums.iter_mut().zip(line.split_whitespace()) {
|
|
73
|
+
*sum += u64::from_str_radix(value, 16).unwrap_or(0);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
if text.trim().is_empty() {
|
|
77
|
+
return BTreeMap::new();
|
|
78
|
+
}
|
|
79
|
+
["processed", "dropped", "squeezed"].iter().zip(sums).map(|(name, sum)| (format!("Softnet.{name}"), sum)).collect()
|
|
80
|
+
}
|
|
81
|
+
|
|
8
82
|
/// Prints one event line, with the time of the call on CLOCK_MONOTONIC.
|
|
9
83
|
pub fn emit(event: &str, fields: Value) {
|
|
10
84
|
emit_at(event, monotonic_ns(), fields);
|
|
@@ -48,4 +122,39 @@ mod tests {
|
|
|
48
122
|
assert!(arrivals_of(r#"{"format":"rigor-schedule/1"}"#).is_err());
|
|
49
123
|
assert!(arrivals_of(r#"{"format":"rigor-schedule/1","times":["a"]}"#).is_err());
|
|
50
124
|
}
|
|
125
|
+
|
|
126
|
+
#[test]
|
|
127
|
+
fn the_counters_of_snmp_and_netstat_come_by_prefix_and_name() {
|
|
128
|
+
let snmp = "Ip: Forwarding DefaultTTL InDiscards\nIp: 1 64 3\n\
|
|
129
|
+
IcmpMsg: InType3\nIcmpMsg: 2\n\
|
|
130
|
+
Tcp: RtoAlgorithm MaxConn RetransSegs\nTcp: 1 -1 7\n";
|
|
131
|
+
let counters = pairs_of(snmp);
|
|
132
|
+
assert_eq!(counters["Ip.InDiscards"], 3);
|
|
133
|
+
assert_eq!(counters["IcmpMsg.InType3"], 2);
|
|
134
|
+
assert_eq!(counters["Tcp.RetransSegs"], 7);
|
|
135
|
+
assert!(!counters.contains_key("Tcp.MaxConn"));
|
|
136
|
+
let netstat = "TcpExt: TCPACKSkippedTimeWait TCPChallengeACK\nTcpExt: 4 0\nIpExt: InNoRoutes\nIpExt: 0\n";
|
|
137
|
+
let counters = pairs_of(netstat);
|
|
138
|
+
assert_eq!(counters["TcpExt.TCPACKSkippedTimeWait"], 4);
|
|
139
|
+
assert_eq!(counters["IpExt.InNoRoutes"], 0);
|
|
140
|
+
assert!(pairs_of("Tcp: RetransSegs\nUdp: InDatagrams\nUdp: 5\n").get("Tcp.RetransSegs").is_none());
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#[test]
|
|
144
|
+
fn the_counters_of_a_device_and_of_the_backlog_come_from_their_columns() {
|
|
145
|
+
let dev = "Inter-| Receive | Transmit\n face |bytes packets errs drop|bytes\n\
|
|
146
|
+
eth0: 1000 10 1 2 0 0 0 0 2000 20 3 4 0 0 0 0\n";
|
|
147
|
+
let counters = devices_of(dev);
|
|
148
|
+
assert_eq!(counters["Dev.eth0.rx_packets"], 10);
|
|
149
|
+
assert_eq!(counters["Dev.eth0.rx_errs"], 1);
|
|
150
|
+
assert_eq!(counters["Dev.eth0.rx_drop"], 2);
|
|
151
|
+
assert_eq!(counters["Dev.eth0.tx_packets"], 20);
|
|
152
|
+
assert_eq!(counters["Dev.eth0.tx_errs"], 3);
|
|
153
|
+
assert_eq!(counters["Dev.eth0.tx_drop"], 4);
|
|
154
|
+
assert_eq!(counters.len(), 6);
|
|
155
|
+
let softnet = "0000000a 00000001 00000002 00000000\n00000010 00000000 00000001 00000000\n";
|
|
156
|
+
let counters = softnet_of(softnet);
|
|
157
|
+
assert_eq!((counters["Softnet.processed"], counters["Softnet.dropped"], counters["Softnet.squeezed"]), (26, 1, 3));
|
|
158
|
+
assert!(softnet_of("").is_empty());
|
|
159
|
+
}
|
|
51
160
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/harness",
|
|
4
|
-
"version": "0.16.
|
|
5
|
-
"description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its disk tier cuts the power of a program on LazyFS: the disk loses each write after the last fsync. Its memory tier sets the limits of the cgroup of a client, and judges its throttle above memory.high and the choice of the OOM killer. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
|
|
4
|
+
"version": "0.16.9",
|
|
5
|
+
"description": "Network labs in Docker, declared as data. A cell builds a topology of networks, routers and proxies around a stock target. It injects a fault at layer 3 or 4 from a NET_ADMIN sidecar, measures the records of the kernel and judges a prediction. The faults are black holes, resets, ICMP unreachable, one-way and MTU drops, tc netem, the toxics of Toxiproxy and frozen processes. Its disk tier cuts the power of a program on LazyFS: the disk loses each write after the last fsync. Its memory tier sets the limits of the cgroup of a client, and judges its throttle above memory.high and the choice of the OOM killer. Its egress tier puts a netem or tbf qdisc on the interface of a client, and judges the departure of each datagram from the stamps of the kernel. Its replicated groups are Redis with Sentinels, MongoDB replica sets, PostgreSQL standbys, Kafka, RabbitMQ and BGP fabrics with BFD. A lab can also operate in a QEMU guest. Its first use is connection timers: keep-alive, TCP retransmission, heartbeats and reconnects.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"fault-injection",
|
|
8
8
|
"chaos-engineering",
|
|
@@ -119,7 +119,7 @@
|
|
|
119
119
|
"node": ">=22.19"
|
|
120
120
|
},
|
|
121
121
|
"dependencies": {
|
|
122
|
-
"@mark1russell7/prober": "^0.3.
|
|
122
|
+
"@mark1russell7/prober": "^0.3.5",
|
|
123
123
|
"@mark1russell7/quantity": "^0.4.1",
|
|
124
124
|
"@mark1russell7/rigor-bench": "^0.2.10",
|
|
125
125
|
"@mark1russell7/rigor-chaos": "^0.3.3",
|