@rocket.chat/houston 0.27.0-next.3 → 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.
Files changed (293) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +108 -15
  3. package/bin/houston +62 -0
  4. package/data/docs/ARCHITECTURE.md +387 -0
  5. package/data/docs/automation.md +107 -0
  6. package/data/docs/e2ee.md +76 -0
  7. package/data/docs/eks.md +258 -0
  8. package/data/docs/gui.md +282 -0
  9. package/data/docs/guide.md +669 -0
  10. package/data/docs/kubernetes.md +138 -0
  11. package/data/docs/troubleshooting.md +193 -0
  12. package/data/docs/upgrading.md +84 -0
  13. package/data/docs/voice.md +253 -0
  14. package/data/iam/engineer-policy.json +11 -0
  15. package/data/iam/engineer-rbac.yaml +42 -0
  16. package/data/iam/operator-policy.json +211 -0
  17. package/data/loadtest/badbot.js +22 -0
  18. package/data/loadtest/common.js +168 -0
  19. package/data/loadtest/custom.js +20 -0
  20. package/data/loadtest/journey.js +58 -0
  21. package/data/loadtest/login.js +18 -0
  22. package/data/loadtest/messages.js +13 -0
  23. package/data/loadtest/mixed.js +39 -0
  24. package/data/loadtest/read.js +12 -0
  25. package/data/loadtest/webhook.js +20 -0
  26. package/data/monitoring/houston-logs.json +98 -0
  27. package/data/monitoring/k6-loadtest.json +610 -0
  28. package/data/monitoring/mongodb-exporter.json +3007 -0
  29. package/data/monitoring/node-exporter-full.json +16114 -0
  30. package/data/monitoring/rocketchat-metrics.json +6471 -0
  31. package/data/presets/airgapped.yaml +16 -0
  32. package/data/presets/default.yaml +9 -0
  33. package/data/seed/avatar-0.png +0 -0
  34. package/data/seed/avatar-1.png +0 -0
  35. package/data/seed/avatar-2.png +0 -0
  36. package/data/seed/avatar-3.png +0 -0
  37. package/data/seed/avatar-4.png +0 -0
  38. package/data/seed/avatar-5.png +0 -0
  39. package/data/seed/avatar-6.png +0 -0
  40. package/data/seed/avatar-7.png +0 -0
  41. package/data/seed/seed-metrics.csv +3 -0
  42. package/data/seed/seed-preview.png +0 -0
  43. package/data/seed/seed-report.pdf +32 -0
  44. package/data/seed/seed-runbook.txt +3 -0
  45. package/data/skill/SKILL.md +399 -0
  46. package/data/versions.yaml +55 -0
  47. package/data/voice/freeswitch/drachtio.xml +52 -0
  48. package/data/voice/freeswitch/public.xml +87 -0
  49. package/data/webui/app.css +2003 -0
  50. package/data/webui/index.html +678 -0
  51. package/data/webui/js/api.js +561 -0
  52. package/data/webui/js/boot.js +44 -0
  53. package/data/webui/js/clusters-tail.js +1377 -0
  54. package/data/webui/js/clusters.js +896 -0
  55. package/data/webui/js/create.js +276 -0
  56. package/data/webui/js/detail.js +507 -0
  57. package/data/webui/js/jobs.js +636 -0
  58. package/data/webui/js/logs.js +634 -0
  59. package/data/webui/js/main.js +14 -0
  60. package/data/webui/js/options.js +408 -0
  61. package/data/webui/js/people.js +438 -0
  62. package/data/webui/js/perf.js +303 -0
  63. package/data/webui/js/render.js +438 -0
  64. package/data/webui/js/shared.js +3 -0
  65. package/data/webui/js/state.js +583 -0
  66. package/data/webui/js/theme.js +123 -0
  67. package/data/webui/js/util.js +584 -0
  68. package/dist/cli/app.js +593 -0
  69. package/dist/cli/capabilities.js +76 -0
  70. package/dist/cli/cell-widths.js +495 -0
  71. package/dist/cli/entry.js +10 -0
  72. package/dist/cli/error-panel.js +492 -0
  73. package/dist/cli/handlers/actor.js +84 -0
  74. package/dist/cli/handlers/https.js +614 -0
  75. package/dist/cli/handlers/prompt.js +299 -0
  76. package/dist/cli/handlers/users.js +226 -0
  77. package/dist/cli/handlers.js +3678 -0
  78. package/dist/cli/help.js +183 -0
  79. package/dist/cli/index.js +15 -0
  80. package/dist/cli/perf.js +810 -0
  81. package/dist/cli/render.js +254 -0
  82. package/dist/cli/serve.js +858 -0
  83. package/dist/cli/spec-data.js +2593 -0
  84. package/dist/cli/spec-types.js +8 -0
  85. package/dist/cli/usage-error.js +520 -0
  86. package/dist/cli/wire.js +70 -0
  87. package/dist/core/audit.js +346 -0
  88. package/dist/core/backup-compat.js +85 -0
  89. package/dist/core/backup.js +1639 -0
  90. package/dist/core/cluster.js +1398 -0
  91. package/dist/core/configimport.js +344 -0
  92. package/dist/core/data.js +267 -0
  93. package/dist/core/database-of.js +82 -0
  94. package/dist/core/diagnose.js +159 -0
  95. package/dist/core/doctor.js +1518 -0
  96. package/dist/core/edge/acme.js +338 -0
  97. package/dist/core/edge/engine.js +500 -0
  98. package/dist/core/edge/networks.js +174 -0
  99. package/dist/core/edge/paths.js +107 -0
  100. package/dist/core/edge/routes.js +251 -0
  101. package/dist/core/edge/routeyml.js +195 -0
  102. package/dist/core/edge/runtime.js +493 -0
  103. package/dist/core/edge/spec.js +305 -0
  104. package/dist/core/edge/types.js +202 -0
  105. package/dist/core/eks-docs.js +135 -0
  106. package/dist/core/eks.js +2240 -0
  107. package/dist/core/envvars.js +562 -0
  108. package/dist/core/eventlog.js +541 -0
  109. package/dist/core/firstrun.js +153 -0
  110. package/dist/core/journal.js +691 -0
  111. package/dist/core/kube/ask.js +231 -0
  112. package/dist/core/kube/capabilities.js +269 -0
  113. package/dist/core/kube/certmanager.js +452 -0
  114. package/dist/core/kube/chart.js +413 -0
  115. package/dist/core/kube/cluster.js +196 -0
  116. package/dist/core/kube/context.js +545 -0
  117. package/dist/core/kube/endpoints.js +448 -0
  118. package/dist/core/kube/exec.js +195 -0
  119. package/dist/core/kube/forward.js +732 -0
  120. package/dist/core/kube/grafana-ingress.js +110 -0
  121. package/dist/core/kube/ingress.js +218 -0
  122. package/dist/core/kube/manifests.js +361 -0
  123. package/dist/core/kube/monitoring.js +768 -0
  124. package/dist/core/kube/names.js +237 -0
  125. package/dist/core/kube/namespace.js +678 -0
  126. package/dist/core/kube/operator.js +941 -0
  127. package/dist/core/kube/probe.js +202 -0
  128. package/dist/core/kube/reachability.js +163 -0
  129. package/dist/core/kube/release.js +439 -0
  130. package/dist/core/kube/replicaset.js +180 -0
  131. package/dist/core/kube/scale.js +398 -0
  132. package/dist/core/kube/status.js +633 -0
  133. package/dist/core/kube/tools.js +238 -0
  134. package/dist/core/kube/transfer.js +173 -0
  135. package/dist/core/kube/workspace.js +423 -0
  136. package/dist/core/lifecycle/admin.js +64 -0
  137. package/dist/core/lifecycle/create-docker.js +1533 -0
  138. package/dist/core/lifecycle/create-k8s.js +939 -0
  139. package/dist/core/lifecycle/destroy.js +339 -0
  140. package/dist/core/lifecycle/inspect.js +635 -0
  141. package/dist/core/lifecycle/naming.js +298 -0
  142. package/dist/core/lifecycle/notes.js +726 -0
  143. package/dist/core/lifecycle/ownership.js +313 -0
  144. package/dist/core/lifecycle/payload.js +401 -0
  145. package/dist/core/lifecycle/ports.js +388 -0
  146. package/dist/core/lifecycle/preconditions.js +367 -0
  147. package/dist/core/lifecycle/pruning.js +551 -0
  148. package/dist/core/lifecycle/ready.js +753 -0
  149. package/dist/core/lifecycle/request.js +525 -0
  150. package/dist/core/lifecycle/seeding.js +281 -0
  151. package/dist/core/lifecycle/sizing.js +392 -0
  152. package/dist/core/lifecycle/state.js +286 -0
  153. package/dist/core/lifecycle/tlsplan.js +704 -0
  154. package/dist/core/lifecycle/types.js +232 -0
  155. package/dist/core/loadtest.js +995 -0
  156. package/dist/core/migrate.js +612 -0
  157. package/dist/core/monitor.js +494 -0
  158. package/dist/core/postready.js +969 -0
  159. package/dist/core/promote.js +804 -0
  160. package/dist/core/rcapi.js +1285 -0
  161. package/dist/core/recovery.js +75 -0
  162. package/dist/core/runner/engine.js +394 -0
  163. package/dist/core/runner/host.js +298 -0
  164. package/dist/core/runner/locks.js +129 -0
  165. package/dist/core/runner/paths.js +173 -0
  166. package/dist/core/runner/ports.js +172 -0
  167. package/dist/core/runner/queries.js +612 -0
  168. package/dist/core/runner/record.js +563 -0
  169. package/dist/core/scaleseed.js +271 -0
  170. package/dist/core/seed-db.js +208 -0
  171. package/dist/core/sessions.js +472 -0
  172. package/dist/core/skill.js +326 -0
  173. package/dist/core/sso-identities.js +172 -0
  174. package/dist/core/sso.js +703 -0
  175. package/dist/core/tls-local.js +311 -0
  176. package/dist/core/tls.js +878 -0
  177. package/dist/core/topology.js +482 -0
  178. package/dist/core/upgrade.js +868 -0
  179. package/dist/core/users.js +739 -0
  180. package/dist/lib/audit.js +100 -0
  181. package/dist/lib/close-matches.js +238 -0
  182. package/dist/lib/compose.js +672 -0
  183. package/dist/lib/config.js +1398 -0
  184. package/dist/lib/context.js +18 -0
  185. package/dist/lib/errors.js +305 -0
  186. package/dist/lib/events.js +208 -0
  187. package/dist/lib/float-text.js +126 -0
  188. package/dist/lib/format.js +1320 -0
  189. package/dist/lib/home.js +325 -0
  190. package/dist/lib/journal.js +122 -0
  191. package/dist/lib/json-text.js +733 -0
  192. package/dist/lib/jsonout.js +382 -0
  193. package/dist/lib/lock.js +516 -0
  194. package/dist/lib/login-name.js +202 -0
  195. package/dist/lib/map-limit.js +29 -0
  196. package/dist/lib/mkdir-parents.js +90 -0
  197. package/dist/lib/mongo-kernel.js +67 -0
  198. package/dist/lib/monitoring.js +492 -0
  199. package/dist/lib/platform-name.js +59 -0
  200. package/dist/lib/presets/common.js +390 -0
  201. package/dist/lib/presets/composite.js +326 -0
  202. package/dist/lib/presets/e2ee.js +143 -0
  203. package/dist/lib/presets/email.js +172 -0
  204. package/dist/lib/presets/guides.js +27 -0
  205. package/dist/lib/presets/index.js +490 -0
  206. package/dist/lib/presets/keycloak.js +369 -0
  207. package/dist/lib/presets/ldap.js +1285 -0
  208. package/dist/lib/presets/livechat.js +220 -0
  209. package/dist/lib/presets/multi-instance.js +124 -0
  210. package/dist/lib/presets/oidc.js +161 -0
  211. package/dist/lib/presets/public.js +496 -0
  212. package/dist/lib/presets/registry.js +64 -0
  213. package/dist/lib/presets/s3-minio.js +300 -0
  214. package/dist/lib/presets/saml.js +149 -0
  215. package/dist/lib/presets/scenario.js +51 -0
  216. package/dist/lib/presets/types.js +86 -0
  217. package/dist/lib/presets/voice-pbx.js +320 -0
  218. package/dist/lib/presets/voice.js +345 -0
  219. package/dist/lib/presets/webhooks.js +182 -0
  220. package/dist/lib/redact.js +106 -0
  221. package/dist/lib/seed-options.js +68 -0
  222. package/dist/lib/seed-profiles.js +59 -0
  223. package/dist/lib/targz.js +1383 -0
  224. package/dist/lib/teammode.js +25 -0
  225. package/dist/lib/tempdir.js +162 -0
  226. package/dist/lib/unicode-tables.js +2335 -0
  227. package/dist/lib/version-spec.js +357 -0
  228. package/dist/lib/versions.js +463 -0
  229. package/dist/lib/yaml-dump.js +1361 -0
  230. package/dist/perf/baseline.js +168 -0
  231. package/dist/perf/constrain.js +296 -0
  232. package/dist/perf/k6.js +235 -0
  233. package/dist/perf/mongoprof.js +171 -0
  234. package/dist/perf/rcmetrics.js +178 -0
  235. package/dist/perf/report.js +386 -0
  236. package/dist/perf/resources.js +224 -0
  237. package/dist/perf/slo.js +111 -0
  238. package/dist/perf/timeline.js +187 -0
  239. package/dist/perf/timings.js +85 -0
  240. package/dist/perf/verdict.js +201 -0
  241. package/dist/seams/aws-cli.js +126 -0
  242. package/dist/seams/docker-cli.js +280 -0
  243. package/dist/seams/exec.js +861 -0
  244. package/dist/seams/fs/lock.js +528 -0
  245. package/dist/seams/kubectl.js +83 -0
  246. package/dist/seams/rc-http.js +921 -0
  247. package/dist/seed/apply.js +190 -0
  248. package/dist/seed/assets.js +76 -0
  249. package/dist/seed/check.js +391 -0
  250. package/dist/seed/client.js +172 -0
  251. package/dist/seed/executor.js +726 -0
  252. package/dist/seed/history.js +281 -0
  253. package/dist/seed/kinds.js +91 -0
  254. package/dist/seed/plan.js +432 -0
  255. package/dist/seed/receipt.js +339 -0
  256. package/dist/seed/repairs.js +75 -0
  257. package/dist/seed/verification.js +363 -0
  258. package/dist/seed/wording.js +248 -0
  259. package/dist/web/app.js +326 -0
  260. package/dist/web/jobs.js +510 -0
  261. package/dist/web/route-deps.js +211 -0
  262. package/dist/web/route-table.js +213 -0
  263. package/dist/web/routes/backup.js +244 -0
  264. package/dist/web/routes/clusters.js +303 -0
  265. package/dist/web/routes/data.js +187 -0
  266. package/dist/web/routes/edge.js +82 -0
  267. package/dist/web/routes/index.js +63 -0
  268. package/dist/web/routes/jobs.js +95 -0
  269. package/dist/web/routes/logs.js +297 -0
  270. package/dist/web/routes/meta.js +191 -0
  271. package/dist/web/routes/people.js +151 -0
  272. package/dist/web/routes/perf.js +95 -0
  273. package/dist/web/routes/repros.js +550 -0
  274. package/dist/web/routes/session.js +361 -0
  275. package/dist/web/routes/spa.js +198 -0
  276. package/dist/web/security.js +475 -0
  277. package/dist/web/signin.js +246 -0
  278. package/package.json +67 -32
  279. package/.eslintrc +0 -94
  280. package/.swcrc +0 -18
  281. package/dist/bin.js +0 -3
  282. package/dist/cli.js +0 -184
  283. package/dist/commands/createBranch.js +0 -194
  284. package/dist/outputCI.js +0 -59
  285. package/src/bin.js +0 -4
  286. package/src/cli.ts +0 -25
  287. package/src/commands/createBranch.ts +0 -28
  288. package/src/outputCI.ts +0 -12
  289. package/src-old/logs.js +0 -323
  290. package/src-old/md.js +0 -191
  291. package/src-old/release-table.js +0 -60
  292. package/src-old/set-version.js +0 -614
  293. package/src-old/utils.js +0 -15
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LATENCY_KEYS = void 0;
4
+ exports.parse = parse;
5
+ exports.evaluate = evaluate;
6
+ exports.fmtActual = fmtActual;
7
+ /**
8
+ * Parse and evaluate an SLO gate against a k6 load-test summary.
9
+ *
10
+ * Rule syntax (comma-separated): `p95=300ms,error=1%,rps=100`
11
+ *
12
+ * - latency metrics (`avg` `min` `max` `p50` `p90` `p95` `p99`) — the value is an UPPER
13
+ * BOUND in ms (`300ms`, `1.5s` or a bare number).
14
+ * - `error` — max allowed error rate, a percent (`1%` or `1`).
15
+ * - `rps` — a LOWER BOUND on requests/second (the one "at least" metric).
16
+ *
17
+ * `evaluate` returns one result per rule; the load-test command fails (non-zero exit) if
18
+ * any rule is not met — the CI-gate use case.
19
+ *
20
+ * THE THRESHOLD IS PARSED WITH `lib/format.parseFloat_`, not `Number`. `Number('')` is
21
+ * 0, so an empty threshold would become a gate of zero that every run passes;
22
+ * `parseFloat_('')` throws, and a gate that cannot be read must refuse rather than pass.
23
+ */
24
+ const format_1 = require("../lib/format");
25
+ exports.LATENCY_KEYS = new Set([
26
+ 'avg',
27
+ 'min',
28
+ 'max',
29
+ 'p50',
30
+ 'p90',
31
+ 'p95',
32
+ 'p99',
33
+ ]);
34
+ function parseMs(v) {
35
+ const text = v.trim().toLowerCase();
36
+ if (text.endsWith('ms'))
37
+ return (0, format_1.parseFloat_)(text.slice(0, -2));
38
+ if (text.endsWith('s'))
39
+ return (0, format_1.parseFloat_)(text.slice(0, -1)) * 1000;
40
+ return (0, format_1.parseFloat_)(text);
41
+ }
42
+ /** Parse `"p95=300ms,error=1%"` into rules. */
43
+ function parse(spec) {
44
+ const rules = [];
45
+ for (const piece of spec.split(',')) {
46
+ const part = piece.trim();
47
+ if (!part)
48
+ continue;
49
+ if (!part.includes('='))
50
+ throw new Error(`bad rule '${part}' (expected key=value)`);
51
+ const at = part.indexOf('=');
52
+ const key = part.slice(0, at).trim().toLowerCase();
53
+ const val = part.slice(at + 1).trim();
54
+ if (exports.LATENCY_KEYS.has(key)) {
55
+ rules.push({ key, op: '<=', threshold: parseMs(val), raw: val });
56
+ }
57
+ else if (key === 'error') {
58
+ rules.push({ key, op: '<=', threshold: (0, format_1.parseFloat_)(val.replace(/%+$/u, '')), raw: val });
59
+ }
60
+ else if (key === 'rps') {
61
+ rules.push({ key, op: '>=', threshold: (0, format_1.parseFloat_)(val), raw: val });
62
+ }
63
+ else {
64
+ throw new Error(`unknown metric '${key}' (use p50/p90/p95/p99/avg/min/max/error/rps)`);
65
+ }
66
+ }
67
+ return rules;
68
+ }
69
+ /** The summary key each rule metric reads from (latency keys map to themselves). */
70
+ const SUMMARY_KEY = Object.freeze({
71
+ error: 'error_rate',
72
+ rps: 'rps',
73
+ });
74
+ function summaryKey(key) {
75
+ return SUMMARY_KEY[key] ?? key;
76
+ }
77
+ function actualOf(key, summary) {
78
+ const raw = summary[summaryKey(key)];
79
+ // A null value becomes 0 rather than crashing; `measured` is what records that it was
80
+ // not a real reading.
81
+ const value = raw === null || raw === undefined ? 0.0 : Number(raw);
82
+ return key === 'error' ? value * 100 : value;
83
+ }
84
+ /**
85
+ * One result per rule.
86
+ *
87
+ * A rule whose metric is ABSENT from the summary is reported as not `measured` and FAILS
88
+ * -- a metric that was not captured must never silently PASS at 0.0, which is what an
89
+ * upper-bound rule would do.
90
+ */
91
+ function evaluate(rules, summary) {
92
+ const out = [];
93
+ for (const { key, op, threshold, raw } of rules) {
94
+ // A present-but-null value is not a real measurement -- it must fail as "not
95
+ // measured", never pass at 0.0.
96
+ const present = summary[summaryKey(key)];
97
+ const measured = present !== null && present !== undefined;
98
+ const actual = actualOf(key, summary);
99
+ const ok = measured && (op === '<=' ? actual <= threshold : actual >= threshold);
100
+ out.push({ key, op, threshold, raw, actual, ok, measured });
101
+ }
102
+ return out;
103
+ }
104
+ /** Human string for an observed value, matching the metric's unit. */
105
+ function fmtActual(key, actual) {
106
+ if (exports.LATENCY_KEYS.has(key))
107
+ return `${(0, format_1.formatFixed)(actual, 0)}ms`;
108
+ if (key === 'error')
109
+ return `${(0, format_1.formatFixed)(actual, 2)}%`;
110
+ return (0, format_1.formatFixed)(actual, 1);
111
+ }
@@ -0,0 +1,187 @@
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.TARGET_BUCKETS = exports.MAX_BYTES = void 0;
37
+ exports.ts = ts;
38
+ exports.parse = parse;
39
+ exports.spikeRecovery = spikeRecovery;
40
+ exports.renderAscii = renderAscii;
41
+ /**
42
+ * Latency-over-time from a k6 run.
43
+ *
44
+ * k6's `--out json` streams every measurement as a JSON line; this downsamples
45
+ * `http_req_duration` (plus `http_req_failed`) into at most thirty time buckets, which is
46
+ * what turns "p95 was 900ms" into "p95 was fine for 40s, then degraded as RAM filled" -- and
47
+ * pins WHEN errors started.
48
+ */
49
+ const fs = __importStar(require("node:fs"));
50
+ const format_1 = require("../lib/format");
51
+ const timings_1 = require("./timings");
52
+ /** A soak test can produce a huge stream -- bail politely rather than reading it all. */
53
+ exports.MAX_BYTES = 200 * 1024 * 1024;
54
+ exports.TARGET_BUCKETS = 30;
55
+ /** k6 emits nanosecond precision; the ISO reader takes at most six digits. */
56
+ const FRAC_RE = /\.(\d{6})\d+/u;
57
+ /**
58
+ * One k6 timestamp as epoch seconds.
59
+ *
60
+ * Only DIFFERENCES of these are ever used -- `t - t0`, `span`, `first_error_s` -- so a
61
+ * constant offset cancels, which is what makes the naive/aware question ISO parsing raises
62
+ * here harmless.
63
+ */
64
+ function ts(iso) {
65
+ return Date.parse(iso.replace(FRAC_RE, '.$1')) / 1000;
66
+ }
67
+ function pct(sortedVals, p) {
68
+ if (sortedVals.length === 0)
69
+ return 0.0;
70
+ return sortedVals[Math.min(sortedVals.length - 1, Math.ceil((p / 100) * sortedVals.length) - 1)];
71
+ }
72
+ /**
73
+ * The timeline, or null (no file, too big, or nothing usable).
74
+ *
75
+ * The `"Point"` prefilter runs BEFORE the JSON parse, because the stream can be millions
76
+ * of lines and metric-definition lines never contain it.
77
+ */
78
+ function parse(path) {
79
+ const durations = [];
80
+ const failures = [];
81
+ try {
82
+ if (!fs.existsSync(path) || fs.statSync(path).size > exports.MAX_BYTES)
83
+ return null;
84
+ for (const line of fs.readFileSync(path, 'utf8').split('\n')) {
85
+ if (!line.includes('"Point"'))
86
+ continue;
87
+ if (line.includes('"http_req_duration"')) {
88
+ const d = JSON.parse(line).data;
89
+ durations.push([ts(d.time), Number(d.value)]);
90
+ }
91
+ else if (line.includes('"http_req_failed"')) {
92
+ const d = JSON.parse(line).data;
93
+ if (d.value)
94
+ failures.push(ts(d.time));
95
+ }
96
+ }
97
+ }
98
+ catch {
99
+ return null;
100
+ }
101
+ if (durations.length < 2)
102
+ return null;
103
+ const t0 = Math.min(...durations.map(([t]) => t));
104
+ const span = Math.max(...durations.map(([t]) => t)) - t0;
105
+ const width = Math.max(1, Math.ceil(span / exports.TARGET_BUCKETS));
106
+ const n = Math.floor(span / width) + 1;
107
+ const per = Array.from({ length: n }, () => []);
108
+ const errs = new Array(n).fill(0);
109
+ for (const [t, ms] of durations) {
110
+ per[Math.min(n - 1, Math.trunc((t - t0) / width))].push(ms);
111
+ }
112
+ for (const t of failures) {
113
+ const i = Math.trunc((t - t0) / width);
114
+ if (i >= 0 && i < n)
115
+ errs[i] = errs[i] + 1;
116
+ }
117
+ const buckets = per.map((vals, i) => {
118
+ vals.sort((a, b) => a - b);
119
+ return {
120
+ t0: i * width,
121
+ reqs: vals.length,
122
+ p50: pct(vals, 50),
123
+ p95: pct(vals, 95),
124
+ max: vals.length > 0 ? vals[vals.length - 1] : 0.0,
125
+ errors: errs[i],
126
+ };
127
+ });
128
+ const firstErr = buckets.find((b) => b.errors > 0)?.t0 ?? null;
129
+ return { width_s: width, span_s: span, buckets, first_error_s: firstErr };
130
+ }
131
+ /**
132
+ * For a `--spike` run (base third / peak third / recovery third): how long after the spike
133
+ * ended did p95 return to at most 1.5x the pre-spike baseline?
134
+ */
135
+ function spikeRecovery(tl) {
136
+ const buckets = tl.buckets;
137
+ if (buckets.length < 6)
138
+ return null;
139
+ const span = buckets[buckets.length - 1].t0 + (tl.width_s || 1);
140
+ const third = span / 3;
141
+ const pre = buckets
142
+ .filter((b) => b.t0 < third && b.reqs > 0)
143
+ .map((b) => b.p95)
144
+ .sort((a, b) => a - b);
145
+ const mid = buckets
146
+ .filter((b) => b.t0 >= third && b.t0 < 2 * third && b.reqs > 0)
147
+ .map((b) => b.p95);
148
+ const post = buckets.filter((b) => b.t0 >= 2 * third && b.reqs > 0);
149
+ if (pre.length === 0 || post.length === 0)
150
+ return null;
151
+ // Median of the pre-spike third.
152
+ const baseline = pre[Math.floor(pre.length / 2)];
153
+ const threshold = baseline * 1.5;
154
+ const found = post.find((b) => b.p95 <= threshold);
155
+ const recovered = found === undefined ? null : found.t0 - 2 * third;
156
+ return {
157
+ baseline_p95: baseline,
158
+ spike_p95: mid.length > 0 ? Math.max(...mid) : 0.0,
159
+ recovered_after_s: recovered === null ? null : (0, format_1.roundHalfEven)(recovered),
160
+ };
161
+ }
162
+ /** ASCII only -- the same ramp as `timings.histogram`. */
163
+ const RAMP = ' .:-=+*#';
164
+ /** Two compact lines: p95 trend over the run, plus error positions if any. */
165
+ function renderAscii(tl) {
166
+ const buckets = tl.buckets;
167
+ const p95s = buckets.map((b) => b.p95);
168
+ const lo = Math.min(...p95s);
169
+ const hi = Math.max(...p95s);
170
+ const rng = hi - lo || 1.0;
171
+ const chart = p95s
172
+ .map((v) => RAMP.charAt(Math.min(RAMP.length - 1, Math.trunc(((v - lo) / rng) * (RAMP.length - 1)))))
173
+ .join('');
174
+ const lines = [
175
+ `p95 over time ${(0, timings_1.fmtMs)(lo)} |${chart}| ${(0, timings_1.fmtMs)(hi)} ` +
176
+ // `width_s` is a whole number of seconds (a ceiling), so it is written with `String`
177
+ // and not a format spec -- `formatFixed` here would drop a fractional width that
178
+ // a hand-built timeline could carry.
179
+ `(${buckets.length} buckets of ${String(tl.width_s)}s)`,
180
+ ];
181
+ if (buckets.some((b) => b.errors > 0)) {
182
+ const marks = buckets.map((b) => (b.errors > 0 ? 'x' : '.')).join('');
183
+ lines.push(`errors ${' '.repeat((0, timings_1.fmtMs)(lo).length)} |${marks}| ` +
184
+ `(first at ~${String(tl.first_error_s)}s)`);
185
+ }
186
+ return lines;
187
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Timings = void 0;
4
+ exports.fmtMs = fmtMs;
5
+ /**
6
+ * Latency accumulator: collect per-call durations, report the distribution.
7
+ *
8
+ * Dependency-free -- percentiles via nearest-rank on a sorted copy, which is fine for the
9
+ * thousands of samples a seed or load run produces.
10
+ *
11
+ * THE NUMBERS ARE RENDERED, so they go through `lib/format`. `formatFixed(ms, 0)` rounds
12
+ * half to EVEN and `toFixed(0)` rounds half away from zero, and a mean that lands on a half
13
+ * is exactly the kind of value this module produces -- `sum(s) / n` over a round number of
14
+ * samples. A report read beside one an earlier release wrote must not disagree by a digit.
15
+ */
16
+ const format_1 = require("../lib/format");
17
+ /**
18
+ * ASCII density ramp for the inline histogram -- width-1 in every terminal.
19
+ *
20
+ * No ambiguous-width Unicode block glyphs, which misalign on some terminals.
21
+ */
22
+ const RAMP = ' .:-=+*#';
23
+ class Timings {
24
+ constructor(samplesMs = []) {
25
+ this.samplesMs = samplesMs;
26
+ }
27
+ add(ms) {
28
+ this.samplesMs.push(ms);
29
+ }
30
+ get length() {
31
+ return this.samplesMs.length;
32
+ }
33
+ /** Nearest-rank percentile in ms (0 if empty). */
34
+ pct(p) {
35
+ if (this.samplesMs.length === 0)
36
+ return 0.0;
37
+ const s = [...this.samplesMs].sort((a, b) => a - b);
38
+ const k = Math.max(0, Math.min(s.length - 1, Math.ceil((p / 100) * s.length) - 1));
39
+ return s[k];
40
+ }
41
+ summary() {
42
+ const n = this.samplesMs.length;
43
+ if (n === 0)
44
+ return { count: 0 };
45
+ const s = [...this.samplesMs].sort((a, b) => a - b);
46
+ return {
47
+ count: n,
48
+ mean: s.reduce((a, b) => a + b, 0) / n,
49
+ min: s[0],
50
+ max: s[s.length - 1],
51
+ p50: this.pct(50),
52
+ p90: this.pct(90),
53
+ p95: this.pct(95),
54
+ p99: this.pct(99),
55
+ };
56
+ }
57
+ ratePerS(wallS) {
58
+ return wallS > 0 ? this.samplesMs.length / wallS : 0.0;
59
+ }
60
+ /** A single-line ASCII density strip over `buckets` linear latency bins. */
61
+ histogram(buckets = 12) {
62
+ if (this.samplesMs.length < 2)
63
+ return '';
64
+ const lo = Math.min(...this.samplesMs);
65
+ const hi = Math.max(...this.samplesMs);
66
+ if (hi <= lo)
67
+ return '';
68
+ const counts = new Array(buckets).fill(0);
69
+ const span = hi - lo;
70
+ for (const v of this.samplesMs) {
71
+ // Truncated toward zero; the ratio is never negative here.
72
+ const i = Math.min(buckets - 1, Math.trunc(((v - lo) / span) * buckets));
73
+ counts[i] = counts[i] + 1;
74
+ }
75
+ const cmax = Math.max(...counts) || 1;
76
+ return counts
77
+ .map((c) => RAMP.charAt(Math.min(RAMP.length - 1, (0, format_1.roundHalfEven)((c / cmax) * (RAMP.length - 1)))))
78
+ .join('');
79
+ }
80
+ }
81
+ exports.Timings = Timings;
82
+ /** Human latency: 42ms, 1.20s. */
83
+ function fmtMs(ms) {
84
+ return ms < 1000 ? `${(0, format_1.formatFixed)(ms, 0)}ms` : `${(0, format_1.formatFixed)(ms / 1000, 2)}s`;
85
+ }
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LAG_MAX_SAT_S = exports.LAG_MEAN_WARN_S = void 0;
4
+ exports.analyze = analyze;
5
+ /**
6
+ * Rule-based diagnosis of a load-test run.
7
+ *
8
+ * Combines the client-side result (latency and errors) with the server-side signals a
9
+ * `--diag` run collects -- RC's event-loop lag, Mongo's slow-query profile, container CPU --
10
+ * into a few plain-language findings: not "p95 was 900ms" but "RC's event loop saturated;
11
+ * Mongo was idle — the Node process is the bottleneck".
12
+ *
13
+ * Deliberately hedged wording ("likely") and simple thresholds; this is triage evidence
14
+ * for a ticket, not an oracle.
15
+ *
16
+ * EVERY NUMBER HERE IS RENDERED INTO A SENTENCE somebody pastes into a ticket, so the
17
+ * format strings go through `lib/format`. `formatFixed(x, 0)` rounds half to even and
18
+ * `toFixed` does not, and a CPU peak of exactly 85.5% is not an unusual reading.
19
+ */
20
+ const format_1 = require("../lib/format");
21
+ const timings_1 = require("./timings");
22
+ /** Node event-loop lag: >100ms mean is degraded, >500ms peak is saturated. */
23
+ exports.LAG_MEAN_WARN_S = 0.1;
24
+ exports.LAG_MAX_SAT_S = 0.5;
25
+ function asBag(value) {
26
+ return typeof value === 'object' && value !== null && !Array.isArray(value) ? value : {};
27
+ }
28
+ function num(value, fallback = 0) {
29
+ if (value === null || value === undefined)
30
+ return fallback;
31
+ const parsed = Number(value);
32
+ return Number.isNaN(parsed) ? fallback : parsed;
33
+ }
34
+ /**
35
+ * Rocket.Chat's own event-loop lag, which is the first thing to break under load.
36
+ *
37
+ * Judged by the per-interval lag HISTOGRAM peak (`eventloop_lag_max_s`); the instantaneous
38
+ * gauge samples BETWEEN stalls and stays near zero even while requests queue.
39
+ */
40
+ function eventLoopFinding(findings, rcmetrics) {
41
+ let worstSvc = null;
42
+ let worst = null;
43
+ for (const [svc, raw] of Object.entries(asBag(rcmetrics))) {
44
+ const m = asBag(raw);
45
+ const lagRaw = m.eventloop_lag_max_s ?? m.eventloop_lag_s;
46
+ const lag = asBag(lagRaw);
47
+ // An empty mapping counts as absent, and so does a missing key.
48
+ if (Object.keys(lag).length === 0)
49
+ continue;
50
+ const candidate = { max: num(lag.max), mean: num(lag.mean) };
51
+ if (worst === null || candidate.max > worst.max) {
52
+ worstSvc = svc;
53
+ worst = candidate;
54
+ }
55
+ }
56
+ if (worst === null)
57
+ return false;
58
+ if (worst.max >= exports.LAG_MAX_SAT_S) {
59
+ findings.push(`RC event loop saturated: lag peaked at ${(0, timings_1.fmtMs)(worst.max * 1000)} on ${String(worstSvc)} — ` +
60
+ 'the Node process is the bottleneck; more CPU or more instances (multi-instance ' +
61
+ 'preset) will help.');
62
+ return true;
63
+ }
64
+ if (worst.mean >= exports.LAG_MEAN_WARN_S) {
65
+ // Degraded is judged on the SUSTAINED lag (mean), not a lone peak -- a single ~100ms
66
+ // peak is routine and should not read as "degraded".
67
+ findings.push(`RC event loop degraded: lag averaged ${(0, timings_1.fmtMs)(worst.mean * 1000)} (peaks to ` +
68
+ `${(0, timings_1.fmtMs)(worst.max * 1000)}) on ${String(worstSvc)} — approaching CPU saturation ` +
69
+ 'at this load.');
70
+ return true;
71
+ }
72
+ return false;
73
+ }
74
+ /** Slow queries and the container that ran out of what it was given. */
75
+ function mongoAndResourceFindings(findings, lagFound, mongo, resources) {
76
+ const m = asBag(mongo);
77
+ // Absent for null and for an empty mapping alike.
78
+ if (Object.keys(m).length > 0) {
79
+ const slow = Array.isArray(m.slow) ? m.slow : [];
80
+ if (num(m.collscan) > 0) {
81
+ // Name the slowest COLLSCAN only if one made the top list -- citing a non-COLLSCAN
82
+ // row here would point at the wrong query.
83
+ const top = slow.find((s) => String(s.plan ?? '').includes('COLLSCAN'));
84
+ const where = top !== undefined ? ` — slowest: ${String(top.ns)} ${(0, timings_1.fmtMs)(num(top.millis))}` : '';
85
+ findings.push(`MongoDB ran ${String(m.collscan)} collection scan(s) (COLLSCAN) among the ` +
86
+ `profiled slow queries — likely a missing index${where}.`);
87
+ }
88
+ else if (slow.length > 0) {
89
+ const top = slow[0];
90
+ const total = m.total ?? slow.length;
91
+ findings.push(`${String(total)} MongoDB quer(ies) exceeded the slow threshold — slowest: ` +
92
+ `${String(top.ns)} ${String(top.op)} ${(0, timings_1.fmtMs)(num(top.millis))} ` +
93
+ `(${String(top.plan) || 'no plan'}).`);
94
+ }
95
+ }
96
+ // Where the CPU actually went (needs --stats).
97
+ const r = asBag(resources);
98
+ // The same shape: absent for null and for an empty mapping.
99
+ if (Object.keys(r).length > 0) {
100
+ const peaks = {};
101
+ for (const [svc, st] of Object.entries(r))
102
+ peaks[svc] = num(asBag(st).peak_cpu);
103
+ const rcPeaks = Object.entries(peaks)
104
+ .filter(([k]) => k.startsWith('rocketchat'))
105
+ .map(([, v]) => v);
106
+ const rcPeak = rcPeaks.length > 0 ? Math.max(...rcPeaks) : 0.0;
107
+ const mongoPeak = peaks.mongodb ?? 0.0;
108
+ if (mongoPeak > 85 && mongoPeak > rcPeak * 1.5) {
109
+ findings.push(`MongoDB was the hot container (${(0, format_1.formatFixed)(mongoPeak, 0)}% CPU vs RC ` +
110
+ `${(0, format_1.formatFixed)(rcPeak, 0)}%) — likely Mongo-bound at this load.`);
111
+ }
112
+ else if (rcPeak > 85 && rcPeak > mongoPeak * 1.5 && !lagFound) {
113
+ findings.push(`Rocket.Chat was the hot container (${(0, format_1.formatFixed)(rcPeak, 0)}% CPU vs Mongo ` +
114
+ `${(0, format_1.formatFixed)(mongoPeak, 0)}%) — likely CPU-bound in RC.`);
115
+ }
116
+ }
117
+ }
118
+ /** What an error rate means depends on which errors they were. */
119
+ function errorRateFinding(findings, summary, timeline) {
120
+ const err = num(summary.error_rate);
121
+ if (err <= 0.01)
122
+ return;
123
+ const st = asBag(summary.status);
124
+ const kinds = [];
125
+ if (num(st['429']) > 0)
126
+ kinds.push(`${Math.trunc(num(st['429']))}x 429 (throttled)`);
127
+ if (num(st['5xx']) > 0)
128
+ kinds.push(`${Math.trunc(num(st['5xx']))}x 5xx (server errors)`);
129
+ if (num(st['4xx']) > 0)
130
+ kinds.push(`${Math.trunc(num(st['4xx']))}x 4xx`);
131
+ // Only a timeline that is present and holds a `first_error_s`.
132
+ const t = asBag(timeline);
133
+ const firstError = t.first_error_s;
134
+ const when = Object.keys(t).length > 0 && firstError !== null && firstError !== undefined
135
+ ? `, starting ~${String(firstError)}s into the run`
136
+ : '';
137
+ findings.push(`${(0, format_1.formatFixed)(err * 100, 1)}% of requests failed` +
138
+ (kinds.length > 0 ? `: ${kinds.join(', ')}` : '') +
139
+ when +
140
+ '.');
141
+ }
142
+ /** 1-5 plain-language findings, most important first. */
143
+ function analyze(summary, options = {}) {
144
+ const { rcmetrics = null, mongo = null, resources = null, timeline = null, soak = null, spike = null, } = options;
145
+ const findings = [];
146
+ // NOTHING WAS MEASURED. A run that issued no requests emits no latency keys at all
147
+ // (handleSummary drops undefined values), and every `num(...)` below would read that
148
+ // absence as a measured 0ms -- ending in "the workspace has headroom at this load" for a
149
+ // test that never ran.
150
+ if (summary.p95 === null || summary.p95 === undefined || summary.count === 0) {
151
+ return [
152
+ 'No requests were recorded, so this run says nothing about the workspace - the ' +
153
+ 'load generator produced no measurements. Check that k6 could reach the target ' +
154
+ 'and that the scenario ran.',
155
+ ];
156
+ }
157
+ // Spike recovery -- only worth a finding when it did NOT bounce back.
158
+ const sp = asBag(spike);
159
+ // A spike is absent for null AND for an empty mapping, so the emptiness check is the
160
+ // whole guard.
161
+ if (Object.keys(sp).length > 0) {
162
+ const recovered = sp.recovered_after_s;
163
+ if (recovered === null || recovered === undefined) {
164
+ findings.push('Did not recover from the spike within the run: p95 stayed above 1.5x the ' +
165
+ `pre-spike baseline (${(0, timings_1.fmtMs)(num(sp.baseline_p95))}) after load dropped — ` +
166
+ 'connections/queues are not draining.');
167
+ }
168
+ else if (num(recovered) > 30) {
169
+ findings.push(`Slow spike recovery: p95 took ~${String(recovered)}s to return to normal after ` +
170
+ `load dropped (baseline ${(0, timings_1.fmtMs)(num(sp.baseline_p95))}).`);
171
+ }
172
+ }
173
+ const lagFound = eventLoopFinding(findings, rcmetrics);
174
+ mongoAndResourceFindings(findings, lagFound, mongo, resources);
175
+ errorRateFinding(findings, summary, timeline);
176
+ // Sustained-run RAM growth (soak signal) -- only reported for long runs.
177
+ for (const [svc, raw] of Object.entries(asBag(soak))) {
178
+ const perHour = num(raw);
179
+ // > ~30MB/h upward is worth an eyebrow.
180
+ if (perHour > 30e6) {
181
+ findings.push(`${svc} RAM grew ~${(0, format_1.formatFixed)(perHour / 1e6, 0)}MB/h over this sustained run — ` +
182
+ 'if a longer soak repeats this slope, treat it as a leak candidate.');
183
+ }
184
+ }
185
+ // High client latency with NO server-side signal: time is being spent queueing outside
186
+ // the event loop (CPU throttling/CFS, Mongo waits, connection backlog) -- say so instead
187
+ // of a false "healthy".
188
+ if (findings.length === 0 && num(summary.p95) >= 1000) {
189
+ findings.push(`High client latency (p95 ${(0, format_1.formatFixed)(num(summary.p95), 0)}ms) without RC ` +
190
+ 'event-loop saturation — requests are queueing outside the Node loop (CPU ' +
191
+ "throttling, Mongo waits, or connection backlog). If this run was --constrain'ed, " +
192
+ "that's the cap at work.");
193
+ }
194
+ if (findings.length === 0) {
195
+ findings.push(`No saturation signals: p95 ${(0, format_1.formatFixed)(num(summary.p95), 0)}ms at ` +
196
+ `${(0, format_1.formatFixed)(num(summary.rps), 1)} req/s, ` +
197
+ `${(0, format_1.formatFixed)(num(summary.error_rate) * 100, 2)}% errors — the workspace has ` +
198
+ 'headroom at this load.');
199
+ }
200
+ return findings;
201
+ }