@mark1russell7/harness 0.16.17 → 0.16.18

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
@@ -1,4 +1,4 @@
1
- import { A as targetSourceOf, B as versionsOf, C as programOf, D as subjectClient, E as sources, F as goVersions, G as requestFirst, H as environmentProblems, I as jarVersions, L as locksOf, M as unpinnedBases, N as LOCK_NAMES, O as subjectProblems, P as cargoVersions, R as npmDrift, S as planOf, T as shippedSource, U as isHopPlace, V as CLIENT_CAPABILITIES, W as latestEndOf, _ as kafkaClientImage, a as SHIPPED_NAMES, b as nodeHttpImage, c as buildRecordOf, d as harnessImage, f as harnessVersion, g as inContext, h as imageProblems, i as SHIPPED_CLIENTS, j as unlockedManifests, k as targetImageOf, l as goHttpImage, m as imageOf, n as PINNED, o as amqpClientImage, p as hikariClientImage, r as REPOSITORY, s as basesOf, t as CLIENT_NAMES, u as grpcClientImage, v as mongoClientImage, w as routerImage, x as pgClientImage, y as nodeClientImage, z as npmVersions } from "./image-BE9H5gIv.js";
1
+ import { $ as hostLimitsOf, A as targetSourceOf, B as versionsOf, C as programOf, D as subjectClient, E as sources, F as goVersions, G as requestFirst, H as environmentProblems, I as jarVersions, J as cgroupKeyed, K as RESOURCES_EVENT, L as locksOf, M as unpinnedBases, N as LOCK_NAMES, O as subjectProblems, P as cargoVersions, Q as cpuStatOf, R as npmDrift, S as planOf, T as shippedSource, U as isHopPlace, V as CLIENT_CAPABILITIES, W as latestEndOf, X as cgroupNumber, Y as cgroupLimit, Z as cpuMaxOf, _ as kafkaClientImage, a as SHIPPED_NAMES, at as resourceReadingIn, b as nodeHttpImage, c as buildRecordOf, d as harnessImage, et as limitsProblems, f as harnessVersion, g as inContext, h as imageProblems, i as SHIPPED_CLIENTS, it as resourceChange, j as unlockedManifests, k as targetImageOf, l as goHttpImage, m as imageOf, n as PINNED, nt as networkOf, o as amqpClientImage, ot as resourceReadingOf, p as hikariClientImage, q as RESOURCES_PROGRAM, r as REPOSITORY, rt as resourceArgs, s as basesOf, t as CLIENT_NAMES, tt as memoryStatOf, u as grpcClientImage, v as mongoClientImage, w as routerImage, x as pgClientImage, y as nodeClientImage, z as npmVersions } from "./image-CjrmLPA7.js";
2
2
  import { LAYERS, LAYER_FACTS, LIMITS, layerOf, limitsOf } from "./layers.js";
3
3
  import { quantity, valueIn } from "@mark1russell7/quantity";
4
4
  import { median, medianInterval as medianInterval$1, quantile, quantileSorted } from "@mark1russell7/rigor-statistics";
@@ -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$2 = (lines, match) => lines.filter((line) => matches(line, match)).length;
1158
+ const countOf$1 = (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$2(lines, each.match);
1162
+ const seen = countOf$1(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$1 = (value, field) => {
2069
+ const countOf = (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$1(stats?.["after"], field) ?? 0) - (countOf$1(stats?.["before"], field) ?? 0);
2150
+ const rise = (field) => (countOf(stats?.["after"], field) ?? 0) - (countOf(stats?.["before"], field) ?? 0);
2151
2151
  const egress = {
2152
2152
  kind,
2153
2153
  packets,
@@ -3819,337 +3819,6 @@ 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
- };
4153
3822
  // src/fabric.ts
4154
3823
  /**
4155
3824
  * A fabric is a routed network between the client and the target, on layer E3 (docs/S7.md). Four
@@ -9694,7 +9363,7 @@ const LINES_MS = 5e3;
9694
9363
  */
9695
9364
  const linesCounted = async (lab, from, counts) => {
9696
9365
  const started = Date.now();
9697
- const short = () => counts.some((each) => countOf$2(lab.server.slice(from), each.match) < each.count);
9366
+ const short = () => counts.some((each) => countOf$1(lab.server.slice(from), each.match) < each.count);
9698
9367
  while (short() && Date.now() - started < LINES_MS) await setTimeout$1(20);
9699
9368
  await setTimeout$1(250);
9700
9369
  };
@@ -9735,7 +9404,7 @@ const once = async (lab, cell, environment, index, dry = false) => {
9735
9404
  content: load.content,
9736
9405
  target: LOAD_PATH
9737
9406
  }]];
9738
- const probe = await lab.probe(probeArgs(cell, lab), files.length === 0 ? void 0 : files, cell.cgroup);
9407
+ const probe = await lab.probe(probeArgs(cell, lab), files.length === 0 ? void 0 : files, cell.cgroup, cell.clientLimits);
9739
9408
  const server = cell.observer === "server";
9740
9409
  const peer = server ? {
9741
9410
  freeze: () => probe.freeze(),
@@ -9773,8 +9442,15 @@ const once = async (lab, cell, environment, index, dry = false) => {
9773
9442
  let heal = null;
9774
9443
  const signalled = !server && cell.target.program !== void 0;
9775
9444
  let thawing = null;
9445
+ let reader;
9446
+ let start;
9447
+ let end;
9776
9448
  try {
9777
9449
  await probe.until(["ready"], 15e3);
9450
+ if (cell.resources !== void 0) {
9451
+ reader = await lab.resources(cell.resources);
9452
+ start = await reader.read();
9453
+ }
9778
9454
  if (dry) {
9779
9455
  if (cell.probe.mode !== "idle") await go();
9780
9456
  await setTimeout$1(500);
@@ -9983,8 +9659,10 @@ const once = async (lab, cell, environment, index, dry = false) => {
9983
9659
  await setTimeout$1(TAIL_MS);
9984
9660
  }
9985
9661
  }
9662
+ if (reader !== void 0) end = await reader.read();
9986
9663
  } finally {
9987
9664
  await probe.stop();
9665
+ await reader?.stop();
9988
9666
  }
9989
9667
  const settled = await lab.settle();
9990
9668
  const lost = settled === null ? null : settled - lostBefore;
@@ -10007,6 +9685,11 @@ const once = async (lab, cell, environment, index, dry = false) => {
10007
9685
  before: sessions,
10008
9686
  after: await lab.fabric.sessions()
10009
9687
  }
9688
+ } },
9689
+ ...reader === void 0 || start === void 0 || end === void 0 ? {} : { resources: {
9690
+ start,
9691
+ end,
9692
+ series: [...reader.series]
10010
9693
  } }
10011
9694
  };
10012
9695
  };