@rocket.chat/houston 0.27.0-next.3 → 2.1.9
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 +109 -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 +642 -0
- package/data/docs/kubernetes.md +138 -0
- package/data/docs/loadtest.md +264 -0
- package/data/docs/troubleshooting.md +203 -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 +170 -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 +57 -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 +3694 -0
- package/dist/cli/help.js +183 -0
- package/dist/cli/index.js +15 -0
- package/dist/cli/perf.js +814 -0
- package/dist/cli/render.js +254 -0
- package/dist/cli/serve.js +858 -0
- package/dist/cli/spec-data.js +2599 -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 +345 -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 +694 -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 +1549 -0
- package/dist/core/lifecycle/create-k8s.js +960 -0
- package/dist/core/lifecycle/destroy.js +339 -0
- package/dist/core/lifecycle/inspect.js +636 -0
- package/dist/core/lifecycle/naming.js +298 -0
- package/dist/core/lifecycle/notes.js +862 -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 +818 -0
- package/dist/core/lifecycle/request.js +510 -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 +1051 -0
- package/dist/core/migrate.js +612 -0
- package/dist/core/monitor.js +494 -0
- package/dist/core/postready.js +976 -0
- package/dist/core/promote.js +804 -0
- package/dist/core/rcapi.js +1336 -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 +877 -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 +371 -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 +299 -0
- package/dist/perf/k6.js +235 -0
- package/dist/perf/mongoprof.js +171 -0
- package/dist/perf/rcmetrics.js +191 -0
- package/dist/perf/report.js +386 -0
- package/dist/perf/resources.js +236 -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 +70 -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 -194
- package/dist/outputCI.js +0 -59
- package/src/bin.js +0 -4
- package/src/cli.ts +0 -25
- package/src/commands/createBranch.ts +0 -28
- package/src/outputCI.ts +0 -12
- 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,634 @@
|
|
|
1
|
+
import { ctx } from "./shared.js";
|
|
2
|
+
|
|
3
|
+
// ---- logs viewer ------------------------------------------------------------
|
|
4
|
+
const LEVELS = ["trace", "debug", "info", "warn", "error", "fatal"];
|
|
5
|
+
const PINO = { 10: "trace", 20: "debug", 30: "info", 40: "warn", 50: "error", 60: "fatal" };
|
|
6
|
+
const MONGOSEV = { D: "debug", I: "info", W: "warn", E: "error", F: "fatal" };
|
|
7
|
+
const LOG_MAX = 3000;
|
|
8
|
+
const logv = { buf: [], min: "info", svc: "", q: "", follow: true,
|
|
9
|
+
pending: [], frame: 0, unseen: 0, onUnseen: null };
|
|
10
|
+
|
|
11
|
+
// Lines arrive one WebSocket message at a time, and each one used to do three
|
|
12
|
+
// things that cost the whole list: rescan the entire 3000-entry buffer to rebuild
|
|
13
|
+
// the service dropdown, append a row, and then READ scrollHeight to follow --
|
|
14
|
+
// which forces a synchronous layout. The stream opens with `tail=300`, so that is
|
|
15
|
+
// 300 forced reflows back to back before a chatty container has even started, and
|
|
16
|
+
// then one per line after it. That is the one-to-two second freeze, and the
|
|
17
|
+
// thrash of the view jumping per line instead of settling once.
|
|
18
|
+
//
|
|
19
|
+
// So: parse and buffer immediately (cheap), and do the DOM once per frame.
|
|
20
|
+
function flushLogs() {
|
|
21
|
+
logv.frame = 0;
|
|
22
|
+
const batch = logv.pending;
|
|
23
|
+
logv.pending = [];
|
|
24
|
+
const box = ctx.$("#logview");
|
|
25
|
+
if (!box || !batch.length) return;
|
|
26
|
+
const frag = document.createDocumentFragment();
|
|
27
|
+
for (const e of batch) if (passes(e)) frag.append(logRow(e));
|
|
28
|
+
// Once per frame rather than once per line, and still read from the buffer, so
|
|
29
|
+
// a service that has aged out of it still stops being offered.
|
|
30
|
+
refreshServiceOptions();
|
|
31
|
+
if (!frag.childElementCount) return;
|
|
32
|
+
const added = frag.childElementCount;
|
|
33
|
+
box.append(frag);
|
|
34
|
+
// The buffer is capped and the DOM has to be capped with it, or rows
|
|
35
|
+
// accumulate without limit on a repro that never stops talking.
|
|
36
|
+
while (box.childElementCount > LOG_MAX) box.removeChild(box.firstChild);
|
|
37
|
+
if (logv.follow) { box.scrollTop = box.scrollHeight; return; }
|
|
38
|
+
logv.unseen += added;
|
|
39
|
+
if (logv.onUnseen) logv.onUnseen();
|
|
40
|
+
}
|
|
41
|
+
function queueLog(e) {
|
|
42
|
+
logv.pending.push(e);
|
|
43
|
+
// Frames can pause while the WebSocket keeps streaming (for example in a
|
|
44
|
+
// background tab). Keep only the latest window, just like the main buffer.
|
|
45
|
+
if (logv.pending.length > LOG_MAX) logv.pending.shift();
|
|
46
|
+
if (!logv.frame) logv.frame = requestAnimationFrame(flushLogs);
|
|
47
|
+
}
|
|
48
|
+
function releaseLogsView() {
|
|
49
|
+
if (logv.frame) cancelAnimationFrame(logv.frame);
|
|
50
|
+
logv.frame = 0;
|
|
51
|
+
logv.pending = [];
|
|
52
|
+
logv.buf = [];
|
|
53
|
+
logv.unseen = 0;
|
|
54
|
+
logv.onUnseen = null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// kubectl's `--prefix`: `[pod/<pod>/<container>] the actual line`. On a microservices
|
|
58
|
+
// workspace every line arrives like this from nine pods at once, and this function knew
|
|
59
|
+
// only Compose's `service-1 | line` -- so the SERVICE column was empty on the runtime
|
|
60
|
+
// where it matters most, the filter had nothing to offer, and 55 characters of pod name
|
|
61
|
+
// sat in front of every message pushing the content out of alignment. When the line was
|
|
62
|
+
// JSON the prefix was silently dropped instead, which is worse: nine pods' logs
|
|
63
|
+
// interleaved with no way to tell which said what.
|
|
64
|
+
const K8S_PREFIX = /^\[pod\/([^/\]]+)\/([^/\]]+)\]\s?/;
|
|
65
|
+
|
|
66
|
+
function parseLogLine(line) {
|
|
67
|
+
let service = "", content = line, pod = "";
|
|
68
|
+
const k = K8S_PREFIX.exec(line);
|
|
69
|
+
if (k) {
|
|
70
|
+
pod = k[1];
|
|
71
|
+
// The CONTAINER, not the pod: a pod name carries a replicaset hash that changes on
|
|
72
|
+
// every rollout, and the container is the same word Compose calls a service --
|
|
73
|
+
// `rocketchat`, `ddp-streamer`, `presence`. The chart suffixes half of them with
|
|
74
|
+
// `-service`, which is noise in a 92px column where every row has it.
|
|
75
|
+
service = k[2].replace(/-service$/, "");
|
|
76
|
+
content = line.slice(k[0].length);
|
|
77
|
+
}
|
|
78
|
+
const bar = content.indexOf("|");
|
|
79
|
+
if (!k && bar > 0 && bar < 40) { service = content.slice(0, bar).trim().replace(/-\d+$/, ""); content = content.slice(bar + 1).trim(); }
|
|
80
|
+
let level = "info", msg = content, ts = "";
|
|
81
|
+
const b = content.indexOf("{");
|
|
82
|
+
if (b >= 0) {
|
|
83
|
+
try {
|
|
84
|
+
const o = JSON.parse(content.slice(b));
|
|
85
|
+
msg = o.msg || o.message || content;
|
|
86
|
+
if (typeof o.level === "number") level = PINO[o.level] || "info";
|
|
87
|
+
else if (o.s) level = MONGOSEV[o.s] || "info";
|
|
88
|
+
else if (typeof o.level === "string" && LEVELS.includes(o.level.toLowerCase())) level = o.level.toLowerCase();
|
|
89
|
+
const t = o.time || (o.t && o.t.$date);
|
|
90
|
+
if (t) { const d = new Date(t); if (!isNaN(d)) ts = d.toLocaleTimeString(); }
|
|
91
|
+
if (o.name) msg = `[${o.name}] ${msg}`;
|
|
92
|
+
} catch (_) { /* not JSON — keep raw */ }
|
|
93
|
+
}
|
|
94
|
+
return { service, level, msg, ts, pod, raw: line };
|
|
95
|
+
}
|
|
96
|
+
function passes(e) {
|
|
97
|
+
return LEVELS.indexOf(e.level) >= LEVELS.indexOf(logv.min)
|
|
98
|
+
&& (!logv.svc || e.service === logv.svc)
|
|
99
|
+
&& (!logv.q || e.msg.toLowerCase().includes(logv.q));
|
|
100
|
+
}
|
|
101
|
+
function logRow(e) {
|
|
102
|
+
// The pod on the service cell's tooltip: two replicas of one service are the same
|
|
103
|
+
// word in this column, and which of the two said it is occasionally the whole
|
|
104
|
+
// question. Not in the column itself -- a replicaset hash is 20 characters of noise
|
|
105
|
+
// on every row to answer a question nobody asks most of the time.
|
|
106
|
+
return ctx.el("div", { class: "logrow lv-" + e.level },
|
|
107
|
+
ctx.el("span", { class: "lt" }, e.ts || ""),
|
|
108
|
+
ctx.el("span", { class: "ll lv-" + e.level }, e.level.toUpperCase()),
|
|
109
|
+
ctx.el("span", { class: "ls", title: e.pod || "" }, e.service || ""),
|
|
110
|
+
ctx.el("span", { class: "lm" }, e.msg));
|
|
111
|
+
}
|
|
112
|
+
// The service filter's options, rebuilt from whatever services the buffer has seen.
|
|
113
|
+
// Its own function because it has TWO callers: a full re-render, and each arriving
|
|
114
|
+
// log line. It used to live only inside renderLogList(), which the WebSocket handler
|
|
115
|
+
// never calls -- it appends rows straight to the DOM to avoid re-rendering the whole
|
|
116
|
+
// list per line. So the dropdown stayed on "all services" no matter how many
|
|
117
|
+
// services were streaming, and only filled in once something ELSE forced a
|
|
118
|
+
// re-render: changing the level, typing in search, or toggling follow.
|
|
119
|
+
function refreshServiceOptions() {
|
|
120
|
+
const sel = ctx.$("#log-svc"); if (!sel) return;
|
|
121
|
+
const svcs = [...new Set(logv.buf.map((e) => e.service).filter(Boolean))].sort();
|
|
122
|
+
// Nothing to do when the options already match; this runs per log line.
|
|
123
|
+
const shown = [...sel.options].map((o) => o.value).filter(Boolean);
|
|
124
|
+
if (shown.length === svcs.length && shown.every((s, i) => s === svcs[i])) return;
|
|
125
|
+
const cur = logv.svc;
|
|
126
|
+
// Built with el() rather than an innerHTML template: a "service" is just the
|
|
127
|
+
// text before the first `|` of a container log line (parseLogLine), so it is
|
|
128
|
+
// attacker-influenced content and must never be parsed as markup.
|
|
129
|
+
sel.innerHTML = "";
|
|
130
|
+
sel.append(ctx.el("option", { value: "" }, "all services"));
|
|
131
|
+
for (const s of svcs) sel.append(ctx.el("option", { value: s }, s));
|
|
132
|
+
// A service that has aged out of the buffer shows "all services", as the
|
|
133
|
+
// previous `selected`-attribute build did (setting .value to a missing
|
|
134
|
+
// option would instead blank the select).
|
|
135
|
+
if (!svcs.includes(cur)) logv.svc = ""; // else passes() filters to permanent empty
|
|
136
|
+
sel.value = logv.svc;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function renderLogList() {
|
|
140
|
+
const box = ctx.$("#logview"); if (!box) return;
|
|
141
|
+
// One fragment, one insertion: appending 3000 rows straight into a live node
|
|
142
|
+
// relaid the list 3000 times, which is the same defect as the stream had.
|
|
143
|
+
const frag = document.createDocumentFragment();
|
|
144
|
+
for (const e of logv.buf) if (passes(e)) frag.append(logRow(e));
|
|
145
|
+
box.innerHTML = "";
|
|
146
|
+
box.append(frag);
|
|
147
|
+
refreshServiceOptions();
|
|
148
|
+
if (logv.follow) box.scrollTop = box.scrollHeight;
|
|
149
|
+
}
|
|
150
|
+
function renderLogs(body, d) {
|
|
151
|
+
logv.buf = [];
|
|
152
|
+
const ctl = ctx.el("div", { class: "logctl" });
|
|
153
|
+
const levelSel = ctx.el("select", { class: "input", onchange: (e) => { logv.min = e.target.value; renderLogList(); } },
|
|
154
|
+
...["trace", "debug", "info", "warn", "error"].map((l) => ctx.el("option", { value: l }, l + "+")));
|
|
155
|
+
levelSel.value = logv.min;
|
|
156
|
+
const svcSel = ctx.el("select", { id: "log-svc", class: "input", onchange: (e) => { logv.svc = e.target.value; renderLogList(); } }, ctx.el("option", { value: "" }, "all services"));
|
|
157
|
+
const search = ctx.el("input", { class: "input", placeholder: "search…", "aria-label": "filter log lines",
|
|
158
|
+
oninput: (e) => { logv.q = e.target.value.trim().toLowerCase(); renderLogList(); } });
|
|
159
|
+
// logv persists across tab switches by design, but the input was rebuilt EMPTY --
|
|
160
|
+
// so an active search looked like "the container stopped logging".
|
|
161
|
+
search.value = logv.q;
|
|
162
|
+
const followCb = ctx.el("input", { type: "checkbox", onchange: (e) => { logv.follow = e.target.checked; renderLogList(); } });
|
|
163
|
+
followCb.checked = logv.follow;
|
|
164
|
+
const follow = ctx.el("label", { class: "logfollow" }, followCb, " follow");
|
|
165
|
+
const clear = ctx.el("button", { class: "btn small", onclick: () => { logv.buf = []; renderLogList(); } }, "Clear");
|
|
166
|
+
// What the stream is DOING. Without this, "connected and the container is quiet"
|
|
167
|
+
// and "the socket was refused ten seconds ago" are the same picture: an empty
|
|
168
|
+
// box. Five minutes of that is unreadable, and it is the state you most need
|
|
169
|
+
// named, because the two have nothing in common as problems.
|
|
170
|
+
const stat = ctx.el("span", { class: "logstat", id: "log-stat" });
|
|
171
|
+
ctl.append(levelSel, svcSel, search, follow, clear, stat);
|
|
172
|
+
if (d.grafana_url) ctl.append(ctx.el("a", { class: "linkchip monitor", href: d.grafana_url + "/d/houston-logs", target: "_blank",
|
|
173
|
+
...(ctx.remoteLoopback(d.grafana_url) ? { title: ctx.LOOPBACK_TITLE } : {}) }, "Logs in Grafana (Loki)"));
|
|
174
|
+
const box = ctx.el("div", { class: "logview", id: "logview" });
|
|
175
|
+
// The way back. Scrolling up detaches you from the stream, so there has to be
|
|
176
|
+
// one press that returns -- and it says how much arrived while you were reading,
|
|
177
|
+
// which is the thing you actually want to know before you go back.
|
|
178
|
+
const jump = ctx.el("button", { class: "logjump", id: "log-jump", hidden: true,
|
|
179
|
+
onclick: () => { box.scrollTop = box.scrollHeight; } });
|
|
180
|
+
const setJump = () => {
|
|
181
|
+
jump.textContent = logv.unseen ? `↓ ${logv.unseen} new` : "↓ Latest";
|
|
182
|
+
};
|
|
183
|
+
setJump();
|
|
184
|
+
// Following is a PLACE, not a mode you have to remember to switch off. Scroll up
|
|
185
|
+
// to read something and the stream stops dragging you back; scroll to the bottom
|
|
186
|
+
// and it picks up again. The checkbox says which, so the state is never a
|
|
187
|
+
// mystery -- and untangling that is most of what "lots of scrolling" was.
|
|
188
|
+
box.addEventListener("scroll", () => {
|
|
189
|
+
const atEnd = box.scrollHeight - box.scrollTop - box.clientHeight < 24;
|
|
190
|
+
if (atEnd === logv.follow) return;
|
|
191
|
+
logv.follow = atEnd;
|
|
192
|
+
followCb.checked = atEnd;
|
|
193
|
+
if (atEnd) logv.unseen = 0;
|
|
194
|
+
jump.hidden = atEnd;
|
|
195
|
+
setJump();
|
|
196
|
+
}, { passive: true });
|
|
197
|
+
logv.onUnseen = setJump;
|
|
198
|
+
body.append(ctx.el("div", { class: "logbox" }, ctl, box, jump));
|
|
199
|
+
|
|
200
|
+
const proto = location.protocol === "https:" ? "wss" : "ws";
|
|
201
|
+
// No credential in the URL any more: the session cookie rides along on the
|
|
202
|
+
// upgrade automatically, which is the only reason ?t= ever existed here.
|
|
203
|
+
const setStat = (kind, text, retry) => {
|
|
204
|
+
stat.className = "logstat " + kind;
|
|
205
|
+
stat.textContent = text;
|
|
206
|
+
if (retry) {
|
|
207
|
+
stat.append(ctx.el("button", { class: "logretry", onclick: () => ctx.renderDetail() }, "Retry"));
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
setStat("wait", "connecting…");
|
|
211
|
+
|
|
212
|
+
// A replaced pod and a restarted serve both end a previously healthy stream.
|
|
213
|
+
// Retry while this workspace is up; a successful dashboard poll can reopen it
|
|
214
|
+
// after a longer outage. Superseded streams never reconnect into another tab.
|
|
215
|
+
let tries = 0, policyClosed = false, established = false, recoveryAllowed = false;
|
|
216
|
+
const connect = () => {
|
|
217
|
+
const ws = new WebSocket(`${proto}://${location.host}/api/repros/${d.name}/logs/stream?tail=300`);
|
|
218
|
+
ctx.dstate.logsWS = ws;
|
|
219
|
+
let opened = false, got = 0, since = 0;
|
|
220
|
+
ws.onopen = () => {
|
|
221
|
+
opened = true;
|
|
222
|
+
established = true;
|
|
223
|
+
recoveryAllowed = false;
|
|
224
|
+
since = Date.now();
|
|
225
|
+
setStat("live", "streaming");
|
|
226
|
+
// A container that has printed nothing looks exactly like a broken stream.
|
|
227
|
+
// After a few seconds of an OPEN socket with no line, say which it is.
|
|
228
|
+
setTimeout(() => {
|
|
229
|
+
if (ctx.dstate.logsWS === ws && ws.readyState === 1 && !got) {
|
|
230
|
+
setStat("idle", "connected · nothing logged yet");
|
|
231
|
+
}
|
|
232
|
+
}, 4000);
|
|
233
|
+
};
|
|
234
|
+
ws.onmessage = (m) => {
|
|
235
|
+
if (ctx.dstate.logsWS !== ws) return;
|
|
236
|
+
if (!got++) setStat("live", "streaming");
|
|
237
|
+
const e = parseLogLine(m.data);
|
|
238
|
+
logv.buf.push(e);
|
|
239
|
+
if (logv.buf.length > LOG_MAX) logv.buf.shift();
|
|
240
|
+
// Buffered unfiltered, deliberately: a service that only logs at info still
|
|
241
|
+
// has to appear in the filter while the level is set to error, or you cannot
|
|
242
|
+
// select the service whose errors you are looking for.
|
|
243
|
+
queueLog(e);
|
|
244
|
+
};
|
|
245
|
+
// A socket that never opened was refused or never arrived -- the server closes
|
|
246
|
+
// before accept() for a missing session or an insufficient role, and a browser
|
|
247
|
+
// reports that as a failed handshake, not as a close code worth printing. One
|
|
248
|
+
// that opened and then closed is a stream that ended, which is a different
|
|
249
|
+
// sentence and a different thing to do about it.
|
|
250
|
+
ws.onclose = (event) => {
|
|
251
|
+
if (ctx.dstate.logsWS !== ws) return; // superseded by a newer stream
|
|
252
|
+
ctx.dstate.logsWS = null;
|
|
253
|
+
if (event.code === 1008) {
|
|
254
|
+
// A permission refusal is not a transient outage. This panel remains
|
|
255
|
+
// blocked even if the list poll succeeds or the server later recovers.
|
|
256
|
+
policyClosed = true;
|
|
257
|
+
setStat("bad", "stream refused — your session is not permitted to read these logs", true);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
const row = (ctx.ALL_REPROS || []).find((r) => r.name === d.name);
|
|
261
|
+
const up = row && ["running", "starting"].includes(row.state);
|
|
262
|
+
if (since && Date.now() - since > 60000) tries = 0; // it had been following fine
|
|
263
|
+
if (up && tries < 5 && (established || recoveryAllowed || tries > 0)) {
|
|
264
|
+
tries += 1;
|
|
265
|
+
setStat("wait", "stream ended · reconnecting…");
|
|
266
|
+
// Only into the panel it was opened for: a tab switch or a redraw since then has
|
|
267
|
+
// its own stream, and this status line is no longer on the page.
|
|
268
|
+
ctx.dstate.logsRetryTimer = setTimeout(() => {
|
|
269
|
+
ctx.dstate.logsRetryTimer = null;
|
|
270
|
+
reconnect();
|
|
271
|
+
}, 1500 * tries);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
setStat("bad", opened ? "stream ended" : "could not connect — refused or unreachable", true);
|
|
275
|
+
};
|
|
276
|
+
ws.onerror = () => { if (ctx.dstate.logsWS === ws && !opened) setStat("bad", "could not connect", true); };
|
|
277
|
+
};
|
|
278
|
+
const reconnect = ({ serverRecovered = false } = {}) => {
|
|
279
|
+
const row = (ctx.ALL_REPROS || []).find((r) => r.name === d.name);
|
|
280
|
+
if (policyClosed || !stat.isConnected || ctx.SELECTED !== d.name || ctx.VIEW !== "workspace"
|
|
281
|
+
|| ctx.dstate.tab !== "logs" || !ctx.canChange(d) || !ctx.SERVER_ONLINE || ctx.dstate.logsWS
|
|
282
|
+
|| !row || !["running", "starting"].includes(row.state)) return;
|
|
283
|
+
// Ordinary successful polls do not reset the five-attempt budget. A real
|
|
284
|
+
// unavailable -> available transition is a new chance to connect, including
|
|
285
|
+
// a first handshake that failed while serve was down.
|
|
286
|
+
if (serverRecovered) { tries = 0; recoveryAllowed = true; }
|
|
287
|
+
if (tries > 5 || (!established && !recoveryAllowed)) return;
|
|
288
|
+
if (ctx.dstate.logsRetryTimer) { clearTimeout(ctx.dstate.logsRetryTimer); ctx.dstate.logsRetryTimer = null; }
|
|
289
|
+
connect();
|
|
290
|
+
};
|
|
291
|
+
ctx.dstate.logsReconnect = reconnect;
|
|
292
|
+
if (ctx.SERVER_ONLINE) connect();
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
// A refusal, shown in place of the chart. Kept until another workspace is selected: a
|
|
296
|
+
// Kubernetes panel re-renders as its pods change, and each render asked again for an
|
|
297
|
+
// answer that was always going to be 409.
|
|
298
|
+
function statsRefused(message) {
|
|
299
|
+
ctx.dstate.statsRefused = message;
|
|
300
|
+
const box = ctx.$("#chart");
|
|
301
|
+
if (box) { box.innerHTML = ""; box.append(ctx.el("p", { class: "hint pre" }, message)); }
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function startStats() {
|
|
305
|
+
if (ctx.dstate.statsTimer) clearInterval(ctx.dstate.statsTimer);
|
|
306
|
+
ctx.dstate.statsTimer = null;
|
|
307
|
+
if (ctx.dstate.statsRefused) { statsRefused(ctx.dstate.statsRefused); return; }
|
|
308
|
+
// ONE IN FLIGHT, AND ONLY FOR THE WORKSPACE THAT ASKED. `docker stats` can take
|
|
309
|
+
// most of a minute on a loaded box while this fires every three seconds, so
|
|
310
|
+
// without a guard the calls pile up and each one makes the next slower. And the
|
|
311
|
+
// response carries no workspace name: a poll started for A that lands after the
|
|
312
|
+
// reader has clicked B pushed A's CPU and memory onto B's chart, which is a
|
|
313
|
+
// plausible-looking wrong answer rather than a visible glitch.
|
|
314
|
+
let inFlight = false;
|
|
315
|
+
const poll = async () => {
|
|
316
|
+
if (document.hidden) return; // same reasoning as the dashboard poll below
|
|
317
|
+
if (inFlight) return;
|
|
318
|
+
const asked = ctx.SELECTED;
|
|
319
|
+
inFlight = true;
|
|
320
|
+
try {
|
|
321
|
+
const s = await ctx.api(`/api/repros/${asked}/stats`);
|
|
322
|
+
if (asked !== ctx.SELECTED) return; // the reader moved on; this is A's data
|
|
323
|
+
ctx.dstate.points.push({ cpu: s.cpu || 0, mem: s.mem_mb || 0 });
|
|
324
|
+
if (ctx.dstate.points.length > 60) ctx.dstate.points.shift();
|
|
325
|
+
drawChart();
|
|
326
|
+
} catch (e) {
|
|
327
|
+
// A refusal will not fix itself in three seconds. kind ships no
|
|
328
|
+
// metrics-server, so a Kubernetes workspace answers 409 to this forever --
|
|
329
|
+
// and swallowing it left an empty box under a title that says "live",
|
|
330
|
+
// repainting every 3s, while the server's own instructions for fixing it
|
|
331
|
+
// were thrown away. Stop asking and show them.
|
|
332
|
+
if (e && (e.status === 409 || e.status === 400) && asked === ctx.SELECTED) {
|
|
333
|
+
if (ctx.dstate.statsTimer) { clearInterval(ctx.dstate.statsTimer); ctx.dstate.statsTimer = null; }
|
|
334
|
+
statsRefused(e.message);
|
|
335
|
+
}
|
|
336
|
+
/* anything else is transient: keep polling */
|
|
337
|
+
} finally {
|
|
338
|
+
// RELEASED ON EVERY PATH, including the early return above. A guard that
|
|
339
|
+
// leaks stops the chart forever, which is a worse failure than the pile-up
|
|
340
|
+
// it prevents.
|
|
341
|
+
inFlight = false;
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
poll();
|
|
345
|
+
ctx.dstate.statsTimer = setInterval(poll, 3000);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Compatibility bindings for browser diagnostics and the existing behavioural
|
|
349
|
+
// tests. The fragments share lexical code, but explicit exports make these
|
|
350
|
+
// implementation-coupled helpers observable without exposing new server API.
|
|
351
|
+
|
|
352
|
+
const STATS_INTERVAL_S = 3;
|
|
353
|
+
// A round ceiling that does not throw away the panel. [1,2,2.5,5,10] sent a peak
|
|
354
|
+
// of 1090 MB to an axis of 2000, so the line drew across the middle of an empty
|
|
355
|
+
// box; the finer steps put it at 1500 and the shape is readable again.
|
|
356
|
+
function niceMax(v, floor) {
|
|
357
|
+
v = Math.max(v, floor);
|
|
358
|
+
const pow = Math.pow(10, Math.floor(Math.log10(v)));
|
|
359
|
+
for (const m of [1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 7.5, 10]) if (m * pow >= v) return m * pow;
|
|
360
|
+
return 10 * pow;
|
|
361
|
+
}
|
|
362
|
+
// Seconds, always. The buffer holds 60 samples at STATS_INTERVAL_S, so this axis
|
|
363
|
+
// can never span more than three minutes -- and switching units inside that range
|
|
364
|
+
// produced "-2m -1m -59s", where the third label is larger than the second it
|
|
365
|
+
// sits to the right of. Fractional minutes ("-1.9m") were no better.
|
|
366
|
+
function fmtAgo(s) { return s <= 0 ? "now" : `-${s}s`; }
|
|
367
|
+
|
|
368
|
+
/* CPU and memory, as two panels rather than two lines on one plot.
|
|
369
|
+
|
|
370
|
+
It was a DUAL-AXIS chart: CPU % scaled to the left edge, MB to the right, both
|
|
371
|
+
drawn on the same grid. Where those two lines cross, and which one looks
|
|
372
|
+
higher, is decided entirely by the two independent `niceMax` calls -- so the
|
|
373
|
+
picture invents a relationship between CPU and memory that is not in the data,
|
|
374
|
+
and changes it whenever either series happens to peak. Two measures on two
|
|
375
|
+
scales are two charts.
|
|
376
|
+
|
|
377
|
+
Each panel now has one series and one honest axis, they share the time axis at
|
|
378
|
+
the bottom, and the latest value is written at the end of its own line -- which
|
|
379
|
+
is the number you actually came for, and it was previously only inferable by
|
|
380
|
+
eye against an axis. One hue for both: a single series per panel needs no
|
|
381
|
+
colour to tell it apart from anything, and green is spoken for elsewhere in
|
|
382
|
+
this interface (green = running). */
|
|
383
|
+
function drawChart() {
|
|
384
|
+
const box = ctx.$("#chart"); if (!box) return;
|
|
385
|
+
const pts = ctx.dstate.points;
|
|
386
|
+
const n = pts.length;
|
|
387
|
+
const W = 600, mL = 42, mR = 58, PH = 78, PGAP = 26, TOP = 16, XBAND = 22;
|
|
388
|
+
const H = TOP + PH + PGAP + PH + XBAND;
|
|
389
|
+
const x0 = mL, x1 = W - mR;
|
|
390
|
+
const px = (i) => (n < 2 ? x1 : x0 + (i / (n - 1)) * (x1 - x0));
|
|
391
|
+
const MUT = "var(--muted)", DIM = "var(--dim)", GRID = "var(--line)";
|
|
392
|
+
const HUE = "var(--accent-fill)", SURF = "var(--panel)";
|
|
393
|
+
|
|
394
|
+
let g = `<svg viewBox="0 0 ${W} ${H}" width="100%" style="height:auto;display:block" `
|
|
395
|
+
+ `font-family="ui-monospace, Menlo, monospace" font-size="10" `
|
|
396
|
+
+ `role="img" aria-label="CPU percent and memory in megabytes over the last few minutes">`;
|
|
397
|
+
|
|
398
|
+
const panel = (top, key, title, unit, floor, fmt) => {
|
|
399
|
+
const yTop = top, yBot = top + PH;
|
|
400
|
+
const max = niceMax(Math.max(...pts.map((p) => p[key]), 0), floor);
|
|
401
|
+
const py = (v) => yBot - (v / max) * (yBot - yTop);
|
|
402
|
+
let s = `<text x="${x0}" y="${yTop - 5}" fill="${MUT}">${title}</text>`;
|
|
403
|
+
// Solid hairlines. Dashed gridlines read as a threshold or a projection when
|
|
404
|
+
// they are only a grid.
|
|
405
|
+
for (const f of [0, 0.5, 1]) {
|
|
406
|
+
const y = yBot - f * (yBot - yTop);
|
|
407
|
+
s += `<line x1="${x0}" y1="${y}" x2="${x1}" y2="${y}" stroke="${GRID}"/>`;
|
|
408
|
+
s += `<text x="${x0 - 6}" y="${y + 3}" fill="${DIM}" text-anchor="end">${fmt(max * f)}</text>`;
|
|
409
|
+
}
|
|
410
|
+
if (n < 2) {
|
|
411
|
+
return s + `<text x="${(x0 + x1) / 2}" y="${(yTop + yBot) / 2}" fill="${DIM}" `
|
|
412
|
+
+ `text-anchor="middle">collecting…</text>`;
|
|
413
|
+
}
|
|
414
|
+
const line = pts.map((p, i) => `${px(i).toFixed(1)},${py(p[key]).toFixed(1)}`).join(" ");
|
|
415
|
+
s += `<polygon points="${x0},${yBot} ${line} ${x1},${yBot}" fill="${HUE}" opacity=".10"/>`;
|
|
416
|
+
s += `<polyline points="${line}" fill="none" stroke="${HUE}" stroke-width="2" `
|
|
417
|
+
+ `stroke-linejoin="round" stroke-linecap="round"/>`;
|
|
418
|
+
// The end of the line is where the reader looks, so it carries a marker and
|
|
419
|
+
// the current number. The ring is the surface colour, not a border.
|
|
420
|
+
const last = pts[n - 1][key], ly = py(last);
|
|
421
|
+
s += `<circle cx="${x1}" cy="${ly.toFixed(1)}" r="4" fill="${HUE}" stroke="${SURF}" stroke-width="2"/>`;
|
|
422
|
+
s += `<text x="${x1 + 9}" y="${(ly + 3.5).toFixed(1)}" fill="var(--ink)" font-weight="700">`
|
|
423
|
+
+ `${fmt(last)}<tspan fill="${DIM}" font-weight="400"> ${unit}</tspan></text>`;
|
|
424
|
+
return s;
|
|
425
|
+
};
|
|
426
|
+
|
|
427
|
+
g += panel(TOP, "cpu", "CPU", "%", 10, (v) => v.toFixed(0));
|
|
428
|
+
g += panel(TOP + PH + PGAP, "mem", "Memory", "MB", 100, (v) => v.toFixed(0));
|
|
429
|
+
|
|
430
|
+
// One time axis under both, because both panels are the same window.
|
|
431
|
+
const yAx = TOP + PH + PGAP + PH;
|
|
432
|
+
const span = (n - 1) * STATS_INTERVAL_S;
|
|
433
|
+
for (let k = 0; k <= 4; k++) {
|
|
434
|
+
const f = k / 4, x = x0 + f * (x1 - x0);
|
|
435
|
+
g += `<text x="${x}" y="${yAx + 14}" fill="${DIM}" text-anchor="middle">`
|
|
436
|
+
+ `${fmtAgo(Math.round((1 - f) * span))}</text>`;
|
|
437
|
+
}
|
|
438
|
+
box.innerHTML = g + `</svg>`;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// ---- actions ----------------------------------------------------------------
|
|
442
|
+
async function refreshDetail({ force = false } = {}) {
|
|
443
|
+
if (!ctx.SELECTED) return;
|
|
444
|
+
const name = ctx.SELECTED;
|
|
445
|
+
let d;
|
|
446
|
+
try { d = await ctx.api(`/api/repros/${name}/detail`); } catch (_) { return; } // keep old
|
|
447
|
+
if (ctx.SELECTED !== name) return;
|
|
448
|
+
ctx.dstate.detail = d;
|
|
449
|
+
// Re-rendering rebuilds the tab body, which resets logv.buf and reopens the log
|
|
450
|
+
// WebSocket -- so an unrelated job finishing used to blank the log the user was
|
|
451
|
+
// reading. A slightly stale header beats losing the logs; it refreshes on switch.
|
|
452
|
+
// `force` is for a finished lifecycle action, which MUST redraw: its spinner is
|
|
453
|
+
// in the action row, so skipping the render would strand "Stopping…" on screen.
|
|
454
|
+
if (!force && ctx.dstate.tab === "logs" && ctx.dstate.logsWS) return;
|
|
455
|
+
ctx.renderDetail();
|
|
456
|
+
}
|
|
457
|
+
// Stop/start/restart take real time -- `docker compose stop` alone spends RC's 10s
|
|
458
|
+
// SIGTERM grace period, and a Kubernetes stop waits up to 60s for pods to go -- so
|
|
459
|
+
// they are jobs, and the job dialog carries the feedback runAction used to.
|
|
460
|
+
const STATE_LABEL = { stop: "Stop", start: "Start", restart: "Restart" };
|
|
461
|
+
async function doState(name, action) {
|
|
462
|
+
// A JOB, like every other operation that takes real time. On Kubernetes a stop
|
|
463
|
+
// waits up to 60s for pods to go and says so while it waits; as a blocking call
|
|
464
|
+
// all of that was discarded and the button just sat there.
|
|
465
|
+
//
|
|
466
|
+
// A KUBERNETES START IS ALSO NOT FINISHED WHEN THE SCALE RETURNS. The URL is a
|
|
467
|
+
// port-forward that died with the old pod, and one can only be attached after the
|
|
468
|
+
// pod is ready. The service reports that as `needs_ready` rather than leaving this
|
|
469
|
+
// file to infer it from "did anything get emitted" -- a proxy that would answer
|
|
470
|
+
// wrongly the moment any other warning was added.
|
|
471
|
+
try {
|
|
472
|
+
const { job_id } = await ctx.api(`/api/repros/${name}/state`,
|
|
473
|
+
{ method: "POST", body: JSON.stringify({ action }) });
|
|
474
|
+
ctx.streamJob(job_id, `${STATE_LABEL[action] || action}: ${name}`, async (res) => {
|
|
475
|
+
await ctx.loadRepros();
|
|
476
|
+
if (res && res.needs_ready) {
|
|
477
|
+
try {
|
|
478
|
+
const r = await ctx.api(`/api/repros/${name}/ready`, { method: "POST" });
|
|
479
|
+
ctx.streamJob(r.job_id, `Waiting for ${name} to serve`, ctx.renderCreateResult);
|
|
480
|
+
} catch (e) { ctx.toast(e.message); }
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
} catch (e) { ctx.toast(e.message); }
|
|
484
|
+
}
|
|
485
|
+
async function doMonitor(name, off) {
|
|
486
|
+
if (off && !confirm(`Detach Prometheus + Grafana from ${name}?\n\nThis also deletes their data volumes.`)) return;
|
|
487
|
+
try {
|
|
488
|
+
const { job_id } = await ctx.api(`/api/repros/${name}/monitor?off=${off ? "true" : "false"}`, { method: "POST" });
|
|
489
|
+
ctx.streamJob(job_id, `${off ? "Detaching" : "Attaching"} monitoring: ${name}`, ctx.renderCreateResult);
|
|
490
|
+
} catch (e) { ctx.toast(e.message); }
|
|
491
|
+
}
|
|
492
|
+
async function doBringUp(name) {
|
|
493
|
+
try {
|
|
494
|
+
const { job_id } = await ctx.api(`/api/repros/${name}/up`, { method: "POST" });
|
|
495
|
+
ctx.streamJob(job_id, `Bringing up ${name}`, ctx.renderCreateResult);
|
|
496
|
+
} catch (e) { ctx.toast(e.message); }
|
|
497
|
+
}
|
|
498
|
+
// Take down (`del` false: the containers go, the data stays) or Delete (`del` true: everything
|
|
499
|
+
// goes), from the pane's two buttons. One dialog, replacing two browser confirm boxes whose
|
|
500
|
+
// second read Cancel as "keep the data", so a reader could not tell which button kept what.
|
|
501
|
+
// Delete asks for the name typed.
|
|
502
|
+
function doDown(name, del = false) {
|
|
503
|
+
// Everyone can act on everything -- that is deliberate, support engineers cover for each
|
|
504
|
+
// other. What they must not do is destroy a colleague's data without being told whose it
|
|
505
|
+
// is. The pane is only drawn for a viewer the ownership gate lets change this workspace.
|
|
506
|
+
const row = ctx.ALL_REPROS.find((r) => r.name === name) || {};
|
|
507
|
+
const owner = row.owner || row.created_by || "";
|
|
508
|
+
const d = ctx.dstate.detail && ctx.dstate.detail.name === name ? ctx.dstate.detail : {};
|
|
509
|
+
const kube = d.runtime === "kubernetes";
|
|
510
|
+
ctx.$("#down-title").textContent = del ? `Delete ${name}?` : `Take ${name} down?`;
|
|
511
|
+
ctx.$("#down-what").textContent = del
|
|
512
|
+
? (d.state === "down" ? "Its data and record are deleted." : "It is deleted with its data and record.")
|
|
513
|
+
+ " This cannot be undone."
|
|
514
|
+
: (kube ? "Its release is uninstalled. " : "Its containers are removed, and their logs with them. ")
|
|
515
|
+
+ "Its data and record are kept, and it is listed as down: Bring up starts it again. "
|
|
516
|
+
+ "To only pause it, use Stop.";
|
|
517
|
+
const whose = ctx.$("#down-whose");
|
|
518
|
+
whose.hidden = !owner || owner === ctx.ME;
|
|
519
|
+
whose.textContent = whose.hidden ? "" : `This workspace belongs to ${owner}, not you.`;
|
|
520
|
+
const typed = ctx.$("#down-typed"), input = ctx.$("#down-input"), go = ctx.$("#down-go");
|
|
521
|
+
typed.hidden = !del;
|
|
522
|
+
ctx.$("#down-name").textContent = name;
|
|
523
|
+
input.value = "";
|
|
524
|
+
go.textContent = del ? "Delete" : "Take down";
|
|
525
|
+
go.className = del ? "btn danger" : "btn";
|
|
526
|
+
go.disabled = del;
|
|
527
|
+
input.oninput = () => { go.disabled = input.value.trim() !== name; };
|
|
528
|
+
// Enter in the name submits the form, and a method=dialog form closed the dialog with nothing
|
|
529
|
+
// done: it presses Delete instead, once the name is right.
|
|
530
|
+
ctx.$("#down-form").onsubmit = (e) => { e.preventDefault(); if (!go.disabled) go.click(); };
|
|
531
|
+
ctx.$("#down-cancel").onclick = () => ctx.$("#down-dialog").close();
|
|
532
|
+
// A job now. Measured at 48-61s on Kubernetes, where the teardown waits for the namespace
|
|
533
|
+
// and its PersistentVolumeClaims to actually go -- a wait worth watching rather than a
|
|
534
|
+
// button that looks hung for a minute.
|
|
535
|
+
go.onclick = async () => {
|
|
536
|
+
if (del && input.value.trim() !== name) return;
|
|
537
|
+
ctx.$("#down-dialog").close();
|
|
538
|
+
try {
|
|
539
|
+
const { job_id } = await ctx.api(`/api/repros/${name}?volumes=${del}&confirm=${del}`,
|
|
540
|
+
{ method: "DELETE" });
|
|
541
|
+
ctx.streamJob(job_id, `${del ? "Deleting" : "Taking down"} ${name}`, () => ctx.loadRepros());
|
|
542
|
+
} catch (e) { ctx.toast(e.message); }
|
|
543
|
+
};
|
|
544
|
+
ctx.$("#down-dialog").showModal();
|
|
545
|
+
if (del) input.focus();
|
|
546
|
+
}
|
|
547
|
+
// ---- seed dialog ------------------------------------------------------------
|
|
548
|
+
let SEED_TARGET = null;
|
|
549
|
+
async function openSeed(name) {
|
|
550
|
+
await ctx.loadSeedChoices();
|
|
551
|
+
SEED_TARGET = name;
|
|
552
|
+
ctx.$("#seed-title").textContent = `Add sample data: ${name}`;
|
|
553
|
+
ctx.$("#seed-form").reset();
|
|
554
|
+
syncSeedMode();
|
|
555
|
+
ctx.$("#seed-dialog").showModal();
|
|
556
|
+
}
|
|
557
|
+
function syncSeedMode() {
|
|
558
|
+
const scale = ctx.$("#seed-mode").value === "scale";
|
|
559
|
+
ctx.$("#seed-profile-row").hidden = scale;
|
|
560
|
+
ctx.$("#seed-scale-row").hidden = !scale;
|
|
561
|
+
ctx.$("#seed-options").hidden = scale;
|
|
562
|
+
ctx.$("#seed-form").profile.disabled = scale;
|
|
563
|
+
for (const input of ctx.$("#seed-options").querySelectorAll("input")) input.disabled = scale;
|
|
564
|
+
ctx.$("#seed-form").history_days.disabled = scale || !ctx.$("#seed-form").history.checked;
|
|
565
|
+
ctx.$("#seed-hint").textContent = scale
|
|
566
|
+
? "Writes straight into the database: users who cannot sign in, no Rocket.Chat checks. "
|
|
567
|
+
+ "For load and capacity tests only."
|
|
568
|
+
: "Creates users you can sign in as, with their rooms and messages, through Rocket.Chat itself.";
|
|
569
|
+
}
|
|
570
|
+
async function submitSeed() {
|
|
571
|
+
const f = ctx.$("#seed-form");
|
|
572
|
+
const scale = f.mode.value === "scale";
|
|
573
|
+
// Validate first: closing the dialog before checking discarded the typed spec and
|
|
574
|
+
// reset the mode selector, so the user had to re-pick "Bulk --scale" every time.
|
|
575
|
+
if (scale && !f.scale.value.trim()) { ctx.toast("enter a scale spec"); return; }
|
|
576
|
+
const selection = scale ? null : ctx.seedRequest(f);
|
|
577
|
+
if (!scale && selection === null) return;
|
|
578
|
+
ctx.$("#seed-dialog").close();
|
|
579
|
+
try {
|
|
580
|
+
let job;
|
|
581
|
+
if (scale) {
|
|
582
|
+
job = await ctx.api(`/api/repros/${SEED_TARGET}/scale`, { method: "POST", body: JSON.stringify({ scale: f.scale.value.trim() }) });
|
|
583
|
+
ctx.streamJob(job.job_id, `Bulk test data: ${SEED_TARGET}`);
|
|
584
|
+
} else {
|
|
585
|
+
job = await ctx.api(`/api/repros/${SEED_TARGET}/seed`, { method: "POST", body: JSON.stringify({ profile: f.profile.value, ...selection }) });
|
|
586
|
+
// The renderer goes here as well as in JOB_RESULT_RENDERER: the table only
|
|
587
|
+
// covers reopening a job from Activity, and the run you just started is the
|
|
588
|
+
// one you are watching.
|
|
589
|
+
ctx.streamJob(job.job_id, `Seeding ${SEED_TARGET} (${f.profile.value})`,
|
|
590
|
+
ctx.renderSeedResult);
|
|
591
|
+
}
|
|
592
|
+
} catch (e) { ctx.toast(e.message); }
|
|
593
|
+
}
|
|
594
|
+
async function clearScale() {
|
|
595
|
+
if (!confirm(`Remove all bulk test data from ${SEED_TARGET}?`)) return;
|
|
596
|
+
ctx.$("#seed-dialog").close();
|
|
597
|
+
try { const { job_id } = await ctx.api(`/api/repros/${SEED_TARGET}/scale`, { method: "DELETE" }); ctx.streamJob(job_id, `Removing bulk test data: ${SEED_TARGET}`); }
|
|
598
|
+
catch (e) { ctx.toast(e.message); }
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
Object.defineProperties(ctx, {
|
|
602
|
+
"LEVELS": { enumerable: true, get: () => LEVELS },
|
|
603
|
+
"PINO": { enumerable: true, get: () => PINO },
|
|
604
|
+
"MONGOSEV": { enumerable: true, get: () => MONGOSEV },
|
|
605
|
+
"LOG_MAX": { enumerable: true, get: () => LOG_MAX },
|
|
606
|
+
"logv": { enumerable: true, get: () => logv },
|
|
607
|
+
"flushLogs": { enumerable: true, get: () => flushLogs },
|
|
608
|
+
"queueLog": { enumerable: true, get: () => queueLog },
|
|
609
|
+
"releaseLogsView": { enumerable: true, get: () => releaseLogsView },
|
|
610
|
+
"K8S_PREFIX": { enumerable: true, get: () => K8S_PREFIX },
|
|
611
|
+
"parseLogLine": { enumerable: true, get: () => parseLogLine },
|
|
612
|
+
"passes": { enumerable: true, get: () => passes },
|
|
613
|
+
"logRow": { enumerable: true, get: () => logRow },
|
|
614
|
+
"refreshServiceOptions": { enumerable: true, get: () => refreshServiceOptions },
|
|
615
|
+
"renderLogList": { enumerable: true, get: () => renderLogList },
|
|
616
|
+
"renderLogs": { enumerable: true, get: () => renderLogs },
|
|
617
|
+
"startStats": { enumerable: true, get: () => startStats },
|
|
618
|
+
"STATS_INTERVAL_S": { enumerable: true, get: () => STATS_INTERVAL_S },
|
|
619
|
+
"niceMax": { enumerable: true, get: () => niceMax },
|
|
620
|
+
"fmtAgo": { enumerable: true, get: () => fmtAgo },
|
|
621
|
+
"drawChart": { enumerable: true, get: () => drawChart },
|
|
622
|
+
"refreshDetail": { enumerable: true, get: () => refreshDetail },
|
|
623
|
+
"STATE_LABEL": { enumerable: true, get: () => STATE_LABEL },
|
|
624
|
+
"doState": { enumerable: true, get: () => doState },
|
|
625
|
+
"doMonitor": { enumerable: true, get: () => doMonitor },
|
|
626
|
+
"doBringUp": { enumerable: true, get: () => doBringUp },
|
|
627
|
+
"doDown": { enumerable: true, get: () => doDown },
|
|
628
|
+
"SEED_TARGET": { enumerable: true, get: () => SEED_TARGET, set: value => { SEED_TARGET = value; } },
|
|
629
|
+
"openSeed": { enumerable: true, get: () => openSeed },
|
|
630
|
+
"syncSeedMode": { enumerable: true, get: () => syncSeedMode },
|
|
631
|
+
"submitSeed": { enumerable: true, get: () => submitSeed },
|
|
632
|
+
"clearScale": { enumerable: true, get: () => clearScale },
|
|
633
|
+
});
|
|
634
|
+
export { LEVELS, PINO, MONGOSEV, LOG_MAX, logv, flushLogs, queueLog, releaseLogsView, K8S_PREFIX, parseLogLine, passes, logRow, refreshServiceOptions, renderLogList, renderLogs, startStats, STATS_INTERVAL_S, niceMax, fmtAgo, drawChart, refreshDetail, STATE_LABEL, doState, doMonitor, doBringUp, doDown, SEED_TARGET, openSeed, syncSeedMode, submitSeed, clearScale };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import "./util.js";
|
|
2
|
+
import "./api.js";
|
|
3
|
+
import "./state.js";
|
|
4
|
+
import "./render.js";
|
|
5
|
+
import "./detail.js";
|
|
6
|
+
import "./logs.js";
|
|
7
|
+
import "./jobs.js";
|
|
8
|
+
import "./create.js";
|
|
9
|
+
import "./people.js";
|
|
10
|
+
import "./clusters.js";
|
|
11
|
+
import "./options.js";
|
|
12
|
+
import "./perf.js";
|
|
13
|
+
import "./theme.js";
|
|
14
|
+
import "./clusters-tail.js";
|