@mark1russell7/harness 0.16.28 → 0.16.29
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 +8 -0
- package/build/index.d.ts +39 -2
- package/build/index.js +136 -17
- package/build/index.js.map +1 -1
- package/image/lazyfs/start.mts +42 -3
- package/package.json +4 -3
package/image/lazyfs/start.mts
CHANGED
|
@@ -6,14 +6,23 @@
|
|
|
6
6
|
* descriptor 3, and this process keeps the reader open. Thus LazyFS starts at once, and a write after a reader went away
|
|
7
7
|
* does not stop it.
|
|
8
8
|
*
|
|
9
|
+
* LazyFS answers only `lazyfs::clear-cache` on `done.fifo`. Thus this process reads the log of LazyFS, and writes one line
|
|
10
|
+
* to `acks` for each answer to a fault command: `ok` when LazyFS took the fault, `error` when it refused the fault.
|
|
11
|
+
*
|
|
9
12
|
* This process is PID 1 of the container. It gives `SIGTERM` and `SIGINT` to LazyFS, and it ends with the exit of LazyFS.
|
|
13
|
+
* When the file `armed` exists, the end of LazyFS is a fault: this process writes the exit of LazyFS to `exit`, and keeps
|
|
14
|
+
* the container for the check until a signal.
|
|
10
15
|
*/
|
|
11
16
|
import { execFileSync, spawn } from "node:child_process";
|
|
12
|
-
import { constants, openSync } from "node:fs";
|
|
17
|
+
import { appendFileSync, constants, existsSync, openSync, writeFileSync } from "node:fs";
|
|
13
18
|
import { constants as os } from "node:os";
|
|
19
|
+
import type { Readable } from "node:stream";
|
|
14
20
|
|
|
15
21
|
const FAULTS = "/run/lazyfs/faults.fifo";
|
|
16
22
|
const DONE = "/run/lazyfs/done.fifo";
|
|
23
|
+
const ARMED = "/run/lazyfs/armed";
|
|
24
|
+
const EXIT = "/run/lazyfs/exit";
|
|
25
|
+
const ACKS = "/run/lazyfs/acks";
|
|
17
26
|
|
|
18
27
|
execFileSync("mkfifo", [FAULTS, DONE], { stdio: "inherit" });
|
|
19
28
|
// On Linux, an open of a FIFO to read and write does not wait for the other end, the same as `exec 3<>` of a shell
|
|
@@ -21,13 +30,43 @@ const reader = openSync(DONE, constants.O_RDWR);
|
|
|
21
30
|
const lazyfs = spawn(
|
|
22
31
|
"/usr/local/bin/lazyfs",
|
|
23
32
|
["/mnt/disk", "--config-path", "/etc/lazyfs/config.toml", "-o", "allow_other", "-o", "modules=subdir", "-o", "subdir=/var/disk", "-f"],
|
|
24
|
-
{ stdio: ["inherit", "
|
|
33
|
+
{ stdio: ["inherit", "pipe", "pipe", reader] },
|
|
25
34
|
);
|
|
26
|
-
|
|
35
|
+
|
|
36
|
+
/** This function copies a stream of the log of LazyFS to the log of the container, and writes each answer to `acks`. */
|
|
37
|
+
const watch = (from: Readable, to: NodeJS.WriteStream): void => {
|
|
38
|
+
let rest = "";
|
|
39
|
+
from.on("data", (chunk: Buffer) => {
|
|
40
|
+
to.write(chunk);
|
|
41
|
+
const lines = (rest + chunk.toString("utf8")).split("\n");
|
|
42
|
+
rest = lines.pop() ?? "";
|
|
43
|
+
for (const line of lines) {
|
|
44
|
+
if (line.includes("configured successfully") || line.includes("received: VALID crash fault")) appendFileSync(ACKS, `ok ${line}\n`);
|
|
45
|
+
else if (line.includes("received: INVALID")) appendFileSync(ACKS, `error ${line}\n`);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
if (lazyfs.stdout !== null) watch(lazyfs.stdout, process.stdout);
|
|
50
|
+
if (lazyfs.stderr !== null) watch(lazyfs.stderr, process.stderr);
|
|
51
|
+
|
|
52
|
+
let ended = false;
|
|
53
|
+
for (const signal of ["SIGTERM", "SIGINT"] as const) {
|
|
54
|
+
process.on(signal, () => {
|
|
55
|
+
if (ended) process.exit(0);
|
|
56
|
+
lazyfs.kill(signal);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
27
59
|
lazyfs.on("error", (error) => {
|
|
28
60
|
console.error(`LazyFS did not start: ${error.message}`);
|
|
29
61
|
process.exit(1);
|
|
30
62
|
});
|
|
31
63
|
lazyfs.on("exit", (code, signal) => {
|
|
64
|
+
ended = true;
|
|
65
|
+
if (existsSync(ARMED)) {
|
|
66
|
+
writeFileSync(EXIT, signal === null ? `code=${String(code)}\n` : `signal=${signal}\n`);
|
|
67
|
+
// The timer keeps this process, and with it the container, until a signal
|
|
68
|
+
setInterval(() => undefined, 1 << 30);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
32
71
|
process.exit(code ?? (signal === null ? 1 : 128 + os.signals[signal]));
|
|
33
72
|
});
|
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.29",
|
|
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,11 +124,12 @@
|
|
|
124
124
|
},
|
|
125
125
|
"dependencies": {
|
|
126
126
|
"@mark1russell7/prober": "^0.3.7",
|
|
127
|
-
"@mark1russell7/quantity": "^0.5.
|
|
127
|
+
"@mark1russell7/quantity": "^0.5.3",
|
|
128
128
|
"@mark1russell7/rigor-bench": "^0.2.10",
|
|
129
|
-
"@mark1russell7/rigor-chaos": "^0.
|
|
129
|
+
"@mark1russell7/rigor-chaos": "^0.5.0",
|
|
130
130
|
"@mark1russell7/rigor-statistics": "^0.2.1",
|
|
131
131
|
"@mark1russell7/rigor-testkit": "^0.1.14",
|
|
132
|
+
"@mark1russell7/text": "^0.0.28",
|
|
132
133
|
"semver": "^7.8.5",
|
|
133
134
|
"testcontainers": "12.2.1"
|
|
134
135
|
},
|