@rebasepro/cli 0.31.0 → 0.32.0
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/dist/{agent-setup-DqAcoDcn.js → agent-setup-Cg_zBWoW.js} +3 -3
- package/dist/{agent-setup-DqAcoDcn.js.map → agent-setup-Cg_zBWoW.js.map} +1 -1
- package/dist/api-TbmW33D7.js +275 -0
- package/dist/api-TbmW33D7.js.map +1 -0
- package/dist/{api-keys-eIUjMqWn.js → api-keys-fPQ55DCm.js} +151 -158
- package/dist/api-keys-fPQ55DCm.js.map +1 -0
- package/dist/{apps-DExO4PEl.js → apps-DBTRoOeP.js} +18 -13
- package/dist/apps-DBTRoOeP.js.map +1 -0
- package/dist/{args-CaCcrYE1.js → args-DHyrshtI.js} +3 -132
- package/dist/args-DHyrshtI.js.map +1 -0
- package/dist/{atlas-dev-database-DOCKk6ht.js → atlas-dev-database-D6h65f2x.js} +3 -3
- package/dist/{atlas-dev-database-DOCKk6ht.js.map → atlas-dev-database-D6h65f2x.js.map} +1 -1
- package/dist/{auth-ofQETpM5.js → auth-BpyYLEFY.js} +93 -12
- package/dist/auth-BpyYLEFY.js.map +1 -0
- package/dist/auth-session-B6aT0Dyj.js +371 -0
- package/dist/auth-session-B6aT0Dyj.js.map +1 -0
- package/dist/{backend-guard-C0mVkXBw.js → backend-guard-Cf8eMK_f.js} +2 -2
- package/dist/{backend-guard-C0mVkXBw.js.map → backend-guard-Cf8eMK_f.js.map} +1 -1
- package/dist/{branch-pointer-DMPyvZoK.js → branch-pointer-BJOF2Ubv.js} +1 -1
- package/dist/{build-CA5R07tw.js → build-BfdT-AUR.js} +12 -10
- package/dist/{build-CA5R07tw.js.map → build-BfdT-AUR.js.map} +1 -1
- package/dist/{bundle-DgILeA5b.js → bundle-CIiKGrte.js} +78 -12
- package/dist/bundle-CIiKGrte.js.map +1 -0
- package/dist/bundle.d.ts +31 -1
- package/dist/{cloud-CYMk92iG.js → cloud-MqnyPnmX.js} +1540 -1531
- package/dist/cloud-MqnyPnmX.js.map +1 -0
- package/dist/{cms-directories-BK3vcswg.js → cms-directories-BaV-Is9a.js} +2 -2
- package/dist/{cms-directories-BK3vcswg.js.map → cms-directories-BaV-Is9a.js.map} +1 -1
- package/dist/codemod/collections-to-tables/backend.d.ts +0 -2
- package/dist/codemod/collections-to-tables/customization.d.ts +2 -1
- package/dist/codemod/collections-to-tables/modules.d.ts +32 -0
- package/dist/codemod/collections-to-tables/plan-context.d.ts +7 -1
- package/dist/{command-D5lhW_-B.js → command-D9g46gg9.js} +68 -42
- package/dist/command-D9g46gg9.js.map +1 -0
- package/dist/commands/api-keys.d.ts +89 -52
- package/dist/commands/api.d.ts +114 -0
- package/dist/commands/auth-session.d.ts +94 -0
- package/dist/commands/auth.d.ts +1 -1
- package/dist/commands/cloud/alerts.d.ts +29 -0
- package/dist/commands/cloud/context.d.ts +8 -0
- package/dist/commands/cloud/debug.d.ts +16 -1
- package/dist/commands/cloud/deploy-hooks.d.ts +19 -0
- package/dist/commands/cloud/deploy.d.ts +25 -0
- package/dist/commands/cloud/env.d.ts +1 -0
- package/dist/commands/cloud/index.d.ts +5 -0
- package/dist/commands/cloud/maintenance.d.ts +26 -1
- package/dist/commands/cloud/not-served.d.ts +27 -0
- package/dist/commands/cloud/orgs.d.ts +5 -0
- package/dist/commands/cloud/resources.d.ts +82 -2
- package/dist/commands/cloud/runtime-logs.d.ts +57 -0
- package/dist/commands/cloud/settings.d.ts +3 -0
- package/dist/commands/cron.d.ts +68 -0
- package/dist/commands/data.d.ts +197 -0
- package/dist/commands/functions.d.ts +38 -0
- package/dist/commands/logs.d.ts +22 -0
- package/dist/commands/rls.d.ts +31 -0
- package/dist/commands/schema-reconcile.d.ts +2 -1
- package/dist/commands/schema-show.d.ts +38 -0
- package/dist/commands/storage-objects.d.ts +88 -0
- package/dist/commands/storage.d.ts +18 -2
- package/dist/commands/users.d.ts +147 -0
- package/dist/{consent-BXLIrMl8.js → consent-UV6ObCME.js} +2 -2
- package/dist/{consent-BXLIrMl8.js.map → consent-UV6ObCME.js.map} +1 -1
- package/dist/{console-DjThnr3f.js → console-BVoYOLAO.js} +6 -6
- package/dist/{console-DjThnr3f.js.map → console-BVoYOLAO.js.map} +1 -1
- package/dist/{context--JwaHaZp.js → context-BOMEoKxn.js} +80 -9
- package/dist/{context--JwaHaZp.js.map → context-BOMEoKxn.js.map} +1 -1
- package/dist/cron-CpUsQ739.js +298 -0
- package/dist/cron-CpUsQ739.js.map +1 -0
- package/dist/cron-ZRXsla0v.js +259 -0
- package/dist/cron-ZRXsla0v.js.map +1 -0
- package/dist/{daemon-w30PsdwV.js → daemon-D5gdG7gx.js} +3 -3
- package/dist/{daemon-w30PsdwV.js.map → daemon-D5gdG7gx.js.map} +1 -1
- package/dist/{daemon-entry-zOC1revO.js → daemon-entry--ummUJnk.js} +2 -2
- package/dist/{daemon-entry-zOC1revO.js.map → daemon-entry--ummUJnk.js.map} +1 -1
- package/dist/data-BJ9AZFUC.js +947 -0
- package/dist/data-BJ9AZFUC.js.map +1 -0
- package/dist/{db-Bz2RFGJj.js → db-D_iF4E-v.js} +38 -34
- package/dist/{db-Bz2RFGJj.js.map → db-D_iF4E-v.js.map} +1 -1
- package/dist/debug-nNbbxAeo.js +1114 -0
- package/dist/debug-nNbbxAeo.js.map +1 -0
- package/dist/{derive-C3ezmY-p.js → derive-Mky_u59_.js} +3 -3
- package/dist/{derive-C3ezmY-p.js.map → derive-Mky_u59_.js.map} +1 -1
- package/dist/{dev-D8TxrE_I.js → dev-bj6dEeSQ.js} +13 -13
- package/dist/{dev-D8TxrE_I.js.map → dev-bj6dEeSQ.js.map} +1 -1
- package/dist/dev-db/pull.d.ts +13 -3
- package/dist/{dev-preflight-DjvcV6SK.js → dev-preflight-BMOf2N6r.js} +2 -2
- package/dist/{dev-preflight-DjvcV6SK.js.map → dev-preflight-BMOf2N6r.js.map} +1 -1
- package/dist/{dev-server-BLxCbQEP.js → dev-server-2XHSHM_q.js} +2 -2
- package/dist/{dev-server-BLxCbQEP.js.map → dev-server-2XHSHM_q.js.map} +1 -1
- package/dist/{doctor-Du-mSxoE.js → doctor-2Jlau0Rm.js} +9 -8
- package/dist/{doctor-Du-mSxoE.js.map → doctor-2Jlau0Rm.js.map} +1 -1
- package/dist/{eject-Bhzd6hgb.js → eject-DK_M9kor.js} +4 -4
- package/dist/{eject-Bhzd6hgb.js.map → eject-DK_M9kor.js.map} +1 -1
- package/dist/{fold-static-CKewnAPX.js → fold-static-2t3UUX4z.js} +10 -6
- package/dist/fold-static-2t3UUX4z.js.map +1 -0
- package/dist/fold-static.d.ts +7 -0
- package/dist/functions-B4JR6EZL.js +120 -0
- package/dist/functions-B4JR6EZL.js.map +1 -0
- package/dist/{generate-view-CTOluXvH.js → generate-view-BMaLQm8H.js} +5 -5
- package/dist/{generate-view-CTOluXvH.js.map → generate-view-BMaLQm8H.js.map} +1 -1
- package/dist/{generate_sdk-De-aLC1L.js → generate_sdk-ByD-gTsK.js} +7 -7
- package/dist/{generate_sdk-De-aLC1L.js.map → generate_sdk-ByD-gTsK.js.map} +1 -1
- package/dist/index.es.js +123 -47
- package/dist/index.es.js.map +1 -1
- package/dist/{init-Dtl-IcXf.js → init-DHCe5mJ5.js} +59 -11
- package/dist/init-DHCe5mJ5.js.map +1 -0
- package/dist/{invoked-command-CG_rIa_o.js → invoked-command-FBeIBS8o.js} +2 -2
- package/dist/{invoked-command-CG_rIa_o.js.map → invoked-command-FBeIBS8o.js.map} +1 -1
- package/dist/last-dev-database-CBVkEUEl.js +2 -0
- package/dist/logs-CIgfLBsu.js +192 -0
- package/dist/logs-CIgfLBsu.js.map +1 -0
- package/dist/{manifest-C3uLDrrJ.js → manifest-RjqxfCpb.js} +114 -5
- package/dist/manifest-RjqxfCpb.js.map +1 -0
- package/dist/{migrate-VrKoi3nB.js → migrate-Cx8-Y4TG.js} +5 -4
- package/dist/{migrate-VrKoi3nB.js.map → migrate-Cx8-Y4TG.js.map} +1 -1
- package/dist/{normalize-imports-DwxqEMYq.js → normalize-imports-P86NVfpo.js} +3 -3
- package/dist/{normalize-imports-DwxqEMYq.js.map → normalize-imports-P86NVfpo.js.map} +1 -1
- package/dist/{path-flags-7O5uPBcQ.js → path-flags-ekLdkbra.js} +3 -3
- package/dist/{path-flags-7O5uPBcQ.js.map → path-flags-ekLdkbra.js.map} +1 -1
- package/dist/{prepare-Ccxspoj-.js → prepare-BaJe0Zik.js} +4 -4
- package/dist/{prepare-Ccxspoj-.js.map → prepare-BaJe0Zik.js.map} +1 -1
- package/dist/{project-CLcF5i8c.js → project-DALmhb5R.js} +2 -2
- package/dist/{project-CLcF5i8c.js.map → project-DALmhb5R.js.map} +1 -1
- package/dist/project-command-Cl9EZzjr.js +662 -0
- package/dist/project-command-Cl9EZzjr.js.map +1 -0
- package/dist/{project-schema-CsSOG2gE.js → project-schema-Dm6Jk0Y_.js} +4 -2
- package/dist/{project-schema-CsSOG2gE.js.map → project-schema-Dm6Jk0Y_.js.map} +1 -1
- package/dist/{pull-BMuiUyjb.js → pull-CTIsST6T.js} +66 -5
- package/dist/pull-CTIsST6T.js.map +1 -0
- package/dist/resolve-C36px9tR.js +2 -0
- package/dist/{resources-Dpfs2y8P.js → resources-Db3USuPO.js} +5 -5
- package/dist/{resources-Dpfs2y8P.js.map → resources-Db3USuPO.js.map} +1 -1
- package/dist/rls-BxrQ0P50.js +133 -0
- package/dist/rls-BxrQ0P50.js.map +1 -0
- package/dist/{schema-Dv6nHkb0.js → schema-_FzZEoB8.js} +54 -40
- package/dist/schema-_FzZEoB8.js.map +1 -0
- package/dist/{schema-dir-Cd1kvYbf.js → schema-dir-ChcYfWjP.js} +2 -2
- package/dist/{schema-dir-Cd1kvYbf.js.map → schema-dir-ChcYfWjP.js.map} +1 -1
- package/dist/schema-reconcile-DV14XY4o.js +2 -0
- package/dist/schema-show-h72UJ9zH.js +127 -0
- package/dist/schema-show-h72UJ9zH.js.map +1 -0
- package/dist/{skills-CXjA9TWw.js → skills-DQ2bZGkj.js} +6 -5
- package/dist/{skills-CXjA9TWw.js.map → skills-DQ2bZGkj.js.map} +1 -1
- package/dist/star-nudge.d.ts +28 -0
- package/dist/{start-Bwbtt2W5.js → start-Cjx4W0bJ.js} +7 -7
- package/dist/{start-Bwbtt2W5.js.map → start-Cjx4W0bJ.js.map} +1 -1
- package/dist/{status-BTgTWzlQ.js → status-CDBk25VO.js} +9 -9
- package/dist/{status-BTgTWzlQ.js.map → status-CDBk25VO.js.map} +1 -1
- package/dist/{storage-iTqj5-Av.js → storage-Clc8dLG8.js} +79 -36
- package/dist/storage-Clc8dLG8.js.map +1 -0
- package/dist/storage-objects-CfRKlTDe.js +279 -0
- package/dist/storage-objects-CfRKlTDe.js.map +1 -0
- package/dist/{telemetry-BP_1Cl9r.js → telemetry-DZU2-NCm.js} +5 -4
- package/dist/{telemetry-BP_1Cl9r.js.map → telemetry-DZU2-NCm.js.map} +1 -1
- package/dist/{telemetry-M3HjlyhZ.js → telemetry-EVtASbKb.js} +2 -2
- package/dist/{telemetry-M3HjlyhZ.js.map → telemetry-EVtASbKb.js.map} +1 -1
- package/dist/unknown-command-DnZ2uhGs.js +139 -0
- package/dist/unknown-command-DnZ2uhGs.js.map +1 -0
- package/dist/{upgrade-oZzJ13jM.js → upgrade-DhpUFb6p.js} +5 -5
- package/dist/{upgrade-oZzJ13jM.js.map → upgrade-DhpUFb6p.js.map} +1 -1
- package/dist/users-5PkqBY6R.js +561 -0
- package/dist/users-5PkqBY6R.js.map +1 -0
- package/dist/utils/project-command.d.ts +38 -0
- package/dist/utils/project-target.d.ts +193 -0
- package/dist/{verify-BkUVGLqo.js → verify-BdeqNb-V.js} +138 -12
- package/dist/verify-BdeqNb-V.js.map +1 -0
- package/dist/{version-Buyyo1ut.js → version-ONIeo7jl.js} +7 -2
- package/dist/{version-Buyyo1ut.js.map → version-ONIeo7jl.js.map} +1 -1
- package/package.json +10 -10
- package/dist/api-keys-eIUjMqWn.js.map +0 -1
- package/dist/apps-DExO4PEl.js.map +0 -1
- package/dist/args-CaCcrYE1.js.map +0 -1
- package/dist/auth-ofQETpM5.js.map +0 -1
- package/dist/bundle-DgILeA5b.js.map +0 -1
- package/dist/cloud-CYMk92iG.js.map +0 -1
- package/dist/command-D5lhW_-B.js.map +0 -1
- package/dist/fold-static-CKewnAPX.js.map +0 -1
- package/dist/init-Dtl-IcXf.js.map +0 -1
- package/dist/last-dev-database-Dc8cP01o.js +0 -2
- package/dist/manifest-C3uLDrrJ.js.map +0 -1
- package/dist/pull-BMuiUyjb.js.map +0 -1
- package/dist/resolve-BY7bSFRT.js +0 -2
- package/dist/schema-Dv6nHkb0.js.map +0 -1
- package/dist/schema-reconcile-CjxLaRHB.js +0 -2
- package/dist/storage-iTqj5-Av.js.map +0 -1
- package/dist/verify-BkUVGLqo.js.map +0 -1
|
@@ -0,0 +1,1114 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
+
import { r as unknownCommandMessage } from "./unknown-command-DnZ2uhGs.js";
|
|
3
|
+
import { B as projectHost, F as parseCloudArgs, G as reportError, I as printGroupHelp, K as requireClient, X as requireProject, b as fetchTenantBaseDomain, c as colorStatus, f as displayProjectRef, k as keyValues, m as emit, v as fail } from "./context-BOMEoKxn.js";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import arg from "arg";
|
|
6
|
+
import { warnDeprecated } from "@rebasepro/common";
|
|
7
|
+
//#region src/commands/cloud/debug.ts
|
|
8
|
+
/**
|
|
9
|
+
* `rebase cloud debug <subcommand>` — one entry point for "why is my deployed
|
|
10
|
+
* app not behaving".
|
|
11
|
+
*
|
|
12
|
+
* ## Why this exists
|
|
13
|
+
*
|
|
14
|
+
* The useful signals for a deployed project live in four different places — the
|
|
15
|
+
* control plane, the workload's pods, the tenant database, and the public URL —
|
|
16
|
+
* and each is normally reached with a different tool and a different set of
|
|
17
|
+
* flags. Getting to a log should not be a research task. This started life as a
|
|
18
|
+
* hand-rolled `prod-debug.sh` for a single project, with the namespace and the
|
|
19
|
+
* URL hardcoded at the top; it earned its place twice in one week, so it is
|
|
20
|
+
* generalised here to any project the CLI can already resolve.
|
|
21
|
+
*
|
|
22
|
+
* ## Read-only by default
|
|
23
|
+
*
|
|
24
|
+
* Every subcommand here only reads. The two things the original script could do
|
|
25
|
+
* that mutate are deliberately NOT reproduced as-is:
|
|
26
|
+
*
|
|
27
|
+
* - restarting the workload lives at `rebase cloud restart`, which already
|
|
28
|
+
* gates downtime behind `--yes`; duplicating it here would give the same
|
|
29
|
+
* destructive act a second, ungated spelling.
|
|
30
|
+
* - `debug db` prints the port-forward recipe and the connection's *shape*.
|
|
31
|
+
* It opens no session and prints no password — `rebase cloud db info
|
|
32
|
+
* --reveal` is the explicit, auditable way to get one.
|
|
33
|
+
*
|
|
34
|
+
* ## The probes are the point
|
|
35
|
+
*
|
|
36
|
+
* `debug health` is the highest-value piece and the reason the script existed.
|
|
37
|
+
* A bare status code is not a diagnosis: a 404 from a functions route means
|
|
38
|
+
* something completely different from a 404 at the root, and a 200 on an
|
|
39
|
+
* unauthenticated read is a finding rather than a success. So every probe ships
|
|
40
|
+
* with the interpretation of what it got, not just the number — see
|
|
41
|
+
* {@link PROBES}.
|
|
42
|
+
*/
|
|
43
|
+
var debug_exports = /* @__PURE__ */ __exportAll({
|
|
44
|
+
HEALTH_FLAGS: () => HEALTH_FLAGS,
|
|
45
|
+
LOG_VIEW_FLAGS: () => LOG_VIEW_FLAGS,
|
|
46
|
+
PROBES: () => PROBES,
|
|
47
|
+
REQUESTS_FLAGS: () => REQUESTS_FLAGS,
|
|
48
|
+
SERVER_MAX_TAIL_LINES: () => SERVER_MAX_TAIL_LINES,
|
|
49
|
+
assessCoverage: () => assessCoverage,
|
|
50
|
+
bootReach: () => bootReach,
|
|
51
|
+
debugCommand: () => debugCommand,
|
|
52
|
+
formatDuration: () => formatDuration,
|
|
53
|
+
formatSpan: () => formatSpan,
|
|
54
|
+
functionNames: () => functionNames,
|
|
55
|
+
isBootLine: () => isBootLine,
|
|
56
|
+
isErrorLine: () => isErrorLine,
|
|
57
|
+
overallVerdict: () => overallVerdict,
|
|
58
|
+
parseLogLine: () => parseLogLine,
|
|
59
|
+
parseRequestLine: () => parseRequestLine,
|
|
60
|
+
parseSince: () => parseSince,
|
|
61
|
+
printDebugHelp: () => printDebugHelp,
|
|
62
|
+
resolveOrigin: () => resolveOrigin,
|
|
63
|
+
resolveProbeTable: () => resolveProbeTable,
|
|
64
|
+
resolveTail: () => resolveTail,
|
|
65
|
+
runProbe: () => runProbe
|
|
66
|
+
});
|
|
67
|
+
/** A response never arrived: DNS, TLS, ingress, or the pod. */
|
|
68
|
+
var NO_RESPONSE = {
|
|
69
|
+
verdict: "fail",
|
|
70
|
+
meaning: "nothing answered — the hostname does not resolve, the ingress has no route, or no pod is running"
|
|
71
|
+
};
|
|
72
|
+
function serverError(what) {
|
|
73
|
+
return {
|
|
74
|
+
verdict: "fail",
|
|
75
|
+
meaning: `the server is running but ${what}`
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The probe set, in the order a failure cascades: if `health` is down, nothing
|
|
80
|
+
* below it is meaningful, so it is checked first and reported first.
|
|
81
|
+
*/
|
|
82
|
+
var PROBES = [
|
|
83
|
+
{
|
|
84
|
+
id: "health",
|
|
85
|
+
label: "health",
|
|
86
|
+
method: "GET",
|
|
87
|
+
path: () => "/health",
|
|
88
|
+
healthy: "200 — the backend is up",
|
|
89
|
+
interpret: (status) => {
|
|
90
|
+
if (status === null) return NO_RESPONSE;
|
|
91
|
+
if (status === 200) return {
|
|
92
|
+
verdict: "ok",
|
|
93
|
+
meaning: "the backend is up and serving"
|
|
94
|
+
};
|
|
95
|
+
if (status === 404) return {
|
|
96
|
+
verdict: "fail",
|
|
97
|
+
meaning: "something answered but it is not a Rebase backend — the ingress is routing this host elsewhere"
|
|
98
|
+
};
|
|
99
|
+
if (status >= 500) return serverError("its health endpoint is failing");
|
|
100
|
+
return {
|
|
101
|
+
verdict: "unknown",
|
|
102
|
+
meaning: "unexpected for a health endpoint"
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
id: "spa",
|
|
108
|
+
label: "spa",
|
|
109
|
+
method: "GET",
|
|
110
|
+
path: () => "/",
|
|
111
|
+
healthy: "200 — the frontend is being served",
|
|
112
|
+
interpret: (status) => {
|
|
113
|
+
if (status === null) return NO_RESPONSE;
|
|
114
|
+
if (status === 200) return {
|
|
115
|
+
verdict: "ok",
|
|
116
|
+
meaning: "the frontend bundle is being served"
|
|
117
|
+
};
|
|
118
|
+
if (status === 404) return {
|
|
119
|
+
verdict: "warn",
|
|
120
|
+
meaning: "no frontend at the root — expected for a backend-only project, otherwise the SPA assets were not bundled into the image"
|
|
121
|
+
};
|
|
122
|
+
if (status >= 500) return serverError("the root route throws");
|
|
123
|
+
return {
|
|
124
|
+
verdict: "unknown",
|
|
125
|
+
meaning: "unexpected at the site root"
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
},
|
|
129
|
+
{
|
|
130
|
+
id: "auth",
|
|
131
|
+
label: "auth",
|
|
132
|
+
method: "POST",
|
|
133
|
+
path: () => "/api/auth/login",
|
|
134
|
+
body: {},
|
|
135
|
+
healthy: "400 — auth is mounted and rejects an empty body",
|
|
136
|
+
interpret: (status) => {
|
|
137
|
+
if (status === null) return NO_RESPONSE;
|
|
138
|
+
if (status === 400 || status === 422) return {
|
|
139
|
+
verdict: "ok",
|
|
140
|
+
meaning: "auth is mounted and rejected the empty body, as it should"
|
|
141
|
+
};
|
|
142
|
+
if (status === 401 || status === 403) return {
|
|
143
|
+
verdict: "ok",
|
|
144
|
+
meaning: "auth is mounted and refused the credentials"
|
|
145
|
+
};
|
|
146
|
+
if (status === 404) return {
|
|
147
|
+
verdict: "fail",
|
|
148
|
+
meaning: "the auth routes are NOT mounted — this project cannot sign anyone in"
|
|
149
|
+
};
|
|
150
|
+
if (status === 200) return {
|
|
151
|
+
verdict: "fail",
|
|
152
|
+
meaning: "an EMPTY login body was accepted — a login with no credentials must never succeed"
|
|
153
|
+
};
|
|
154
|
+
if (status >= 500) return serverError("the login route throws — often a missing or unmigrated auth table");
|
|
155
|
+
return {
|
|
156
|
+
verdict: "unknown",
|
|
157
|
+
meaning: "unexpected for a login route"
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
id: "unauthRead",
|
|
163
|
+
label: "unauth read",
|
|
164
|
+
method: "GET",
|
|
165
|
+
path: (t) => `/api/data/${encodeURIComponent(t.collection)}`,
|
|
166
|
+
healthy: "401 — reads require authentication",
|
|
167
|
+
interpret: (status) => {
|
|
168
|
+
if (status === null) return NO_RESPONSE;
|
|
169
|
+
if (status === 401 || status === 403) return {
|
|
170
|
+
verdict: "ok",
|
|
171
|
+
meaning: "unauthenticated reads are refused — row-level security is enforced"
|
|
172
|
+
};
|
|
173
|
+
if (status === 200) return {
|
|
174
|
+
verdict: "warn",
|
|
175
|
+
meaning: "this table is readable with NO authentication — correct only if it is deliberately public"
|
|
176
|
+
};
|
|
177
|
+
if (status === 404) return {
|
|
178
|
+
verdict: "warn",
|
|
179
|
+
meaning: "no such table on this deployment — check the name, or pass --table"
|
|
180
|
+
};
|
|
181
|
+
if (status >= 500) return serverError("the read reached the database and failed — most often an RLS policy naming a column or table that is not there");
|
|
182
|
+
return {
|
|
183
|
+
verdict: "unknown",
|
|
184
|
+
meaning: "unexpected for a data read"
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: "functions",
|
|
190
|
+
label: "functions",
|
|
191
|
+
method: "GET",
|
|
192
|
+
/**
|
|
193
|
+
* The router's own listing endpoint, NOT a function's path.
|
|
194
|
+
*
|
|
195
|
+
* This matters, and it is the one place the original script got a wrong
|
|
196
|
+
* answer. A function is a Hono sub-app mounted at `/<name>`, and it
|
|
197
|
+
* usually defines only sub-routes (`/get`, `/list`) — so
|
|
198
|
+
* `/api/functions/<name>` 404s **even when everything is mounted and
|
|
199
|
+
* healthy**. Probing there cannot separate "the router is missing" from
|
|
200
|
+
* "that function defines no root route", and reporting the first is how
|
|
201
|
+
* you send someone to debug a deployment that was fine.
|
|
202
|
+
*
|
|
203
|
+
* `GET /api/functions` is unambiguous: the router registers a listing
|
|
204
|
+
* route at its own root (see `createFunctionRoutes`), so a 200 proves
|
|
205
|
+
* the mount *and* names every function that loaded.
|
|
206
|
+
*/
|
|
207
|
+
path: () => "/api/functions",
|
|
208
|
+
healthy: "200 — the functions router is mounted and lists its functions",
|
|
209
|
+
interpret: (status) => {
|
|
210
|
+
if (status === null) return NO_RESPONSE;
|
|
211
|
+
if (status === 200) return {
|
|
212
|
+
verdict: "ok",
|
|
213
|
+
meaning: "the functions router is mounted"
|
|
214
|
+
};
|
|
215
|
+
if (status === 401 || status === 403) return {
|
|
216
|
+
verdict: "ok",
|
|
217
|
+
meaning: "the functions router is mounted (its listing requires auth)"
|
|
218
|
+
};
|
|
219
|
+
if (status === 404) return {
|
|
220
|
+
verdict: "fail",
|
|
221
|
+
meaning: "the functions router did not mount — no functions directory was found at build time, or it held no functions, so every function on this project is unreachable"
|
|
222
|
+
};
|
|
223
|
+
if (status >= 500) return serverError("the functions router throws");
|
|
224
|
+
return {
|
|
225
|
+
verdict: "unknown",
|
|
226
|
+
meaning: "unexpected for the functions listing"
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
needsBody: true,
|
|
230
|
+
refine: (body, t) => {
|
|
231
|
+
const names = functionNames(body);
|
|
232
|
+
if (!names) return null;
|
|
233
|
+
if (t.fn && !names.includes(t.fn)) return {
|
|
234
|
+
verdict: "fail",
|
|
235
|
+
meaning: `the router is mounted but no function is named "${t.fn}" — it loaded ${names.length}: ${names.join(", ")}`
|
|
236
|
+
};
|
|
237
|
+
const found = t.fn ? `, including ${t.fn}` : "";
|
|
238
|
+
return {
|
|
239
|
+
verdict: "ok",
|
|
240
|
+
meaning: `the functions router is mounted and loaded ${names.length} function${names.length === 1 ? "" : "s"}${found}`
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
];
|
|
245
|
+
/** The function names out of a listing body, or null when it is not one. */
|
|
246
|
+
function functionNames(body) {
|
|
247
|
+
const list = body?.functions;
|
|
248
|
+
if (!Array.isArray(list)) return null;
|
|
249
|
+
const names = list.map((f) => f?.name).filter((n) => typeof n === "string");
|
|
250
|
+
return names.length === list.length ? names : null;
|
|
251
|
+
}
|
|
252
|
+
/** Milliseconds before a probe is treated as unanswered. */
|
|
253
|
+
var PROBE_TIMEOUT_MS = 1e4;
|
|
254
|
+
/**
|
|
255
|
+
* Ceiling on a probe body we will parse. The only body read is the function
|
|
256
|
+
* listing; anything larger is a page we have no use for, and a debug command
|
|
257
|
+
* must not be the thing that runs a machine out of memory.
|
|
258
|
+
*/
|
|
259
|
+
var MAX_PROBE_BODY_BYTES = 256 * 1024;
|
|
260
|
+
/**
|
|
261
|
+
* Run one probe. A transport failure is a `null` status, never a thrown error:
|
|
262
|
+
* "nothing answered" is a diagnosis in its own right and the other probes still
|
|
263
|
+
* need to run.
|
|
264
|
+
*/
|
|
265
|
+
async function runProbe(origin, spec, targets) {
|
|
266
|
+
const url = `${origin}${spec.path(targets)}`;
|
|
267
|
+
const started = Date.now();
|
|
268
|
+
let status = null;
|
|
269
|
+
let body;
|
|
270
|
+
try {
|
|
271
|
+
const res = await fetch(url, {
|
|
272
|
+
method: spec.method,
|
|
273
|
+
headers: spec.body ? { "Content-Type": "application/json" } : void 0,
|
|
274
|
+
body: spec.body ? JSON.stringify(spec.body) : void 0,
|
|
275
|
+
redirect: "manual",
|
|
276
|
+
signal: AbortSignal.timeout(PROBE_TIMEOUT_MS)
|
|
277
|
+
});
|
|
278
|
+
status = res.status;
|
|
279
|
+
if (spec.needsBody && res.ok) {
|
|
280
|
+
const text = await res.text();
|
|
281
|
+
if (text.length <= MAX_PROBE_BODY_BYTES) try {
|
|
282
|
+
body = JSON.parse(text);
|
|
283
|
+
} catch {}
|
|
284
|
+
}
|
|
285
|
+
} catch {
|
|
286
|
+
status = null;
|
|
287
|
+
}
|
|
288
|
+
const statusReading = spec.interpret(status);
|
|
289
|
+
const reading = status !== null && spec.refine?.(body, targets) || statusReading;
|
|
290
|
+
return {
|
|
291
|
+
statusOk: statusReading.verdict === "ok",
|
|
292
|
+
id: spec.id,
|
|
293
|
+
label: spec.label,
|
|
294
|
+
method: spec.method,
|
|
295
|
+
url,
|
|
296
|
+
status,
|
|
297
|
+
ms: Date.now() - started,
|
|
298
|
+
verdict: reading.verdict,
|
|
299
|
+
meaning: reading.meaning,
|
|
300
|
+
healthy: spec.healthy
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
/** The worst verdict across probes — what the command's exit code keys off. */
|
|
304
|
+
function overallVerdict(results) {
|
|
305
|
+
if (results.some((r) => r.verdict === "fail")) return "fail";
|
|
306
|
+
if (results.some((r) => r.verdict === "unknown")) return "unknown";
|
|
307
|
+
if (results.some((r) => r.verdict === "warn")) return "warn";
|
|
308
|
+
return "ok";
|
|
309
|
+
}
|
|
310
|
+
function verdictMark(v) {
|
|
311
|
+
switch (v) {
|
|
312
|
+
case "ok": return chalk.green("✓");
|
|
313
|
+
case "warn": return chalk.yellow("!");
|
|
314
|
+
case "fail": return chalk.red("✗");
|
|
315
|
+
default: return chalk.gray("?");
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
var LOG_PREFIX_RE = /^(?:(\d{4}-\d{2}-\d{2}T[\d:.]+Z?)\s+)?(?:\[([^\]]+)\]\s+)?([\s\S]*)$/;
|
|
319
|
+
function parseLogLine(line) {
|
|
320
|
+
const m = LOG_PREFIX_RE.exec(line);
|
|
321
|
+
if (!m) return {
|
|
322
|
+
ts: null,
|
|
323
|
+
pod: null,
|
|
324
|
+
text: line
|
|
325
|
+
};
|
|
326
|
+
return {
|
|
327
|
+
ts: m[1] ?? null,
|
|
328
|
+
pod: m[2] ?? null,
|
|
329
|
+
text: m[3] ?? ""
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Lines an operator scanning for a fault wants to see.
|
|
334
|
+
*
|
|
335
|
+
* Matches the structured `severity` field first, then the shapes that show up
|
|
336
|
+
* in unstructured output. `refus`/`denied` are in the list because a permission
|
|
337
|
+
* failure often logs at info level and is exactly what one is hunting for.
|
|
338
|
+
*/
|
|
339
|
+
function isErrorLine(text) {
|
|
340
|
+
return /"(?:severity|level)":\s*"(?:ERROR|WARN(?:ING)?|error|warn)"|\bError:|\bERR!|refus|denied|EACCES|ECONNREFUSED/i.test(text);
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Pull an HTTP request record out of a log line, or null when it is not one.
|
|
344
|
+
*
|
|
345
|
+
* Only structured request lines are recognised. Guessing at prose would produce
|
|
346
|
+
* a table with invented columns, which is worse than a short one.
|
|
347
|
+
*/
|
|
348
|
+
function parseRequestLine(text) {
|
|
349
|
+
const start = text.indexOf("{");
|
|
350
|
+
if (start === -1) return null;
|
|
351
|
+
let parsed;
|
|
352
|
+
try {
|
|
353
|
+
parsed = JSON.parse(text.slice(start));
|
|
354
|
+
} catch {
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
357
|
+
if (parsed.message !== "request" && parsed.msg !== "request") return null;
|
|
358
|
+
const num = (v) => {
|
|
359
|
+
const n = typeof v === "string" ? Number(v) : typeof v === "number" ? v : NaN;
|
|
360
|
+
return Number.isFinite(n) ? n : null;
|
|
361
|
+
};
|
|
362
|
+
return {
|
|
363
|
+
status: num(parsed.status),
|
|
364
|
+
method: typeof parsed.method === "string" ? parsed.method : "",
|
|
365
|
+
path: typeof parsed.path === "string" ? parsed.path : "",
|
|
366
|
+
latencyMs: num(parsed.latencyMs ?? parsed.durationMs)
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
* Startup lines: what the server *decided* it was going to do. Which storage
|
|
371
|
+
* backend it bound, which functions it loaded, whether auth tables were found.
|
|
372
|
+
* This is the fastest way to tell a misconfiguration from a runtime fault.
|
|
373
|
+
*/
|
|
374
|
+
function isBootLine(text) {
|
|
375
|
+
return /storage|Loaded (?:custom )?function|Loaded cron|Cron jobs scheduled|Cron scheduler|Mounted|Auth tables|Server running|listening|Refusing|migrat/i.test(text);
|
|
376
|
+
}
|
|
377
|
+
/** Render a number of seconds back as the compact duration a user would type. */
|
|
378
|
+
function formatDuration(seconds) {
|
|
379
|
+
if (seconds % 86400 === 0 && seconds >= 86400) return `${seconds / 86400}d`;
|
|
380
|
+
if (seconds % 3600 === 0 && seconds >= 3600) return `${seconds / 3600}h`;
|
|
381
|
+
if (seconds % 60 === 0 && seconds >= 60) return `${seconds / 60}m`;
|
|
382
|
+
return `${seconds}s`;
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* Parse a duration like `15m`, `2h`, `90s`, `1d` (or a bare number of seconds)
|
|
386
|
+
* into seconds. Returns null when it is not a duration.
|
|
387
|
+
*/
|
|
388
|
+
function parseSince(input) {
|
|
389
|
+
if (!input) return null;
|
|
390
|
+
const m = /^(\d+(?:\.\d+)?)\s*([smhd])?$/i.exec(input.trim());
|
|
391
|
+
if (!m) return null;
|
|
392
|
+
const value = parseFloat(m[1]);
|
|
393
|
+
const unit = (m[2] || "s").toLowerCase();
|
|
394
|
+
return Math.round(value * (unit === "s" ? 1 : unit === "m" ? 60 : unit === "h" ? 3600 : 86400));
|
|
395
|
+
}
|
|
396
|
+
/**
|
|
397
|
+
* The most lines `runtime-logs` returns per pod.
|
|
398
|
+
*
|
|
399
|
+
* The control plane enforces this (`MAX_TAIL_LINES` in
|
|
400
|
+
* `saas/backend/functions/runtime-logs.ts`) by clamping a larger `tailLines`
|
|
401
|
+
* without saying so: its answer names neither the limit nor the value it used.
|
|
402
|
+
* `--tail 200000` therefore came back as 2000 lines reported as untruncated.
|
|
403
|
+
* The CLI clamps first, with the same number, so the lowering is something it
|
|
404
|
+
* can print rather than something that happened out of sight.
|
|
405
|
+
*/
|
|
406
|
+
var SERVER_MAX_TAIL_LINES = 2e3;
|
|
407
|
+
function resolveTail(requested, explicit) {
|
|
408
|
+
const applied = Math.min(requested, SERVER_MAX_TAIL_LINES);
|
|
409
|
+
return {
|
|
410
|
+
requested,
|
|
411
|
+
applied,
|
|
412
|
+
explicit,
|
|
413
|
+
note: applied < requested ? `--tail ${requested} was lowered to ${applied}: the control plane returns at most ${SERVER_MAX_TAIL_LINES} lines per pod.` : null
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/** Read `--tail`, refusing anything that is not a positive whole number. */
|
|
417
|
+
function tailFromFlag(value, fallback) {
|
|
418
|
+
if (value === void 0) return resolveTail(fallback, false);
|
|
419
|
+
if (!Number.isInteger(value) || value <= 0) fail(`--tail must be a positive whole number of lines; received "${value}".`, void 0, "usage");
|
|
420
|
+
return resolveTail(value, true);
|
|
421
|
+
}
|
|
422
|
+
/** A span of milliseconds as `29d 23h`, `2h 5m`, `35m`, `40s`. */
|
|
423
|
+
function formatSpan(ms) {
|
|
424
|
+
const s = Math.max(0, Math.round(ms / 1e3));
|
|
425
|
+
const d = Math.floor(s / 86400);
|
|
426
|
+
const h = Math.floor(s % 86400 / 3600);
|
|
427
|
+
const m = Math.floor(s % 3600 / 60);
|
|
428
|
+
if (d > 0) return h > 0 ? `${d}d ${h}h` : `${d}d`;
|
|
429
|
+
if (h > 0) return m > 0 ? `${h}h ${m}m` : `${h}h`;
|
|
430
|
+
if (m > 0) return `${m}m`;
|
|
431
|
+
return `${s}s`;
|
|
432
|
+
}
|
|
433
|
+
function timestampRange(lines) {
|
|
434
|
+
let first = null;
|
|
435
|
+
let last = null;
|
|
436
|
+
for (const l of lines) {
|
|
437
|
+
if (!l.ts) continue;
|
|
438
|
+
const ms = Date.parse(l.ts);
|
|
439
|
+
if (Number.isNaN(ms)) continue;
|
|
440
|
+
if (!first || ms < first.ms) first = {
|
|
441
|
+
text: l.ts,
|
|
442
|
+
ms
|
|
443
|
+
};
|
|
444
|
+
if (!last || ms > last.ms) last = {
|
|
445
|
+
text: l.ts,
|
|
446
|
+
ms
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
return {
|
|
450
|
+
first: first?.text ?? null,
|
|
451
|
+
last: last?.text ?? null
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Compare what a read covered with what it asked for.
|
|
456
|
+
*
|
|
457
|
+
* The server's `truncated` describes only its byte budgets and pod ceiling, so
|
|
458
|
+
* a pod that filled the line limit came back marked complete however much of
|
|
459
|
+
* the window it left unread. The line limit is the cut that matters most, and
|
|
460
|
+
* it is detected here: a pod that returned as many lines as the limit, whose
|
|
461
|
+
* earliest line is later than the start of the window, was cut by it.
|
|
462
|
+
*
|
|
463
|
+
* Filling the limit is the half that separates a cut from a young pod. A pod
|
|
464
|
+
* that started an hour ago also has no line older than an hour; it returned
|
|
465
|
+
* fewer lines than the limit, so what came back is its whole log, and nothing
|
|
466
|
+
* was cut.
|
|
467
|
+
*/
|
|
468
|
+
function assessCoverage(opts) {
|
|
469
|
+
const { res, lines, sinceSeconds, tail, now } = opts;
|
|
470
|
+
const windowStartMs = sinceSeconds === null ? null : now - sinceSeconds * 1e3;
|
|
471
|
+
const requestedFrom = windowStartMs === null ? null : new Date(windowStartMs).toISOString();
|
|
472
|
+
const limitName = tail.note ? `the control plane's ceiling of ${tail.applied} lines per pod` : tail.explicit ? `the --tail ${tail.applied} limit` : `the default of ${tail.applied} lines per pod`;
|
|
473
|
+
const raise = tail.applied < 2e3 ? ` Raise --tail (at most ${SERVER_MAX_TAIL_LINES}) to read further back.` : ` The control plane returns only each pod's newest ${SERVER_MAX_TAIL_LINES}, so older lines cannot be read from here.`;
|
|
474
|
+
const pods = (res.pods ?? []).map((p) => {
|
|
475
|
+
const range = timestampRange(lines.filter((l) => l.pod === p.pod));
|
|
476
|
+
const base = {
|
|
477
|
+
...p,
|
|
478
|
+
firstTimestamp: range.first,
|
|
479
|
+
lastTimestamp: range.last
|
|
480
|
+
};
|
|
481
|
+
if (p.state !== "ok") return {
|
|
482
|
+
...base,
|
|
483
|
+
truncated: false,
|
|
484
|
+
truncatedBy: null,
|
|
485
|
+
truncatedReason: null,
|
|
486
|
+
complete: false
|
|
487
|
+
};
|
|
488
|
+
if (p.truncated) return {
|
|
489
|
+
...base,
|
|
490
|
+
truncated: true,
|
|
491
|
+
truncatedBy: "bytes",
|
|
492
|
+
truncatedReason: `${p.pod}: the control plane's per-pod byte budget cut this pod's output short` + (range.first ? ` — what fit runs ${range.first} to ${range.last}.` : "."),
|
|
493
|
+
complete: false
|
|
494
|
+
};
|
|
495
|
+
const firstMs = range.first ? Date.parse(range.first) : null;
|
|
496
|
+
const startsLate = windowStartMs === null || firstMs === null || firstMs > windowStartMs;
|
|
497
|
+
if (p.lines >= tail.applied && startsLate) {
|
|
498
|
+
let reason;
|
|
499
|
+
if (firstMs === null) reason = `${p.pod}: returned ${p.lines} lines, ${limitName}; they carry no timestamps, so how far back they reach is unknown.`;
|
|
500
|
+
else if (sinceSeconds !== null && windowStartMs !== null) reason = `${p.pod}: returned ${p.lines} lines, ${limitName}, and the earliest is ${range.first} — ${formatSpan(firstMs - windowStartMs)} after the ${formatDuration(sinceSeconds)} window begins (${requestedFrom}). Lines in between were not read.${raise}`;
|
|
501
|
+
else reason = `${p.pod}: returned ${p.lines} lines, ${limitName}, so its log before ${range.first} was not read.${raise}`;
|
|
502
|
+
return {
|
|
503
|
+
...base,
|
|
504
|
+
truncated: true,
|
|
505
|
+
truncatedBy: "tail",
|
|
506
|
+
truncatedReason: reason,
|
|
507
|
+
complete: false
|
|
508
|
+
};
|
|
509
|
+
}
|
|
510
|
+
return {
|
|
511
|
+
...base,
|
|
512
|
+
truncated: false,
|
|
513
|
+
truncatedBy: null,
|
|
514
|
+
truncatedReason: null,
|
|
515
|
+
complete: true
|
|
516
|
+
};
|
|
517
|
+
});
|
|
518
|
+
const truncatedReasons = pods.flatMap((p) => p.truncatedReason ? [p.truncatedReason] : []);
|
|
519
|
+
if (res.truncated && !pods.some((p) => p.truncatedBy === "bytes")) truncatedReasons.push("The control plane trimmed the combined result (its total byte budget, or the most pods it reads at once); the oldest lines were dropped.");
|
|
520
|
+
const overall = timestampRange(lines);
|
|
521
|
+
return {
|
|
522
|
+
requestedFrom,
|
|
523
|
+
firstTimestamp: overall.first,
|
|
524
|
+
lastTimestamp: overall.last,
|
|
525
|
+
pods,
|
|
526
|
+
truncated: Boolean(res.truncated) || pods.some((p) => p.truncated),
|
|
527
|
+
truncatedReasons
|
|
528
|
+
};
|
|
529
|
+
}
|
|
530
|
+
async function fetchRuntimeLogs(client, projectId, opts) {
|
|
531
|
+
const params = new URLSearchParams();
|
|
532
|
+
if (opts.sinceSeconds !== void 0) params.set("sinceSeconds", String(opts.sinceSeconds));
|
|
533
|
+
if (opts.tailLines !== void 0) params.set("tailLines", String(opts.tailLines));
|
|
534
|
+
if (opts.previous) params.set("previous", "true");
|
|
535
|
+
params.set("timestamps", "true");
|
|
536
|
+
const qs = params.toString();
|
|
537
|
+
return client.functions.invoke("runtime-logs", void 0, {
|
|
538
|
+
method: "GET",
|
|
539
|
+
path: `${projectId}${qs ? `?${qs}` : ""}`
|
|
540
|
+
});
|
|
541
|
+
}
|
|
542
|
+
/** Print the per-pod states runtime-logs reports, including its hints. */
|
|
543
|
+
function printPodStates(res) {
|
|
544
|
+
if (res.state === "no_pods") {
|
|
545
|
+
console.log(chalk.yellow(` ${res.message ?? "No pods are running for this project."}`));
|
|
546
|
+
console.log("");
|
|
547
|
+
return;
|
|
548
|
+
}
|
|
549
|
+
for (const p of res.pods ?? []) {
|
|
550
|
+
if (p.state === "ok") continue;
|
|
551
|
+
console.log(` ${chalk.yellow(p.pod)} ${chalk.gray(`(${p.state})`)}`);
|
|
552
|
+
if (p.message) console.log(chalk.gray(` ${p.message}`));
|
|
553
|
+
if (p.hint) console.log(chalk.cyan(` → ${p.hint}`));
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
/**
|
|
557
|
+
* The window asked for, the window delivered, and every cut between them.
|
|
558
|
+
* Printed after the lines, where a reader's eye is when the output ends.
|
|
559
|
+
*/
|
|
560
|
+
function printCoverage(coverage, tail) {
|
|
561
|
+
const asked = coverage.requestedFrom ? `from ${coverage.requestedFrom}` : "from each pod's start";
|
|
562
|
+
const got = coverage.firstTimestamp && coverage.lastTimestamp ? `${coverage.firstTimestamp} → ${coverage.lastTimestamp} (${formatSpan(Date.parse(coverage.lastTimestamp) - Date.parse(coverage.firstTimestamp))})` : "no timestamped lines";
|
|
563
|
+
console.log(chalk.gray(` Asked for: ${asked}`));
|
|
564
|
+
console.log(chalk.gray(` Returned: ${got}`));
|
|
565
|
+
if (tail.note) console.log(chalk.yellow(` ! ${tail.note}`));
|
|
566
|
+
if (coverage.truncated) {
|
|
567
|
+
console.log(chalk.yellow(" ! Truncated — the lines above do not cover the window asked for:"));
|
|
568
|
+
for (const reason of coverage.truncatedReasons) console.log(chalk.yellow(` ${reason}`));
|
|
569
|
+
}
|
|
570
|
+
console.log("");
|
|
571
|
+
}
|
|
572
|
+
/**
|
|
573
|
+
* Resolve the public origin a project is served at — or `--host`, when given.
|
|
574
|
+
*
|
|
575
|
+
* Shared with `rebase cloud cron`, which reads the runtime at the same address
|
|
576
|
+
* `debug health` probes.
|
|
577
|
+
*/
|
|
578
|
+
async function resolveOrigin(rawArgs, client, url, projectId) {
|
|
579
|
+
const parsed = arg({ "--host": String }, {
|
|
580
|
+
argv: rawArgs.slice(3),
|
|
581
|
+
permissive: true
|
|
582
|
+
});
|
|
583
|
+
if (parsed["--host"]) {
|
|
584
|
+
const h = parsed["--host"].trim().replace(/\/+$/, "");
|
|
585
|
+
return /^https?:\/\//.test(h) ? h : `https://${h}`;
|
|
586
|
+
}
|
|
587
|
+
const [project, baseDomain] = await Promise.all([client.data.table("projects").findById(projectId), fetchTenantBaseDomain(client, url)]);
|
|
588
|
+
if (!project) fail(`Project ${displayProjectRef(rawArgs)} not found.`);
|
|
589
|
+
const host = projectHost(project, baseDomain);
|
|
590
|
+
if (!host) fail("Could not determine the public URL for this project.", "It may never have been deployed. Pass --host <hostname> to probe an address directly.");
|
|
591
|
+
return `https://${host}`;
|
|
592
|
+
}
|
|
593
|
+
async function healthCommand(rawArgs) {
|
|
594
|
+
const { flags: parsed } = parseCloudArgs({
|
|
595
|
+
spec: HEALTH_FLAGS,
|
|
596
|
+
rawArgs,
|
|
597
|
+
commandWords: 3,
|
|
598
|
+
command: "cloud debug",
|
|
599
|
+
maxPositionals: 0
|
|
600
|
+
});
|
|
601
|
+
const targets = {
|
|
602
|
+
collection: resolveProbeTable(parsed) || "users",
|
|
603
|
+
fn: parsed["--function"]
|
|
604
|
+
};
|
|
605
|
+
const { client, url } = await requireClient(rawArgs);
|
|
606
|
+
const origin = await resolveOrigin(rawArgs, client, url, await requireProject(rawArgs, client));
|
|
607
|
+
const results = [];
|
|
608
|
+
for (const spec of PROBES) results.push(await runProbe(origin, spec, targets));
|
|
609
|
+
const overall = overallVerdict(results);
|
|
610
|
+
emit(() => {
|
|
611
|
+
console.log("");
|
|
612
|
+
console.log(chalk.bold(` 🩺 Health — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${origin}`));
|
|
613
|
+
console.log("");
|
|
614
|
+
const width = Math.max(...results.map((r) => r.label.length));
|
|
615
|
+
for (const r of results) {
|
|
616
|
+
const code = r.status === null ? chalk.red("---") : String(r.status);
|
|
617
|
+
console.log(` ${verdictMark(r.verdict)} ${chalk.bold(r.label.padEnd(width))} ${code.padStart(3)} ${chalk.gray(`${r.ms}ms`)}`);
|
|
618
|
+
console.log(` ${chalk.gray(r.meaning)}`);
|
|
619
|
+
}
|
|
620
|
+
console.log("");
|
|
621
|
+
if (overall === "ok") console.log(chalk.green(" Everything reachable and wired as expected."));
|
|
622
|
+
else {
|
|
623
|
+
const bad = results.filter((r) => r.verdict === "fail" || r.verdict === "warn");
|
|
624
|
+
console.log(chalk.gray(` ${bad.length} of ${results.length} check${bad.length === 1 ? "" : "s"} need attention.`));
|
|
625
|
+
const wrongStatus = bad.filter((r) => !r.statusOk);
|
|
626
|
+
if (wrongStatus.length > 0) {
|
|
627
|
+
console.log(chalk.gray(" A healthy deployment answers:"));
|
|
628
|
+
for (const r of wrongStatus) console.log(chalk.gray(` ${r.label.padEnd(width)} ${r.healthy}`));
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
console.log("");
|
|
632
|
+
}, {
|
|
633
|
+
origin,
|
|
634
|
+
overall,
|
|
635
|
+
probes: results
|
|
636
|
+
});
|
|
637
|
+
if (overall === "fail") process.exit(1);
|
|
638
|
+
}
|
|
639
|
+
/** What `debug logs`, `errors` and `boot` parse. Their help pairs against this. */
|
|
640
|
+
var LOG_VIEW_FLAGS = {
|
|
641
|
+
"--since": String,
|
|
642
|
+
"--tail": Number,
|
|
643
|
+
"--previous": Boolean
|
|
644
|
+
};
|
|
645
|
+
/** What `debug requests` parses. */
|
|
646
|
+
var REQUESTS_FLAGS = {
|
|
647
|
+
"--since": String,
|
|
648
|
+
"--tail": Number
|
|
649
|
+
};
|
|
650
|
+
/** What `debug health` parses. */
|
|
651
|
+
var HEALTH_FLAGS = {
|
|
652
|
+
"--table": String,
|
|
653
|
+
/** @deprecated Use `--table` instead. Accepted, with a warning, until a later release. */
|
|
654
|
+
"--collection": String,
|
|
655
|
+
"--function": String,
|
|
656
|
+
"--host": String
|
|
657
|
+
};
|
|
658
|
+
/**
|
|
659
|
+
* The table `debug health` probes, from `--table` or its deprecated spelling
|
|
660
|
+
* `--collection`, which still works and warns once. Undefined when neither was
|
|
661
|
+
* given.
|
|
662
|
+
*
|
|
663
|
+
* "Table" is the word for the app's data; "collection" is the CMS's. Both
|
|
664
|
+
* spellings at once is refused unless they agree, since one of them would be
|
|
665
|
+
* ignored.
|
|
666
|
+
*/
|
|
667
|
+
function resolveProbeTable(flags) {
|
|
668
|
+
const table = flags["--table"];
|
|
669
|
+
const collection = flags["--collection"];
|
|
670
|
+
if (collection === void 0) return table;
|
|
671
|
+
warnDeprecated("cli.cloud-debug-health-collection", "`rebase cloud debug health --collection` is deprecated; use `--table` instead.");
|
|
672
|
+
if (table !== void 0 && table !== collection) fail("--table and --collection name the same thing; pass --table alone.", void 0, "usage");
|
|
673
|
+
return table ?? collection;
|
|
674
|
+
}
|
|
675
|
+
var LOG_VIEWS = {
|
|
676
|
+
logs: {
|
|
677
|
+
defaultSinceSeconds: 900,
|
|
678
|
+
defaultTail: 500,
|
|
679
|
+
limit: 200,
|
|
680
|
+
title: "📄 Logs"
|
|
681
|
+
},
|
|
682
|
+
errors: {
|
|
683
|
+
filter: isErrorLine,
|
|
684
|
+
defaultSinceSeconds: 3600,
|
|
685
|
+
defaultTail: 500,
|
|
686
|
+
limit: 40,
|
|
687
|
+
title: "🔥 Errors"
|
|
688
|
+
},
|
|
689
|
+
boot: {
|
|
690
|
+
filter: isBootLine,
|
|
691
|
+
defaultSinceSeconds: null,
|
|
692
|
+
defaultTail: SERVER_MAX_TAIL_LINES,
|
|
693
|
+
limit: 25,
|
|
694
|
+
title: "🚀 Boot",
|
|
695
|
+
needsStart: true
|
|
696
|
+
}
|
|
697
|
+
};
|
|
698
|
+
var REQUESTS_DEFAULTS = {
|
|
699
|
+
sinceSeconds: 900,
|
|
700
|
+
tail: 1e3
|
|
701
|
+
};
|
|
702
|
+
/** Read `--since`, refusing anything that is not a duration. Undefined when it was not given. */
|
|
703
|
+
function sinceFromFlag(sinceArg) {
|
|
704
|
+
if (sinceArg === void 0) return void 0;
|
|
705
|
+
const seconds = parseSince(sinceArg);
|
|
706
|
+
if (seconds === null) fail(`--since must be a duration like 15m, 2h or 90s; received "${sinceArg}".`);
|
|
707
|
+
return seconds;
|
|
708
|
+
}
|
|
709
|
+
function windowLabel(sinceSeconds) {
|
|
710
|
+
return sinceSeconds === null ? "since each pod started" : `last ${formatDuration(sinceSeconds)}`;
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Whether a boot read reached each pod's start, which is where its startup
|
|
714
|
+
* lines are. A pod whose read was cut has not been looked at there, so finding
|
|
715
|
+
* no startup lines in it means nothing — and a line from later in its life
|
|
716
|
+
* that happens to mention `storage` is not its startup.
|
|
717
|
+
*
|
|
718
|
+
* Under `--since` a pod is never counted as reached: a complete read of the
|
|
719
|
+
* window starts at the pod's first line only if the pod started inside it, and
|
|
720
|
+
* nothing in the answer says whether it did.
|
|
721
|
+
*/
|
|
722
|
+
function bootReach(pods, sinceSeconds) {
|
|
723
|
+
const unreached = pods.filter((p) => p.state === "ok" && (!p.complete || sinceSeconds !== null)).map((p) => p.pod);
|
|
724
|
+
return {
|
|
725
|
+
reachedStart: unreached.length === 0,
|
|
726
|
+
unreached
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
async function logView(rawArgs, view) {
|
|
730
|
+
const { flags: parsed } = parseCloudArgs({
|
|
731
|
+
spec: LOG_VIEW_FLAGS,
|
|
732
|
+
rawArgs,
|
|
733
|
+
commandWords: 3,
|
|
734
|
+
command: "cloud debug",
|
|
735
|
+
maxPositionals: 0
|
|
736
|
+
});
|
|
737
|
+
const sinceSeconds = sinceFromFlag(parsed["--since"]) ?? view.defaultSinceSeconds;
|
|
738
|
+
const tail = tailFromFlag(parsed["--tail"], view.defaultTail);
|
|
739
|
+
const { client } = await requireClient(rawArgs);
|
|
740
|
+
const projectId = await requireProject(rawArgs, client);
|
|
741
|
+
let res;
|
|
742
|
+
try {
|
|
743
|
+
res = await fetchRuntimeLogs(client, projectId, {
|
|
744
|
+
sinceSeconds: sinceSeconds ?? void 0,
|
|
745
|
+
tailLines: tail.applied,
|
|
746
|
+
previous: Boolean(parsed["--previous"])
|
|
747
|
+
});
|
|
748
|
+
} catch (e) {
|
|
749
|
+
reportError(e, "Failed to fetch runtime logs");
|
|
750
|
+
}
|
|
751
|
+
const parsedLines = (res.logs ?? "").split("\n").filter((l) => l !== "").map(parseLogLine);
|
|
752
|
+
const kept = view.filter ? parsedLines.filter((l) => view.filter(l.text)) : parsedLines;
|
|
753
|
+
const shown = kept.slice(-view.limit);
|
|
754
|
+
const coverage = assessCoverage({
|
|
755
|
+
res,
|
|
756
|
+
lines: parsedLines,
|
|
757
|
+
sinceSeconds,
|
|
758
|
+
tail,
|
|
759
|
+
now: Date.now()
|
|
760
|
+
});
|
|
761
|
+
const reach = view.needsStart ? bootReach(coverage.pods, sinceSeconds) : null;
|
|
762
|
+
emit(() => {
|
|
763
|
+
console.log("");
|
|
764
|
+
console.log(chalk.bold(` ${view.title} — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${windowLabel(sinceSeconds)}`));
|
|
765
|
+
console.log("");
|
|
766
|
+
printPodStates(res);
|
|
767
|
+
if (shown.length === 0) {
|
|
768
|
+
console.log(chalk.gray(" (nothing matched in what was read)"));
|
|
769
|
+
console.log("");
|
|
770
|
+
} else {
|
|
771
|
+
for (const l of shown) console.log(` ${l.pod ? chalk.gray(`[${l.pod}] `) : ""}${l.text}`);
|
|
772
|
+
console.log("");
|
|
773
|
+
if (kept.length > shown.length) {
|
|
774
|
+
console.log(chalk.gray(` (showing the last ${shown.length} of ${kept.length} matching lines)`));
|
|
775
|
+
console.log("");
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
printCoverage(coverage, tail);
|
|
779
|
+
if (reach && !reach.reachedStart) {
|
|
780
|
+
const which = reach.unreached.join(", ");
|
|
781
|
+
console.log(chalk.yellow(sinceSeconds === null ? ` ! The start of ${which} was not read, so its startup lines are not among the lines above.` : ` ! The start of ${which} may not have been read: --since limits the read to a recent window. Drop it to read each pod from its start.`));
|
|
782
|
+
console.log("");
|
|
783
|
+
}
|
|
784
|
+
}, {
|
|
785
|
+
sinceSeconds,
|
|
786
|
+
tail: {
|
|
787
|
+
requested: tail.requested,
|
|
788
|
+
applied: tail.applied,
|
|
789
|
+
serverMax: SERVER_MAX_TAIL_LINES,
|
|
790
|
+
note: tail.note
|
|
791
|
+
},
|
|
792
|
+
window: {
|
|
793
|
+
requestedFrom: coverage.requestedFrom,
|
|
794
|
+
firstTimestamp: coverage.firstTimestamp,
|
|
795
|
+
lastTimestamp: coverage.lastTimestamp
|
|
796
|
+
},
|
|
797
|
+
state: res.state ?? null,
|
|
798
|
+
pods: coverage.pods,
|
|
799
|
+
truncated: coverage.truncated,
|
|
800
|
+
truncatedReasons: coverage.truncatedReasons,
|
|
801
|
+
...reach ? {
|
|
802
|
+
reachedStart: reach.reachedStart,
|
|
803
|
+
unreachedPods: reach.unreached
|
|
804
|
+
} : {},
|
|
805
|
+
matched: kept.length,
|
|
806
|
+
lines: shown
|
|
807
|
+
});
|
|
808
|
+
}
|
|
809
|
+
async function requestsCommand(rawArgs) {
|
|
810
|
+
const { flags: parsed } = parseCloudArgs({
|
|
811
|
+
spec: REQUESTS_FLAGS,
|
|
812
|
+
rawArgs,
|
|
813
|
+
commandWords: 3,
|
|
814
|
+
command: "cloud debug",
|
|
815
|
+
maxPositionals: 0
|
|
816
|
+
});
|
|
817
|
+
const sinceSeconds = sinceFromFlag(parsed["--since"]) ?? REQUESTS_DEFAULTS.sinceSeconds;
|
|
818
|
+
const tail = tailFromFlag(parsed["--tail"], REQUESTS_DEFAULTS.tail);
|
|
819
|
+
const { client } = await requireClient(rawArgs);
|
|
820
|
+
const projectId = await requireProject(rawArgs, client);
|
|
821
|
+
let res;
|
|
822
|
+
try {
|
|
823
|
+
res = await fetchRuntimeLogs(client, projectId, {
|
|
824
|
+
sinceSeconds,
|
|
825
|
+
tailLines: tail.applied
|
|
826
|
+
});
|
|
827
|
+
} catch (e) {
|
|
828
|
+
reportError(e, "Failed to fetch runtime logs");
|
|
829
|
+
}
|
|
830
|
+
const parsedLines = (res.logs ?? "").split("\n").filter((l) => l !== "").map(parseLogLine);
|
|
831
|
+
const shown = parsedLines.map((l) => parseRequestLine(l.text)).filter((e) => e !== null).slice(-40);
|
|
832
|
+
const coverage = assessCoverage({
|
|
833
|
+
res,
|
|
834
|
+
lines: parsedLines,
|
|
835
|
+
sinceSeconds,
|
|
836
|
+
tail,
|
|
837
|
+
now: Date.now()
|
|
838
|
+
});
|
|
839
|
+
emit(() => {
|
|
840
|
+
console.log("");
|
|
841
|
+
console.log(chalk.bold(` 🌐 Requests — ${displayProjectRef(rawArgs)}`) + chalk.gray(` ${windowLabel(sinceSeconds)}`));
|
|
842
|
+
console.log("");
|
|
843
|
+
printPodStates(res);
|
|
844
|
+
if (shown.length === 0) {
|
|
845
|
+
console.log(chalk.gray(" No structured request lines in what was read."));
|
|
846
|
+
console.log(chalk.gray(" (this view needs the server's request logging; try `debug logs`)"));
|
|
847
|
+
console.log("");
|
|
848
|
+
printCoverage(coverage, tail);
|
|
849
|
+
return;
|
|
850
|
+
}
|
|
851
|
+
for (const e of shown) {
|
|
852
|
+
const status = e.status ?? 0;
|
|
853
|
+
const color = status >= 500 ? chalk.red : status >= 400 ? chalk.yellow : chalk.green;
|
|
854
|
+
console.log(` ${color(String(e.status ?? "---").padStart(3))} ${e.method.padEnd(6)} ${e.path.slice(0, 70).padEnd(70)} ${chalk.gray(e.latencyMs === null ? "" : `${e.latencyMs}ms`)}`);
|
|
855
|
+
}
|
|
856
|
+
console.log("");
|
|
857
|
+
printCoverage(coverage, tail);
|
|
858
|
+
}, {
|
|
859
|
+
sinceSeconds,
|
|
860
|
+
tail: {
|
|
861
|
+
requested: tail.requested,
|
|
862
|
+
applied: tail.applied,
|
|
863
|
+
serverMax: SERVER_MAX_TAIL_LINES,
|
|
864
|
+
note: tail.note
|
|
865
|
+
},
|
|
866
|
+
window: {
|
|
867
|
+
requestedFrom: coverage.requestedFrom,
|
|
868
|
+
firstTimestamp: coverage.firstTimestamp,
|
|
869
|
+
lastTimestamp: coverage.lastTimestamp
|
|
870
|
+
},
|
|
871
|
+
pods: coverage.pods,
|
|
872
|
+
truncated: coverage.truncated,
|
|
873
|
+
truncatedReasons: coverage.truncatedReasons,
|
|
874
|
+
requests: shown
|
|
875
|
+
});
|
|
876
|
+
}
|
|
877
|
+
async function podCommand(rawArgs) {
|
|
878
|
+
parseCloudArgs({
|
|
879
|
+
spec: {},
|
|
880
|
+
rawArgs,
|
|
881
|
+
commandWords: 3,
|
|
882
|
+
command: "cloud debug",
|
|
883
|
+
maxPositionals: 0
|
|
884
|
+
});
|
|
885
|
+
const { client } = await requireClient(rawArgs);
|
|
886
|
+
const projectId = await requireProject(rawArgs, client);
|
|
887
|
+
let m;
|
|
888
|
+
try {
|
|
889
|
+
m = await client.functions.invoke("metrics", void 0, {
|
|
890
|
+
method: "GET",
|
|
891
|
+
path: projectId
|
|
892
|
+
});
|
|
893
|
+
} catch (e) {
|
|
894
|
+
reportError(e, "Failed to read workload placement");
|
|
895
|
+
}
|
|
896
|
+
const p = m.placement ?? {};
|
|
897
|
+
const replicas = p.replicas ?? {};
|
|
898
|
+
emit(() => {
|
|
899
|
+
console.log("");
|
|
900
|
+
console.log(chalk.bold(` ☸ Workload — ${displayProjectRef(rawArgs)}`));
|
|
901
|
+
console.log("");
|
|
902
|
+
keyValues([
|
|
903
|
+
["Status", m.status ? colorStatus(m.status === "running" ? "active" : m.status) : void 0],
|
|
904
|
+
["Replicas", replicas.desired === void 0 ? void 0 : `${replicas.available ?? 0} / ${replicas.desired} available`],
|
|
905
|
+
["Namespace", p.namespace],
|
|
906
|
+
["Cluster", p.cluster],
|
|
907
|
+
["Region", [p.provider, p.region].filter(Boolean).join(" · ") || void 0],
|
|
908
|
+
["Host", p.host],
|
|
909
|
+
["Image", p.image],
|
|
910
|
+
["CPU", m.cpu ?? void 0],
|
|
911
|
+
["Memory", m.memory ?? void 0]
|
|
912
|
+
]);
|
|
913
|
+
console.log("");
|
|
914
|
+
if ((replicas.available ?? 0) === 0 && (replicas.desired ?? 0) > 0) {
|
|
915
|
+
console.log(chalk.yellow(" No replica is available — the pod is not passing its readiness check."));
|
|
916
|
+
console.log(chalk.gray(" See why with: ") + chalk.bold("rebase cloud debug logs --previous"));
|
|
917
|
+
console.log("");
|
|
918
|
+
}
|
|
919
|
+
}, {
|
|
920
|
+
status: m.status ?? null,
|
|
921
|
+
placement: p
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
async function dbDebugCommand(rawArgs) {
|
|
925
|
+
parseCloudArgs({
|
|
926
|
+
spec: {},
|
|
927
|
+
rawArgs,
|
|
928
|
+
commandWords: 3,
|
|
929
|
+
command: "cloud debug",
|
|
930
|
+
maxPositionals: 0
|
|
931
|
+
});
|
|
932
|
+
const { client } = await requireClient(rawArgs);
|
|
933
|
+
const projectId = await requireProject(rawArgs, client);
|
|
934
|
+
let info;
|
|
935
|
+
try {
|
|
936
|
+
info = await client.functions.invoke("db-info", void 0, {
|
|
937
|
+
method: "GET",
|
|
938
|
+
path: projectId
|
|
939
|
+
});
|
|
940
|
+
} catch (e) {
|
|
941
|
+
reportError(e, "Failed to read database connection info");
|
|
942
|
+
}
|
|
943
|
+
const access = info.directAccess;
|
|
944
|
+
const connectCmd = access ? "rebase cloud db connect" : null;
|
|
945
|
+
const psqlCmd = access && info.username && info.database ? `psql -h 127.0.0.1 -p 5432 -U ${info.username} -d ${info.database}` : null;
|
|
946
|
+
const kubectlCmd = access?.kubectl ? `kubectl port-forward -n ${access.kubectl.namespace} svc/${access.kubectl.service} ${access.kubectl.localPort}:${access.kubectl.remotePort}` : null;
|
|
947
|
+
emit(() => {
|
|
948
|
+
console.log("");
|
|
949
|
+
console.log(chalk.bold(` 🐘 Database — ${displayProjectRef(rawArgs)}`));
|
|
950
|
+
console.log("");
|
|
951
|
+
if (info.unavailableReason) {
|
|
952
|
+
console.log(chalk.yellow(` ${info.unavailableReason}`));
|
|
953
|
+
console.log("");
|
|
954
|
+
return;
|
|
955
|
+
}
|
|
956
|
+
keyValues([
|
|
957
|
+
["Type", info.type],
|
|
958
|
+
["Host", info.host],
|
|
959
|
+
["Port", info.port],
|
|
960
|
+
["Database", info.database],
|
|
961
|
+
["Username", info.username],
|
|
962
|
+
["Password", info.passwordAvailable ? chalk.gray("stored — not shown here") : chalk.yellow("none stored")]
|
|
963
|
+
]);
|
|
964
|
+
console.log("");
|
|
965
|
+
if (connectCmd) {
|
|
966
|
+
console.log(chalk.gray(" That host is inside the platform's cluster and does not resolve here."));
|
|
967
|
+
console.log(chalk.gray(" To reach the database from this machine:"));
|
|
968
|
+
console.log("");
|
|
969
|
+
console.log(` ${connectCmd}`);
|
|
970
|
+
if (psqlCmd) console.log(` ${psqlCmd}`);
|
|
971
|
+
console.log("");
|
|
972
|
+
if (kubectlCmd) {
|
|
973
|
+
console.log(chalk.gray(" Or, on your own cluster:"));
|
|
974
|
+
console.log(` ${kubectlCmd}`);
|
|
975
|
+
console.log("");
|
|
976
|
+
}
|
|
977
|
+
if (info.passwordAvailable) {
|
|
978
|
+
console.log(chalk.gray(" Get the password with: ") + chalk.bold("rebase cloud db info --reveal"));
|
|
979
|
+
console.log("");
|
|
980
|
+
}
|
|
981
|
+
}
|
|
982
|
+
}, {
|
|
983
|
+
type: info.type ?? null,
|
|
984
|
+
host: info.host ?? null,
|
|
985
|
+
port: info.port ?? null,
|
|
986
|
+
database: info.database ?? null,
|
|
987
|
+
username: info.username ?? null,
|
|
988
|
+
passwordAvailable: Boolean(info.passwordAvailable),
|
|
989
|
+
connectCommand: connectCmd,
|
|
990
|
+
kubectlCommand: kubectlCmd,
|
|
991
|
+
psqlCommand: psqlCmd
|
|
992
|
+
});
|
|
993
|
+
}
|
|
994
|
+
/**
|
|
995
|
+
* Everything the switch below dispatches, for the did-you-mean. `workload` is
|
|
996
|
+
* the older spelling of `pod` and stays out of it: suggesting the name we no
|
|
997
|
+
* longer print in the help would teach the wrong one.
|
|
998
|
+
*/
|
|
999
|
+
var DEBUG_SUBCOMMANDS = [
|
|
1000
|
+
"health",
|
|
1001
|
+
"logs",
|
|
1002
|
+
"errors",
|
|
1003
|
+
"boot",
|
|
1004
|
+
"requests",
|
|
1005
|
+
"pod",
|
|
1006
|
+
"db"
|
|
1007
|
+
];
|
|
1008
|
+
async function debugCommand(action, rawArgs) {
|
|
1009
|
+
switch (action) {
|
|
1010
|
+
case void 0:
|
|
1011
|
+
case "health":
|
|
1012
|
+
await healthCommand(rawArgs);
|
|
1013
|
+
break;
|
|
1014
|
+
case "logs":
|
|
1015
|
+
case "errors":
|
|
1016
|
+
case "boot":
|
|
1017
|
+
await logView(rawArgs, LOG_VIEWS[action]);
|
|
1018
|
+
break;
|
|
1019
|
+
case "requests":
|
|
1020
|
+
await requestsCommand(rawArgs);
|
|
1021
|
+
break;
|
|
1022
|
+
case "pod":
|
|
1023
|
+
case "workload":
|
|
1024
|
+
await podCommand(rawArgs);
|
|
1025
|
+
break;
|
|
1026
|
+
case "db":
|
|
1027
|
+
await dbDebugCommand(rawArgs);
|
|
1028
|
+
break;
|
|
1029
|
+
case "help":
|
|
1030
|
+
case "--help":
|
|
1031
|
+
printDebugHelp();
|
|
1032
|
+
break;
|
|
1033
|
+
default: fail(unknownCommandMessage(action, DEBUG_SUBCOMMANDS, "cloud debug"), void 0, "unknown_command");
|
|
1034
|
+
}
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* The log flags as one action's help lists them, with THAT action's defaults.
|
|
1038
|
+
* They were one group-wide list saying "Default: 500", which was true of two of
|
|
1039
|
+
* the four actions, and offered `--previous` to `requests`, which rejects it.
|
|
1040
|
+
*/
|
|
1041
|
+
function logFlagHelp(defaults, previous) {
|
|
1042
|
+
const flags = [["--since <dur>", defaults.sinceSeconds === null ? "Only lines this recent: 90s, 15m, 2h, 1d. Default: from each pod's start" : `Lookback window: 90s, 15m, 2h, 1d. Default: ${formatDuration(defaults.sinceSeconds)}`], ["--tail <n>", `Newest lines to read per pod, at most ${SERVER_MAX_TAIL_LINES}. Default: ${defaults.tail}`]];
|
|
1043
|
+
if (previous) flags.push(["--previous", "Read the CRASHED container instance, where the reason lives"]);
|
|
1044
|
+
return flags;
|
|
1045
|
+
}
|
|
1046
|
+
function logViewFlagHelp(view) {
|
|
1047
|
+
return logFlagHelp({
|
|
1048
|
+
sinceSeconds: view.defaultSinceSeconds,
|
|
1049
|
+
tail: view.defaultTail
|
|
1050
|
+
}, true);
|
|
1051
|
+
}
|
|
1052
|
+
function printDebugHelp() {
|
|
1053
|
+
printGroupHelp({
|
|
1054
|
+
command: "cloud debug",
|
|
1055
|
+
title: "Find out why a deployed project is misbehaving",
|
|
1056
|
+
actions: [
|
|
1057
|
+
{
|
|
1058
|
+
action: "health",
|
|
1059
|
+
section: "End-to-end",
|
|
1060
|
+
description: "Probe the live URL and explain every status code (the default)",
|
|
1061
|
+
flags: [
|
|
1062
|
+
["--host <hostname>", "Probe this address instead of the project's own"],
|
|
1063
|
+
["--table <name>", "Table for the unauth-read probe. Default: users"],
|
|
1064
|
+
["--collection <name>", "Deprecated spelling of --table. Still works, and warns"],
|
|
1065
|
+
["--function <name>", "Also assert this function loaded, against the listing"]
|
|
1066
|
+
]
|
|
1067
|
+
},
|
|
1068
|
+
{
|
|
1069
|
+
action: "logs",
|
|
1070
|
+
section: "Runtime",
|
|
1071
|
+
description: "Recent application logs",
|
|
1072
|
+
flags: logViewFlagHelp(LOG_VIEWS.logs)
|
|
1073
|
+
},
|
|
1074
|
+
{
|
|
1075
|
+
action: "errors",
|
|
1076
|
+
section: "Runtime",
|
|
1077
|
+
description: "Error and warning lines only",
|
|
1078
|
+
flags: logViewFlagHelp(LOG_VIEWS.errors)
|
|
1079
|
+
},
|
|
1080
|
+
{
|
|
1081
|
+
action: "requests",
|
|
1082
|
+
section: "Runtime",
|
|
1083
|
+
description: "HTTP requests the server logged: status, path, latency",
|
|
1084
|
+
flags: logFlagHelp(REQUESTS_DEFAULTS, false)
|
|
1085
|
+
},
|
|
1086
|
+
{
|
|
1087
|
+
action: "boot",
|
|
1088
|
+
section: "Runtime",
|
|
1089
|
+
description: "What the server decided at startup: storage, functions, auth",
|
|
1090
|
+
flags: logViewFlagHelp(LOG_VIEWS.boot)
|
|
1091
|
+
},
|
|
1092
|
+
{
|
|
1093
|
+
action: "pod",
|
|
1094
|
+
section: "Runtime",
|
|
1095
|
+
description: "Replicas, image, namespace, cluster placement"
|
|
1096
|
+
},
|
|
1097
|
+
{
|
|
1098
|
+
action: "db",
|
|
1099
|
+
section: "Data",
|
|
1100
|
+
description: "Connection shape and the port-forward recipe. Never the password"
|
|
1101
|
+
}
|
|
1102
|
+
],
|
|
1103
|
+
notes: [
|
|
1104
|
+
"Everything here is read-only. `health` exits non-zero when a check fails, so it works in a",
|
|
1105
|
+
"deploy script. To restart a workload, use `rebase cloud restart`.",
|
|
1106
|
+
"The log views end with the window asked for, the window returned, and anything that cut",
|
|
1107
|
+
`between them. The control plane returns at most ${SERVER_MAX_TAIL_LINES} lines per pod.`
|
|
1108
|
+
]
|
|
1109
|
+
});
|
|
1110
|
+
}
|
|
1111
|
+
//#endregion
|
|
1112
|
+
export { parseLogLine as a, resolveOrigin as c, isErrorLine as i, resolveTail as l, debugCommand as n, parseSince as o, debug_exports as r, printDebugHelp as s, SERVER_MAX_TAIL_LINES as t };
|
|
1113
|
+
|
|
1114
|
+
//# sourceMappingURL=debug-nNbbxAeo.js.map
|