@rocket.chat/houston 0.27.0-next.2 → 2.1.8
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/LICENSE +1 -1
- package/README.md +108 -15
- package/bin/houston +62 -0
- package/data/docs/ARCHITECTURE.md +387 -0
- package/data/docs/automation.md +107 -0
- package/data/docs/e2ee.md +76 -0
- package/data/docs/eks.md +258 -0
- package/data/docs/gui.md +282 -0
- package/data/docs/guide.md +669 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/troubleshooting.md +193 -0
- package/data/docs/upgrading.md +84 -0
- package/data/docs/voice.md +253 -0
- package/data/iam/engineer-policy.json +11 -0
- package/data/iam/engineer-rbac.yaml +42 -0
- package/data/iam/operator-policy.json +211 -0
- package/data/loadtest/badbot.js +22 -0
- package/data/loadtest/common.js +168 -0
- package/data/loadtest/custom.js +20 -0
- package/data/loadtest/journey.js +58 -0
- package/data/loadtest/login.js +18 -0
- package/data/loadtest/messages.js +13 -0
- package/data/loadtest/mixed.js +39 -0
- package/data/loadtest/read.js +12 -0
- package/data/loadtest/webhook.js +20 -0
- package/data/monitoring/houston-logs.json +98 -0
- package/data/monitoring/k6-loadtest.json +610 -0
- package/data/monitoring/mongodb-exporter.json +3007 -0
- package/data/monitoring/node-exporter-full.json +16114 -0
- package/data/monitoring/rocketchat-metrics.json +6471 -0
- package/data/presets/airgapped.yaml +16 -0
- package/data/presets/default.yaml +9 -0
- package/data/seed/avatar-0.png +0 -0
- package/data/seed/avatar-1.png +0 -0
- package/data/seed/avatar-2.png +0 -0
- package/data/seed/avatar-3.png +0 -0
- package/data/seed/avatar-4.png +0 -0
- package/data/seed/avatar-5.png +0 -0
- package/data/seed/avatar-6.png +0 -0
- package/data/seed/avatar-7.png +0 -0
- package/data/seed/seed-metrics.csv +3 -0
- package/data/seed/seed-preview.png +0 -0
- package/data/seed/seed-report.pdf +32 -0
- package/data/seed/seed-runbook.txt +3 -0
- package/data/skill/SKILL.md +399 -0
- package/data/versions.yaml +55 -0
- package/data/voice/freeswitch/drachtio.xml +52 -0
- package/data/voice/freeswitch/public.xml +87 -0
- package/data/webui/app.css +2003 -0
- package/data/webui/index.html +678 -0
- package/data/webui/js/api.js +561 -0
- package/data/webui/js/boot.js +44 -0
- package/data/webui/js/clusters-tail.js +1377 -0
- package/data/webui/js/clusters.js +896 -0
- package/data/webui/js/create.js +276 -0
- package/data/webui/js/detail.js +507 -0
- package/data/webui/js/jobs.js +636 -0
- package/data/webui/js/logs.js +634 -0
- package/data/webui/js/main.js +14 -0
- package/data/webui/js/options.js +408 -0
- package/data/webui/js/people.js +438 -0
- package/data/webui/js/perf.js +303 -0
- package/data/webui/js/render.js +438 -0
- package/data/webui/js/shared.js +3 -0
- package/data/webui/js/state.js +583 -0
- package/data/webui/js/theme.js +123 -0
- package/data/webui/js/util.js +584 -0
- package/dist/cli/app.js +593 -0
- package/dist/cli/capabilities.js +76 -0
- package/dist/cli/cell-widths.js +495 -0
- package/dist/cli/entry.js +10 -0
- package/dist/cli/error-panel.js +492 -0
- package/dist/cli/handlers/actor.js +84 -0
- package/dist/cli/handlers/https.js +614 -0
- package/dist/cli/handlers/prompt.js +299 -0
- package/dist/cli/handlers/users.js +226 -0
- package/dist/cli/handlers.js +3678 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +810 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2593 -0
- package/dist/cli/spec-types.js +8 -0
- package/dist/cli/usage-error.js +520 -0
- package/dist/cli/wire.js +70 -0
- package/dist/core/audit.js +346 -0
- package/dist/core/backup-compat.js +85 -0
- package/dist/core/backup.js +1639 -0
- package/dist/core/cluster.js +1398 -0
- package/dist/core/configimport.js +344 -0
- package/dist/core/data.js +267 -0
- package/dist/core/database-of.js +82 -0
- package/dist/core/diagnose.js +159 -0
- package/dist/core/doctor.js +1518 -0
- package/dist/core/edge/acme.js +338 -0
- package/dist/core/edge/engine.js +500 -0
- package/dist/core/edge/networks.js +174 -0
- package/dist/core/edge/paths.js +107 -0
- package/dist/core/edge/routes.js +251 -0
- package/dist/core/edge/routeyml.js +195 -0
- package/dist/core/edge/runtime.js +493 -0
- package/dist/core/edge/spec.js +305 -0
- package/dist/core/edge/types.js +202 -0
- package/dist/core/eks-docs.js +135 -0
- package/dist/core/eks.js +2240 -0
- package/dist/core/envvars.js +562 -0
- package/dist/core/eventlog.js +541 -0
- package/dist/core/firstrun.js +153 -0
- package/dist/core/journal.js +691 -0
- package/dist/core/kube/ask.js +231 -0
- package/dist/core/kube/capabilities.js +269 -0
- package/dist/core/kube/certmanager.js +452 -0
- package/dist/core/kube/chart.js +413 -0
- package/dist/core/kube/cluster.js +196 -0
- package/dist/core/kube/context.js +545 -0
- package/dist/core/kube/endpoints.js +448 -0
- package/dist/core/kube/exec.js +195 -0
- package/dist/core/kube/forward.js +732 -0
- package/dist/core/kube/grafana-ingress.js +110 -0
- package/dist/core/kube/ingress.js +218 -0
- package/dist/core/kube/manifests.js +361 -0
- package/dist/core/kube/monitoring.js +768 -0
- package/dist/core/kube/names.js +237 -0
- package/dist/core/kube/namespace.js +678 -0
- package/dist/core/kube/operator.js +941 -0
- package/dist/core/kube/probe.js +202 -0
- package/dist/core/kube/reachability.js +163 -0
- package/dist/core/kube/release.js +439 -0
- package/dist/core/kube/replicaset.js +180 -0
- package/dist/core/kube/scale.js +398 -0
- package/dist/core/kube/status.js +633 -0
- package/dist/core/kube/tools.js +238 -0
- package/dist/core/kube/transfer.js +173 -0
- package/dist/core/kube/workspace.js +423 -0
- package/dist/core/lifecycle/admin.js +64 -0
- package/dist/core/lifecycle/create-docker.js +1533 -0
- package/dist/core/lifecycle/create-k8s.js +939 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +635 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +726 -0
- package/dist/core/lifecycle/ownership.js +313 -0
- package/dist/core/lifecycle/payload.js +401 -0
- package/dist/core/lifecycle/ports.js +388 -0
- package/dist/core/lifecycle/preconditions.js +367 -0
- package/dist/core/lifecycle/pruning.js +551 -0
- package/dist/core/lifecycle/ready.js +753 -0
- package/dist/core/lifecycle/request.js +525 -0
- package/dist/core/lifecycle/seeding.js +281 -0
- package/dist/core/lifecycle/sizing.js +392 -0
- package/dist/core/lifecycle/state.js +286 -0
- package/dist/core/lifecycle/tlsplan.js +704 -0
- package/dist/core/lifecycle/types.js +232 -0
- package/dist/core/loadtest.js +995 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +969 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1285 -0
- package/dist/core/recovery.js +75 -0
- package/dist/core/runner/engine.js +394 -0
- package/dist/core/runner/host.js +298 -0
- package/dist/core/runner/locks.js +129 -0
- package/dist/core/runner/paths.js +173 -0
- package/dist/core/runner/ports.js +172 -0
- package/dist/core/runner/queries.js +612 -0
- package/dist/core/runner/record.js +563 -0
- package/dist/core/scaleseed.js +271 -0
- package/dist/core/seed-db.js +208 -0
- package/dist/core/sessions.js +472 -0
- package/dist/core/skill.js +326 -0
- package/dist/core/sso-identities.js +172 -0
- package/dist/core/sso.js +703 -0
- package/dist/core/tls-local.js +311 -0
- package/dist/core/tls.js +878 -0
- package/dist/core/topology.js +482 -0
- package/dist/core/upgrade.js +868 -0
- package/dist/core/users.js +739 -0
- package/dist/lib/audit.js +100 -0
- package/dist/lib/close-matches.js +238 -0
- package/dist/lib/compose.js +672 -0
- package/dist/lib/config.js +1398 -0
- package/dist/lib/context.js +18 -0
- package/dist/lib/errors.js +305 -0
- package/dist/lib/events.js +208 -0
- package/dist/lib/float-text.js +126 -0
- package/dist/lib/format.js +1320 -0
- package/dist/lib/home.js +325 -0
- package/dist/lib/journal.js +122 -0
- package/dist/lib/json-text.js +733 -0
- package/dist/lib/jsonout.js +382 -0
- package/dist/lib/lock.js +516 -0
- package/dist/lib/login-name.js +202 -0
- package/dist/lib/map-limit.js +29 -0
- package/dist/lib/mkdir-parents.js +90 -0
- package/dist/lib/mongo-kernel.js +67 -0
- package/dist/lib/monitoring.js +492 -0
- package/dist/lib/platform-name.js +59 -0
- package/dist/lib/presets/common.js +390 -0
- package/dist/lib/presets/composite.js +326 -0
- package/dist/lib/presets/e2ee.js +143 -0
- package/dist/lib/presets/email.js +172 -0
- package/dist/lib/presets/guides.js +27 -0
- package/dist/lib/presets/index.js +490 -0
- package/dist/lib/presets/keycloak.js +369 -0
- package/dist/lib/presets/ldap.js +1285 -0
- package/dist/lib/presets/livechat.js +220 -0
- package/dist/lib/presets/multi-instance.js +124 -0
- package/dist/lib/presets/oidc.js +161 -0
- package/dist/lib/presets/public.js +496 -0
- package/dist/lib/presets/registry.js +64 -0
- package/dist/lib/presets/s3-minio.js +300 -0
- package/dist/lib/presets/saml.js +149 -0
- package/dist/lib/presets/scenario.js +51 -0
- package/dist/lib/presets/types.js +86 -0
- package/dist/lib/presets/voice-pbx.js +320 -0
- package/dist/lib/presets/voice.js +345 -0
- package/dist/lib/presets/webhooks.js +182 -0
- package/dist/lib/redact.js +106 -0
- package/dist/lib/seed-options.js +68 -0
- package/dist/lib/seed-profiles.js +59 -0
- package/dist/lib/targz.js +1383 -0
- package/dist/lib/teammode.js +25 -0
- package/dist/lib/tempdir.js +162 -0
- package/dist/lib/unicode-tables.js +2335 -0
- package/dist/lib/version-spec.js +357 -0
- package/dist/lib/versions.js +463 -0
- package/dist/lib/yaml-dump.js +1361 -0
- package/dist/perf/baseline.js +168 -0
- package/dist/perf/constrain.js +296 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +178 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +224 -0
- package/dist/perf/slo.js +111 -0
- package/dist/perf/timeline.js +187 -0
- package/dist/perf/timings.js +85 -0
- package/dist/perf/verdict.js +201 -0
- package/dist/seams/aws-cli.js +126 -0
- package/dist/seams/docker-cli.js +280 -0
- package/dist/seams/exec.js +861 -0
- package/dist/seams/fs/lock.js +528 -0
- package/dist/seams/kubectl.js +83 -0
- package/dist/seams/rc-http.js +921 -0
- package/dist/seed/apply.js +190 -0
- package/dist/seed/assets.js +76 -0
- package/dist/seed/check.js +391 -0
- package/dist/seed/client.js +172 -0
- package/dist/seed/executor.js +726 -0
- package/dist/seed/history.js +281 -0
- package/dist/seed/kinds.js +91 -0
- package/dist/seed/plan.js +432 -0
- package/dist/seed/receipt.js +339 -0
- package/dist/seed/repairs.js +75 -0
- package/dist/seed/verification.js +363 -0
- package/dist/seed/wording.js +248 -0
- package/dist/web/app.js +326 -0
- package/dist/web/jobs.js +510 -0
- package/dist/web/route-deps.js +211 -0
- package/dist/web/route-table.js +213 -0
- package/dist/web/routes/backup.js +244 -0
- package/dist/web/routes/clusters.js +303 -0
- package/dist/web/routes/data.js +187 -0
- package/dist/web/routes/edge.js +82 -0
- package/dist/web/routes/index.js +63 -0
- package/dist/web/routes/jobs.js +95 -0
- package/dist/web/routes/logs.js +297 -0
- package/dist/web/routes/meta.js +191 -0
- package/dist/web/routes/people.js +151 -0
- package/dist/web/routes/perf.js +95 -0
- package/dist/web/routes/repros.js +550 -0
- package/dist/web/routes/session.js +361 -0
- package/dist/web/routes/spa.js +198 -0
- package/dist/web/security.js +475 -0
- package/dist/web/signin.js +246 -0
- package/package.json +67 -32
- package/.eslintrc +0 -94
- package/.swcrc +0 -18
- package/dist/bin.js +0 -3
- package/dist/cli.js +0 -184
- package/dist/commands/createBranch.js +0 -192
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -25
- package/src-old/logs.js +0 -323
- package/src-old/md.js +0 -191
- package/src-old/release-table.js +0 -60
- package/src-old/set-version.js +0 -614
- package/src-old/utils.js +0 -15
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.statusBreakdown = statusBreakdown;
|
|
37
|
+
exports.cell = cell;
|
|
38
|
+
exports.loadtestMarkdown = loadtestMarkdown;
|
|
39
|
+
exports.writeLoadtest = writeLoadtest;
|
|
40
|
+
exports.writeCapacity = writeCapacity;
|
|
41
|
+
/**
|
|
42
|
+
* Render performance results -- a console summary table and a detailed shareable markdown
|
|
43
|
+
* report.
|
|
44
|
+
*
|
|
45
|
+
* EVERY NUMBER HERE IS A FORMAT STRING, so all of them go through `lib/format`: `{:.0f}`
|
|
46
|
+
* and `{:.1f}` are round-half-to-even, `{:.2%}` multiplies by a hundred first and then
|
|
47
|
+
* applies the same tie rule, and `{:+.0f}` always shows a sign -- a bare `0` in a delta
|
|
48
|
+
* column would read as "not measured" rather than "no meaningful change".
|
|
49
|
+
*/
|
|
50
|
+
const fs = __importStar(require("node:fs"));
|
|
51
|
+
const path = __importStar(require("node:path"));
|
|
52
|
+
const config = __importStar(require("../lib/config"));
|
|
53
|
+
const home_1 = require("../lib/home");
|
|
54
|
+
const format_1 = require("../lib/format");
|
|
55
|
+
const baseline_1 = require("./baseline");
|
|
56
|
+
const slo_1 = require("./slo");
|
|
57
|
+
const timings_1 = require("./timings");
|
|
58
|
+
const SCENARIO_DESC = Object.freeze({
|
|
59
|
+
messages: 'POST `chat.postMessage` to `#general` — the write path.',
|
|
60
|
+
login: 'POST `/api/v1/login` repeatedly — auth throughput.',
|
|
61
|
+
read: 'GET `channels.history` — the read path.',
|
|
62
|
+
mixed: '60% reads, 30% posts, 10% logins — a realistic blend.',
|
|
63
|
+
journey: 'a full user session per iteration — login → rooms → open → post → sync, each step timed.',
|
|
64
|
+
webhook: 'POST through a real incoming-webhook integration — an alert-storm write path.',
|
|
65
|
+
badbot: 'a badly-written client: tight unpaginated polling of history/users.list/channels.list.',
|
|
66
|
+
custom: 'a caller-supplied endpoint.',
|
|
67
|
+
});
|
|
68
|
+
function asBag(value) {
|
|
69
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* The established truthiness of a value read out of an untyped bag.
|
|
73
|
+
*
|
|
74
|
+
* False for null, false, 0, '', [] and {} alike -- which is what every presence test on a
|
|
75
|
+
* summary key means, and what a bare JavaScript truthiness test gets wrong for an empty
|
|
76
|
+
* array or object.
|
|
77
|
+
*/
|
|
78
|
+
function truthy(value) {
|
|
79
|
+
if (value === null || value === undefined || value === false)
|
|
80
|
+
return false;
|
|
81
|
+
if (value === 0 || value === '')
|
|
82
|
+
return false;
|
|
83
|
+
if (Array.isArray(value))
|
|
84
|
+
return value.length > 0;
|
|
85
|
+
if (typeof value === 'object')
|
|
86
|
+
return Object.keys(value).length > 0;
|
|
87
|
+
return Boolean(value);
|
|
88
|
+
}
|
|
89
|
+
function num(value, fallback = 0) {
|
|
90
|
+
if (value === null || value === undefined)
|
|
91
|
+
return fallback;
|
|
92
|
+
const parsed = Number(value);
|
|
93
|
+
return Number.isNaN(parsed) ? fallback : parsed;
|
|
94
|
+
}
|
|
95
|
+
/** `'2xx 1158 · 429 61 · 5xx 41'` from the summary's status buckets (non-zero only). */
|
|
96
|
+
function statusBreakdown(summary) {
|
|
97
|
+
const st = asBag(summary.status);
|
|
98
|
+
const order = ['2xx', '429', '4xx', '5xx', 'other'];
|
|
99
|
+
return order
|
|
100
|
+
.filter((k) => num(st[k]) !== 0)
|
|
101
|
+
.map((k) => `${k} ${String(Math.trunc(num(st[k])))}`)
|
|
102
|
+
.join(' · ');
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* One metric cell, or `'-'` when the metric is ABSENT.
|
|
106
|
+
*
|
|
107
|
+
* A run that issued no requests emits no latency or checks keys at all, so a `?? 0` would
|
|
108
|
+
* render "not measured" as a confident 0ms / 0%.
|
|
109
|
+
*/
|
|
110
|
+
function cell(summary, key, render = (v) => `${(0, format_1.formatFixed)(v, 0)}ms`, bold = false) {
|
|
111
|
+
const v = summary[key];
|
|
112
|
+
if (v === null || v === undefined)
|
|
113
|
+
return '-';
|
|
114
|
+
const s = render(Number(v));
|
|
115
|
+
return bold ? `**${s}**` : s;
|
|
116
|
+
}
|
|
117
|
+
/** Whether the SLO held, and what the containers cost while it did. */
|
|
118
|
+
function reportGates(lines, resources, sloResults) {
|
|
119
|
+
if (sloResults !== null && sloResults.length > 0) {
|
|
120
|
+
const passed = sloResults.every((r) => truthy(r.ok));
|
|
121
|
+
lines.push(`## SLO gate — ${passed ? 'PASS' : 'FAIL'}`, '', '| rule | threshold | actual | result |', '|---|---|---|---|');
|
|
122
|
+
for (const r of sloResults) {
|
|
123
|
+
const mark = truthy(r.ok) ? 'PASS' : 'FAIL';
|
|
124
|
+
const actual = r.measured === false ? 'not measured' : (0, slo_1.fmtActual)(String(r.key), num(r.actual));
|
|
125
|
+
lines.push(`| ${String(r.key)} | ${String(r.op)} ${String(r.raw)} | ${actual} | ${mark} |`);
|
|
126
|
+
}
|
|
127
|
+
lines.push('');
|
|
128
|
+
}
|
|
129
|
+
const res = asBag(resources);
|
|
130
|
+
if (Object.keys(res).length > 0) {
|
|
131
|
+
lines.push('## Resource cost during the test', '', '| container | idle CPU | peak CPU | peak RAM | mem limit |', '|---|---|---|---|---|');
|
|
132
|
+
for (const cname of Object.keys(res).sort()) {
|
|
133
|
+
const rr = asBag(res[cname]);
|
|
134
|
+
lines.push(`| ${cname} | ${(0, format_1.formatFixed)(num(rr.idle_cpu), 0)}% | ` +
|
|
135
|
+
`${(0, format_1.formatFixed)(num(rr.peak_cpu), 0)}% | ` +
|
|
136
|
+
`${(0, format_1.formatFixed)(num(rr.peak_mem) / 1e6, 0)}MB | ` +
|
|
137
|
+
`${(0, format_1.formatFixed)(num(rr.limit_mem) / 1e6, 0)}MB |`);
|
|
138
|
+
}
|
|
139
|
+
lines.push('');
|
|
140
|
+
}
|
|
141
|
+
return lines;
|
|
142
|
+
}
|
|
143
|
+
/** Rocket.Chat's own metrics, Mongo's slow queries, and the comparison with a baseline. */
|
|
144
|
+
function reportDiagnosis(compare, diag, lines) {
|
|
145
|
+
const d = asBag(diag);
|
|
146
|
+
const rcm = asBag(d.rcmetrics);
|
|
147
|
+
if (Object.keys(rcm).length > 0) {
|
|
148
|
+
lines.push('## RC internals during the test', '', '| instance | event-loop lag peak | lag p99 | heap peak | ddp users |', '|---|---|---|---|---|');
|
|
149
|
+
for (const svc of Object.keys(rcm).sort()) {
|
|
150
|
+
const m = asBag(rcm[svc]);
|
|
151
|
+
const peak = asBag(m.eventloop_lag_max_s ?? m.eventloop_lag_s);
|
|
152
|
+
const p99 = asBag(m.eventloop_lag_p99_s);
|
|
153
|
+
const heap = asBag(m.heap_used_bytes);
|
|
154
|
+
const ddp = asBag(m.ddp_users);
|
|
155
|
+
const peakS = Object.keys(peak).length > 0 ? (0, timings_1.fmtMs)(num(peak.max) * 1000) : '-';
|
|
156
|
+
const p99S = Object.keys(p99).length > 0 ? (0, timings_1.fmtMs)(num(p99.max) * 1000) : '-';
|
|
157
|
+
const heapS = Object.keys(heap).length > 0 ? `${(0, format_1.formatFixed)(num(heap.max) / 1e6, 0)}MB` : '-';
|
|
158
|
+
const ddpS = Object.keys(ddp).length > 0 ? (0, format_1.formatFixed)(num(ddp.max), 0) : '-';
|
|
159
|
+
lines.push(`| ${svc} | ${peakS} | ${p99S} | ${heapS} | ${ddpS} |`);
|
|
160
|
+
}
|
|
161
|
+
lines.push('', '> Event-loop lag is the Node saturation signal: once the loop lags, every request ' +
|
|
162
|
+
'queues behind it.', '');
|
|
163
|
+
}
|
|
164
|
+
const mg = asBag(d.mongo);
|
|
165
|
+
const slow = Array.isArray(mg.slow) ? mg.slow : [];
|
|
166
|
+
if (Object.keys(mg).length > 0 && (slow.length > 0 || num(mg.total) !== 0)) {
|
|
167
|
+
lines.push(`## Slow MongoDB queries (${String(mg.total ?? 0)} profiled, ` +
|
|
168
|
+
`${String(mg.collscan ?? 0)} COLLSCAN)`, '');
|
|
169
|
+
if (slow.length > 0) {
|
|
170
|
+
lines.push('| time | namespace | op | plan | docs examined | returned |', '|---|---|---|---|---|---|');
|
|
171
|
+
for (const s of slow) {
|
|
172
|
+
lines.push(`| ${(0, timings_1.fmtMs)(num(s.millis))} | ${String(s.ns)} | ${String(s.op)} | ` +
|
|
173
|
+
`${String(s.plan) || '?'} | ${String(s.docs)} | ${String(s.ret)} |`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
lines.push('');
|
|
177
|
+
}
|
|
178
|
+
const cmp = asBag(compare);
|
|
179
|
+
const rows = Array.isArray(cmp.rows) ? cmp.rows : [];
|
|
180
|
+
if (rows.length > 0) {
|
|
181
|
+
lines.push(`## vs baseline \`${String(cmp.label ?? '?')}\` ` +
|
|
182
|
+
`(saved ${String(cmp.saved_at ?? '').slice(0, 19)})`, '', '| metric | baseline | this run | delta | |', '|---|---|---|---|---|');
|
|
183
|
+
for (const r of rows) {
|
|
184
|
+
const metric = String(r.metric);
|
|
185
|
+
const render = metric.includes('rps')
|
|
186
|
+
? (v) => (0, format_1.formatFixed)(v, 1)
|
|
187
|
+
: metric.includes('error')
|
|
188
|
+
? (v) => (0, format_1.formatPercent)(v, 2)
|
|
189
|
+
: (v) => (0, timings_1.fmtMs)(v);
|
|
190
|
+
const flag = truthy(r.flag)
|
|
191
|
+
? '**regression**'
|
|
192
|
+
: !truthy(r.worse) && Math.abs(num(r.pct)) > 25
|
|
193
|
+
? 'improved'
|
|
194
|
+
: '';
|
|
195
|
+
lines.push(`| ${metric} | ${render(num(r.before))} | ${render(num(r.after))} | ` +
|
|
196
|
+
`${(0, format_1.formatSigned)(num(r.pct), 0)}% | ${flag} |`);
|
|
197
|
+
}
|
|
198
|
+
lines.push('');
|
|
199
|
+
}
|
|
200
|
+
return lines;
|
|
201
|
+
}
|
|
202
|
+
/** The responses, the verdict, the steps and the shape of the run over time. */
|
|
203
|
+
function reportWhatHappened(diag, lines, summary) {
|
|
204
|
+
const responses = statusBreakdown(summary);
|
|
205
|
+
if (responses)
|
|
206
|
+
lines.push(`| responses | ${responses} |`);
|
|
207
|
+
lines.push('');
|
|
208
|
+
const d = asBag(diag);
|
|
209
|
+
const verdict = Array.isArray(d.verdict) ? d.verdict : [];
|
|
210
|
+
if (verdict.length > 0) {
|
|
211
|
+
lines.push('## Verdict', '');
|
|
212
|
+
for (const v of verdict)
|
|
213
|
+
lines.push(`- ${v}`);
|
|
214
|
+
lines.push('');
|
|
215
|
+
}
|
|
216
|
+
const steps = asBag(summary.steps);
|
|
217
|
+
if (Object.keys(steps).length > 0) {
|
|
218
|
+
lines.push('## Per-step latency', '', '| step | count | p50 | p95 | p99 |', '|---|---|---|---|---|');
|
|
219
|
+
for (const s of (0, baseline_1.stepOrder)(steps)) {
|
|
220
|
+
const v = asBag(steps[s]);
|
|
221
|
+
lines.push(`| ${s} | ${(0, format_1.formatFixed)(num(v.count), 0)} | ${(0, timings_1.fmtMs)(num(v.p50))} | ` +
|
|
222
|
+
`${(0, timings_1.fmtMs)(num(v.p95))} | ${(0, timings_1.fmtMs)(num(v.p99))} |`);
|
|
223
|
+
}
|
|
224
|
+
lines.push('');
|
|
225
|
+
}
|
|
226
|
+
const tl = asBag(d.timeline);
|
|
227
|
+
if (Object.keys(tl).length > 0) {
|
|
228
|
+
lines.push(`## Latency over time (${String(tl.width_s)}s buckets)`, '', '| t | reqs | p50 | p95 | max | errors |', '|---|---|---|---|---|---|');
|
|
229
|
+
for (const raw of (Array.isArray(tl.buckets) ? tl.buckets : [])) {
|
|
230
|
+
const b = asBag(raw);
|
|
231
|
+
lines.push(`| ${String(b.t0)}s | ${String(b.reqs)} | ${(0, timings_1.fmtMs)(num(b.p50))} | ` +
|
|
232
|
+
`${(0, timings_1.fmtMs)(num(b.p95))} | ${(0, timings_1.fmtMs)(num(b.max))} | ${truthy(b.errors) ? String(b.errors) : ''} |`);
|
|
233
|
+
}
|
|
234
|
+
if (tl.first_error_s !== null && tl.first_error_s !== undefined) {
|
|
235
|
+
lines.push('');
|
|
236
|
+
lines.push(`> Errors began ~${String(tl.first_error_s)}s into the run.`);
|
|
237
|
+
}
|
|
238
|
+
lines.push('');
|
|
239
|
+
}
|
|
240
|
+
const sp = asBag(d.spike);
|
|
241
|
+
if (Object.keys(sp).length > 0) {
|
|
242
|
+
const rec = sp.recovered_after_s;
|
|
243
|
+
lines.push('## Spike recovery', '', `- baseline p95 ${(0, timings_1.fmtMs)(num(sp.baseline_p95))} → spike p95 ` +
|
|
244
|
+
`${(0, timings_1.fmtMs)(num(sp.spike_p95))} → ` +
|
|
245
|
+
(rec !== null && rec !== undefined
|
|
246
|
+
? `**recovered ~${String(rec)}s** after load dropped`
|
|
247
|
+
: '**did not recover** within the run'), '');
|
|
248
|
+
}
|
|
249
|
+
return lines;
|
|
250
|
+
}
|
|
251
|
+
/** What was run, against what, on what machine. */
|
|
252
|
+
function reportHeader(ctx, host, snapshot, summary, when) {
|
|
253
|
+
// A spike run's `vus` is the value the CLI told the user it was IGNORING, so reporting it
|
|
254
|
+
// labelled the run as a load shape that never happened.
|
|
255
|
+
const load = (truthy(ctx.spike)
|
|
256
|
+
? `spike ${String(ctx.spike)} VUs`
|
|
257
|
+
: truthy(ctx.ramp)
|
|
258
|
+
? `ramp ${String(ctx.ramp)} VUs`
|
|
259
|
+
: `${String(ctx.vus)} VUs`) + ` for ${String(ctx.duration)}`;
|
|
260
|
+
const identity = truthy(ctx.users)
|
|
261
|
+
? `${String(ctx.users)} seeded users (round-robin per VU)`
|
|
262
|
+
: 'the admin token';
|
|
263
|
+
const lines = [
|
|
264
|
+
'# houston load-test report',
|
|
265
|
+
'',
|
|
266
|
+
`- **Generated:** ${when}`,
|
|
267
|
+
`- **Workspace:** \`${String(ctx.name)}\` — Rocket.Chat ${String(ctx.version)}`,
|
|
268
|
+
`- **Host:** ${String(host.os ?? '?')} · ${String(host.cpu ?? '?')} CPUs · ` +
|
|
269
|
+
`Docker ${String(host.docker ?? '?')} · Compose ${String(host.compose ?? '?')}`,
|
|
270
|
+
`- **Scenario:** \`${String(ctx.label ?? ctx.scenario)}\` — ` +
|
|
271
|
+
`${SCENARIO_DESC[String(ctx.scenario)] ?? ''}`,
|
|
272
|
+
`- **Load:** ${load}, as **${identity}**, generated by k6 on the workspace's ` +
|
|
273
|
+
`docker network (target \`${String(ctx.target)}\`)`,
|
|
274
|
+
'',
|
|
275
|
+
'> k6 drives load against the **internal** service address (no host-port round trip). ' +
|
|
276
|
+
'The REST rate limiter is disabled for the run and restored after. Absolute numbers ' +
|
|
277
|
+
'are host-specific; use them to compare runs on the same machine.',
|
|
278
|
+
'',
|
|
279
|
+
];
|
|
280
|
+
const snap = asBag(snapshot);
|
|
281
|
+
if (Object.keys(snap).length > 0) {
|
|
282
|
+
lines.push('## Workspace', '', '| | |', '|---|---|', `| Rocket.Chat | ${String(snap.rc_version ?? '?')} |`, `| preset | ${String(snap.preset ?? '?')} |`, `| RC instances | ${String(snap.instances ?? 1)} |`);
|
|
283
|
+
for (const [k, lbl] of [
|
|
284
|
+
['users', 'users'],
|
|
285
|
+
['rooms', 'rooms'],
|
|
286
|
+
['messages', 'messages'],
|
|
287
|
+
]) {
|
|
288
|
+
if (snap[k] !== null && snap[k] !== undefined) {
|
|
289
|
+
lines.push(`| ${lbl} in workspace | ${String(snap[k])} |`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
if (truthy(snap.constraints)) {
|
|
293
|
+
lines.push(`| **resource caps** | ${String(snap.constraints)} (via docker update, ` +
|
|
294
|
+
'restored after the test) |');
|
|
295
|
+
}
|
|
296
|
+
lines.push('');
|
|
297
|
+
}
|
|
298
|
+
lines.push('## Results', '', '| metric | value |', '|---|---|', `| requests | ${cell(summary, 'count', (v) => (0, format_1.formatFixed)(v, 0))} |`, `| throughput | ${cell(summary, 'rps', (v) => `${(0, format_1.formatFixed)(v, 1)} req/s`, true)} |`, `| latency p50 | ${cell(summary, 'p50')} |`, `| latency p90 | ${cell(summary, 'p90')} |`, `| latency p95 | ${cell(summary, 'p95', undefined, true)} |`, `| latency p99 | ${cell(summary, 'p99')} |`, `| latency avg / min / max | ${cell(summary, 'avg', (v) => (0, format_1.formatFixed)(v, 0))} / ` +
|
|
299
|
+
`${cell(summary, 'min', (v) => (0, format_1.formatFixed)(v, 0))} / ` +
|
|
300
|
+
`${cell(summary, 'max', (v) => (0, format_1.formatFixed)(v, 0))} ms |`, `| error rate | ${cell(summary, 'error_rate', (v) => (0, format_1.formatPercent)(v, 2))} |`, `| checks passed | ${cell(summary, 'checks_rate', (v) => (0, format_1.formatPercent)(v, 1))} |`);
|
|
301
|
+
return lines;
|
|
302
|
+
}
|
|
303
|
+
/** The UTC time to the second, as `YYYY-MM-DDTHH:MM:SS+00:00`. */
|
|
304
|
+
function nowIso() {
|
|
305
|
+
return `${new Date().toISOString().slice(0, 19)}+00:00`;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* Render a shareable load-test report.
|
|
309
|
+
*
|
|
310
|
+
* `ctx` carries the run parameters (repro, version, scenario, vus, duration, ramp, target,
|
|
311
|
+
* users); `snapshot` the workspace context; `compare` an optional baseline diff
|
|
312
|
+
* ({label, saved_at, rows}).
|
|
313
|
+
*/
|
|
314
|
+
function loadtestMarkdown(ctx, summary, sloResults, resources, host, { snapshot = null, compare = null, diag = null } = {}) {
|
|
315
|
+
const when = nowIso();
|
|
316
|
+
let lines = reportHeader(ctx, host, snapshot, summary, when);
|
|
317
|
+
lines = reportWhatHappened(diag, lines, summary);
|
|
318
|
+
lines = reportDiagnosis(compare, diag, lines);
|
|
319
|
+
lines = reportGates(lines, resources, sloResults);
|
|
320
|
+
return lines.join('\n') + '\n';
|
|
321
|
+
}
|
|
322
|
+
function writeLoadtest(ctx, summary, sloResults, resources, host, stamp, dest = null, extras = {}) {
|
|
323
|
+
const filename = `loadtest-${String(ctx.scenario)}-${stamp}.md`;
|
|
324
|
+
const md = loadtestMarkdown(ctx, summary, sloResults, resources, host, extras);
|
|
325
|
+
return write(md, filename, dest);
|
|
326
|
+
}
|
|
327
|
+
/** Shareable markdown for a capacity search. */
|
|
328
|
+
function writeCapacity(ctx, steps, result, why, host, stamp, dest = null) {
|
|
329
|
+
const when = nowIso();
|
|
330
|
+
const lines = [
|
|
331
|
+
'# houston capacity report',
|
|
332
|
+
'',
|
|
333
|
+
`- **Generated:** ${when}`,
|
|
334
|
+
`- **Workspace:** \`${String(ctx.name)}\` — Rocket.Chat ${String(ctx.version)}`,
|
|
335
|
+
`- **Host:** ${String(host.os ?? '?')} · ${String(host.cpu ?? '?')} CPUs · ` +
|
|
336
|
+
`Docker ${String(host.docker ?? '?')} · Compose ${String(host.compose ?? '?')}`,
|
|
337
|
+
`- **Workload:** \`${String(ctx.scenario)}\` as ` +
|
|
338
|
+
`${truthy(ctx.users) ? String(ctx.users) : 'the admin token — no'} seeded users, ` +
|
|
339
|
+
`steps of ${String(ctx.step_duration)} (target \`${String(ctx.target)}\`)`,
|
|
340
|
+
`- **SLO:** \`${String(ctx.slo)}\``,
|
|
341
|
+
];
|
|
342
|
+
if (truthy(ctx.constrained)) {
|
|
343
|
+
lines.push(`- **Resource caps:** ${String(ctx.constrained)} (docker update, restored after)`);
|
|
344
|
+
}
|
|
345
|
+
lines.push('', `## Result — ${result}`, '');
|
|
346
|
+
if (why !== '')
|
|
347
|
+
lines.push(`> ${why}`, '');
|
|
348
|
+
lines.push('| VUs | req/s | p95 | error rate | event-loop lag peak | SLO |', '|---|---|---|---|---|---|');
|
|
349
|
+
for (const s of [...steps].sort((a, b) => num(a.vus) - num(b.vus))) {
|
|
350
|
+
const breached = Array.isArray(s.breached) ? s.breached : [];
|
|
351
|
+
lines.push(`| ${String(s.vus)} | ${(0, format_1.formatFixed)(num(s.rps), 1)} | ${(0, timings_1.fmtMs)(num(s.p95))} | ` +
|
|
352
|
+
`${(0, format_1.formatFixed)(num(s.error_rate) * 100, 2)}% | ` +
|
|
353
|
+
`${(0, timings_1.fmtMs)(num(s.lag_max_s) * 1000)} | ` +
|
|
354
|
+
(truthy(s.ok) ? 'PASS' : `**FAIL** — ${breached.join('; ')}`) +
|
|
355
|
+
' |');
|
|
356
|
+
}
|
|
357
|
+
lines.push('', '> Steps double until the SLO breaks, then bisect between the last pass and first ' +
|
|
358
|
+
'fail. Absolute numbers are host-specific; the shape (where it breaks, and why) is ' +
|
|
359
|
+
'the signal.', '');
|
|
360
|
+
return write(lines.join('\n') + '\n', `capacity-${stamp}.md`, dest);
|
|
361
|
+
}
|
|
362
|
+
/** Write `content`; `dest` may be a file or a directory, default `reportsDir()`. */
|
|
363
|
+
function write(content, filename, dest) {
|
|
364
|
+
let target;
|
|
365
|
+
if (dest !== null && dest !== '') {
|
|
366
|
+
// `dest` with its `~` expanded and joined component by component (`pathExpandUser`):
|
|
367
|
+
// an earlier version replaced a leading `~` alone, by `path.join`, so `~bob/r.md` went
|
|
368
|
+
// into the current user's `bob/`, and a trailing or doubled `/` was printed in the path
|
|
369
|
+
// the report was written to.
|
|
370
|
+
const expanded = (0, home_1.pathExpandUser)(dest);
|
|
371
|
+
let isDir;
|
|
372
|
+
try {
|
|
373
|
+
isDir = fs.statSync(expanded).isDirectory();
|
|
374
|
+
}
|
|
375
|
+
catch {
|
|
376
|
+
isDir = false;
|
|
377
|
+
}
|
|
378
|
+
target = isDir || /[/\\]$/u.test(dest) ? (0, home_1.joinPath)(expanded, filename) : expanded;
|
|
379
|
+
}
|
|
380
|
+
else {
|
|
381
|
+
target = (0, home_1.joinPath)(config.reportsDir(), filename);
|
|
382
|
+
}
|
|
383
|
+
fs.mkdirSync(path.dirname(target), { recursive: true });
|
|
384
|
+
fs.writeFileSync(target, content, 'utf8');
|
|
385
|
+
return target;
|
|
386
|
+
}
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceMonitor = exports.STOP_JOIN_MS = void 0;
|
|
4
|
+
exports.parseCpu = parseCpu;
|
|
5
|
+
exports.toBytes = toBytes;
|
|
6
|
+
exports.parseMem = parseMem;
|
|
7
|
+
/**
|
|
8
|
+
* Background resource sampler: poll `docker stats` for a repro's containers, so any
|
|
9
|
+
* operation can be wrapped and its CPU/RAM cost reported.
|
|
10
|
+
*
|
|
11
|
+
* PORTABILITY. `docker stats` works on Docker Desktop and Linux. On Docker Desktop CPU% is
|
|
12
|
+
* relative to the VM's allocated CPUs and memory is the VM's view (consistent with
|
|
13
|
+
* node-exporter). The idle->peak DELTAS are the trustworthy signal; absolute numbers are
|
|
14
|
+
* host-specific.
|
|
15
|
+
*
|
|
16
|
+
* A sampler on a thread would guard its series with a lock, because `stop()` waits with a
|
|
17
|
+
* timeout and `report()`/`memSlopes()` are callable while the sampler runs. Here it is
|
|
18
|
+
* cooperative asynchronous concurrency: one loop, a stop flag, and a `stop()` that awaits
|
|
19
|
+
* the loop for at most `STOP_JOIN_MS`. A reader that runs between awaits sees a consistent
|
|
20
|
+
* array, so the snapshot copy is kept for its other reason -- a caller may hold the result
|
|
21
|
+
* while sampling continues -- rather than for mutual exclusion.
|
|
22
|
+
*/
|
|
23
|
+
const engine_1 = require("../core/runner/engine");
|
|
24
|
+
const queries_1 = require("../core/runner/queries");
|
|
25
|
+
const MEM_UNITS = Object.freeze({
|
|
26
|
+
b: 1,
|
|
27
|
+
kb: 1000,
|
|
28
|
+
mb: 1000 ** 2,
|
|
29
|
+
gb: 1000 ** 3,
|
|
30
|
+
tb: 1000 ** 4,
|
|
31
|
+
kib: 1024,
|
|
32
|
+
mib: 1024 ** 2,
|
|
33
|
+
gib: 1024 ** 3,
|
|
34
|
+
tib: 1024 ** 4,
|
|
35
|
+
});
|
|
36
|
+
function parseCpu(tok) {
|
|
37
|
+
const text = tok.trim().replace(/%+$/u, '');
|
|
38
|
+
const value = Number(text);
|
|
39
|
+
// Anything that is not a number reads as 0.0. `Number('')` is 0, which happens to agree
|
|
40
|
+
// here, but an explicit check says so.
|
|
41
|
+
return text === '' || Number.isNaN(value) ? 0.0 : value;
|
|
42
|
+
}
|
|
43
|
+
function toBytes(tok) {
|
|
44
|
+
const m = /^\s*([\d.]+)\s*([A-Za-z]+)/u.exec(tok);
|
|
45
|
+
if (m === null)
|
|
46
|
+
return 0.0;
|
|
47
|
+
const value = Number(m[1]);
|
|
48
|
+
if (Number.isNaN(value))
|
|
49
|
+
return 0.0;
|
|
50
|
+
return value * (MEM_UNITS[m[2].toLowerCase()] ?? 1);
|
|
51
|
+
}
|
|
52
|
+
/** `"540MiB / 2GiB"` -> `[used, limit]`. */
|
|
53
|
+
function parseMem(tok) {
|
|
54
|
+
const parts = tok.split('/');
|
|
55
|
+
const used = parts.length > 0 ? toBytes(parts[0]) : 0.0;
|
|
56
|
+
const limit = parts.length > 1 ? toBytes(parts[1]) : 0.0;
|
|
57
|
+
return [used, limit];
|
|
58
|
+
}
|
|
59
|
+
/** How long `stop()` waits for a sample still in flight: five seconds. */
|
|
60
|
+
exports.STOP_JOIN_MS = 5000;
|
|
61
|
+
/**
|
|
62
|
+
* Usage: `const mon = new ResourceMonitor(name).start(); … ; const rep = await mon.stop();`
|
|
63
|
+
*/
|
|
64
|
+
class ResourceMonitor {
|
|
65
|
+
constructor(reproName, interval = 1.0) {
|
|
66
|
+
this.series = new Map();
|
|
67
|
+
this.stopping = false;
|
|
68
|
+
this.running = null;
|
|
69
|
+
this.t0 = 0;
|
|
70
|
+
this.reproName = reproName;
|
|
71
|
+
this.interval = interval;
|
|
72
|
+
}
|
|
73
|
+
start() {
|
|
74
|
+
this.stopping = false;
|
|
75
|
+
this.t0 = now();
|
|
76
|
+
this.running = this.loop();
|
|
77
|
+
return this;
|
|
78
|
+
}
|
|
79
|
+
async loop() {
|
|
80
|
+
// ON A LATER TURN, so the first read runs after `start()` has returned rather than in
|
|
81
|
+
// `start()` itself. Called straight through, the first `docker compose ps -q` was
|
|
82
|
+
// spawned before `start()` returned -- ahead of the k6 run it is there to watch, on
|
|
83
|
+
// every run -- and a k6 that returned at once still left a sample, and a 'Resource cost'
|
|
84
|
+
// table the established report, still waiting for its first answer, never prints. A
|
|
85
|
+
// wrapped create still gets its first sample: the loop re-asks for ids below.
|
|
86
|
+
await new Promise((resolve) => {
|
|
87
|
+
setImmediate(resolve);
|
|
88
|
+
});
|
|
89
|
+
let ids = await (0, engine_1.containerIds)(this.reproName);
|
|
90
|
+
while (!this.stopping) {
|
|
91
|
+
// A workspace whose containers were not up yet at the first poll gets another
|
|
92
|
+
// chance, which is what makes wrapping a create work.
|
|
93
|
+
if (ids.length === 0)
|
|
94
|
+
ids = await (0, engine_1.containerIds)(this.reproName);
|
|
95
|
+
const t = now() - this.t0;
|
|
96
|
+
for (const line of (await (0, queries_1.dockerStats)(ids)).split('\n')) {
|
|
97
|
+
const parts = line.split('\t');
|
|
98
|
+
if (parts.length >= 3) {
|
|
99
|
+
const [used, limit] = parseMem(parts[2]);
|
|
100
|
+
const key = parts[0];
|
|
101
|
+
let entry = this.series.get(key);
|
|
102
|
+
if (entry === undefined) {
|
|
103
|
+
entry = [];
|
|
104
|
+
this.series.set(key, entry);
|
|
105
|
+
}
|
|
106
|
+
entry.push([t, parseCpu(parts[1]), used, limit]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
await this.wait(this.interval);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/** `Event.wait(interval)` -- returns early when `stop()` is called. */
|
|
113
|
+
wait(seconds) {
|
|
114
|
+
return new Promise((resolve) => {
|
|
115
|
+
if (this.stopping) {
|
|
116
|
+
resolve();
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const timer = setTimeout(() => {
|
|
120
|
+
clearInterval(poll);
|
|
121
|
+
resolve();
|
|
122
|
+
}, seconds * 1000);
|
|
123
|
+
const poll = setInterval(() => {
|
|
124
|
+
if (this.stopping) {
|
|
125
|
+
clearTimeout(timer);
|
|
126
|
+
clearInterval(poll);
|
|
127
|
+
resolve();
|
|
128
|
+
}
|
|
129
|
+
}, 25);
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Stop sampling and report what was sampled.
|
|
134
|
+
*
|
|
135
|
+
* Waits for the loop at most `STOP_JOIN_MS`, then reports without the sample in flight.
|
|
136
|
+
* This waited for the loop however long `docker stats` took: on a loaded daemon whose
|
|
137
|
+
* first sample needs 7 s, `stats --for 1` printed a resource table the established report
|
|
138
|
+
* never prints, since it is read at 6 s from a series still empty. A sample that lands
|
|
139
|
+
* later is appended to a report already made, as it always has been.
|
|
140
|
+
*/
|
|
141
|
+
async stop() {
|
|
142
|
+
this.stopping = true;
|
|
143
|
+
const running = this.running;
|
|
144
|
+
if (running !== null) {
|
|
145
|
+
let timer;
|
|
146
|
+
try {
|
|
147
|
+
const joined = await Promise.race([
|
|
148
|
+
running.then(() => true),
|
|
149
|
+
new Promise((resolve) => {
|
|
150
|
+
timer = setTimeout(() => {
|
|
151
|
+
resolve(false);
|
|
152
|
+
}, exports.STOP_JOIN_MS);
|
|
153
|
+
}),
|
|
154
|
+
]);
|
|
155
|
+
if (joined)
|
|
156
|
+
this.running = null;
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
clearTimeout(timer);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return this.report();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* A shallow copy of the series, so callers can read it while sampling continues.
|
|
166
|
+
*/
|
|
167
|
+
snapshot() {
|
|
168
|
+
const out = {};
|
|
169
|
+
for (const [name, series] of this.series)
|
|
170
|
+
out[name] = [...series];
|
|
171
|
+
return out;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Per-container RAM growth in bytes/hour over the sampled span (a simple endpoint
|
|
175
|
+
* slope) -- the soak-test leak signal.
|
|
176
|
+
*
|
|
177
|
+
* Empty unless the monitor ran for at least `minSpanS`: short runs say nothing about
|
|
178
|
+
* leaks, and reporting a slope from thirty seconds of samples would be noise dressed as
|
|
179
|
+
* evidence.
|
|
180
|
+
*/
|
|
181
|
+
memSlopes(minSpanS = 600.0) {
|
|
182
|
+
const out = {};
|
|
183
|
+
for (const [name, series] of Object.entries(this.snapshot())) {
|
|
184
|
+
if (series.length < 2)
|
|
185
|
+
continue;
|
|
186
|
+
const first = series[0];
|
|
187
|
+
const last = series[series.length - 1];
|
|
188
|
+
const span = last[0] - first[0];
|
|
189
|
+
if (span < minSpanS)
|
|
190
|
+
continue;
|
|
191
|
+
out[name] = ((last[2] - first[2]) / span) * 3600;
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
}
|
|
195
|
+
/** Per-container stats, optionally restricted to a `[t0, t1]` window. */
|
|
196
|
+
report(window) {
|
|
197
|
+
const out = {};
|
|
198
|
+
for (const [name, series] of Object.entries(this.snapshot())) {
|
|
199
|
+
const sel = series.filter((s) => window === undefined || (window[0] <= s[0] && s[0] <= window[1]));
|
|
200
|
+
if (sel.length === 0)
|
|
201
|
+
continue;
|
|
202
|
+
// `max(sel, key=...)` keeps the FIRST maximum; `reduce` with a strict `>` does too.
|
|
203
|
+
const peak = sel.reduce((best, s) => (s[1] > best[1] ? s : best), sel[0]);
|
|
204
|
+
out[name] = {
|
|
205
|
+
idle_cpu: sel[0][1],
|
|
206
|
+
peak_cpu: peak[1],
|
|
207
|
+
idle_mem: sel[0][2],
|
|
208
|
+
peak_mem: Math.max(...sel.map((s) => s[2])),
|
|
209
|
+
limit_mem: sel[sel.length - 1][3],
|
|
210
|
+
peak_cpu_t: peak[0],
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
return out;
|
|
214
|
+
}
|
|
215
|
+
/** For a test that needs a series without running docker. */
|
|
216
|
+
seed(name, samples) {
|
|
217
|
+
this.series.set(name, [...samples]);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
exports.ResourceMonitor = ResourceMonitor;
|
|
221
|
+
/** `time.monotonic()`, in seconds. */
|
|
222
|
+
function now() {
|
|
223
|
+
return Number(process.hrtime.bigint()) / 1e9;
|
|
224
|
+
}
|