@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,694 @@
|
|
|
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.OUTLIVE_THE_WORKSPACE = exports.WORKSPACE_KINDS = exports.ADVISORY = exports.EMAIL_2FA_SETTING = exports.KINDS = exports.CLUSTER_UNFINISHED = exports.DATABASE_DROPPED = exports.E2EE_DEFAULT_OFF = exports.EMAIL_2FA_OFF = exports.MONGO_PROFILER_ON = exports.RC_METRICS_ON = exports.CREATE_UNFINISHED = exports.CONSTRAINTS_APPLIED = exports.BENCH_WORKSPACE = exports.ROCKETCHAT_STOPPED = exports.RATE_LIMITER_OFF = exports.DIRNAME = void 0;
|
|
37
|
+
exports.journalDir = journalDir;
|
|
38
|
+
exports.procStarted = procStarted;
|
|
39
|
+
exports.ownerAlive = ownerAlive;
|
|
40
|
+
exports.record = record;
|
|
41
|
+
exports.clear = clear;
|
|
42
|
+
exports.clearKind = clearKind;
|
|
43
|
+
exports.clearWorkspace = clearWorkspace;
|
|
44
|
+
exports.sideEffect = sideEffect;
|
|
45
|
+
exports.openEntries = openEntries;
|
|
46
|
+
exports.registerSubjectPredicate = registerSubjectPredicate;
|
|
47
|
+
exports.subjectPredicateKinds = subjectPredicateKinds;
|
|
48
|
+
exports.stillThere = stillThere;
|
|
49
|
+
exports.abandoned = abandoned;
|
|
50
|
+
exports.describe = describe;
|
|
51
|
+
exports.registerRepair = registerRepair;
|
|
52
|
+
exports.repairKinds = repairKinds;
|
|
53
|
+
exports.recover = recover;
|
|
54
|
+
exports.pendingSeed = pendingSeed;
|
|
55
|
+
exports.installSink = installSink;
|
|
56
|
+
/**
|
|
57
|
+
* Durable notes about side effects that must be undone, so a killed process does not
|
|
58
|
+
* leave them behind.
|
|
59
|
+
*
|
|
60
|
+
* WHY A FILE AND NOT A `finally`. The GUI runs long operations in the background, so
|
|
61
|
+
* `systemctl restart`, an OOM kill or a plain SIGKILL ends them where they stand and skips
|
|
62
|
+
* every `finally` they were relying on. Those blocks are doing real work: `backup` stops
|
|
63
|
+
* Rocket.Chat for the duration of the dump, `loadtest` turns the API rate limiter OFF,
|
|
64
|
+
* `capacity` arms the Mongo profiler and applies container CPU/RAM caps. Interrupted, all
|
|
65
|
+
* of that outlives the process -- a workspace that silently is not serving, a rate limiter
|
|
66
|
+
* left off -- with nothing anywhere recording that it happened.
|
|
67
|
+
*
|
|
68
|
+
* Cooperative cancellation cannot fix this. It helps a graceful shutdown; the dangerous
|
|
69
|
+
* exit is the one where no code runs at all. What survives that is a note written BEFORE
|
|
70
|
+
* the risky change and removed AFTER it is undone.
|
|
71
|
+
*
|
|
72
|
+
* THE HARD PART IS NOT WRITING IT, IT IS KNOWING WHOSE IT IS. An open entry belongs either
|
|
73
|
+
* to a job still running or to a process that died. Repairing the first would re-enable the
|
|
74
|
+
* rate limiter underneath a load test that is still going. So each entry records the pid
|
|
75
|
+
* AND that process's start time, and recovery touches an entry only when its owner is
|
|
76
|
+
* provably gone -- pid alone is not enough, because the OS recycles them.
|
|
77
|
+
*
|
|
78
|
+
* ## This module is the SINK; `lib/journal.ts` is the registry
|
|
79
|
+
*
|
|
80
|
+
* `core/eks` writes the most expensive note in the product and sits BELOW this file, so the
|
|
81
|
+
* registry is the dependency inversion. This installs itself at import, and replays any
|
|
82
|
+
* subject predicate registered before it arrived -- which is why that queue exists.
|
|
83
|
+
*
|
|
84
|
+
* ## `record` and `clear` are SYNCHRONOUS, and that is a deliberate departure
|
|
85
|
+
*
|
|
86
|
+
* Atomic filesystem helpers expose asynchronous APIs, so that nothing blocks the event
|
|
87
|
+
* loop. This module is the exception, and the reason is the thing it exists for.
|
|
88
|
+
*
|
|
89
|
+
* `core/eks` writes CLUSTER_UNFINISHED on the line BEFORE `eksctl create cluster` -- a
|
|
90
|
+
* twenty-minute call that builds a VPC, a NAT gateway and a control plane. An awaited write
|
|
91
|
+
* yields the event loop between "decided to write the note" and "the note is on disk", and
|
|
92
|
+
* that gap is precisely the window the note exists to cover: a SIGKILL landing in it leaves
|
|
93
|
+
* a billing cluster with no record anywhere that it was ever started. It has always been
|
|
94
|
+
* synchronous here for that reason, and `lib/journal.ts`'s registry is declared
|
|
95
|
+
* synchronous and id-returning because `eks` has to be able to clear the note it wrote.
|
|
96
|
+
*
|
|
97
|
+
* So the write is `writeFileSync` + `renameSync` -- the same temp-file-then-rename
|
|
98
|
+
* `runner/paths.atomicWrite` does, spelled synchronously. It is one small file, not a
|
|
99
|
+
* subprocess or a network call, which is the class of work the async rule is about.
|
|
100
|
+
*/
|
|
101
|
+
const node_crypto_1 = require("node:crypto");
|
|
102
|
+
const fs = __importStar(require("node:fs"));
|
|
103
|
+
const path = __importStar(require("node:path"));
|
|
104
|
+
const config = __importStar(require("../lib/config"));
|
|
105
|
+
const events_1 = require("../lib/events");
|
|
106
|
+
const home_1 = require("../lib/home");
|
|
107
|
+
const journal_1 = require("../lib/journal");
|
|
108
|
+
const mkdir_parents_1 = require("../lib/mkdir-parents");
|
|
109
|
+
const engine_1 = require("./runner/engine");
|
|
110
|
+
const paths_1 = require("./runner/paths");
|
|
111
|
+
/**
|
|
112
|
+
* One file per open side effect. A DIRECTORY rather than a single log, because entries are
|
|
113
|
+
* created and cleared concurrently by unrelated jobs, and an unlink is atomic where a
|
|
114
|
+
* rewrite of a shared file is a lost-update race.
|
|
115
|
+
*/
|
|
116
|
+
exports.DIRNAME = 'journal';
|
|
117
|
+
exports.RATE_LIMITER_OFF = 'rate_limiter_off';
|
|
118
|
+
exports.ROCKETCHAT_STOPPED = 'rocketchat_stopped';
|
|
119
|
+
/**
|
|
120
|
+
* A throwaway workspace the deleted `benchmark` command meant to delete.
|
|
121
|
+
*
|
|
122
|
+
* NOTHING RECORDS THIS ANY MORE and it stays anyway. `benchmark` is gone, but a
|
|
123
|
+
* journal note is durable state on somebody's disk, and the entire purpose of this module
|
|
124
|
+
* is that a killed process's side effects are recoverable LATER -- by a build that may be
|
|
125
|
+
* newer than the one that made the mess. Dropping the kind from a closed vocabulary would
|
|
126
|
+
* strand exactly the notes it exists to honour.
|
|
127
|
+
*/
|
|
128
|
+
exports.BENCH_WORKSPACE = 'bench_workspace';
|
|
129
|
+
exports.CONSTRAINTS_APPLIED = 'constraints_applied';
|
|
130
|
+
exports.CREATE_UNFINISHED = 'create_unfinished';
|
|
131
|
+
exports.RC_METRICS_ON = 'rc_metrics_on';
|
|
132
|
+
exports.MONGO_PROFILER_ON = 'mongo_profiler_on';
|
|
133
|
+
exports.EMAIL_2FA_OFF = 'email_2fa_off';
|
|
134
|
+
/** One of `config.E2EE_ROOM_DEFAULT_SETTINGS`, named in `detail.setting`, off for a seed. */
|
|
135
|
+
exports.E2EE_DEFAULT_OFF = 'e2ee_default_off';
|
|
136
|
+
exports.DATABASE_DROPPED = 'database_dropped';
|
|
137
|
+
exports.CLUSTER_UNFINISHED = 'cluster_unfinished';
|
|
138
|
+
/**
|
|
139
|
+
* Kinds, CLOSED on purpose: recovery has to know how to undo each one, so a kind nothing
|
|
140
|
+
* can repair is a note that would sit there forever looking like a fault.
|
|
141
|
+
*/
|
|
142
|
+
exports.KINDS = Object.freeze([
|
|
143
|
+
exports.RATE_LIMITER_OFF,
|
|
144
|
+
exports.ROCKETCHAT_STOPPED,
|
|
145
|
+
exports.BENCH_WORKSPACE,
|
|
146
|
+
exports.CONSTRAINTS_APPLIED,
|
|
147
|
+
exports.CREATE_UNFINISHED,
|
|
148
|
+
exports.RC_METRICS_ON,
|
|
149
|
+
exports.MONGO_PROFILER_ON,
|
|
150
|
+
exports.EMAIL_2FA_OFF,
|
|
151
|
+
exports.DATABASE_DROPPED,
|
|
152
|
+
exports.CLUSTER_UNFINISHED,
|
|
153
|
+
exports.E2EE_DEFAULT_OFF,
|
|
154
|
+
]);
|
|
155
|
+
/** Named once so the seed path and the repair cannot disagree about which key they mean. */
|
|
156
|
+
exports.EMAIL_2FA_SETTING = 'Accounts_TwoFactorAuthentication_By_Email_Enabled';
|
|
157
|
+
/**
|
|
158
|
+
* Kinds recovery REPORTS but does not undo by itself.
|
|
159
|
+
*
|
|
160
|
+
* `CREATE_UNFINISHED` is here for a timing reason: finishing a create means waiting for
|
|
161
|
+
* Rocket.Chat to serve and then running the preset's self-configuration, which can take the
|
|
162
|
+
* full readiness timeout, and doing that inside `serve`'s startup would hold the GUI shut
|
|
163
|
+
* for minutes on a workspace nobody asked about. The other two are here because acting on
|
|
164
|
+
* them is destructive and a process that already crashed is not what should decide to.
|
|
165
|
+
*/
|
|
166
|
+
exports.ADVISORY = Object.freeze([
|
|
167
|
+
exports.CREATE_UNFINISHED,
|
|
168
|
+
exports.DATABASE_DROPPED,
|
|
169
|
+
exports.CLUSTER_UNFINISHED,
|
|
170
|
+
]);
|
|
171
|
+
/**
|
|
172
|
+
* Kinds whose note is ABOUT A WORKSPACE, and so goes when that workspace's record does.
|
|
173
|
+
*
|
|
174
|
+
* `down --volumes` and `prune` delete the containers, the data and the record, and nothing
|
|
175
|
+
* cleared the notes about them: only a create that finishes and `ready` ever closed a
|
|
176
|
+
* `CREATE_UNFINISHED`, and both need the workspace to exist. Seen as 28 notes for one
|
|
177
|
+
* workspace that `down --volumes` had removed, and `doctor` went on advising `houston ready
|
|
178
|
+
* --name <it>` -- advice that cannot work on a workspace that is gone. `serve`'s recovery
|
|
179
|
+
* drops such notes at its next start, but a CLI-only box never starts one, and `doctor` is
|
|
180
|
+
* what tells that box.
|
|
181
|
+
*
|
|
182
|
+
* Each one, and why it goes with the workspace:
|
|
183
|
+
* RATE_LIMITER_OFF, EMAIL_2FA_OFF, RC_METRICS_ON, MONGO_PROFILER_ON, E2EE_DEFAULT_OFF -- a
|
|
184
|
+
* setting held in the workspace's database, which the deletion took with its volume.
|
|
185
|
+
* ROCKETCHAT_STOPPED, CONSTRAINTS_APPLIED -- the state of a container, and the containers
|
|
186
|
+
* are gone.
|
|
187
|
+
* BENCH_WORKSPACE -- its repair IS deleting the workspace, which has just happened.
|
|
188
|
+
* CREATE_UNFINISHED -- `ready` completes a workspace; there is none left to complete.
|
|
189
|
+
* DATABASE_DROPPED -- the half-loaded database went with the volume.
|
|
190
|
+
*/
|
|
191
|
+
exports.WORKSPACE_KINDS = Object.freeze([
|
|
192
|
+
exports.RATE_LIMITER_OFF,
|
|
193
|
+
exports.ROCKETCHAT_STOPPED,
|
|
194
|
+
exports.BENCH_WORKSPACE,
|
|
195
|
+
exports.CONSTRAINTS_APPLIED,
|
|
196
|
+
exports.CREATE_UNFINISHED,
|
|
197
|
+
exports.RC_METRICS_ON,
|
|
198
|
+
exports.MONGO_PROFILER_ON,
|
|
199
|
+
exports.EMAIL_2FA_OFF,
|
|
200
|
+
exports.DATABASE_DROPPED,
|
|
201
|
+
exports.E2EE_DEFAULT_OFF,
|
|
202
|
+
]);
|
|
203
|
+
/**
|
|
204
|
+
* The kinds that must OUTLIVE a workspace of the same name, and why.
|
|
205
|
+
* CLUSTER_UNFINISHED -- its `workspace` field carries a CLUSTER name, and the cluster may
|
|
206
|
+
* be billing now. A workspace called the same is not that cluster, and deleting it
|
|
207
|
+
* says nothing about whether an interrupted `eksctl create` left a VPC and a NAT
|
|
208
|
+
* gateway behind.
|
|
209
|
+
* Every kind is in exactly one of the two, so a new kind has to be decided here rather than
|
|
210
|
+
* fall into whichever default was nearest.
|
|
211
|
+
*/
|
|
212
|
+
exports.OUTLIVE_THE_WORKSPACE = Object.freeze([exports.CLUSTER_UNFINISHED]);
|
|
213
|
+
function journalDir() {
|
|
214
|
+
// Joined component by component, a `..` kept, as every path under the home is.
|
|
215
|
+
return (0, home_1.joinPath)(config.home(), exports.DIRNAME);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* A process's start time as a stable string, or null if it is not running.
|
|
219
|
+
*
|
|
220
|
+
* Field 22 of `/proc/<pid>/stat`, in clock ticks since boot. Read from the raw bytes and
|
|
221
|
+
* split from the RIGHT of the last ')', because field 2 is the executable name and may
|
|
222
|
+
* itself contain spaces or brackets.
|
|
223
|
+
*
|
|
224
|
+
* Returns '' for "running, but the start time could not be read", which is a different
|
|
225
|
+
* answer from null and is what `ownerAlive` leans on.
|
|
226
|
+
*
|
|
227
|
+
* Off Linux there is no /proc, and reading it answered null -- "not running" -- for every
|
|
228
|
+
* pid, this process's own included: on a Mac a CLI cluster build in another terminal read as
|
|
229
|
+
* "failed part-way", and `serve`'s startup recovery would undo work still in progress. There
|
|
230
|
+
* the answer is liveness alone, '' for a pid that exists: kill(0) succeeds, or is refused for
|
|
231
|
+
* someone else's process.
|
|
232
|
+
*
|
|
233
|
+
* ponytail: pid only, so a recycled pid keeps a dead owner's note alive (left alone, never
|
|
234
|
+
* undone). `ps -o lstart=` would add the start time, at the cost of an async `record`.
|
|
235
|
+
*/
|
|
236
|
+
function procStarted(pid) {
|
|
237
|
+
if (process.platform !== 'linux') {
|
|
238
|
+
// kill(0) and kill(-n) address process GROUPS, which are always "running".
|
|
239
|
+
if (!(Math.trunc(pid) > 0))
|
|
240
|
+
return null;
|
|
241
|
+
try {
|
|
242
|
+
process.kill(Math.trunc(pid), 0);
|
|
243
|
+
}
|
|
244
|
+
catch (error) {
|
|
245
|
+
if (error.code !== 'EPERM')
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
250
|
+
let raw;
|
|
251
|
+
try {
|
|
252
|
+
raw = fs.readFileSync(`/proc/${Math.trunc(pid)}/stat`, 'utf8');
|
|
253
|
+
}
|
|
254
|
+
catch {
|
|
255
|
+
return null;
|
|
256
|
+
}
|
|
257
|
+
const close = raw.lastIndexOf(')');
|
|
258
|
+
if (close < 0)
|
|
259
|
+
return '';
|
|
260
|
+
const fields = raw
|
|
261
|
+
.slice(close + 1)
|
|
262
|
+
.trim()
|
|
263
|
+
.split(/\s+/u);
|
|
264
|
+
return fields[19] ?? '';
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Whether the process that wrote this is still running.
|
|
268
|
+
*
|
|
269
|
+
* pid AND start time, because a recycled pid is a different process. An unknowable start
|
|
270
|
+
* time falls back to pid liveness, which is the conservative direction: it means "assume
|
|
271
|
+
* the owner is alive", so recovery leaves the entry alone rather than undoing live work.
|
|
272
|
+
*/
|
|
273
|
+
function ownerAlive(entry) {
|
|
274
|
+
const current = procStarted(entry.pid);
|
|
275
|
+
if (current === null)
|
|
276
|
+
return false;
|
|
277
|
+
if (!entry.started)
|
|
278
|
+
return true;
|
|
279
|
+
return current === entry.started;
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* The current UTC time as `YYYY-MM-DDTHH:MM:SSZ`.
|
|
283
|
+
*
|
|
284
|
+
* UTC, LIKE EVERY OTHER TIMESTAMP HERE. `strftime` with no argument is LOCAL time, so one
|
|
285
|
+
* event once read 22:29 in a journal note and 16:59 in the `repro.json` written beside it
|
|
286
|
+
* -- and a note is read next to `doctor`, `list` and an audit line, all of which are UTC.
|
|
287
|
+
*/
|
|
288
|
+
function stamp() {
|
|
289
|
+
return `${new Date().toISOString().slice(0, 19)}Z`;
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Note a side effect that must be undone. Returns the entry id, or '' if unwritable.
|
|
293
|
+
*
|
|
294
|
+
* Best-effort by design: a journal that cannot be written must not stop the operation it
|
|
295
|
+
* was describing. The operation's own `finally` is still the primary cleanup -- this is
|
|
296
|
+
* only what covers the case where no `finally` runs.
|
|
297
|
+
*/
|
|
298
|
+
function record(kind, workspace, detail = {}) {
|
|
299
|
+
if (!exports.KINDS.includes(kind)) {
|
|
300
|
+
throw new Error(`unknown journal kind '${kind}' (want: ${exports.KINDS.join(', ')})`);
|
|
301
|
+
}
|
|
302
|
+
const entry = {
|
|
303
|
+
id: (0, node_crypto_1.randomBytes)(8).toString('hex'),
|
|
304
|
+
kind,
|
|
305
|
+
workspace,
|
|
306
|
+
pid: process.pid,
|
|
307
|
+
started: procStarted(process.pid) ?? '',
|
|
308
|
+
at: stamp(),
|
|
309
|
+
detail: { ...detail },
|
|
310
|
+
};
|
|
311
|
+
try {
|
|
312
|
+
const dir = journalDir();
|
|
313
|
+
// Made with its parents, the mode 0700 on the leaf only.
|
|
314
|
+
(0, mkdir_parents_1.mkdirParents)(dir, 0o700);
|
|
315
|
+
atomicWriteSync((0, home_1.joinPath)(dir, `${entry.id}.json`), JSON.stringify(entry, null, 2));
|
|
316
|
+
}
|
|
317
|
+
catch {
|
|
318
|
+
return '';
|
|
319
|
+
}
|
|
320
|
+
return entry.id;
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* `runner/paths.atomicWrite`, spelled synchronously. See the module docstring for why.
|
|
324
|
+
*
|
|
325
|
+
* The temp name is unique per call for the reason the async one gives: a fixed
|
|
326
|
+
* `<name>.tmp` meant two concurrent writers shared one path and clobbered each other,
|
|
327
|
+
* defeating the atomicity it exists to provide.
|
|
328
|
+
*/
|
|
329
|
+
function atomicWriteSync(target, content) {
|
|
330
|
+
const unique = `${String(process.pid)}.${(0, node_crypto_1.randomBytes)(4).toString('hex')}`;
|
|
331
|
+
const temporary = (0, home_1.joinPath)(path.dirname(target), `${path.basename(target)}.${unique}.tmp`);
|
|
332
|
+
try {
|
|
333
|
+
fs.writeFileSync(temporary, content, { encoding: 'utf8' });
|
|
334
|
+
fs.renameSync(temporary, target);
|
|
335
|
+
}
|
|
336
|
+
finally {
|
|
337
|
+
// A no-op after a successful rename; the cleanup that matters is the failed one.
|
|
338
|
+
try {
|
|
339
|
+
fs.rmSync(temporary, { force: true });
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
/* already renamed away */
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
/** Forget an entry, because whatever it described has been undone. */
|
|
347
|
+
function clear(entryId) {
|
|
348
|
+
if (!entryId)
|
|
349
|
+
return;
|
|
350
|
+
try {
|
|
351
|
+
fs.rmSync((0, home_1.joinPath)(journalDir(), `${entryId}.json`), { force: true });
|
|
352
|
+
}
|
|
353
|
+
catch {
|
|
354
|
+
/* best-effort */
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Forget EVERY note of one kind for one workspace. Returns how many went.
|
|
359
|
+
*
|
|
360
|
+
* Some facts invalidate other processes' notes, not just your own. "This workspace's create
|
|
361
|
+
* finished" is one: a create that failed left a `CREATE_UNFINISHED` note behind, and a
|
|
362
|
+
* later create of the same name that succeeded cleared only the note it had written itself
|
|
363
|
+
* -- so the stale one went on claiming a complete workspace had never finished. Seen
|
|
364
|
+
* exactly that way, when a failed attempt was followed by a good one.
|
|
365
|
+
*/
|
|
366
|
+
function clearKind(kind, workspace) {
|
|
367
|
+
let gone = 0;
|
|
368
|
+
for (const entry of openEntries()) {
|
|
369
|
+
if (entry.kind === kind && entry.workspace === workspace) {
|
|
370
|
+
clear(entry.id);
|
|
371
|
+
gone += 1;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return gone;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Forget every note ABOUT one workspace, because its record is being deleted.
|
|
378
|
+
*
|
|
379
|
+
* Whoever owns the note, alive or not -- unlike recovery, which touches abandoned ones only.
|
|
380
|
+
* A live owner's note describes work on a workspace that is going away, so there is nothing
|
|
381
|
+
* left for it to put back. Every caller holds the workspace's `reproLock`, which is where a
|
|
382
|
+
* create writes its note, so no create can have one here for a workspace it has not made
|
|
383
|
+
* yet. See `WORKSPACE_KINDS` for which kinds go.
|
|
384
|
+
*/
|
|
385
|
+
function clearWorkspace(workspace, kinds = exports.WORKSPACE_KINDS) {
|
|
386
|
+
let gone = 0;
|
|
387
|
+
for (const entry of openEntries()) {
|
|
388
|
+
if (kinds.includes(entry.kind) && entry.workspace === workspace) {
|
|
389
|
+
clear(entry.id);
|
|
390
|
+
gone += 1;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
return gone;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Record on the way in, clear on the way out -- however that happens.
|
|
397
|
+
*
|
|
398
|
+
* Wraps an existing `finally` rather than replacing it: the note is cleared when the normal
|
|
399
|
+
* cleanup has run, so a surviving entry means precisely "the cleanup did not happen".
|
|
400
|
+
*/
|
|
401
|
+
async function sideEffect(kind, workspace, body, detail = {}) {
|
|
402
|
+
const entryId = record(kind, workspace, detail);
|
|
403
|
+
try {
|
|
404
|
+
return await body(entryId);
|
|
405
|
+
}
|
|
406
|
+
finally {
|
|
407
|
+
clear(entryId);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
/** Every entry on disk, newest last. Unreadable files are skipped, not raised. */
|
|
411
|
+
function openEntries() {
|
|
412
|
+
const out = [];
|
|
413
|
+
let names;
|
|
414
|
+
try {
|
|
415
|
+
names = fs
|
|
416
|
+
.readdirSync(journalDir())
|
|
417
|
+
.filter((n) => n.endsWith('.json'))
|
|
418
|
+
.sort();
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
return out;
|
|
422
|
+
}
|
|
423
|
+
for (const name of names) {
|
|
424
|
+
try {
|
|
425
|
+
const data = JSON.parse(fs.readFileSync((0, home_1.joinPath)(journalDir(), name), 'utf8'));
|
|
426
|
+
const rawDetail = data.detail;
|
|
427
|
+
out.push({
|
|
428
|
+
id: String(data.id ?? '') || name.replace(/\.json$/u, ''),
|
|
429
|
+
kind: String(data.kind ?? ''),
|
|
430
|
+
workspace: String(data.workspace ?? ''),
|
|
431
|
+
pid: Number.parseInt(String(data.pid ?? 0), 10) || 0,
|
|
432
|
+
started: String(data.started ?? ''),
|
|
433
|
+
at: String(data.at ?? ''),
|
|
434
|
+
detail: typeof rawDetail === 'object' && rawDetail !== null && !Array.isArray(rawDetail)
|
|
435
|
+
? { ...rawDetail }
|
|
436
|
+
: {},
|
|
437
|
+
});
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
continue;
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
// By when each was written: the ids are random, so the file names alone are no order.
|
|
444
|
+
return out.sort((a, b) => (a.at < b.at ? -1 : a.at > b.at ? 1 : 0));
|
|
445
|
+
}
|
|
446
|
+
/**
|
|
447
|
+
* How to ask "is the thing this note is ABOUT still here", per kind.
|
|
448
|
+
*
|
|
449
|
+
* `recover()` clears an advisory note whose subject is gone, and it used to ask that as
|
|
450
|
+
* `exists(entry.workspace)`. That is the right question for every kind today,
|
|
451
|
+
* because every one of them is about a workspace -- and it is only ACCIDENTALLY right. A
|
|
452
|
+
* note whose subject is NOT a workspace -- a cluster, say -- would find that false always,
|
|
453
|
+
* and be cleared silently at the next `serve` startup. The most expensive note in the
|
|
454
|
+
* product would be the one guaranteed not to survive.
|
|
455
|
+
*
|
|
456
|
+
* The fix is to keep ONE rule and make the rule true, rather than special-casing a kind out
|
|
457
|
+
* of a rule stated as general -- which is the shape that produced this.
|
|
458
|
+
*/
|
|
459
|
+
const SUBJECT_EXISTS = new Map();
|
|
460
|
+
/** Register the owning module's way to ask whether a journal subject exists. */
|
|
461
|
+
function registerSubjectPredicate(kind, predicate) {
|
|
462
|
+
const current = SUBJECT_EXISTS.get(kind);
|
|
463
|
+
if (current !== undefined && current !== predicate) {
|
|
464
|
+
throw new Error(`journal subject predicate already registered for ${kind}`);
|
|
465
|
+
}
|
|
466
|
+
SUBJECT_EXISTS.set(kind, predicate);
|
|
467
|
+
}
|
|
468
|
+
function subjectPredicateKinds() {
|
|
469
|
+
return [...SUBJECT_EXISTS.keys()].sort();
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Whether the thing an advisory note is about still exists.
|
|
473
|
+
*
|
|
474
|
+
* A predicate that THROWS answers true, and that direction is deliberate: "I could not ask"
|
|
475
|
+
* is not "it is gone", and the cost of the two mistakes is not symmetric. Keeping a stale
|
|
476
|
+
* note wastes a line of output; dropping a live one loses the only record that something is
|
|
477
|
+
* still running -- and for a cloud cluster, still billing.
|
|
478
|
+
*/
|
|
479
|
+
async function stillThere(entry) {
|
|
480
|
+
const ask = SUBJECT_EXISTS.get(entry.kind);
|
|
481
|
+
if (ask === undefined)
|
|
482
|
+
return await (0, paths_1.exists)(entry.workspace);
|
|
483
|
+
try {
|
|
484
|
+
return await ask(entry);
|
|
485
|
+
}
|
|
486
|
+
catch {
|
|
487
|
+
return true;
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
/** Entries whose owning process is gone -- the ones safe to act on. */
|
|
491
|
+
function abandoned() {
|
|
492
|
+
return openEntries().filter((e) => !ownerAlive(e));
|
|
493
|
+
}
|
|
494
|
+
/** One line a human can act on, whether or not recovery can. */
|
|
495
|
+
function describe(entry) {
|
|
496
|
+
const w = `'${entry.workspace}'`;
|
|
497
|
+
switch (entry.kind) {
|
|
498
|
+
case exports.RATE_LIMITER_OFF:
|
|
499
|
+
// A seed and a settings import turn it off too, and say so; a note without a
|
|
500
|
+
// purpose is a load test's, as every earlier one was taken to be.
|
|
501
|
+
return (`${w}: the API rate limiter was turned off for ` +
|
|
502
|
+
`${String(entry.detail.purpose ?? 'a performance run')} at ${entry.at} and never ` +
|
|
503
|
+
'turned back on');
|
|
504
|
+
case exports.ROCKETCHAT_STOPPED:
|
|
505
|
+
return `${w}: Rocket.Chat was stopped for a backup at ${entry.at} and never started again`;
|
|
506
|
+
case exports.BENCH_WORKSPACE:
|
|
507
|
+
return (`${w}: a throwaway benchmark workspace from ${entry.at} is still here, ` +
|
|
508
|
+
'holding a Rocket.Chat and a MongoDB');
|
|
509
|
+
case exports.CONSTRAINTS_APPLIED: {
|
|
510
|
+
const applied = Array.isArray(entry.detail.applied)
|
|
511
|
+
? entry.detail.applied
|
|
512
|
+
: [];
|
|
513
|
+
const caps = applied
|
|
514
|
+
.slice(0, 3)
|
|
515
|
+
.map((a) => String(a.service ?? '?'))
|
|
516
|
+
.join(', ');
|
|
517
|
+
return (`${w}: CPU/RAM limits from a performance run at ${entry.at} are still ` +
|
|
518
|
+
`applied (${caps || 'unknown services'})`);
|
|
519
|
+
}
|
|
520
|
+
case exports.DATABASE_DROPPED:
|
|
521
|
+
return (`${w}: a restore from ${String(entry.detail.bundle ?? 'a bundle')} dropped ` +
|
|
522
|
+
`the database at ${entry.at} and never finished loading it — the workspace ` +
|
|
523
|
+
`is running against an EMPTY or partial database. \`houston restore ` +
|
|
524
|
+
`${String(entry.detail.bundle ?? '<bundle>')} --name ${entry.workspace}\` ` +
|
|
525
|
+
'again is what completes it');
|
|
526
|
+
case exports.CLUSTER_UNFINISHED: {
|
|
527
|
+
const name = entry.workspace;
|
|
528
|
+
const region = String(entry.detail.region ?? '<region>');
|
|
529
|
+
const account = String(entry.detail.account ?? 'unknown account');
|
|
530
|
+
// CloudFormation-shaped, because the obvious advice is the advice that fails: a
|
|
531
|
+
// rolled-back `eksctl create` can leave its stack behind, and `eksctl delete` then
|
|
532
|
+
// reports that the cluster does not exist while a VPC and a NAT gateway carry on
|
|
533
|
+
// billing.
|
|
534
|
+
return (`an \`eksctl create cluster\` for '${name}' in ${region} (account ${account}) ` +
|
|
535
|
+
`was interrupted at ${entry.at} and never returned. It may have created a VPC, ` +
|
|
536
|
+
'a NAT gateway and a control plane, which are BILLING NOW. houston will not ' +
|
|
537
|
+
'delete a cloud cluster it did not see finish — that is minutes of destructive ' +
|
|
538
|
+
'work on your AWS account decided by a process that already crashed. Run ' +
|
|
539
|
+
`\`eksctl delete cluster --name ${name} --region ${region} --wait\`; if that ` +
|
|
540
|
+
'says the cluster does not exist, the CloudFormation stack may have rolled back ' +
|
|
541
|
+
`and SURVIVED, so check \`aws cloudformation describe-stacks --stack-name ` +
|
|
542
|
+
`eksctl-${name}-cluster --region ${region}\` and delete it directly`);
|
|
543
|
+
}
|
|
544
|
+
case exports.EMAIL_2FA_OFF:
|
|
545
|
+
return (`${w}: email two-factor authentication was turned off for a seed at ` +
|
|
546
|
+
`${entry.at} and never turned back on — seeded users are loginable and real ` +
|
|
547
|
+
'ones may not be');
|
|
548
|
+
case exports.E2EE_DEFAULT_OFF:
|
|
549
|
+
return (`${w}: ${String(entry.detail.setting ?? 'an end-to-end encryption default')} was ` +
|
|
550
|
+
`turned off for a seed at ${entry.at} and never turned back on — new rooms it ` +
|
|
551
|
+
'covers are not created encrypted');
|
|
552
|
+
case exports.RC_METRICS_ON:
|
|
553
|
+
return (`${w}: Rocket.Chat's Prometheus metrics endpoint was turned on for a ` +
|
|
554
|
+
`diagnostic run at ${entry.at} and never turned off`);
|
|
555
|
+
case exports.MONGO_PROFILER_ON:
|
|
556
|
+
return (`${w}: Mongo's query profiler was armed for a diagnostic run at ${entry.at} ` +
|
|
557
|
+
'and never disarmed — it is still writing a system.profile document for every ' +
|
|
558
|
+
'slow operation');
|
|
559
|
+
case exports.CREATE_UNFINISHED: {
|
|
560
|
+
const seeded = entry.detail.seed === undefined || entry.detail.seed === null || entry.detail.seed === ''
|
|
561
|
+
? ''
|
|
562
|
+
: ' and its seed';
|
|
563
|
+
return (`${w}: the create started at ${entry.at} never finished, so it may be running ` +
|
|
564
|
+
`WITHOUT its preset configuration${seeded || ' or seed data'} — ` +
|
|
565
|
+
`\`houston ready --name ${entry.workspace}\` completes it`);
|
|
566
|
+
}
|
|
567
|
+
default:
|
|
568
|
+
return `${w}: ${entry.kind} since ${entry.at}`;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
const REPAIR_HANDLERS = new Map();
|
|
572
|
+
/** Register one side-effect owner's recovery handler, idempotently. */
|
|
573
|
+
function registerRepair(kind, handler) {
|
|
574
|
+
const current = REPAIR_HANDLERS.get(kind);
|
|
575
|
+
if (current !== undefined && current !== handler) {
|
|
576
|
+
throw new Error(`journal repair handler already registered for ${kind}`);
|
|
577
|
+
}
|
|
578
|
+
REPAIR_HANDLERS.set(kind, handler);
|
|
579
|
+
}
|
|
580
|
+
function repairKinds() {
|
|
581
|
+
return [...REPAIR_HANDLERS.keys()].sort();
|
|
582
|
+
}
|
|
583
|
+
/** Retained for durable notes written by the removed benchmark command. */
|
|
584
|
+
async function repairBench(entry) {
|
|
585
|
+
await (0, engine_1.down)(entry.workspace, { volumes: true });
|
|
586
|
+
await (0, paths_1.remove)(entry.workspace);
|
|
587
|
+
return true;
|
|
588
|
+
}
|
|
589
|
+
registerRepair(exports.BENCH_WORKSPACE, repairBench);
|
|
590
|
+
/** Dispatch to the side-effect owner without importing that owner. */
|
|
591
|
+
async function repairOne(entry, emit, login) {
|
|
592
|
+
if (!(await (0, paths_1.exists)(entry.workspace)))
|
|
593
|
+
return true;
|
|
594
|
+
const handler = REPAIR_HANDLERS.get(entry.kind);
|
|
595
|
+
if (handler === undefined)
|
|
596
|
+
return false;
|
|
597
|
+
return Boolean(await handler(entry, emit, login));
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Undo what abandoned entries describe. Returns one result per entry.
|
|
601
|
+
*
|
|
602
|
+
* NEVER throws: this runs at `serve` startup, and a box that cannot be repaired still has
|
|
603
|
+
* to be able to serve. Each result carries `repaired` so a caller can say what is still
|
|
604
|
+
* outstanding.
|
|
605
|
+
*/
|
|
606
|
+
async function recover(emit = events_1.nullEmit, { dryRun = false, login = null } = {}) {
|
|
607
|
+
const results = [];
|
|
608
|
+
// Newest first: two runs cut short on one workspace both noted a "prior" state, and the
|
|
609
|
+
// second's prior is the first's change, so the oldest note's has to be put back last.
|
|
610
|
+
for (const entry of abandoned().reverse()) {
|
|
611
|
+
const row = {
|
|
612
|
+
id: entry.id,
|
|
613
|
+
kind: entry.kind,
|
|
614
|
+
workspace: entry.workspace,
|
|
615
|
+
what: describe(entry),
|
|
616
|
+
repaired: false,
|
|
617
|
+
why: '',
|
|
618
|
+
};
|
|
619
|
+
if (exports.ADVISORY.includes(entry.kind) && !(await stillThere(entry))) {
|
|
620
|
+
// The thing the note is about is gone, so an unfinished create is no longer
|
|
621
|
+
// anybody's problem. Advisory notes are never repaired, so without this they would
|
|
622
|
+
// warn forever about something that cannot be acted on.
|
|
623
|
+
//
|
|
624
|
+
// UNDER dryRun THIS IS A READ. The clear used to sit above the dry-run check, so a
|
|
625
|
+
// dry run over two notes reported one and DELETED the other -- and a dry run is the
|
|
626
|
+
// only way to inspect the journal without repairing it, which makes mutating one a
|
|
627
|
+
// contradiction in terms.
|
|
628
|
+
if (dryRun) {
|
|
629
|
+
row.why = 'the thing it is about is gone; would be dropped';
|
|
630
|
+
results.push(row);
|
|
631
|
+
continue;
|
|
632
|
+
}
|
|
633
|
+
clear(entry.id);
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
if (dryRun || exports.ADVISORY.includes(entry.kind)) {
|
|
637
|
+
// Reported and left alone. See ADVISORY: undoing this one means waiting for a
|
|
638
|
+
// workspace to serve, which is not something a GUI startup may spend.
|
|
639
|
+
row.why = exports.ADVISORY.includes(entry.kind) ? 'needs `houston ready`' : '';
|
|
640
|
+
results.push(row);
|
|
641
|
+
if (exports.ADVISORY.includes(entry.kind))
|
|
642
|
+
(0, events_1.warn)(emit, row.what, { phase: 'preflight' });
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
try {
|
|
646
|
+
row.repaired = await repairOne(entry, emit, login);
|
|
647
|
+
}
|
|
648
|
+
catch (error) {
|
|
649
|
+
// Recovery must not break startup.
|
|
650
|
+
row.why = error instanceof Error ? error.message : String(error);
|
|
651
|
+
}
|
|
652
|
+
if (row.repaired) {
|
|
653
|
+
clear(entry.id);
|
|
654
|
+
(0, events_1.info)(emit, `repaired: ${row.what}`, { phase: 'preflight' });
|
|
655
|
+
}
|
|
656
|
+
else {
|
|
657
|
+
(0, events_1.warn)(emit, `could NOT repair — ${row.what}${row.why ? ` (${row.why})` : ''}`, {
|
|
658
|
+
phase: 'preflight',
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
results.push(row);
|
|
662
|
+
}
|
|
663
|
+
return results;
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* The seed an interrupted create asked for and never ran, or {}.
|
|
667
|
+
*
|
|
668
|
+
* Read from the NOTE rather than from the workspace's metadata, because that is the only
|
|
669
|
+
* place it survives: the `CreateReq` died with the process, and `meta.extra.seed` is
|
|
670
|
+
* written only after a seed has already succeeded -- so metadata can say "seeded" or say
|
|
671
|
+
* nothing, and "nothing" covers both "none was asked for" and "one was asked for and lost".
|
|
672
|
+
*
|
|
673
|
+
* Only OPEN notes count. A note whose owner is still alive belongs to a create that is
|
|
674
|
+
* still running, and finishing its seed underneath it would seed twice.
|
|
675
|
+
*/
|
|
676
|
+
function pendingSeed(workspace) {
|
|
677
|
+
for (const entry of abandoned()) {
|
|
678
|
+
if (entry.kind === exports.CREATE_UNFINISHED && entry.workspace === workspace) {
|
|
679
|
+
const seed = entry.detail.seed;
|
|
680
|
+
if (seed === true || (typeof seed === 'string' && seed !== ''))
|
|
681
|
+
return { ...entry.detail };
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
return {};
|
|
685
|
+
}
|
|
686
|
+
/** Install this module as the journal `lib/journal.ts` reaches. */
|
|
687
|
+
function installSink() {
|
|
688
|
+
return (0, journal_1.installJournalSink)({
|
|
689
|
+
record,
|
|
690
|
+
clear,
|
|
691
|
+
registerSubjectPredicate,
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
installSink();
|