@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,281 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.checkSeed = checkSeed;
|
|
4
|
+
exports.seedPrepared = seedPrepared;
|
|
5
|
+
exports.seedInlineLocked = seedInlineLocked;
|
|
6
|
+
exports.runSeedInline = runSeedInline;
|
|
7
|
+
/**
|
|
8
|
+
* Seeding a workspace through REST, and checking that what was asked for arrived.
|
|
9
|
+
*
|
|
10
|
+
* Tier 3. `runSeedInline` takes the repro lock -- it was the ONLY mutating operation that did
|
|
11
|
+
* not, and a seed running into a backup's quiesce fails mid-manifest and reports faults
|
|
12
|
+
* nobody caused. Reentrant, so `up --seed` is unaffected.
|
|
13
|
+
*/
|
|
14
|
+
const errors_1 = require("../../lib/errors");
|
|
15
|
+
const events_1 = require("../../lib/events");
|
|
16
|
+
const resources_1 = require("../../perf/resources");
|
|
17
|
+
const apply_1 = require("../../seed/apply");
|
|
18
|
+
const plan_1 = require("../../seed/plan");
|
|
19
|
+
const check_1 = require("../../seed/check");
|
|
20
|
+
const receipt_1 = require("../../seed/receipt");
|
|
21
|
+
const history_1 = require("../../seed/history");
|
|
22
|
+
const verification_1 = require("../../seed/verification");
|
|
23
|
+
const seed_db_1 = require("../seed-db");
|
|
24
|
+
const journal_1 = require("../journal");
|
|
25
|
+
const record_1 = require("../runner/record");
|
|
26
|
+
const locks_1 = require("../runner/locks");
|
|
27
|
+
const admin_1 = require("./admin");
|
|
28
|
+
const types_1 = require("./types");
|
|
29
|
+
/**
|
|
30
|
+
* Read the seeded workspace back, compare it with the manifest, and record it.
|
|
31
|
+
*
|
|
32
|
+
* Both front-ends call this, because both had the same hole: the seed summary was what
|
|
33
|
+
* the seeder ASKED for, and nothing anywhere checked it. `messages: ~62` -- the tilde was
|
|
34
|
+
* the tool admitting it did not know.
|
|
35
|
+
*
|
|
36
|
+
* REPORTS, it does not refuse. A mismatch is written into the result and warned about;
|
|
37
|
+
* whether that ends the command is the caller's decision and the default is that it does
|
|
38
|
+
* not. The version of this idea that shipped elsewhere gated on exact equality over a
|
|
39
|
+
* seeder that was losing every thread reply, so `up --seed` failed on a healthy
|
|
40
|
+
* workspace -- and a check that fails when nothing is wrong is one people learn to
|
|
41
|
+
* bypass.
|
|
42
|
+
*
|
|
43
|
+
* The verification is persisted into `repro.json` either way.
|
|
44
|
+
*/
|
|
45
|
+
async function checkSeed(meta, auth, plan, result, emit = events_1.nullEmit, tokens = {}, receipt, database) {
|
|
46
|
+
let verdict;
|
|
47
|
+
try {
|
|
48
|
+
if (receipt !== undefined) {
|
|
49
|
+
verdict = await (0, verification_1.verifyBatch)(meta.rootUrl, auth, plan, receipt, tokens, result);
|
|
50
|
+
if (database !== undefined) {
|
|
51
|
+
try {
|
|
52
|
+
const history = await (0, history_1.verifyHistory)(receipt, database);
|
|
53
|
+
const faults = Array.isArray(history.faults)
|
|
54
|
+
? history.faults
|
|
55
|
+
: [];
|
|
56
|
+
verdict = {
|
|
57
|
+
...verdict,
|
|
58
|
+
faults: [...verdict.faults, ...faults],
|
|
59
|
+
ok: faults.length > 0 ? false : verdict.ok,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
verdict = {
|
|
64
|
+
...verdict,
|
|
65
|
+
unreadable: [
|
|
66
|
+
...verdict.unreadable,
|
|
67
|
+
{ what: 'historical metadata', why: errorText(error) },
|
|
68
|
+
],
|
|
69
|
+
ok: verdict.ok === false ? false : null,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
const facts = await (0, check_1.readback)(meta.rootUrl, auth, plan, { tokens });
|
|
76
|
+
verdict = (0, check_1.verify)(plan, facts);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// A check must never break the seed.
|
|
81
|
+
(0, events_1.warn)(emit, `could not read the seed back: ${errorText(error)}`, { phase: 'seed' });
|
|
82
|
+
// `why` travels with the verdict, so a caller rendering from the RETURN VALUE can say
|
|
83
|
+
// what went wrong without also subscribing to the events.
|
|
84
|
+
verdict = {
|
|
85
|
+
ok: null,
|
|
86
|
+
faults: [],
|
|
87
|
+
extra: [],
|
|
88
|
+
unreadable: [{ what: 'seed', why: errorText(error) }],
|
|
89
|
+
checked: 0,
|
|
90
|
+
rooms: [],
|
|
91
|
+
};
|
|
92
|
+
result.verification_why = errorText(error);
|
|
93
|
+
}
|
|
94
|
+
result.verification = {
|
|
95
|
+
ok: verdict.ok,
|
|
96
|
+
faults: verdict.faults,
|
|
97
|
+
extra: verdict.extra,
|
|
98
|
+
unreadable: verdict.unreadable,
|
|
99
|
+
checked: verdict.checked,
|
|
100
|
+
...(result.verification_why === undefined ? {} : { why: result.verification_why }),
|
|
101
|
+
...('checks_completed' in verdict
|
|
102
|
+
? {
|
|
103
|
+
checks_completed: verdict.checks_completed,
|
|
104
|
+
features: 'features' in verdict ? verdict.features : {},
|
|
105
|
+
}
|
|
106
|
+
: {}),
|
|
107
|
+
};
|
|
108
|
+
result.readback = verdict.rooms;
|
|
109
|
+
if (receipt !== undefined)
|
|
110
|
+
receipt.record('verification:latest', 'done', result.verification);
|
|
111
|
+
if (verdict.faults.length > 0) {
|
|
112
|
+
(0, events_1.warn)(emit, `seed readback found ${String(verdict.faults.length)} mismatch(es): ` +
|
|
113
|
+
verdict.faults
|
|
114
|
+
.slice(0, 3)
|
|
115
|
+
.map((fault) => `${fault.room || 'users'} wanted ${String(fault.want)}, found ${String(fault.got)}`)
|
|
116
|
+
.join('; '), { phase: 'seed' });
|
|
117
|
+
}
|
|
118
|
+
else if (verdict.extra.length > 0) {
|
|
119
|
+
(0, events_1.info)(emit, `readback: ${String(verdict.extra.length)} room(s) hold more than this run ` +
|
|
120
|
+
'planned — they had content already (a re-seed, a preset, a restore)', { phase: 'seed' });
|
|
121
|
+
}
|
|
122
|
+
else if (verdict.unreadable.length > 0) {
|
|
123
|
+
(0, events_1.warn)(emit, `${String(verdict.unreadable.length)} room(s) could not be read back — ` +
|
|
124
|
+
'not counted as a fault', { phase: 'seed' });
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
(0, events_1.info)(emit, `readback: ${String(verdict.checked)} rooms match the plan`, { phase: 'seed' });
|
|
128
|
+
}
|
|
129
|
+
try {
|
|
130
|
+
await (0, record_1.updateMeta)(meta.name, (current) => {
|
|
131
|
+
current.extra.seed = {
|
|
132
|
+
profile: plan.profile,
|
|
133
|
+
planned: result.planned ?? {},
|
|
134
|
+
// EVERY KEY IS WRITTEN, with `null` for a value this run did not report, as the
|
|
135
|
+
// record has always carried them, and `JSON.stringify` drops a property whose value
|
|
136
|
+
// is `undefined` -- so a partial result produced a record with fewer keys than the
|
|
137
|
+
// established one, which a key-presence comparison of the two records reads as a
|
|
138
|
+
// different document.
|
|
139
|
+
actual: {
|
|
140
|
+
users: result.users ?? null,
|
|
141
|
+
rooms: result.rooms ?? null,
|
|
142
|
+
rooms_total: result.rooms_total ?? null,
|
|
143
|
+
messages: result.messages ?? null,
|
|
144
|
+
threads: result.threads ?? null,
|
|
145
|
+
dms: result.dms ?? null,
|
|
146
|
+
},
|
|
147
|
+
verification: result.verification,
|
|
148
|
+
scenarios: plan.scenarios,
|
|
149
|
+
history: result.history ?? null,
|
|
150
|
+
run_id: result.run_id ?? null,
|
|
151
|
+
features: {
|
|
152
|
+
files: result.files ?? 0,
|
|
153
|
+
total_content: result.total_content ?? null,
|
|
154
|
+
custom_emoji: result.custom_emoji ?? [],
|
|
155
|
+
},
|
|
156
|
+
locations: result.created ?? [],
|
|
157
|
+
at: new Date().toISOString().slice(0, 19) + '+00:00',
|
|
158
|
+
};
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
catch {
|
|
162
|
+
(0, events_1.warn)(emit, 'seed verification could not be projected into workspace metadata; consult the durable seed receipt', { phase: 'seed' });
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
...verdict,
|
|
166
|
+
...(result.verification_why === undefined ? {} : { why: result.verification_why }),
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/** One prepared driver, used by CLI, GUI, creation and readiness recovery. */
|
|
170
|
+
async function seedPrepared(meta, auth, plan, emit, tokens, log) {
|
|
171
|
+
const target = JSON.stringify({
|
|
172
|
+
runtime: meta.extra.runtime ?? 'docker',
|
|
173
|
+
project: meta.project,
|
|
174
|
+
namespace: meta.extra.namespace ?? null,
|
|
175
|
+
context: meta.extra.context ?? null,
|
|
176
|
+
admin: auth.userId,
|
|
177
|
+
});
|
|
178
|
+
// Database resolution and write privilege checks precede all historical API mutations.
|
|
179
|
+
const database = plan.historyDays === null ? null : await (0, seed_db_1.seedDatabase)(meta, auth.userId);
|
|
180
|
+
const receipt = new receipt_1.Receipt(plan, target, meta.name);
|
|
181
|
+
if (database !== null) {
|
|
182
|
+
const prior = receipt.done('database:target');
|
|
183
|
+
if (prior !== null && prior.target !== database.target)
|
|
184
|
+
throw new errors_1.ValidationError('unfinished historical seed has a different database target');
|
|
185
|
+
receipt.record('database:target', 'done', { target: database.target });
|
|
186
|
+
}
|
|
187
|
+
const report = log ?? ((message) => (0, events_1.info)(emit, message.trim(), { phase: 'seed' }));
|
|
188
|
+
const summary = await (0, apply_1.seed)(meta.rootUrl, auth, plan, {
|
|
189
|
+
tokensOut: tokens,
|
|
190
|
+
adminPassword: (0, record_1.adminPass)(meta),
|
|
191
|
+
workspace: meta.name,
|
|
192
|
+
receipt,
|
|
193
|
+
log: report,
|
|
194
|
+
...(typeof meta.extra.seed === 'object' && meta.extra.seed !== null
|
|
195
|
+
? { legacy: meta.extra.seed }
|
|
196
|
+
: {}),
|
|
197
|
+
});
|
|
198
|
+
if (database !== null &&
|
|
199
|
+
((Array.isArray(summary.failed) && summary.failed.length > 0) ||
|
|
200
|
+
(Array.isArray(summary.users_failed) && summary.users_failed.length > 0) ||
|
|
201
|
+
[...receipt.entries.values()].some((entry) => entry.state === 'intent' &&
|
|
202
|
+
!entry.key.startsWith('history:') &&
|
|
203
|
+
!entry.key.startsWith('probe:'))))
|
|
204
|
+
throw new errors_1.ValidationError('historical seed API creation is incomplete; resume the same run before assigning dates');
|
|
205
|
+
if (database !== null)
|
|
206
|
+
summary.history = await (0, history_1.applyHistory)(plan, receipt, database, report);
|
|
207
|
+
await checkSeed(meta, auth, plan, summary, emit, tokens, typeof summary.run_id === 'string' ? receipt : undefined, database ?? undefined);
|
|
208
|
+
if ([...receipt.entries.values()].some((entry) => entry.state === 'intent'))
|
|
209
|
+
throw new errors_1.ValidationError('seed has unresolved operations; its recovery receipt remains active');
|
|
210
|
+
receipt.finish();
|
|
211
|
+
return summary;
|
|
212
|
+
}
|
|
213
|
+
function errorText(error) {
|
|
214
|
+
return error instanceof Error ? error.message : String(error);
|
|
215
|
+
}
|
|
216
|
+
async function seedInlineLocked(meta, profile, stats, emit, overrides = {}) {
|
|
217
|
+
let auth;
|
|
218
|
+
try {
|
|
219
|
+
auth = await (0, admin_1.login)(meta);
|
|
220
|
+
}
|
|
221
|
+
catch (error) {
|
|
222
|
+
throw new errors_1.NotReadyError(`can't seed - workspace not ready: ${errorText(error)}`);
|
|
223
|
+
}
|
|
224
|
+
let plan;
|
|
225
|
+
try {
|
|
226
|
+
plan = (0, plan_1.planFrom)(profile, overrides);
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
throw new errors_1.ValidationError(errorText(error));
|
|
230
|
+
}
|
|
231
|
+
(0, events_1.info)(emit, `seeding (profile ${profile})`, { phase: 'seed' });
|
|
232
|
+
const mon = stats ? new resources_1.ResourceMonitor(meta.name).start() : null;
|
|
233
|
+
const t0 = Date.now();
|
|
234
|
+
const tokens = {};
|
|
235
|
+
let summary;
|
|
236
|
+
const paused = {
|
|
237
|
+
resources: null,
|
|
238
|
+
};
|
|
239
|
+
try {
|
|
240
|
+
summary = await seedPrepared(meta, auth, plan, emit, tokens);
|
|
241
|
+
}
|
|
242
|
+
finally {
|
|
243
|
+
if (mon !== null)
|
|
244
|
+
paused.resources = await mon.stop();
|
|
245
|
+
}
|
|
246
|
+
summary.total_s = (Date.now() - t0) / 1000;
|
|
247
|
+
if (paused.resources !== null)
|
|
248
|
+
summary.resources_keys = Object.keys(paused.resources).sort();
|
|
249
|
+
return summary;
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Seed a workspace through REST, serialised like every other mutating operation.
|
|
253
|
+
*
|
|
254
|
+
* IT WAS THE ONLY ONE THAT WAS NOT. `createRepro`, `setState`, `teardown`, `setEnv`,
|
|
255
|
+
* `monitor.attach`, `backup.create`, `upgrade.run`, `runScale` and `clearScale` all take
|
|
256
|
+
* the lock; a seed writes the same collections through a different door and took nothing.
|
|
257
|
+
*
|
|
258
|
+
* Reentrant, so the `up --seed` path is unaffected: `createRepro` already holds this lock
|
|
259
|
+
* and re-entering it is free.
|
|
260
|
+
*/
|
|
261
|
+
async function runSeedInline(meta, profile, stats, emit, overrides = {}, expectedRun, resumeIf) {
|
|
262
|
+
return await (0, locks_1.reproLock)(meta.name, async () => {
|
|
263
|
+
if (expectedRun !== undefined) {
|
|
264
|
+
const pending = (0, receipt_1.pendingReceipt)(meta.name);
|
|
265
|
+
if (pending === null)
|
|
266
|
+
return { resumed: false };
|
|
267
|
+
if (pending.run !== expectedRun)
|
|
268
|
+
throw new errors_1.ConflictError('the pending seed changed while waiting for its workspace lock');
|
|
269
|
+
}
|
|
270
|
+
if (resumeIf !== undefined && !(await resumeIf()))
|
|
271
|
+
return { resumed: false };
|
|
272
|
+
const result = await seedInlineLocked(meta, profile, stats, emit, overrides);
|
|
273
|
+
// A second ready waiter must not see the same abandoned request after a
|
|
274
|
+
// completed recovery, even if its optional metadata projection was unwritable.
|
|
275
|
+
if (resumeIf !== undefined)
|
|
276
|
+
(0, journal_1.clearKind)(journal_1.CREATE_UNFINISHED, meta.name);
|
|
277
|
+
return result;
|
|
278
|
+
}, {
|
|
279
|
+
timeoutMs: types_1.INTERACTIVE_LOCK_WAIT * 1000,
|
|
280
|
+
});
|
|
281
|
+
}
|
|
@@ -0,0 +1,392 @@
|
|
|
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.ENGINE_FLOOR_MEMORY_GIB = exports.ENGINE_FLOOR_CPUS = exports.MICROSERVICES_MB = exports.KUBE_CHART_MB = exports.CLUSTER_MB = exports.MONITORING_MB = exports.PRESET_MB = exports.WORKSPACE_MB = void 0;
|
|
37
|
+
exports.ldapParamsMb = ldapParamsMb;
|
|
38
|
+
exports.voiceParamsMb = voiceParamsMb;
|
|
39
|
+
exports.hostReserveMb = hostReserveMb;
|
|
40
|
+
exports.capacity = capacity;
|
|
41
|
+
exports.kubeOverheadMb = kubeOverheadMb;
|
|
42
|
+
exports.checkEngineFloor = checkEngineFloor;
|
|
43
|
+
exports.runtimeCost = runtimeCost;
|
|
44
|
+
exports.refuseForCapacity = refuseForCapacity;
|
|
45
|
+
exports.sayWhatIsLeft = sayWhatIsLeft;
|
|
46
|
+
exports.neededMb = neededMb;
|
|
47
|
+
exports.checkCapacity = checkCapacity;
|
|
48
|
+
/**
|
|
49
|
+
* What a workspace costs, and whether this box has it.
|
|
50
|
+
*
|
|
51
|
+
* Tier 0. `checkCapacity` REFUSES rather than warning: the tool is usually run on a laptop
|
|
52
|
+
* already running other stacks, and a create that starts and then cannot finish leaves a
|
|
53
|
+
* half-made workspace behind.
|
|
54
|
+
*/
|
|
55
|
+
const composite_1 = require("../../lib/presets/composite");
|
|
56
|
+
const errors_1 = require("../../lib/errors");
|
|
57
|
+
const format_1 = require("../../lib/format");
|
|
58
|
+
const events_1 = require("../../lib/events");
|
|
59
|
+
const topology = __importStar(require("../topology"));
|
|
60
|
+
const host = __importStar(require("../runner/host"));
|
|
61
|
+
const queries_1 = require("../runner/queries");
|
|
62
|
+
const record_1 = require("../runner/record");
|
|
63
|
+
const request = __importStar(require("./request"));
|
|
64
|
+
/**
|
|
65
|
+
* Rocket.Chat settled at 670-770 MB and MongoDB at 124-184 MB per workspace on the host
|
|
66
|
+
* that OOMed -- so ~950 MB at REST. Rounded UP to 1100, deliberately: those were idle
|
|
67
|
+
* figures, RC's Node heap reached 721 MB under a mild load test, and calibrating to the
|
|
68
|
+
* resting case would have permitted exactly the seven stacks that took the machine down.
|
|
69
|
+
*/
|
|
70
|
+
exports.WORKSPACE_MB = 1100;
|
|
71
|
+
/** Sidecars a preset adds. Keycloak (saml/oidc) is by far the largest. */
|
|
72
|
+
exports.PRESET_MB = Object.freeze({
|
|
73
|
+
saml: 450,
|
|
74
|
+
oidc: 450,
|
|
75
|
+
s3_minio: 120,
|
|
76
|
+
ldap: 80,
|
|
77
|
+
livechat: 60,
|
|
78
|
+
'multi-instance': 400,
|
|
79
|
+
email: 40,
|
|
80
|
+
webhooks: 30,
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* What the ldap preset's params add to its charge. `directory=ad`: Samba held 56 MB with
|
|
84
|
+
* 1,600 users and 103 MB with 20,000 (measured), where OpenLDAP's share of `PRESET_MB.ldap`
|
|
85
|
+
* is small, so it is charged by size. `idp`: a Keycloak, as the saml and oidc presets charge
|
|
86
|
+
* for theirs. A composed workspace names the params `ldap.*`.
|
|
87
|
+
*/
|
|
88
|
+
function ldapParamsMb(params) {
|
|
89
|
+
const param = (key) => params[`ldap.${key}`] ?? params[key];
|
|
90
|
+
let need = 0;
|
|
91
|
+
if (param('directory') === 'ad') {
|
|
92
|
+
const users = Number.parseInt(String(param('users') ?? '5'), 10);
|
|
93
|
+
need += 60 + 3 * Math.ceil((Number.isNaN(users) ? 5 : users) / 1000);
|
|
94
|
+
}
|
|
95
|
+
if (param('idp') === 'saml' || param('idp') === 'oidc')
|
|
96
|
+
need += exports.PRESET_MB.saml ?? 0;
|
|
97
|
+
return need;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* What the voice preset's `sip_integration=on` adds: Drachtio and FreeSWITCH, measured idle at
|
|
101
|
+
* 7 and 27 MiB on 8.7.0, with room for calls; `pbx=on` adds the lab's Asterisk, idle at
|
|
102
|
+
* 48.5 MiB (2026-10-16). A composed workspace names the params `voice.sip_integration` and
|
|
103
|
+
* `voice.pbx`; 2.1.3 spelled the first `sip` (VOICE_PARAM_ALIASES), and its records still do.
|
|
104
|
+
*/
|
|
105
|
+
function voiceParamsMb(params) {
|
|
106
|
+
const on = (key) => String(params[`voice.${key}`] ?? params[key] ?? '')
|
|
107
|
+
.trim()
|
|
108
|
+
.toLowerCase() === 'on';
|
|
109
|
+
return (on('sip_integration') || on('sip') ? 60 : 0) + (on('pbx') ? 80 : 0);
|
|
110
|
+
}
|
|
111
|
+
/** Prometheus + Grafana + Loki + the OTel collector + two exporters. */
|
|
112
|
+
exports.MONITORING_MB = 280;
|
|
113
|
+
/**
|
|
114
|
+
* Kubernetes costs on top of a workspace, and both are load-bearing for the same reason
|
|
115
|
+
* WORKSPACE_MB is: the formula that refuses a create has to know what it is about to
|
|
116
|
+
* start, or it refuses the wrong things and permits the fatal ones.
|
|
117
|
+
*
|
|
118
|
+
* CLUSTER_MB is MEASURED -- `docker stats kind-control-plane` reads 573 MiB idle -- and
|
|
119
|
+
* is charged ONCE, only when the cluster still has to be created. Every workspace after
|
|
120
|
+
* that shares it.
|
|
121
|
+
*/
|
|
122
|
+
exports.CLUSTER_MB = 600;
|
|
123
|
+
/**
|
|
124
|
+
* What the CHART costs beyond the app itself, and it applies to both deployments.
|
|
125
|
+
* Measured, and it corrected an assumption: a "monolith" on this chart is FIVE pods, not
|
|
126
|
+
* two -- it runs NATS regardless of `microservices.enabled`.
|
|
127
|
+
*/
|
|
128
|
+
exports.KUBE_CHART_MB = 500;
|
|
129
|
+
/**
|
|
130
|
+
* MICROSERVICES_MB is now HALF measured: a microservices workspace on chart 7.0.2 is nine
|
|
131
|
+
* pods against a monolith's five, and the four extra are `account`, `authorization`,
|
|
132
|
+
* `ddp-streamer` and `presence`. What those four COST is still estimated, 4 x ~200 MB,
|
|
133
|
+
* and it stays deliberately on the generous side: under-charging lets through a create
|
|
134
|
+
* that OOMs a swapless host.
|
|
135
|
+
*/
|
|
136
|
+
exports.MICROSERVICES_MB = 800;
|
|
137
|
+
/**
|
|
138
|
+
* Left unspent: for the OS, Docker, the page cache -- and, mostly, for GROWTH. A fifth of
|
|
139
|
+
* the host, never below 1 GB.
|
|
140
|
+
*
|
|
141
|
+
* The proportion is the lesson from the incident. That box OOMed while MemAvailable still
|
|
142
|
+
* read ~3.3 GB, because the danger is not the memory a workspace takes at admission but
|
|
143
|
+
* the memory seven already-admitted ones take an hour later.
|
|
144
|
+
*/
|
|
145
|
+
function hostReserveMb(totalMb) {
|
|
146
|
+
return Math.max(1024, Math.floor(totalMb / 5));
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* How much room this machine has left, in workspaces.
|
|
150
|
+
*
|
|
151
|
+
* ONE formula, three consumers: `checkCapacity` refuses a create with it, `houston
|
|
152
|
+
* doctor` reports it, and the GUI's home page leads with it. They used to agree by
|
|
153
|
+
* coincidence -- doctor carried its own copy of the arithmetic -- and a home page that
|
|
154
|
+
* says "room for 2 more" while the create is refused is worse than one that says
|
|
155
|
+
* nothing.
|
|
156
|
+
*
|
|
157
|
+
* `room` IS DENOMINATED IN COMPOSE WORKSPACES, AND SAYS SO. It divided by WORKSPACE_MB
|
|
158
|
+
* (1100) and was reported as the machine's capacity whatever runtime the reader was
|
|
159
|
+
* about to use -- while a Kubernetes microservices workspace costs 2400 plus 600 for a
|
|
160
|
+
* control plane. `room_by_runtime` is the honest answer, and `room` keeps its meaning for
|
|
161
|
+
* the three existing consumers rather than changing under them.
|
|
162
|
+
*/
|
|
163
|
+
async function capacity() {
|
|
164
|
+
const mem = await host.hostMemory();
|
|
165
|
+
if (mem === null)
|
|
166
|
+
return { known: false };
|
|
167
|
+
const [totalMb, availMb, swapMb] = mem;
|
|
168
|
+
const reserve = hostReserveMb(totalMb);
|
|
169
|
+
const usable = Math.max(0, availMb - reserve);
|
|
170
|
+
const rooms = {};
|
|
171
|
+
const shapes = [
|
|
172
|
+
['docker', topology.DOCKER, ''],
|
|
173
|
+
['kubernetes-monolith', topology.KUBERNETES, topology.MONOLITH],
|
|
174
|
+
['kubernetes-microservices', topology.KUBERNETES, topology.MICROSERVICES],
|
|
175
|
+
];
|
|
176
|
+
for (const [label, runtime, deployment] of shapes) {
|
|
177
|
+
const cost = runtimeCost(runtime, deployment);
|
|
178
|
+
const per = Math.trunc(cost.workspace_mb) || exports.WORKSPACE_MB;
|
|
179
|
+
rooms[label] = Math.floor(Math.max(0, usable - Math.trunc(cost.cluster_mb)) / per);
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
known: true,
|
|
183
|
+
total_mb: totalMb,
|
|
184
|
+
available_mb: availMb,
|
|
185
|
+
reserve_mb: reserve,
|
|
186
|
+
swap_mb: swapMb,
|
|
187
|
+
workspace_mb: exports.WORKSPACE_MB,
|
|
188
|
+
room: Math.floor(usable / exports.WORKSPACE_MB),
|
|
189
|
+
room_denominated_in: 'docker',
|
|
190
|
+
room_by_runtime: rooms,
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* What Kubernetes adds to a workspace's memory bill, in MB.
|
|
195
|
+
*
|
|
196
|
+
* Zero for Compose, which is every workspace today. The control plane is charged only
|
|
197
|
+
* when it still has to be created: it is shared, so billing it to the second and third
|
|
198
|
+
* workspace would refuse creates the host could actually hold.
|
|
199
|
+
*/
|
|
200
|
+
function kubeOverheadMb(req, provisioning = true) {
|
|
201
|
+
if (topology.normalize(req.runtime) !== topology.KUBERNETES)
|
|
202
|
+
return 0;
|
|
203
|
+
let need = exports.KUBE_CHART_MB;
|
|
204
|
+
if (provisioning)
|
|
205
|
+
need += exports.CLUSTER_MB;
|
|
206
|
+
// An empty deployment means "that runtime's default", which for Kubernetes is
|
|
207
|
+
// microservices -- the expensive one.
|
|
208
|
+
const deployment = req.deployment || topology.DEPLOYMENTS[topology.KUBERNETES]?.[0];
|
|
209
|
+
if (deployment === topology.MICROSERVICES)
|
|
210
|
+
need += exports.MICROSERVICES_MB;
|
|
211
|
+
return need;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* What the container ENGINE must have before a Kubernetes workspace is worth starting:
|
|
215
|
+
* a control plane, the MongoDB operator or a StatefulSet, and on microservices six more
|
|
216
|
+
* Rocket.Chat processes.
|
|
217
|
+
*/
|
|
218
|
+
exports.ENGINE_FLOOR_CPUS = 4;
|
|
219
|
+
exports.ENGINE_FLOOR_MEMORY_GIB = 6.0;
|
|
220
|
+
/**
|
|
221
|
+
* Refuse a Kubernetes create the container engine is too small for.
|
|
222
|
+
*
|
|
223
|
+
* Compose is left alone: it runs two containers and works on a 2 GB VM, so a floor there
|
|
224
|
+
* would refuse creates that succeed today. Silent when the engine cannot be asked -- an
|
|
225
|
+
* unreadable `docker info` is not evidence of a small VM.
|
|
226
|
+
*/
|
|
227
|
+
async function checkEngineFloor(req, emit = events_1.nullEmit, provisioning = true) {
|
|
228
|
+
if (topology.normalize(req.runtime) !== topology.KUBERNETES)
|
|
229
|
+
return;
|
|
230
|
+
// The floor's whole premise is that the container VM has to hold a control plane. When
|
|
231
|
+
// the cluster is not one houston is about to build in Docker, the premise is void.
|
|
232
|
+
if (!provisioning)
|
|
233
|
+
return;
|
|
234
|
+
const cap = await host.dockerCapacity();
|
|
235
|
+
if (cap === null)
|
|
236
|
+
return;
|
|
237
|
+
const [cpus, memBytes] = cap;
|
|
238
|
+
const gib = memBytes / 1024 ** 3;
|
|
239
|
+
const short = [];
|
|
240
|
+
if (cpus && cpus < exports.ENGINE_FLOOR_CPUS) {
|
|
241
|
+
// `formatFixed`, not `toFixed`: JavaScript rounds half AWAY FROM ZERO and the
|
|
242
|
+
// established format half TO EVEN, so 5.25 renders "5.3" against the established
|
|
243
|
+
// "5.2". This is the only production module in src/ that called toFixed directly.
|
|
244
|
+
short.push(`${(0, format_1.formatFixed)(cpus, 0)} CPUs (needs ${String(exports.ENGINE_FLOOR_CPUS)})`);
|
|
245
|
+
}
|
|
246
|
+
if (gib && gib < exports.ENGINE_FLOOR_MEMORY_GIB) {
|
|
247
|
+
// The established text renders the float as `6.0`, which `String(6.0)` shortens to `6`.
|
|
248
|
+
short.push(`${(0, format_1.formatFixed)(gib, 1)} GiB of memory (needs ${(0, format_1.formatFixed)(exports.ENGINE_FLOOR_MEMORY_GIB, 1)})`);
|
|
249
|
+
}
|
|
250
|
+
if (short.length === 0)
|
|
251
|
+
return;
|
|
252
|
+
if (req.force) {
|
|
253
|
+
(0, events_1.warn)(emit, 'the container engine is below the Kubernetes floor — ' +
|
|
254
|
+
short.join(' and ') +
|
|
255
|
+
'. Continuing because --force was given.', { phase: 'preflight' });
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
throw new errors_1.PreflightError('the container engine has ' +
|
|
259
|
+
short.join(' and ') +
|
|
260
|
+
'. A Kubernetes ' +
|
|
261
|
+
'workspace needs a control plane, MongoDB and the chart, and below this it ' +
|
|
262
|
+
'does not fail cleanly -- pods stay Pending with nothing naming memory. ' +
|
|
263
|
+
'Raise the VM (Docker Desktop: Settings -> Resources; Podman: ' +
|
|
264
|
+
'`podman machine set --cpus 4 --memory 6144`), or use --runtime docker. ' +
|
|
265
|
+
'--force overrides this.');
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Roughly what one workspace costs, from the numbers `checkCapacity` spends.
|
|
269
|
+
*
|
|
270
|
+
* The same constants, not a second set written for the screen: a card that quotes
|
|
271
|
+
* 1.1 GB while the preflight reserves something else is a card that will be
|
|
272
|
+
* contradicted by the refusal it was meant to prevent.
|
|
273
|
+
*/
|
|
274
|
+
function runtimeCost(runtime, deployment = '') {
|
|
275
|
+
if (topology.normalize(runtime) !== topology.KUBERNETES) {
|
|
276
|
+
return { workspace_mb: exports.WORKSPACE_MB, cluster_mb: 0, shape: '2 containers' };
|
|
277
|
+
}
|
|
278
|
+
const shape = deployment || topology.DEPLOYMENTS[topology.KUBERNETES]?.[0];
|
|
279
|
+
const micro = shape === topology.MICROSERVICES;
|
|
280
|
+
return {
|
|
281
|
+
workspace_mb: exports.WORKSPACE_MB + exports.KUBE_CHART_MB + (micro ? exports.MICROSERVICES_MB : 0),
|
|
282
|
+
cluster_mb: exports.CLUSTER_MB,
|
|
283
|
+
shape: micro ? '9 pods' : '5 pods',
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Say no, and say what to stop instead.
|
|
288
|
+
*
|
|
289
|
+
* Long because the message is the product here: a refusal nobody can act on is a refusal
|
|
290
|
+
* they work around with --force.
|
|
291
|
+
*/
|
|
292
|
+
async function refuseForCapacity(availableMb, emit, headroom, need, req, reserve, swapMb, totalMb) {
|
|
293
|
+
// Running ones first, and marked: those are what stopping frees. ONE `compose ls` for every
|
|
294
|
+
// workspace, never a docker call each; when it cannot be asked, none is marked. Anywhere in
|
|
295
|
+
// the status: a running workspace reads `exited(1), running(2)`, its setup container first.
|
|
296
|
+
const states = (await (0, queries_1.projectStates)()) ?? {};
|
|
297
|
+
const isRunning = (meta) => (states[meta.project] ?? '').includes('running(');
|
|
298
|
+
const metas = await (0, record_1.listMeta)();
|
|
299
|
+
const existing = [...metas.filter(isRunning), ...metas.filter((meta) => !isRunning(meta))].map((meta) => {
|
|
300
|
+
const owner = (0, record_1.recordedOwner)(meta);
|
|
301
|
+
const marks = [owner === '' ? '' : `${owner}'s`, isRunning(meta) ? 'running' : ''].filter(Boolean);
|
|
302
|
+
return marks.length === 0 ? meta.name : `${meta.name} (${marks.join(', ')})`;
|
|
303
|
+
});
|
|
304
|
+
const swapNote = swapMb === 0
|
|
305
|
+
? '\n This host has NO SWAP, so there is no buffer at all: memory ' +
|
|
306
|
+
'pressure becomes an OOM kill rather than slowdown.'
|
|
307
|
+
: '';
|
|
308
|
+
if (req.force) {
|
|
309
|
+
// The docstring above has always said "Overridable with --force" and the refusal
|
|
310
|
+
// below has always told the user to pass it -- and nothing here ever read req.force,
|
|
311
|
+
// so the advertised way out did not exist.
|
|
312
|
+
(0, events_1.warn)(emit, `--force: creating anyway, though this workspace wants about ` +
|
|
313
|
+
`${String(need)} MB and only ${String(Math.max(0, headroom))} MB is free to use.` +
|
|
314
|
+
`${swapNote} If the host runs out, the OOM killer chooses what ` +
|
|
315
|
+
`dies — which may be a colleague's workspace, not this one.`, { phase: 'create' });
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
throw new errors_1.PreflightError(`not enough memory: this workspace needs about ${String(need)} MB and only ` +
|
|
319
|
+
`${String(Math.max(0, headroom))} MB is free to use ` +
|
|
320
|
+
`(${String(availableMb)} MB available, ${String(reserve)} MB kept for the OS, Docker and ` +
|
|
321
|
+
`the page cache, ${String(totalMb)} MB total).${swapNote}\n` +
|
|
322
|
+
` ${String(existing.length)} workspace(s) on the machine running houston, running ones ` +
|
|
323
|
+
'first: ' +
|
|
324
|
+
`${existing.slice(0, 6).join(', ') || 'none'}${existing.length > 6 ? ' …' : ''}\n` +
|
|
325
|
+
' Free some memory first: stop one of YOUR running ones (`houston list` shows which); ' +
|
|
326
|
+
"ask the owner before stopping anyone else's.\n" +
|
|
327
|
+
' houston stop --name <it> (keeps its data)\n' +
|
|
328
|
+
" Or override this check if you are sure: --force (if memory runs out, a colleague's " +
|
|
329
|
+
'workspace may be the one killed)');
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Say so while it is still comfortable, so the ceiling is visible before it is hit
|
|
333
|
+
* rather than only in the refusal.
|
|
334
|
+
*/
|
|
335
|
+
function sayWhatIsLeft(emit, headroom, need) {
|
|
336
|
+
if (headroom - need < exports.WORKSPACE_MB) {
|
|
337
|
+
(0, events_1.warn)(emit, `after this one, about ${String(Math.max(0, headroom - need))} MB is left ` +
|
|
338
|
+
`— roughly ${String(Math.floor(Math.max(0, headroom - need) / exports.WORKSPACE_MB))} more ` +
|
|
339
|
+
'workspace(s). `houston list` shows what is running.', { phase: 'create' });
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* What this create will actually take: the workspace, its preset's sidecars, monitoring
|
|
344
|
+
* if asked for, and the Kubernetes overhead -- which is not a Compose workspace with a
|
|
345
|
+
* different label.
|
|
346
|
+
*/
|
|
347
|
+
function neededMb(presetName, provisioning, req) {
|
|
348
|
+
// A composed workspace pays for every preset's sidecars: its combined name is in no table,
|
|
349
|
+
// and charging nothing for it would permit exactly the create this exists to refuse.
|
|
350
|
+
let need = exports.WORKSPACE_MB;
|
|
351
|
+
for (const name of (0, composite_1.namesOf)(presetName))
|
|
352
|
+
need += exports.PRESET_MB[name] ?? 0;
|
|
353
|
+
if ((0, composite_1.namesOf)(presetName).includes('ldap'))
|
|
354
|
+
need += ldapParamsMb(req.params);
|
|
355
|
+
if ((0, composite_1.namesOf)(presetName).includes('voice'))
|
|
356
|
+
need += voiceParamsMb(req.params);
|
|
357
|
+
if (req.monitor)
|
|
358
|
+
need += exports.MONITORING_MB;
|
|
359
|
+
need += kubeOverheadMb(req, provisioning);
|
|
360
|
+
return need;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Refuse to create a workspace the host cannot hold.
|
|
364
|
+
*
|
|
365
|
+
* Written after seven concurrent stacks OOM-killed a 10 GB host with no swap. Every
|
|
366
|
+
* individual `up` had succeeded -- nothing anywhere asked whether there was room for one
|
|
367
|
+
* more, which is exactly the gap docs/design/team-server.md §8 recorded as "made visible,
|
|
368
|
+
* not solved".
|
|
369
|
+
*
|
|
370
|
+
* A REFUSAL rather than a warning, because the failure is not confined to the workspace
|
|
371
|
+
* being created: the OOM killer picks its own victim, so on a shared server this destroys
|
|
372
|
+
* a colleague's work. Overridable with --force, and the message says what to stop instead.
|
|
373
|
+
*/
|
|
374
|
+
async function checkCapacity(req, presetName = '', emit = events_1.nullEmit) {
|
|
375
|
+
// The ENGINE's floor first, and it is a different question from the host's headroom.
|
|
376
|
+
// Probed once and passed to both, because both ask the same question and the probe
|
|
377
|
+
// talks to a cluster.
|
|
378
|
+
const provisioning = await request.willProvision(req);
|
|
379
|
+
await checkEngineFloor(req, emit, provisioning);
|
|
380
|
+
const mem = await host.hostMemory();
|
|
381
|
+
if (mem === null)
|
|
382
|
+
return; // not Linux: skip rather than guess
|
|
383
|
+
const [totalMb, availableMb, swapMb] = mem;
|
|
384
|
+
const need = neededMb(presetName, provisioning, req);
|
|
385
|
+
const reserve = hostReserveMb(totalMb);
|
|
386
|
+
const headroom = availableMb - reserve;
|
|
387
|
+
if (need <= headroom) {
|
|
388
|
+
sayWhatIsLeft(emit, headroom, need);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
await refuseForCapacity(availableMb, emit, headroom, need, req, reserve, swapMb, totalMb);
|
|
392
|
+
}
|