@mark1russell7/harness 0.16.16 → 0.16.17
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 +55 -0
- package/build/{cell-CYOKWfwg.d.ts → cell-CeLvi_tR.d.ts} +19 -1
- package/build/image-BE9H5gIv.js.map +1 -1
- package/build/index.d.ts +227 -4
- package/build/index.js +398 -10
- package/build/index.js.map +1 -1
- package/build/layers.d.ts +1 -1
- package/build/schema.d.ts +1 -1
- package/image/Dockerfile +5 -4
- package/image/native/src/bin/resources.rs +187 -0
- package/package.json +2 -2
package/build/layers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Wt as Topology } from "./cell-CeLvi_tR.js";
|
|
2
2
|
/**
|
|
3
3
|
* A layer is a rung of the laboratory (`docs/S7.md`). E1 is containers on one kernel, and E2 is a
|
|
4
4
|
* cluster of containers on one kernel. A lab with `Topology.fabric` writes E3: routers in containers.
|
package/build/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Ht as Subject, I as ImageSource, i as Client, o as ClientImage } from "./cell-CeLvi_tR.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
/**
|
|
4
4
|
* This schema accepts the source of an image (`ImageSource`). It is a pinned image with its digest,
|
package/image/Dockerfile
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
# The harness's own image: the prober, the cell client, the load driver of HTTP, the injector
|
|
2
|
-
# the namespace admin all run from it. A target's image
|
|
3
|
-
# the crates by Cargo.lock, and the packages apk
|
|
1
|
+
# The harness's own image: the prober, the cell client, the load driver of HTTP, the injector, the
|
|
2
|
+
# reader of the resources of a container and the namespace admin all run from it. A target's image
|
|
3
|
+
# stays stock. Both stages are pinned by digest, the crates by Cargo.lock, and the packages apk
|
|
4
|
+
# installs are recorded in each run's manifest.
|
|
4
5
|
# lab.ts stages the build context: the prober's and the harness's native sources, and the prober's
|
|
5
6
|
# identity fixture, each under its package's name.
|
|
6
7
|
|
|
@@ -26,6 +27,6 @@ FROM alpine:3.23@sha256:865b95f46d98cf867a156fe4a135ad3fe50d2056aa3f25ed31662dff
|
|
|
26
27
|
# tc for netem, ethtool for the offloads that decide whether netem acts on segments
|
|
27
28
|
RUN apk add --no-cache iproute2 iproute2-tc iptables ethtool libelf zlib zstd-libs libgcc
|
|
28
29
|
COPY --from=build /src/prober.bpf.o /src/prober/native/target/release/prober /opt/harness/
|
|
29
|
-
COPY --from=build /src/harness/image/native/target/release/client /src/harness/image/native/target/release/inject /src/harness/image/native/target/release/queue /src/harness/image/native/target/release/ports /src/harness/image/native/target/release/ctfull /src/harness/image/native/target/release/load /src/harness/image/native/target/release/memory /src/harness/image/native/target/release/egress /opt/harness/
|
|
30
|
+
COPY --from=build /src/harness/image/native/target/release/client /src/harness/image/native/target/release/inject /src/harness/image/native/target/release/queue /src/harness/image/native/target/release/ports /src/harness/image/native/target/release/ctfull /src/harness/image/native/target/release/load /src/harness/image/native/target/release/memory /src/harness/image/native/target/release/egress /src/harness/image/native/target/release/resources /opt/harness/
|
|
30
31
|
WORKDIR /opt/harness
|
|
31
32
|
CMD ["sleep", "infinity"]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
//! resources read DIR...
|
|
2
|
+
//! resources watch --period-ms N DIR...
|
|
3
|
+
//!
|
|
4
|
+
//! This program reads the resources of one container. It reads the files of the cgroup of the
|
|
5
|
+
//! container, and the devices of the network namespace that the program is in. Each line is JSON
|
|
6
|
+
//! with the event `resources` and a `t` on CLOCK_MONOTONIC, the clock of each other line of a lab.
|
|
7
|
+
//!
|
|
8
|
+
//! The harness starts the program in a sidecar: in the network namespace of the container, and in
|
|
9
|
+
//! the cgroup namespace of the host. Thus the program is not in the cgroup of the container, and
|
|
10
|
+
//! its own CPU time and memory are not in the readings.
|
|
11
|
+
//!
|
|
12
|
+
//! Each `DIR` is a folder where the cgroup of the container can be. The program takes the first one
|
|
13
|
+
//! that is there: the folder under the cgroup driver of systemd, or under the driver cgroupfs.
|
|
14
|
+
//!
|
|
15
|
+
//! `read` writes one line. `watch` writes one line each `--period-ms` milliseconds, until the
|
|
16
|
+
//! harness stops it. Each line of a series has its place on the clock from the start of the
|
|
17
|
+
//! series, thus the time of a reading does not move the later ones.
|
|
18
|
+
//!
|
|
19
|
+
//! A line has the text of each file, as the kernel gives it. The harness reads the numbers from
|
|
20
|
+
//! that text, thus one program reads each file format. A file that the program cannot read is
|
|
21
|
+
//! `null`: no read, never a zero. `t` is the time before the first file, which is `cpu.stat`. `t1`
|
|
22
|
+
//! is the time after the last file.
|
|
23
|
+
|
|
24
|
+
use harness_native::{emit, emit_at};
|
|
25
|
+
use prober::monotonic_ns;
|
|
26
|
+
use serde_json::{json, Map, Value};
|
|
27
|
+
use std::error::Error;
|
|
28
|
+
use std::path::Path;
|
|
29
|
+
use std::time::Duration;
|
|
30
|
+
|
|
31
|
+
/// the files of the cgroup, in the order of the reads: the CPU time first, next to the stamp
|
|
32
|
+
const FILES: [&str; 9] = [
|
|
33
|
+
"cpu.stat",
|
|
34
|
+
"memory.current",
|
|
35
|
+
"memory.peak",
|
|
36
|
+
"memory.stat",
|
|
37
|
+
"memory.events",
|
|
38
|
+
"pids.current",
|
|
39
|
+
"cpu.max",
|
|
40
|
+
"memory.max",
|
|
41
|
+
"cpuset.cpus.effective",
|
|
42
|
+
];
|
|
43
|
+
/// the counters of each device of the network namespace of the program
|
|
44
|
+
const DEVICES: &str = "/proc/net/dev";
|
|
45
|
+
const MILLISECOND_NS: u64 = 1_000_000;
|
|
46
|
+
const USAGE: &str = "resources read DIR... | resources watch --period-ms N DIR...";
|
|
47
|
+
|
|
48
|
+
#[derive(Debug, PartialEq)]
|
|
49
|
+
struct Plan {
|
|
50
|
+
/// the period of a series in milliseconds, or None for one line
|
|
51
|
+
period_ms: Option<u64>,
|
|
52
|
+
dirs: Vec<String>,
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/// Reads the mode, the period of a series and the folders where the cgroup can be.
|
|
56
|
+
fn plan_of(args: &[String]) -> Result<Plan, Box<dyn Error>> {
|
|
57
|
+
let (mode, rest) = args.split_first().ok_or(USAGE)?;
|
|
58
|
+
let mut period_ms = None;
|
|
59
|
+
let mut dirs = Vec::new();
|
|
60
|
+
let mut rest = rest.iter();
|
|
61
|
+
while let Some(arg) = rest.next() {
|
|
62
|
+
match arg.as_str() {
|
|
63
|
+
"--period-ms" => period_ms = Some(rest.next().ok_or("--period-ms needs a value")?.parse::<u64>()?),
|
|
64
|
+
other if other.starts_with("--") => return Err(format!("no flag {other}").into()),
|
|
65
|
+
dir => dirs.push(dir.to_string()),
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
match (mode.as_str(), period_ms) {
|
|
69
|
+
("read", None) => {}
|
|
70
|
+
("watch", Some(period)) if period > 0 => {}
|
|
71
|
+
("watch", _) => return Err("watch needs --period-ms with a period above 0".into()),
|
|
72
|
+
_ => return Err(USAGE.into()),
|
|
73
|
+
}
|
|
74
|
+
if dirs.is_empty() {
|
|
75
|
+
return Err("resources needs a folder of a cgroup".into());
|
|
76
|
+
}
|
|
77
|
+
Ok(Plan { period_ms, dirs })
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/// The first folder that is there: the cgroup of the container under the cgroup driver of this host.
|
|
81
|
+
fn found_in<'a>(dirs: &'a [String], there: impl Fn(&str) -> bool) -> Option<&'a str> {
|
|
82
|
+
dirs.iter().map(String::as_str).find(|&dir| there(dir))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/// The text of a file, or null when the program cannot read it: no read, never a zero.
|
|
86
|
+
fn text_of(path: &str) -> Value {
|
|
87
|
+
match std::fs::read_to_string(path) {
|
|
88
|
+
Ok(text) => Value::String(text),
|
|
89
|
+
Err(_) => Value::Null,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// One reading: its stamp, and the text of each file of the cgroup and of the devices.
|
|
94
|
+
fn reading(dir: &str) -> (u64, Value) {
|
|
95
|
+
let t = monotonic_ns();
|
|
96
|
+
let mut files = Map::new();
|
|
97
|
+
// the CPU time comes first, next to the stamp
|
|
98
|
+
files.insert(FILES[0].to_string(), text_of(&format!("{dir}/{}", FILES[0])));
|
|
99
|
+
let net = text_of(DEVICES);
|
|
100
|
+
for name in &FILES[1..] {
|
|
101
|
+
files.insert(name.to_string(), text_of(&format!("{dir}/{name}")));
|
|
102
|
+
}
|
|
103
|
+
let t1 = monotonic_ns();
|
|
104
|
+
(t, json!({ "t1": t1, "cgroup": dir, "files": files, "net": net }))
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/// Writes one line of a reading.
|
|
108
|
+
fn line(dir: &str) {
|
|
109
|
+
let (t, fields) = reading(dir);
|
|
110
|
+
emit_at("resources", t, fields);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
fn run(args: &[String]) -> Result<(), Box<dyn Error>> {
|
|
114
|
+
let plan = plan_of(args)?;
|
|
115
|
+
let dir = found_in(&plan.dirs, |dir| Path::new(dir).is_dir())
|
|
116
|
+
.ok_or_else(|| format!("no cgroup folder of the container: {}", plan.dirs.join(", ")))?;
|
|
117
|
+
let Some(period_ms) = plan.period_ms else {
|
|
118
|
+
line(dir);
|
|
119
|
+
return Ok(());
|
|
120
|
+
};
|
|
121
|
+
let period = period_ms * MILLISECOND_NS;
|
|
122
|
+
let start = monotonic_ns();
|
|
123
|
+
loop {
|
|
124
|
+
line(dir);
|
|
125
|
+
let now = monotonic_ns();
|
|
126
|
+
// the next place on the clock after this reading: a slow reading skips a place, and the series does not drift
|
|
127
|
+
let next = start + ((now - start) / period + 1) * period;
|
|
128
|
+
std::thread::sleep(Duration::from_nanos(next - now));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
fn main() {
|
|
133
|
+
let args: Vec<String> = std::env::args().skip(1).collect();
|
|
134
|
+
// an error is a line too: the harness reads it, and it does not take it for a reading
|
|
135
|
+
if let Err(error) = run(&args) {
|
|
136
|
+
emit("error", json!({ "what": error.to_string() }));
|
|
137
|
+
std::process::exit(1);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[cfg(test)]
|
|
142
|
+
mod tests {
|
|
143
|
+
use super::*;
|
|
144
|
+
|
|
145
|
+
fn argv(each: &[&str]) -> Vec<String> {
|
|
146
|
+
each.iter().map(|arg| arg.to_string()).collect()
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#[test]
|
|
150
|
+
fn a_plan_reads_its_mode_its_period_and_its_folders() {
|
|
151
|
+
assert_eq!(plan_of(&argv(&["read", "/a", "/b"])).expect("a plan"), Plan { period_ms: None, dirs: argv(&["/a", "/b"]) });
|
|
152
|
+
assert_eq!(plan_of(&argv(&["watch", "--period-ms", "250", "/a"])).expect("a plan"), Plan { period_ms: Some(250), dirs: argv(&["/a"]) });
|
|
153
|
+
assert!(plan_of(&argv(&[])).is_err());
|
|
154
|
+
assert!(plan_of(&argv(&["read"])).is_err());
|
|
155
|
+
assert!(plan_of(&argv(&["read", "--period-ms", "250", "/a"])).is_err());
|
|
156
|
+
assert!(plan_of(&argv(&["watch", "/a"])).is_err());
|
|
157
|
+
assert!(plan_of(&argv(&["watch", "--period-ms", "0", "/a"])).is_err());
|
|
158
|
+
assert!(plan_of(&argv(&["watch", "--period-ms", "x", "/a"])).is_err());
|
|
159
|
+
assert!(plan_of(&argv(&["watch", "--period-ms"])).is_err());
|
|
160
|
+
assert!(plan_of(&argv(&["read", "--no-such", "/a"])).is_err());
|
|
161
|
+
assert!(plan_of(&argv(&["other", "/a"])).is_err());
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#[test]
|
|
165
|
+
fn the_cgroup_is_the_first_folder_that_is_there() {
|
|
166
|
+
let dirs = argv(&["/sys/fs/cgroup/system.slice/docker-1.scope", "/sys/fs/cgroup/docker/1"]);
|
|
167
|
+
assert_eq!(found_in(&dirs, |dir| dir.starts_with("/sys/fs/cgroup/docker/")), Some("/sys/fs/cgroup/docker/1"));
|
|
168
|
+
assert_eq!(found_in(&dirs, |_| true), Some("/sys/fs/cgroup/system.slice/docker-1.scope"));
|
|
169
|
+
assert_eq!(found_in(&dirs, |_| false), None);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
#[test]
|
|
173
|
+
fn a_reading_has_the_text_of_each_file_and_null_for_a_file_that_is_not_there() {
|
|
174
|
+
let dir = std::env::temp_dir().join(format!("resources-test-{}", std::process::id()));
|
|
175
|
+
std::fs::create_dir_all(&dir).expect("a folder");
|
|
176
|
+
std::fs::write(dir.join("cpu.stat"), "usage_usec 12\n").expect("a file");
|
|
177
|
+
let (t, fields) = reading(dir.to_str().expect("a path"));
|
|
178
|
+
std::fs::remove_dir_all(&dir).expect("a removal");
|
|
179
|
+
assert!(fields["t1"].as_u64().expect("a stamp") >= t);
|
|
180
|
+
assert_eq!(fields["cgroup"], json!(dir.to_str()));
|
|
181
|
+
assert_eq!(fields["files"]["cpu.stat"], json!("usage_usec 12\n"));
|
|
182
|
+
// no read is null: a zero is a value
|
|
183
|
+
assert_eq!(fields["files"]["memory.peak"], Value::Null);
|
|
184
|
+
assert_eq!(fields["files"].as_object().expect("the files").len(), FILES.len());
|
|
185
|
+
assert!(fields.get("net").is_some());
|
|
186
|
+
}
|
|
187
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://json.schemastore.org/package",
|
|
3
3
|
"name": "@mark1russell7/harness",
|
|
4
|
-
"version": "0.16.
|
|
4
|
+
"version": "0.16.17",
|
|
5
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",
|
|
@@ -124,7 +124,7 @@
|
|
|
124
124
|
},
|
|
125
125
|
"dependencies": {
|
|
126
126
|
"@mark1russell7/prober": "^0.3.5",
|
|
127
|
-
"@mark1russell7/quantity": "^0.4.
|
|
127
|
+
"@mark1russell7/quantity": "^0.4.3",
|
|
128
128
|
"@mark1russell7/rigor-bench": "^0.2.10",
|
|
129
129
|
"@mark1russell7/rigor-chaos": "^0.3.3",
|
|
130
130
|
"@mark1russell7/rigor-statistics": "^0.2.1",
|