@mark1russell7/harness 0.16.13 → 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/build/index.js CHANGED
@@ -1155,11 +1155,11 @@ const fieldOf = (line, path) => path.split(".").reduce((value, key) => value !==
1155
1155
  /** This function tells if a line of the client matches a line match: its `ev`, and each field that the match names. */
1156
1156
  const matches = (line, match) => line.ev === match.ev && Object.entries(match.where ?? {}).every(([path, value]) => fieldOf(line, path) === value);
1157
1157
  /** This function gives the count of the lines that match. */
1158
- const countOf$1 = (lines, match) => lines.filter((line) => matches(line, match)).length;
1158
+ const countOf$2 = (lines, match) => lines.filter((line) => matches(line, match)).length;
1159
1159
  /** This function gives the finding of the line counts of a run, or null when each count is the exact one. */
1160
1160
  const countFinding = (counts, lines) => {
1161
1161
  const off = counts.flatMap((each) => {
1162
- const seen = countOf$1(lines, each.match);
1162
+ const seen = countOf$2(lines, each.match);
1163
1163
  return seen === each.count ? [] : [`${each.what}: ${seen} lines, and the law gives ${each.count}`];
1164
1164
  });
1165
1165
  return off.length === 0 ? null : off.join("; ");
@@ -2066,7 +2066,7 @@ const numberOr = (line, field) => {
2066
2066
  };
2067
2067
  /** This function gives one field of an object of a line, or undefined. */
2068
2068
  const fieldOf$1 = (value, field) => typeof value === "object" && value !== null ? value[field] : void 0;
2069
- const countOf = (value, field) => {
2069
+ const countOf$1 = (value, field) => {
2070
2070
  const count = fieldOf$1(value, field);
2071
2071
  return typeof count === "number" ? count : null;
2072
2072
  };
@@ -2147,7 +2147,7 @@ const measureEgress = (run, expected) => {
2147
2147
  };
2148
2148
  });
2149
2149
  const stats = events.find((event) => event.ev === "stats");
2150
- const rise = (field) => (countOf(stats?.["after"], field) ?? 0) - (countOf(stats?.["before"], field) ?? 0);
2150
+ const rise = (field) => (countOf$1(stats?.["after"], field) ?? 0) - (countOf$1(stats?.["before"], field) ?? 0);
2151
2151
  const egress = {
2152
2152
  kind,
2153
2153
  packets,
@@ -3819,6 +3819,337 @@ const measureSocket = (cell, run) => {
3819
3819
  finding
3820
3820
  };
3821
3821
  };
3822
+ // src/resources.ts
3823
+ /**
3824
+ * The resources that one container of a lab used. A reader in a sidecar reads the files of the
3825
+ * cgroup of the container and the devices of its network namespace (`RESOURCES_PROGRAM`). It
3826
+ * writes the text of each file in one JSON line, with a stamp on CLOCK_MONOTONIC. This module reads
3827
+ * each file from that line, and it gives the change between two readings.
3828
+ *
3829
+ * A file that the reader cannot read gives null: no read. It does not give a zero.
3830
+ */
3831
+ /** This name is the event of a line of the reader. */
3832
+ const RESOURCES_EVENT = "resources";
3833
+ /** This path is the reader of the resources, in the image of the harness. */
3834
+ const RESOURCES_PROGRAM = "/opt/harness/resources";
3835
+ /** This count is the smallest CPU limit that Docker takes, in CPUs. */
3836
+ const LEAST_CPUS = .01;
3837
+ /** This amount is the smallest memory limit that Docker takes, in bytes: 6 MiB. */
3838
+ const LEAST_MEMORY = 6291456;
3839
+ /** This function gives the bytes of a memory limit, or null for an amount that is not a count of bytes. */
3840
+ const bytesOf = (memory) => {
3841
+ try {
3842
+ const bytes = Math.round(valueIn(memory, "B"));
3843
+ return Number.isSafeInteger(bytes) ? bytes : null;
3844
+ } catch {
3845
+ return null;
3846
+ }
3847
+ };
3848
+ /** This function tells that a text is a list of CPUs, as `cpuset.cpus` takes it: `0`, `2-3` or `0,2`. */
3849
+ const isCpuList = (text) => /^\d+(-\d+)?(,\d+(-\d+)?)*$/.test(text) && text.split(",").every((range) => {
3850
+ const [first, last] = range.split("-").map(Number);
3851
+ return last === void 0 || first <= last;
3852
+ });
3853
+ /** This function gives the problems of the limits of a container, each as a sentence. Limits with no problem give an empty list. */
3854
+ const limitsProblems = (limits) => {
3855
+ const problems = [];
3856
+ const { cpus, cpuset, memory } = limits;
3857
+ if (cpus !== void 0 && !(Number.isFinite(cpus) && cpus >= LEAST_CPUS)) problems.push(`cpus is ${cpus}: Docker takes ${LEAST_CPUS} CPUs or more`);
3858
+ if (cpuset !== void 0 && !isCpuList(cpuset)) problems.push(`cpuset is "${cpuset}": write a list of CPUs, for example 0, 2-3 or 0,2`);
3859
+ if (memory !== void 0) {
3860
+ const bytes = bytesOf(memory);
3861
+ if (bytes === null) problems.push(`memory is ${memory.value} ${memory.unit}: write an amount of data, for example 512 MiB`);
3862
+ else if (bytes < LEAST_MEMORY) problems.push(`memory is ${bytes} B: Docker takes 6 MiB or more`);
3863
+ }
3864
+ return problems;
3865
+ };
3866
+ /**
3867
+ * This function gives the limits of a container as Docker takes them: the CPU quota, the CPUs and
3868
+ * the memory, with no swap. It throws for limits that have a problem (`limitsProblems`).
3869
+ */
3870
+ const hostLimitsOf = (limits) => {
3871
+ const problems = limitsProblems(limits);
3872
+ if (problems.length > 0) throw new RangeError(`the limits of a container: ${problems.join("; ")}`);
3873
+ const bytes = limits.memory === void 0 ? null : bytesOf(limits.memory);
3874
+ return {
3875
+ ...limits.cpus === void 0 ? {} : { NanoCpus: Math.round(limits.cpus * 1e9) },
3876
+ ...limits.cpuset === void 0 ? {} : { CpusetCpus: limits.cpuset },
3877
+ ...bytes === null ? {} : {
3878
+ Memory: bytes,
3879
+ MemorySwap: bytes
3880
+ }
3881
+ };
3882
+ };
3883
+ /**
3884
+ * This function gives the argv of the reader: one reading, or a series with a period. Each folder
3885
+ * is a place where the cgroup of the container can be. The reader takes the first one that is there.
3886
+ */
3887
+ const resourceArgs = (dirs, period) => {
3888
+ if (period === void 0) return [
3889
+ RESOURCES_PROGRAM,
3890
+ "read",
3891
+ ...dirs
3892
+ ];
3893
+ const ms = Math.round(valueIn(period, "ms"));
3894
+ if (!(ms >= 1)) throw new RangeError(`resourceArgs: the period of a series is ${ms} ms, and the reader takes 1 ms or more`);
3895
+ return [
3896
+ RESOURCES_PROGRAM,
3897
+ "watch",
3898
+ "--period-ms",
3899
+ String(ms),
3900
+ ...dirs
3901
+ ];
3902
+ };
3903
+ /** This function gives a count from its digits, or null for another text and for a count that a number cannot hold. */
3904
+ const countOf = (text) => {
3905
+ if (text === void 0 || !/^\d+$/.test(text)) return null;
3906
+ const count = Number(text);
3907
+ return Number.isSafeInteger(count) ? count : null;
3908
+ };
3909
+ /** This function gives the count of a file of a cgroup that holds one count, as `memory.current` does. Another text gives null. */
3910
+ const cgroupNumber = (text) => countOf(text.trim());
3911
+ /** This function gives a limit of a cgroup, as `memory.max` prints it: its count, or `max` for no limit. Another text gives null. */
3912
+ const cgroupLimit = (text) => text.trim() === "max" ? "max" : cgroupNumber(text);
3913
+ /**
3914
+ * This function gives the counts of a flat keyed file of a cgroup: one key and one count on each
3915
+ * line. `cpu.stat` and `memory.stat` are such files. It skips each other line.
3916
+ */
3917
+ const cgroupKeyed = (text) => Object.fromEntries(text.split("\n").flatMap((line) => {
3918
+ const parts = line.trim().split(/\s+/);
3919
+ const count = parts.length === 2 ? countOf(parts[1]) : null;
3920
+ return count === null ? [] : [[parts[0], count]];
3921
+ }));
3922
+ /** This function gives one count of a flat keyed file, or null for a key that the file does not have. */
3923
+ const keyOf = (counts, key) => Object.hasOwn(counts, key) ? counts[key] : null;
3924
+ /** This function reads `cpu.stat`. It gives null for a text with no usage. */
3925
+ const cpuStatOf = (text) => {
3926
+ const counts = cgroupKeyed(text);
3927
+ const [usage, user, system] = [
3928
+ keyOf(counts, "usage_usec"),
3929
+ keyOf(counts, "user_usec"),
3930
+ keyOf(counts, "system_usec")
3931
+ ];
3932
+ if (usage === null || user === null || system === null) return null;
3933
+ return {
3934
+ usage,
3935
+ user,
3936
+ system,
3937
+ periods: keyOf(counts, "nr_periods"),
3938
+ throttled: keyOf(counts, "nr_throttled"),
3939
+ throttledTime: keyOf(counts, "throttled_usec")
3940
+ };
3941
+ };
3942
+ /** This function reads `memory.stat`: the amounts of `anon`, `file`, `kernel` and `sock`, each null without its key. */
3943
+ const memoryStatOf = (text) => {
3944
+ const counts = cgroupKeyed(text);
3945
+ const [stack, slab] = [keyOf(counts, "kernel_stack"), keyOf(counts, "slab")];
3946
+ return {
3947
+ anon: keyOf(counts, "anon"),
3948
+ file: keyOf(counts, "file"),
3949
+ kernel: keyOf(counts, "kernel") ?? (stack === null || slab === null ? null : stack + slab),
3950
+ sock: keyOf(counts, "sock")
3951
+ };
3952
+ };
3953
+ /** This function reads `cpu.max`: the quota and the period, as `50000 100000` or `max 100000`. Another text gives null. */
3954
+ const cpuMaxOf = (text) => {
3955
+ const parts = text.trim().split(/\s+/);
3956
+ const quota = parts[0] === "max" ? "max" : countOf(parts[0]);
3957
+ const period = countOf(parts[1]);
3958
+ return parts.length !== 2 || quota === null || period === null ? null : {
3959
+ quota,
3960
+ period
3961
+ };
3962
+ };
3963
+ const NO_TRAFFIC = {
3964
+ bytes: 0,
3965
+ packets: 0
3966
+ };
3967
+ const sumOf = (devices, side) => devices.reduce((sum, device) => ({
3968
+ bytes: sum.bytes + device[side].bytes,
3969
+ packets: sum.packets + device[side].packets
3970
+ }), NO_TRAFFIC);
3971
+ /** This function gives the network of some devices: the devices in the order of their names, and their sums. */
3972
+ const networkWith = (devices) => {
3973
+ const sorted = [...devices].sort((one, other) => one.name < other.name ? -1 : one.name > other.name ? 1 : 0);
3974
+ return {
3975
+ devices: sorted,
3976
+ rx: sumOf(sorted, "rx"),
3977
+ tx: sumOf(sorted, "tx")
3978
+ };
3979
+ };
3980
+ /**
3981
+ * This function reads `/proc/net/dev`: the bytes and the packets of each device, without `lo`. It
3982
+ * gives null for a text that is not that file, and for a line of a device that it cannot read.
3983
+ */
3984
+ const networkOf = (text) => {
3985
+ if (!text.includes("|bytes")) return null;
3986
+ const devices = [];
3987
+ for (const line of text.split("\n")) {
3988
+ const colon = line.lastIndexOf(":");
3989
+ if (colon < 0) continue;
3990
+ const name = line.slice(0, colon).trim();
3991
+ const counts = line.slice(colon + 1).trim().split(/\s+/).map(countOf);
3992
+ if (name === "" || counts.length < 16 || counts.includes(null)) return null;
3993
+ if (name === "lo") continue;
3994
+ devices.push({
3995
+ name,
3996
+ rx: {
3997
+ bytes: counts[0],
3998
+ packets: counts[1]
3999
+ },
4000
+ tx: {
4001
+ bytes: counts[8],
4002
+ packets: counts[9]
4003
+ }
4004
+ });
4005
+ }
4006
+ return networkWith(devices);
4007
+ };
4008
+ /** This function gives the text of one file of a line of the reader, or null for no read. */
4009
+ const textOf$1 = (files, name) => {
4010
+ if (typeof files !== "object" || files === null || !Object.hasOwn(files, name)) return null;
4011
+ const text = files[name];
4012
+ return typeof text === "string" ? text : null;
4013
+ };
4014
+ /** This function reads a text with `read`, and gives null for no text. */
4015
+ const readWith = (text, read) => text === null ? null : read(text);
4016
+ /**
4017
+ * This function gives the reading of one line of the reader (`RESOURCES_EVENT`). It gives null for
4018
+ * another line, and for a line with no stamps.
4019
+ */
4020
+ const resourceReadingOf = (line) => {
4021
+ const { t, t1, cgroup, files, net } = line;
4022
+ if (line.ev !== "resources" || typeof t !== "number" || typeof t1 !== "number" || typeof cgroup !== "string") return null;
4023
+ const file = (name) => textOf$1(files, name);
4024
+ const stat = readWith(file("memory.stat"), memoryStatOf) ?? {
4025
+ anon: null,
4026
+ file: null,
4027
+ kernel: null,
4028
+ sock: null
4029
+ };
4030
+ const cpuset = file("cpuset.cpus.effective")?.trim();
4031
+ return {
4032
+ t0: t,
4033
+ t1,
4034
+ cgroup,
4035
+ cpu: readWith(file("cpu.stat"), cpuStatOf),
4036
+ memory: {
4037
+ current: readWith(file("memory.current"), cgroupNumber),
4038
+ peak: readWith(file("memory.peak"), cgroupNumber),
4039
+ ...stat,
4040
+ events: readWith(file("memory.events"), cgroupKeyed)
4041
+ },
4042
+ pids: readWith(file("pids.current"), cgroupNumber),
4043
+ network: typeof net === "string" ? networkOf(net) : null,
4044
+ limits: {
4045
+ cpu: readWith(file("cpu.max"), cpuMaxOf),
4046
+ memory: readWith(file("memory.max"), cgroupLimit),
4047
+ cpuset: cpuset === void 0 || cpuset === "" ? null : cpuset
4048
+ }
4049
+ };
4050
+ };
4051
+ /**
4052
+ * This function gives the reading of the output of one read of the reader. It throws for a text
4053
+ * that is not a line of a reading.
4054
+ */
4055
+ const resourceReadingIn = (output) => {
4056
+ let line = null;
4057
+ try {
4058
+ line = JSON.parse(output);
4059
+ } catch {}
4060
+ const reading = typeof line === "object" && line !== null && typeof line.ev === "string" ? resourceReadingOf(line) : null;
4061
+ if (reading === null) throw new Error(`the reader of the resources gave no reading: ${output.slice(0, 200)}`);
4062
+ return reading;
4063
+ };
4064
+ /** This function gives a time from its microseconds. */
4065
+ const fromMicroseconds = (time) => quantity(time / 1e6, "s");
4066
+ /**
4067
+ * This function gives what a container used between two readings. It gives its CPU time, the time
4068
+ * that its CPU limit stopped it, the traffic of each device, and its last memory. A counter that
4069
+ * went down is in `resets`, and its part is null. It throws when the second reading is the earlier one.
4070
+ */
4071
+ const resourceChange = (before, after) => {
4072
+ if (after.t0 < before.t0) throw new RangeError(`resourceChange: the second reading is ${before.t0 - after.t0} ns before the first`);
4073
+ const resets = [];
4074
+ /** This function gives the rise of a counter. It gives null for a counter that went down, and names it. */
4075
+ const rise = (name, from, to) => {
4076
+ if (to >= from) return to - from;
4077
+ resets.push(name);
4078
+ return null;
4079
+ };
4080
+ /** This function gives the rise of a counter that can have no read. */
4081
+ const riseOf = (name, from, to) => from === null || to === null ? null : rise(name, from, to);
4082
+ const same = before.cgroup === after.cgroup;
4083
+ if (!same) resets.push("cgroup");
4084
+ const cpu = (() => {
4085
+ if (!same || before.cpu === null || after.cpu === null) return null;
4086
+ const [total, user, system] = [
4087
+ rise("cpu.usage", before.cpu.usage, after.cpu.usage),
4088
+ rise("cpu.user", before.cpu.user, after.cpu.user),
4089
+ rise("cpu.system", before.cpu.system, after.cpu.system)
4090
+ ];
4091
+ const periods = riseOf("cpu.periods", before.cpu.periods, after.cpu.periods);
4092
+ const throttledPeriods = riseOf("cpu.throttled", before.cpu.throttled, after.cpu.throttled);
4093
+ const throttled = riseOf("cpu.throttledTime", before.cpu.throttledTime, after.cpu.throttledTime);
4094
+ if (total === null || user === null || system === null) return null;
4095
+ return {
4096
+ total: fromMicroseconds(total),
4097
+ user: fromMicroseconds(user),
4098
+ system: fromMicroseconds(system),
4099
+ throttled: throttled === null ? null : fromMicroseconds(throttled),
4100
+ periods,
4101
+ throttledPeriods
4102
+ };
4103
+ })();
4104
+ const network = (() => {
4105
+ if (before.network === null || after.network === null) return null;
4106
+ const earlier = new Map(before.network.devices.map((device) => [device.name, device]));
4107
+ const devices = [];
4108
+ let whole = true;
4109
+ for (const device of after.network.devices) {
4110
+ const from = earlier.get(device.name) ?? {
4111
+ name: device.name,
4112
+ rx: NO_TRAFFIC,
4113
+ tx: NO_TRAFFIC
4114
+ };
4115
+ earlier.delete(device.name);
4116
+ const each = ["rx", "tx"].map((side) => ({
4117
+ bytes: rise(`network.${device.name}.${side}.bytes`, from[side].bytes, device[side].bytes),
4118
+ packets: rise(`network.${device.name}.${side}.packets`, from[side].packets, device[side].packets)
4119
+ }));
4120
+ const [rx, tx] = [each[0], each[1]];
4121
+ if (rx.bytes === null || rx.packets === null || tx.bytes === null || tx.packets === null) whole = false;
4122
+ else devices.push({
4123
+ name: device.name,
4124
+ rx: {
4125
+ bytes: rx.bytes,
4126
+ packets: rx.packets
4127
+ },
4128
+ tx: {
4129
+ bytes: tx.bytes,
4130
+ packets: tx.packets
4131
+ }
4132
+ });
4133
+ }
4134
+ for (const name of earlier.keys()) {
4135
+ resets.push(`network.${name}`);
4136
+ whole = false;
4137
+ }
4138
+ return whole ? networkWith(devices) : null;
4139
+ })();
4140
+ const [peakBefore, peakAfter] = [before.memory.peak, after.memory.peak];
4141
+ return {
4142
+ elapsed: quantity((after.t0 - before.t0) / 1e9, "s"),
4143
+ cpu,
4144
+ memory: {
4145
+ last: after.memory.current,
4146
+ peak: peakAfter,
4147
+ peakBetween: !same || peakBefore === null || peakAfter === null ? null : peakAfter > peakBefore
4148
+ },
4149
+ network,
4150
+ resets
4151
+ };
4152
+ };
3822
4153
  // src/fabric.ts
3823
4154
  /**
3824
4155
  * A fabric is a routed network between the client and the target, on layer E3 (docs/S7.md). Four
@@ -4535,6 +4866,46 @@ const writeCgroup = async (admin, id, files) => {
4535
4866
  if (reads !== value) throw new Error(`${name} of the cgroup reads ${reads} after the write, not ${value}`);
4536
4867
  }
4537
4868
  };
4869
+ /** This function gives a container its limits: its CPU quota, its CPUs and its memory, with no swap (`hostLimitsOf`). */
4870
+ const withLimits = (container, limits) => {
4871
+ if (limits !== void 0) Object.assign(container.hostConfig, hostLimitsOf(limits));
4872
+ return container;
4873
+ };
4874
+ /** This time is how long a new reader waits for the first reading of its series, in milliseconds. */
4875
+ const FIRST_READING_MS = 15e3;
4876
+ /**
4877
+ * This function starts a reader of the resources of one container, by the full id of the
4878
+ * container. The sidecar of the reader is in the network namespace of the container `network`,
4879
+ * which is the same container without it. A container that shares the namespace of a holder names
4880
+ * that holder. With a period, the series starts before the function gives the reader.
4881
+ */
4882
+ const resourceReader = async (id, options = {}, network = id) => {
4883
+ const { GenericContainer } = await containers();
4884
+ const dirs = cgroupDirs(id);
4885
+ const series = [];
4886
+ const events = lines((line) => {
4887
+ const reading = resourceReadingOf(line);
4888
+ if (reading !== null) series.push(reading);
4889
+ });
4890
+ const stock = withLimits(withCgroupns(new GenericContainer(await harnessImage()).withNetworkMode(`container:${network}`).withPrivilegedMode(), "host"), options.cpuset === void 0 ? void 0 : { cpuset: options.cpuset });
4891
+ const sidecar = await (options.period === void 0 ? stock : stock.withCommand(resourceArgs(dirs, options.period)).withLogConsumer(events.consume)).start();
4892
+ const stop = () => sidecar.stop(STOP).then(() => void 0).catch(() => void 0);
4893
+ if (options.period !== void 0) {
4894
+ const first = await events.until([RESOURCES_EVENT, "error"], FIRST_READING_MS, "reader of the resources").catch(async (error) => {
4895
+ await stop();
4896
+ throw error;
4897
+ });
4898
+ if (first.ev === "error") {
4899
+ await stop();
4900
+ throw new Error(`the reader of the resources of the container ${id}: ${String(first["what"])}`);
4901
+ }
4902
+ }
4903
+ return {
4904
+ series,
4905
+ read: async () => resourceReadingIn(await output(sidecar, resourceArgs(dirs))),
4906
+ stop
4907
+ };
4908
+ };
4538
4909
  /** This container class can share the process namespace of another container. */
4539
4910
  const shared = (Base) => class extends Base {
4540
4911
  withPidMode(mode) {
@@ -4714,12 +5085,14 @@ const openLab = async (target, kind = "tcp", topology, setup = []) => {
4714
5085
  const runtime = await getContainerRuntimeClient();
4715
5086
  const opened = [];
4716
5087
  const networks = [];
5088
+ const readers = [];
4717
5089
  const serverLines = lines();
4718
5090
  let restoreHost = () => Promise.resolve([]);
4719
5091
  let fabric;
4720
5092
  const close = async () => {
4721
5093
  const restored = await restoreHost().then(() => null, (error) => error);
4722
5094
  await fabric?.close();
5095
+ for (const reader of readers.splice(0)) await reader.stop();
4723
5096
  for (const container of opened.reverse()) await container.stop(STOP).catch(() => void 0);
4724
5097
  for (const network of networks.reverse()) await network.stop().catch(() => void 0);
4725
5098
  if (restored !== null) throw restored;
@@ -4740,7 +5113,7 @@ const openLab = async (target, kind = "tcp", topology, setup = []) => {
4740
5113
  for (let at = 0; at <= hops.length; at += 1) networks.push(await new Network().start());
4741
5114
  const last = networks[hops.length];
4742
5115
  const targetImage = await targetImageOf(target);
4743
- let stock = new GenericContainer(targetImage).withNetwork(last).withWaitStrategy(Wait.forLogMessage(target.ready));
5116
+ let stock = withLimits(new GenericContainer(targetImage), target.limits).withNetwork(last).withWaitStrategy(Wait.forLogMessage(target.ready));
4744
5117
  if (target.files !== void 0) stock = stock.withCopyContentToContainer(Object.entries(target.files).map(([path, content]) => ({
4745
5118
  content,
4746
5119
  target: path
@@ -5384,9 +5757,10 @@ const openLab = async (target, kind = "tcp", topology, setup = []) => {
5384
5757
  query
5385
5758
  ]);
5386
5759
  },
5387
- async probe(args, files = [], cgroup) {
5760
+ async probe(args, files = [], cgroup, limits) {
5388
5761
  const events = lines();
5389
- const prober = new GenericContainer(clientImage).withNetworkMode(`container:${client.getId()}`).withCommand([...command, ...args]).withCopyContentToContainer(files.map((file) => ({ ...file }))).withLogConsumer(events.consume);
5762
+ const own = [];
5763
+ const prober = withLimits(new GenericContainer(clientImage), limits).withNetworkMode(`container:${client.getId()}`).withCommand([...command, ...args]).withCopyContentToContainer(files.map((file) => ({ ...file }))).withLogConsumer(events.consume);
5390
5764
  const container = await (capabilities === void 0 ? prober : prober.withAddedCapabilities(...capabilities)).start();
5391
5765
  if (cgroup !== void 0) {
5392
5766
  if (cgroupAdmin === void 0) {
@@ -5403,9 +5777,23 @@ const openLab = async (target, kind = "tcp", topology, setup = []) => {
5403
5777
  freeze: () => runtime.container.getById(container.getId()).pause().then(() => void 0),
5404
5778
  thaw: () => runtime.container.getById(container.getId()).unpause().then(() => void 0),
5405
5779
  kill: () => runtime.container.getById(container.getId()).kill({ signal: "SIGKILL" }).then(() => void 0),
5406
- stop: () => container.stop(STOP).then(() => void 0).catch(() => void 0)
5780
+ async resources(options) {
5781
+ const reader = await resourceReader(container.getId(), options, client.getId());
5782
+ own.push(reader);
5783
+ readers.push(reader);
5784
+ return reader;
5785
+ },
5786
+ async stop() {
5787
+ for (const reader of own.splice(0)) await reader.stop();
5788
+ await container.stop(STOP).catch(() => void 0);
5789
+ }
5407
5790
  };
5408
5791
  },
5792
+ async resources(options) {
5793
+ const reader = await resourceReader(server.getId(), options);
5794
+ readers.push(reader);
5795
+ return reader;
5796
+ },
5409
5797
  async settle() {
5410
5798
  const after = records.seen.length;
5411
5799
  const clock = await new Promise((resolve) => {
@@ -9306,7 +9694,7 @@ const LINES_MS = 5e3;
9306
9694
  */
9307
9695
  const linesCounted = async (lab, from, counts) => {
9308
9696
  const started = Date.now();
9309
- const short = () => counts.some((each) => countOf$1(lab.server.slice(from), each.match) < each.count);
9697
+ const short = () => counts.some((each) => countOf$2(lab.server.slice(from), each.match) < each.count);
9310
9698
  while (short() && Date.now() - started < LINES_MS) await setTimeout$1(20);
9311
9699
  await setTimeout$1(250);
9312
9700
  };
@@ -9904,6 +10292,6 @@ const runCell = async (cell, say = () => {}) => {
9904
10292
  target = larger;
9905
10293
  }
9906
10294
  };
9907
- export { AWS_FROM, CLIENT_CAPABILITIES, CLIENT_NAMES, CLOSED_TOLERANCE, CLOUDS, CLUSTER_STAGES, CONVERGE_MS, DAEMONS, DEBUG, DIRTY, DISK_MOUNT, DISK_RECORD_FORMAT, DISK_ROOT, DISK_SUBJECT, DROP_HANDLING, FABRIC_CLIENT, FABRIC_DEVICE, FABRIC_TARGET, FRR_IMAGE, GIVES_AWAY, HASH_SCRIPT, INJECT, INSERT, KAFKA_TAIL_MS, KEPT, LAYERS, LAYER_FACTS, LIMITS, LINGER_MS, LISTING, LOAD_FORMAT, LOAD_PATH, LOCK_NAMES, LOSS_MARGIN, MEMBER_MARKS, MONITOR_DOWN, NODE_MARKS, NOISE, PINNED, PUMP, PUMP_SLACK, QUIET_MS, RELATIVE, REPLICA_SET_STAGES, REPOSITORY, RESTART, ROUTERS, SCHEDULE_PATH, SEED_DOCUMENT, SHIPPED_CLIENTS, SHIPPED_NAMES, STAGES, STANDBY_READY, STATUS_SCRIPT, STEPS, STEP_DOWN, amqpClientImage, basesOf, bootstrapOf, brokerEnv, buildOf, buildRecordOf, callOf, cancelsOf, cargoVersions, clockOffsetOf, closeOrExit, cloudOf, clusterArgs, clusterConf, clusterCutOf, clusterHostsOf, clusterOnce, clusterStagesOf, clusterViewOf, commitProblems, commitVoid, comparable, controllerEnv, crossingsOf, cutOf, deadlineOf, delayVoids, deliveryFinding, deliveryOf, deviceOf, diskRecordProblems, diskSubjectProblems, drillOnce, drillSpan, dropFinding, dropOf, endpointAfter, envOf, environmentCounts, environmentProblems, errorsOf, estimateOf, estimateVerdict, exitOf, fieldOf, fieldsOf, firstUnanswered, folderDigest, frrConf, goHttpImage, goVersions, groupOnce, groupVerdictOf, grpcClientImage, harnessImage, harnessRecord, harnessVersion, hashOf, highestHeld, hikariClientImage, hzOf, imageOf, imagePinProblems, imageProblems, inContext, infoOf, initiateScript, isFenceLine, isHopPlace, jarVersions, jitterOf, jitterOfLines, judge, kafkaArgs, kafkaClientImage, kafkaCutOf, kafkaOnce, kafkaPauseOnce, kafkaViewOf, lagsOf, laterMove, latestEndOf, layerOf, leafLacks, leftAfter, limitsOf, loadOf, loadPlanOf, loadVerdict, locksOf, logNameOf, logTimeOf, manifestProblems, matches, measure, measureConntrack, measureDriver, measureEgress, measureGroup, measureMemory, measurePause, measurePorts, measureQueue, medianInterval, memAvailableOf, memberCommand, memberConfig, memberLineOf, mongoClientImage, monotonicAt, monotonicOf, namesGroup, nodeClientImage, nodeCommand, nodeHttpImage, nodeIdOf, nodeLineOf, nodeNameOf, nodesOnMonotonic, noiseOf, npmDrift, npmVersions, numbersOf, onMonotonic, openClusterLab, openDiskLab, openFabric, openGroupLab, openKafkaLab, openLab, openReplicaSetLab, openStandby, pairArgs, pairOnce, pairingOf, pairingsOf, pauseReady, peersOf, pgClientImage, pingsOf, plainOf, planOf, pongsOf, poolOf, programLines, programOf, quantileOf, readCpu, readHost, readOplog, reconnectFinding, reconnectOf, recordProblems, recoveryFindings, recoveryOf, referenceOf, reorderingOf, replicaSetArgs, replicaSetOnce, replicaSetStagesOf, requestOf, requestWords, restamped, roomNeeded, roomVoidOf, routeLine, routerImage, routesOf, runCell, runDiskFault, seedScript, sentinelConfig, sessionsOf, shippedClientRecord, shippedSource, sliceQuery, socketAt, socketOf, socketsOf, spread, spreadOf, stagesOf, standaloneCommand, standbyCommand, statusViewOf, stealShare, stepBand, stopScript, streamEnded, streamOf, streamsLoadOf, subjectClient, subjectProblems, subscriptionsOf, substrateHere, substrateKey, substrateOf, substrateOn, targetImageOf, targetSourceOf, templated, toolJsonOf, topicOf, topologyOf, toxicBody, unlockedManifests, unpinnedBases, unpoolable, verdictOf, versionsOf, viewOf, writesOf };
10295
+ export { AWS_FROM, CLIENT_CAPABILITIES, CLIENT_NAMES, CLOSED_TOLERANCE, CLOUDS, CLUSTER_STAGES, CONVERGE_MS, DAEMONS, DEBUG, DIRTY, DISK_MOUNT, DISK_RECORD_FORMAT, DISK_ROOT, DISK_SUBJECT, DROP_HANDLING, FABRIC_CLIENT, FABRIC_DEVICE, FABRIC_TARGET, FRR_IMAGE, GIVES_AWAY, HASH_SCRIPT, INJECT, INSERT, KAFKA_TAIL_MS, KEPT, LAYERS, LAYER_FACTS, LIMITS, LINGER_MS, LISTING, LOAD_FORMAT, LOAD_PATH, LOCK_NAMES, LOSS_MARGIN, MEMBER_MARKS, MONITOR_DOWN, NODE_MARKS, NOISE, PINNED, PUMP, PUMP_SLACK, QUIET_MS, RELATIVE, REPLICA_SET_STAGES, REPOSITORY, RESOURCES_EVENT, RESOURCES_PROGRAM, RESTART, ROUTERS, SCHEDULE_PATH, SEED_DOCUMENT, SHIPPED_CLIENTS, SHIPPED_NAMES, STAGES, STANDBY_READY, STATUS_SCRIPT, STEPS, STEP_DOWN, amqpClientImage, basesOf, bootstrapOf, brokerEnv, buildOf, buildRecordOf, callOf, cancelsOf, cargoVersions, cgroupKeyed, cgroupLimit, cgroupNumber, clockOffsetOf, closeOrExit, cloudOf, clusterArgs, clusterConf, clusterCutOf, clusterHostsOf, clusterOnce, clusterStagesOf, clusterViewOf, commitProblems, commitVoid, comparable, controllerEnv, cpuMaxOf, cpuStatOf, crossingsOf, cutOf, deadlineOf, delayVoids, deliveryFinding, deliveryOf, deviceOf, diskRecordProblems, diskSubjectProblems, drillOnce, drillSpan, dropFinding, dropOf, endpointAfter, envOf, environmentCounts, environmentProblems, errorsOf, estimateOf, estimateVerdict, exitOf, fieldOf, fieldsOf, firstUnanswered, folderDigest, frrConf, goHttpImage, goVersions, groupOnce, groupVerdictOf, grpcClientImage, harnessImage, harnessRecord, harnessVersion, hashOf, highestHeld, hikariClientImage, hostLimitsOf, hzOf, imageOf, imagePinProblems, imageProblems, inContext, infoOf, initiateScript, isFenceLine, isHopPlace, jarVersions, jitterOf, jitterOfLines, judge, kafkaArgs, kafkaClientImage, kafkaCutOf, kafkaOnce, kafkaPauseOnce, kafkaViewOf, lagsOf, laterMove, latestEndOf, layerOf, leafLacks, leftAfter, limitsOf, limitsProblems, loadOf, loadPlanOf, loadVerdict, locksOf, logNameOf, logTimeOf, manifestProblems, matches, measure, measureConntrack, measureDriver, measureEgress, measureGroup, measureMemory, measurePause, measurePorts, measureQueue, medianInterval, memAvailableOf, memberCommand, memberConfig, memberLineOf, memoryStatOf, mongoClientImage, monotonicAt, monotonicOf, namesGroup, networkOf, nodeClientImage, nodeCommand, nodeHttpImage, nodeIdOf, nodeLineOf, nodeNameOf, nodesOnMonotonic, noiseOf, npmDrift, npmVersions, numbersOf, onMonotonic, openClusterLab, openDiskLab, openFabric, openGroupLab, openKafkaLab, openLab, openReplicaSetLab, openStandby, pairArgs, pairOnce, pairingOf, pairingsOf, pauseReady, peersOf, pgClientImage, pingsOf, plainOf, planOf, pongsOf, poolOf, programLines, programOf, quantileOf, readCpu, readHost, readOplog, reconnectFinding, reconnectOf, recordProblems, recoveryFindings, recoveryOf, referenceOf, reorderingOf, replicaSetArgs, replicaSetOnce, replicaSetStagesOf, requestOf, requestWords, resourceArgs, resourceChange, resourceReader, resourceReadingIn, resourceReadingOf, restamped, roomNeeded, roomVoidOf, routeLine, routerImage, routesOf, runCell, runDiskFault, seedScript, sentinelConfig, sessionsOf, shippedClientRecord, shippedSource, sliceQuery, socketAt, socketOf, socketsOf, spread, spreadOf, stagesOf, standaloneCommand, standbyCommand, statusViewOf, stealShare, stepBand, stopScript, streamEnded, streamOf, streamsLoadOf, subjectClient, subjectProblems, subscriptionsOf, substrateHere, substrateKey, substrateOf, substrateOn, targetImageOf, targetSourceOf, templated, toolJsonOf, topicOf, topologyOf, toxicBody, unlockedManifests, unpinnedBases, unpoolable, verdictOf, versionsOf, viewOf, writesOf };
9908
10296
 
9909
10297
  //# sourceMappingURL=index.js.map