@warlock.js/devtools 5.55.0 → 5.56.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/CHANGELOG.md +29 -0
- package/README.md +26 -13
- package/cjs/ai-source-DTpxumMA.cjs +381 -0
- package/cjs/ai-source-DTpxumMA.cjs.map +1 -0
- package/cjs/auth-DzU0gHDG.cjs +1655 -0
- package/cjs/auth-DzU0gHDG.cjs.map +1 -0
- package/cjs/boot-BQi0Etor.cjs +138 -0
- package/cjs/boot-BQi0Etor.cjs.map +1 -0
- package/cjs/capture-CqIiaznN.cjs +1342 -0
- package/cjs/capture-CqIiaznN.cjs.map +1 -0
- package/cjs/cascade-store-pHjKeSFm.cjs +863 -0
- package/cjs/cascade-store-pHjKeSFm.cjs.map +1 -0
- package/cjs/collector-CJbQbzzK.cjs +271 -0
- package/cjs/collector-CJbQbzzK.cjs.map +1 -0
- package/cjs/contracts-CVmplkNb.cjs +112 -0
- package/cjs/contracts-CVmplkNb.cjs.map +1 -0
- package/cjs/current-request-id-BoJJb3y7.cjs +37 -0
- package/cjs/current-request-id-BoJJb3y7.cjs.map +1 -0
- package/cjs/errors-CyZp5yS-.cjs +177 -0
- package/cjs/errors-CyZp5yS-.cjs.map +1 -0
- package/cjs/histogram-BaI-PnCv.cjs +102 -0
- package/cjs/histogram-BaI-PnCv.cjs.map +1 -0
- package/cjs/http-CabcUwBx.cjs +870 -0
- package/cjs/http-CabcUwBx.cjs.map +1 -0
- package/cjs/index.cjs +1 -1
- package/cjs/insights-BKtqxdnP.cjs +811 -0
- package/cjs/insights-BKtqxdnP.cjs.map +1 -0
- package/cjs/ip-DbNhPOzi.cjs +153 -0
- package/cjs/ip-DbNhPOzi.cjs.map +1 -0
- package/cjs/migrations-w7GMsrQw.cjs +297 -0
- package/cjs/migrations-w7GMsrQw.cjs.map +1 -0
- package/cjs/openapi-CC7OAUc6.cjs +52 -0
- package/cjs/openapi-CC7OAUc6.cjs.map +1 -0
- package/cjs/options-CWqFC5__.cjs +181 -0
- package/cjs/options-CWqFC5__.cjs.map +1 -0
- package/cjs/panels-B0dAfGbJ.cjs +298 -0
- package/cjs/panels-B0dAfGbJ.cjs.map +1 -0
- package/cjs/process-panel-DEOnLxoT.cjs +48 -0
- package/cjs/process-panel-DEOnLxoT.cjs.map +1 -0
- package/cjs/production/index.cjs +238 -0
- package/cjs/production/index.cjs.map +1 -0
- package/cjs/rolldown-runtime-Zuuoy_Rh.cjs +52 -0
- package/cjs/server-B6xdeKS8.cjs +184 -0
- package/cjs/server-B6xdeKS8.cjs.map +1 -0
- package/cjs/{src-Xwm3Eel9.cjs → src-Ce-3Lniv.cjs} +163 -295
- package/cjs/src-Ce-3Lniv.cjs.map +1 -0
- package/cjs/store-aq207T8v.cjs +9 -0
- package/cjs/stream-route-BGJa-zQu.cjs +875 -0
- package/cjs/stream-route-BGJa-zQu.cjs.map +1 -0
- package/esm/devtools-connector.d.mts +16 -13
- package/esm/devtools-connector.d.mts.map +1 -1
- package/esm/devtools-connector.mjs +127 -18
- package/esm/devtools-connector.mjs.map +1 -1
- package/esm/index.d.mts +3 -2
- package/esm/options.mjs +2 -1
- package/esm/options.mjs.map +1 -1
- package/esm/panels.mjs +50 -5
- package/esm/panels.mjs.map +1 -1
- package/esm/production/auth/common-passwords.mjs +303 -0
- package/esm/production/auth/common-passwords.mjs.map +1 -0
- package/esm/production/auth/default-crypto.mjs +19 -0
- package/esm/production/auth/default-crypto.mjs.map +1 -0
- package/esm/production/auth/helpers.mjs +77 -0
- package/esm/production/auth/helpers.mjs.map +1 -0
- package/esm/production/auth/index.mjs +6 -0
- package/esm/production/auth/passkeys.mjs +96 -0
- package/esm/production/auth/passkeys.mjs.map +1 -0
- package/esm/production/auth/service.mjs +1166 -0
- package/esm/production/auth/service.mjs.map +1 -0
- package/esm/production/boot.mjs +138 -0
- package/esm/production/boot.mjs.map +1 -0
- package/esm/production/capture/dev-stats.mjs +83 -0
- package/esm/production/capture/dev-stats.mjs.map +1 -0
- package/esm/production/capture/engine.mjs +442 -0
- package/esm/production/capture/engine.mjs.map +1 -0
- package/esm/production/capture/explain.mjs +271 -0
- package/esm/production/capture/explain.mjs.map +1 -0
- package/esm/production/capture/filter.mjs +24 -0
- package/esm/production/capture/filter.mjs.map +1 -0
- package/esm/production/capture/index.mjs +7 -0
- package/esm/production/capture/production-capture.mjs +134 -0
- package/esm/production/capture/production-capture.mjs.map +1 -0
- package/esm/production/capture/redact.mjs +109 -0
- package/esm/production/capture/redact.mjs.map +1 -0
- package/esm/production/capture/stats-stores.mjs +300 -0
- package/esm/production/capture/stats-stores.mjs.map +1 -0
- package/esm/production/cli/actions.mjs +151 -0
- package/esm/production/cli/actions.mjs.map +1 -0
- package/esm/production/cli/index.d.mts +17 -0
- package/esm/production/cli/index.d.mts.map +1 -0
- package/esm/production/cli/index.mjs +86 -0
- package/esm/production/cli/index.mjs.map +1 -0
- package/esm/production/contracts.d.mts +592 -0
- package/esm/production/contracts.d.mts.map +1 -0
- package/esm/production/contracts.mjs +95 -0
- package/esm/production/contracts.mjs.map +1 -0
- package/esm/production/errors.d.mts +31 -0
- package/esm/production/errors.d.mts.map +1 -0
- package/esm/production/errors.mjs +142 -0
- package/esm/production/errors.mjs.map +1 -0
- package/esm/production/http/access.mjs +124 -0
- package/esm/production/http/access.mjs.map +1 -0
- package/esm/production/http/auth-routes.mjs +280 -0
- package/esm/production/http/auth-routes.mjs.map +1 -0
- package/esm/production/http/client.mjs +57 -0
- package/esm/production/http/client.mjs.map +1 -0
- package/esm/production/http/constants.mjs +11 -0
- package/esm/production/http/constants.mjs.map +1 -0
- package/esm/production/http/context.mjs +14 -0
- package/esm/production/http/context.mjs.map +1 -0
- package/esm/production/http/cookie.mjs +39 -0
- package/esm/production/http/cookie.mjs.map +1 -0
- package/esm/production/http/headers.mjs +25 -0
- package/esm/production/http/headers.mjs.map +1 -0
- package/esm/production/http/index.mjs +10 -0
- package/esm/production/http/ip.mjs +130 -0
- package/esm/production/http/ip.mjs.map +1 -0
- package/esm/production/http/mount.mjs +300 -0
- package/esm/production/http/mount.mjs.map +1 -0
- package/esm/production/http/state.mjs +54 -0
- package/esm/production/http/state.mjs.map +1 -0
- package/esm/production/index.d.mts +6 -0
- package/esm/production/index.mjs +5 -0
- package/esm/production/insights/cap-report.mjs +67 -0
- package/esm/production/insights/cap-report.mjs.map +1 -0
- package/esm/production/insights/health.mjs +88 -0
- package/esm/production/insights/health.mjs.map +1 -0
- package/esm/production/insights/index.mjs +10 -0
- package/esm/production/insights/insights.mjs +167 -0
- package/esm/production/insights/insights.mjs.map +1 -0
- package/esm/production/insights/instance.mjs +24 -0
- package/esm/production/insights/instance.mjs.map +1 -0
- package/esm/production/insights/jobs.mjs +100 -0
- package/esm/production/insights/jobs.mjs.map +1 -0
- package/esm/production/insights/reporter.mjs +59 -0
- package/esm/production/insights/reporter.mjs.map +1 -0
- package/esm/production/insights/resources.mjs +139 -0
- package/esm/production/insights/resources.mjs.map +1 -0
- package/esm/production/insights/writer.mjs +72 -0
- package/esm/production/insights/writer.mjs.map +1 -0
- package/esm/production/openapi.mjs +52 -0
- package/esm/production/openapi.mjs.map +1 -0
- package/esm/production/options.d.mts +60 -0
- package/esm/production/options.d.mts.map +1 -0
- package/esm/production/options.mjs +170 -0
- package/esm/production/options.mjs.map +1 -0
- package/esm/production/stats/histogram.mjs +67 -0
- package/esm/production/stats/histogram.mjs.map +1 -0
- package/esm/production/stats/merge.mjs +106 -0
- package/esm/production/stats/merge.mjs.map +1 -0
- package/esm/production/store/cascade-store.mjs +322 -0
- package/esm/production/store/cascade-store.mjs.map +1 -0
- package/esm/production/store/index.mjs +5 -0
- package/esm/production/store/mapping.mjs +258 -0
- package/esm/production/store/mapping.mjs.map +1 -0
- package/esm/production/store/memory-store.mjs +291 -0
- package/esm/production/store/memory-store.mjs.map +1 -0
- package/esm/production/store/migrations.d.mts +11 -0
- package/esm/production/store/migrations.d.mts.map +1 -0
- package/esm/production/store/migrations.mjs +29 -0
- package/esm/production/store/migrations.mjs.map +1 -0
- package/esm/production/store/models/account.migration.mjs +34 -0
- package/esm/production/store/models/account.migration.mjs.map +1 -0
- package/esm/production/store/models/account.model.mjs +13 -0
- package/esm/production/store/models/account.model.mjs.map +1 -0
- package/esm/production/store/models/audit.migration.mjs +30 -0
- package/esm/production/store/models/audit.migration.mjs.map +1 -0
- package/esm/production/store/models/audit.model.mjs +13 -0
- package/esm/production/store/models/audit.model.mjs.map +1 -0
- package/esm/production/store/models/base.mjs +27 -0
- package/esm/production/store/models/base.mjs.map +1 -0
- package/esm/production/store/models/index.mjs +17 -0
- package/esm/production/store/models/invite.migration.mjs +26 -0
- package/esm/production/store/models/invite.migration.mjs.map +1 -0
- package/esm/production/store/models/invite.model.mjs +13 -0
- package/esm/production/store/models/invite.model.mjs.map +1 -0
- package/esm/production/store/models/report.migration.mjs +20 -0
- package/esm/production/store/models/report.migration.mjs.map +1 -0
- package/esm/production/store/models/report.model.mjs +13 -0
- package/esm/production/store/models/report.model.mjs.map +1 -0
- package/esm/production/store/models/sample.migration.mjs +25 -0
- package/esm/production/store/models/sample.migration.mjs.map +1 -0
- package/esm/production/store/models/sample.model.mjs +13 -0
- package/esm/production/store/models/sample.model.mjs.map +1 -0
- package/esm/production/store/models/session.migration.mjs +31 -0
- package/esm/production/store/models/session.migration.mjs.map +1 -0
- package/esm/production/store/models/session.model.mjs +13 -0
- package/esm/production/store/models/session.model.mjs.map +1 -0
- package/esm/production/store/models/state.migration.mjs +26 -0
- package/esm/production/store/models/state.migration.mjs.map +1 -0
- package/esm/production/store/models/state.model.mjs +13 -0
- package/esm/production/store/models/state.model.mjs.map +1 -0
- package/esm/query-shape.mjs +14 -1
- package/esm/query-shape.mjs.map +1 -1
- package/esm/server/explain-route.mjs +26 -1
- package/esm/server/explain-route.mjs.map +1 -1
- package/esm/server/index.mjs +9 -4
- package/esm/server/index.mjs.map +1 -1
- package/esm/server/insights-routes.mjs +62 -0
- package/esm/server/insights-routes.mjs.map +1 -0
- package/esm/server/log-routes.mjs +32 -5
- package/esm/server/log-routes.mjs.map +1 -1
- package/esm/server/openapi-routes.mjs +3 -2
- package/esm/server/openapi-routes.mjs.map +1 -1
- package/esm/server/requests-routes.mjs +125 -0
- package/esm/server/requests-routes.mjs.map +1 -1
- package/esm/server/session-routes.mjs +42 -0
- package/esm/server/session-routes.mjs.map +1 -0
- package/esm/server/stream-route.mjs +81 -11
- package/esm/server/stream-route.mjs.map +1 -1
- package/esm/server/ui-assets.mjs +34 -25
- package/esm/server/ui-assets.mjs.map +1 -1
- package/esm/sources/log-source.mjs +14 -1
- package/esm/sources/log-source.mjs.map +1 -1
- package/esm/types.d.mts +202 -1
- package/esm/types.d.mts.map +1 -1
- package/esm/ui-root.mjs +9 -4
- package/esm/ui-root.mjs.map +1 -1
- package/llms-full.txt +159 -21
- package/llms.txt +2 -2
- package/package.json +32 -8
- package/skills/SKILL.md +159 -21
- package/ui/dashboard/assets/app.css +3 -0
- package/ui/dashboard/assets/app.js +50 -0
- package/ui/dashboard/build-info.json +21 -0
- package/ui/dashboard/index.html +15 -0
- package/cjs/ai-source-Dz_3tlZ5.cjs +0 -703
- package/cjs/ai-source-Dz_3tlZ5.cjs.map +0 -1
- package/cjs/server-B11ShQYE.cjs +0 -628
- package/cjs/server-B11ShQYE.cjs.map +0 -1
- package/cjs/src-Xwm3Eel9.cjs.map +0 -1
- package/ui/app.css +0 -376
- package/ui/app.js +0 -1158
- package/ui/index.html +0 -28
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/production/insights/cap-report.ts
|
|
2
|
+
const sizeOf = (report) => Buffer.byteLength(JSON.stringify(report), "utf8");
|
|
3
|
+
/** The lists to trim, in order, with how to cut each one to its first `keep` entries. */
|
|
4
|
+
const LISTS = [
|
|
5
|
+
{
|
|
6
|
+
length: (r) => r.logs.length,
|
|
7
|
+
cut: (r, keep) => ({
|
|
8
|
+
...r,
|
|
9
|
+
logs: r.logs.slice(0, keep)
|
|
10
|
+
})
|
|
11
|
+
},
|
|
12
|
+
{
|
|
13
|
+
length: (r) => r.errors.length,
|
|
14
|
+
cut: (r, keep) => ({
|
|
15
|
+
...r,
|
|
16
|
+
errors: r.errors.slice(0, keep)
|
|
17
|
+
})
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
length: (r) => r.routes.length,
|
|
21
|
+
cut: (r, keep) => ({
|
|
22
|
+
...r,
|
|
23
|
+
routes: r.routes.slice(0, keep)
|
|
24
|
+
})
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
length: (r) => r.queries.length,
|
|
28
|
+
cut: (r, keep) => ({
|
|
29
|
+
...r,
|
|
30
|
+
queries: r.queries.slice(0, keep)
|
|
31
|
+
})
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
length: (r) => r.resources.history.length,
|
|
35
|
+
cut: (r, keep) => ({
|
|
36
|
+
...r,
|
|
37
|
+
resources: {
|
|
38
|
+
...r.resources,
|
|
39
|
+
history: r.resources.history.slice(0, keep)
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
];
|
|
44
|
+
/**
|
|
45
|
+
* Trims a report's lists from the end until its JSON is at most `maxBytes`
|
|
46
|
+
* (default 256 KB): logs first, then errors, routes, queries and the
|
|
47
|
+
* resource history. A report that already fits is returned unchanged.
|
|
48
|
+
*/
|
|
49
|
+
function capReportSize(report, maxBytes = 262144) {
|
|
50
|
+
let current = report;
|
|
51
|
+
for (const list of LISTS) {
|
|
52
|
+
if (sizeOf(current) <= maxBytes) return current;
|
|
53
|
+
let low = 0;
|
|
54
|
+
let high = list.length(current);
|
|
55
|
+
while (low < high) {
|
|
56
|
+
const middle = Math.ceil((low + high) / 2);
|
|
57
|
+
if (sizeOf(list.cut(current, middle)) <= maxBytes) low = middle;
|
|
58
|
+
else high = middle - 1;
|
|
59
|
+
}
|
|
60
|
+
current = list.cut(current, low);
|
|
61
|
+
}
|
|
62
|
+
return current;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
//#endregion
|
|
66
|
+
export { capReportSize };
|
|
67
|
+
//# sourceMappingURL=cap-report.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cap-report.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/insights/cap-report.ts"],"sourcesContent":["import type { DevtoolsInstanceReport } from \"../contracts\";\n\ntype ListSetter = (report: DevtoolsInstanceReport, keep: number) => DevtoolsInstanceReport;\n\nconst sizeOf = (report: DevtoolsInstanceReport): number =>\n Buffer.byteLength(JSON.stringify(report), \"utf8\");\n\n/** The lists to trim, in order, with how to cut each one to its first `keep` entries. */\nconst LISTS: { length(report: DevtoolsInstanceReport): number; cut: ListSetter }[] = [\n { length: (r) => r.logs.length, cut: (r, keep) => ({ ...r, logs: r.logs.slice(0, keep) }) },\n { length: (r) => r.errors.length, cut: (r, keep) => ({ ...r, errors: r.errors.slice(0, keep) }) },\n { length: (r) => r.routes.length, cut: (r, keep) => ({ ...r, routes: r.routes.slice(0, keep) }) },\n {\n length: (r) => r.queries.length,\n cut: (r, keep) => ({ ...r, queries: r.queries.slice(0, keep) }),\n },\n {\n length: (r) => r.resources.history.length,\n cut: (r, keep) => ({\n ...r,\n resources: { ...r.resources, history: r.resources.history.slice(0, keep) },\n }),\n },\n];\n\n/**\n * Trims a report's lists from the end until its JSON is at most `maxBytes`\n * (default 256 KB): logs first, then errors, routes, queries and the\n * resource history. A report that already fits is returned unchanged.\n */\nexport function capReportSize(\n report: DevtoolsInstanceReport,\n maxBytes = 262_144,\n): DevtoolsInstanceReport {\n let current = report;\n\n for (const list of LISTS) {\n if (sizeOf(current) <= maxBytes) return current;\n\n // The largest number of entries to keep that fits (0 when none does).\n let low = 0;\n let high = list.length(current);\n\n while (low < high) {\n const middle = Math.ceil((low + high) / 2);\n\n if (sizeOf(list.cut(current, middle)) <= maxBytes) low = middle;\n else high = middle - 1;\n }\n\n current = list.cut(current, low);\n }\n\n return current;\n}\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|
1
|
+
//#region ../../packages/devtools/src/production/insights/health.ts
|
|
2
|
+
/** While the app boots, the first check is tried again this often. */
|
|
3
|
+
const BOOT_RETRY_MS = 1e3;
|
|
4
|
+
/** Core's readiness, imported on first use so devtools never loads core at import time. */
|
|
5
|
+
const coreReadiness = async () => {
|
|
6
|
+
const { health, Application } = await import("@warlock.js/core");
|
|
7
|
+
if (!Application.isBooted && !Application.isShuttingDown) return null;
|
|
8
|
+
return health.readiness();
|
|
9
|
+
};
|
|
10
|
+
/** Readiness checks every `intervalMs` (default 30000), 60 history entries. */
|
|
11
|
+
function createHealthHistory(options = {}) {
|
|
12
|
+
const intervalMs = options.intervalMs ?? 3e4;
|
|
13
|
+
const size = Math.max(1, options.size ?? 60);
|
|
14
|
+
const readiness = options.readiness ?? coreReadiness;
|
|
15
|
+
let status = "unknown";
|
|
16
|
+
let checkedAt = null;
|
|
17
|
+
let checks = {};
|
|
18
|
+
const history = [];
|
|
19
|
+
let timer;
|
|
20
|
+
let retry;
|
|
21
|
+
let running;
|
|
22
|
+
function report() {
|
|
23
|
+
return {
|
|
24
|
+
status,
|
|
25
|
+
checkedAt,
|
|
26
|
+
checks: { ...checks },
|
|
27
|
+
history: history.map((e) => ({
|
|
28
|
+
...e,
|
|
29
|
+
failed: [...e.failed]
|
|
30
|
+
}))
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
async function run() {
|
|
34
|
+
try {
|
|
35
|
+
const result = await readiness();
|
|
36
|
+
if (result === null) {
|
|
37
|
+
if (timer && checkedAt === null && retry === void 0) {
|
|
38
|
+
retry = setTimeout(() => {
|
|
39
|
+
retry = void 0;
|
|
40
|
+
check();
|
|
41
|
+
}, BOOT_RETRY_MS);
|
|
42
|
+
retry.unref();
|
|
43
|
+
}
|
|
44
|
+
return report();
|
|
45
|
+
}
|
|
46
|
+
const now = Date.now();
|
|
47
|
+
const failed = Object.entries(result.checks ?? {}).filter(([, passed]) => !passed).map(([name]) => name);
|
|
48
|
+
status = result.status;
|
|
49
|
+
checkedAt = now;
|
|
50
|
+
checks = { ...result.checks ?? {} };
|
|
51
|
+
history.push({
|
|
52
|
+
at: now,
|
|
53
|
+
status: result.status,
|
|
54
|
+
failed
|
|
55
|
+
});
|
|
56
|
+
if (history.length > size) history.splice(0, history.length - size);
|
|
57
|
+
} catch {
|
|
58
|
+
if (checkedAt === null) status = "unknown";
|
|
59
|
+
}
|
|
60
|
+
return report();
|
|
61
|
+
}
|
|
62
|
+
function check() {
|
|
63
|
+
running ??= run().finally(() => {
|
|
64
|
+
running = void 0;
|
|
65
|
+
});
|
|
66
|
+
return running;
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
start() {
|
|
70
|
+
if (timer) return;
|
|
71
|
+
check();
|
|
72
|
+
timer = setInterval(() => void check(), intervalMs);
|
|
73
|
+
timer.unref();
|
|
74
|
+
},
|
|
75
|
+
stop() {
|
|
76
|
+
if (timer) clearInterval(timer);
|
|
77
|
+
if (retry) clearTimeout(retry);
|
|
78
|
+
timer = void 0;
|
|
79
|
+
retry = void 0;
|
|
80
|
+
},
|
|
81
|
+
check,
|
|
82
|
+
report
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { createHealthHistory };
|
|
88
|
+
//# sourceMappingURL=health.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/insights/health.ts"],"sourcesContent":["import type { DevtoolsHealthReport } from \"../contracts\";\nimport type { DevtoolsHealthStatusReader } from \"./readiness\";\nimport type { DevtoolsHealthHistory } from \"./types\";\n\n/** While the app boots, the first check is tried again this often. */\nconst BOOT_RETRY_MS = 1000;\n\n/** Core's readiness, imported on first use so devtools never loads core at import time. */\nconst coreReadiness: DevtoolsHealthStatusReader = async () => {\n const { health, Application } = await import(\"@warlock.js/core\");\n\n // The monitor starts while the app boots, when readiness is `error` with no failed check.\n if (!Application.isBooted && !Application.isShuttingDown) return null;\n\n return health.readiness();\n};\n\n/** Readiness checks every `intervalMs` (default 30000), 60 history entries. */\nexport function createHealthHistory(\n options: { intervalMs?: number; size?: number; readiness?: DevtoolsHealthStatusReader } = {},\n): DevtoolsHealthHistory {\n const intervalMs = options.intervalMs ?? 30_000;\n const size = Math.max(1, options.size ?? 60);\n const readiness = options.readiness ?? coreReadiness;\n\n let status: DevtoolsHealthReport[\"status\"] = \"unknown\";\n let checkedAt: number | null = null;\n let checks: Record<string, boolean> = {};\n const history: DevtoolsHealthReport[\"history\"] = [];\n let timer: ReturnType<typeof setInterval> | undefined;\n let retry: ReturnType<typeof setTimeout> | undefined;\n let running: Promise<DevtoolsHealthReport> | undefined;\n\n function report(): DevtoolsHealthReport {\n return {\n status,\n checkedAt,\n checks: { ...checks },\n history: history.map((e) => ({ ...e, failed: [...e.failed] })),\n };\n }\n\n async function run(): Promise<DevtoolsHealthReport> {\n try {\n const result = await readiness();\n\n if (result === null) {\n // Still booting: nothing to record yet. Until the first answer, try again soon instead of a whole interval later.\n if (timer && checkedAt === null && retry === undefined) {\n retry = setTimeout(() => {\n retry = undefined;\n void check();\n }, BOOT_RETRY_MS);\n retry.unref();\n }\n\n return report();\n }\n\n const now = Date.now();\n const failed = Object.entries(result.checks ?? {})\n .filter(([, passed]) => !passed)\n .map(([name]) => name);\n\n status = result.status;\n checkedAt = now;\n checks = { ...(result.checks ?? {}) };\n history.push({ at: now, status: result.status, failed });\n\n if (history.length > size) history.splice(0, history.length - size);\n } catch {\n // Readiness could not be read (core not loaded yet): keep the last answer.\n if (checkedAt === null) status = \"unknown\";\n }\n\n return report();\n }\n\n function check(): Promise<DevtoolsHealthReport> {\n running ??= run().finally(() => {\n running = undefined;\n });\n\n return running;\n }\n\n return {\n start() {\n if (timer) return;\n\n void check();\n timer = setInterval(() => void check(), intervalMs);\n timer.unref();\n },\n\n stop() {\n if (timer) clearInterval(timer);\n if (retry) clearTimeout(retry);\n\n timer = undefined;\n retry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AAO;IAAQ;GAAO,CAAC;GAEvD,IAAI,QAAQ,SAAS,MAAM,QAAQ,OAAO,GAAG,QAAQ,SAAS,IAAI;EACpE,QAAQ;GAEN,IAAI,cAAc,MAAM,SAAS;EACnC;EAEA,OAAO,OAAO;CAChB;CAEA,SAAS,QAAuC;EAC9C,YAAY,IAAI,CAAC,CAAC,cAAc;GAC9B,UAAU;EACZ,CAAC;EAED,OAAO;CACT;CAEA,OAAO;EACL,QAAQ;GACN,IAAI,OAAO;GAEX,AAAK,MAAM;GACX,QAAQ,kBAAkB,KAAK,MAAM,GAAG,UAAU;GAClD,MAAM,MAAM;EACd;EAEA,OAAO;GACL,IAAI,OAAO,cAAc,KAAK;GAC9B,IAAI,OAAO,aAAa,KAAK;GAE7B,QAAQ;GACR,QAAQ;EACV;EAEA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { capReportSize } from "./cap-report.mjs";
|
|
2
|
+
import { createHealthHistory } from "./health.mjs";
|
|
3
|
+
import { createLocalInsights, createSharedInsights } from "./insights.mjs";
|
|
4
|
+
import { createInstanceInfo } from "./instance.mjs";
|
|
5
|
+
import { createJobsReader } from "./jobs.mjs";
|
|
6
|
+
import { createLocalReporter } from "./reporter.mjs";
|
|
7
|
+
import { createResourceMonitor } from "./resources.mjs";
|
|
8
|
+
import { startReportWriter } from "./writer.mjs";
|
|
9
|
+
|
|
10
|
+
export { capReportSize, createHealthHistory, createInstanceInfo, createJobsReader, createLocalInsights, createLocalReporter, createResourceMonitor, createSharedInsights, startReportWriter };
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { histogramMean, histogramQuantile } from "../stats/histogram.mjs";
|
|
2
|
+
import { mergeErrorGroups, mergeQueryShapeStats, mergeRouteStats } from "../stats/merge.mjs";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/devtools/src/production/insights/insights.ts
|
|
5
|
+
const DEFAULT_INSIGHT_LIMIT = 100;
|
|
6
|
+
const MAX_INSIGHT_LIMIT = 500;
|
|
7
|
+
/** Reports fresher than this are merged into the views. */
|
|
8
|
+
const FRESH_MS = 6e4;
|
|
9
|
+
/** The instances list reaches back this far. */
|
|
10
|
+
const INSTANCES_MS = 3e5;
|
|
11
|
+
function limitOf(query) {
|
|
12
|
+
const limit = query.limit ?? 100;
|
|
13
|
+
return Math.min(500, Math.max(1, Math.floor(limit)));
|
|
14
|
+
}
|
|
15
|
+
function matches(value, needle) {
|
|
16
|
+
return !needle || value.toLowerCase().includes(needle.toLowerCase());
|
|
17
|
+
}
|
|
18
|
+
function infoOf(report) {
|
|
19
|
+
return {
|
|
20
|
+
...report.instance,
|
|
21
|
+
seenAt: report.at
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function build(load, sampleRateOf) {
|
|
25
|
+
/** The fresh reports of the selected instance(s). */
|
|
26
|
+
async function select(query, windowMs = FRESH_MS) {
|
|
27
|
+
const reports = await load(windowMs);
|
|
28
|
+
return query.instance === "all" ? reports : reports.filter((report) => report.instance.id === query.instance);
|
|
29
|
+
}
|
|
30
|
+
const insights = {
|
|
31
|
+
async instances() {
|
|
32
|
+
const reports = await load(INSTANCES_MS);
|
|
33
|
+
const infos = reports.map(infoOf).sort((a, b) => b.seenAt - a.seenAt);
|
|
34
|
+
return {
|
|
35
|
+
current: current(reports),
|
|
36
|
+
instances: infos
|
|
37
|
+
};
|
|
38
|
+
},
|
|
39
|
+
async resources(query) {
|
|
40
|
+
return { instances: (await select(query)).map((report) => ({
|
|
41
|
+
instance: infoOf(report),
|
|
42
|
+
snapshot: report.resources.snapshot,
|
|
43
|
+
history: report.resources.history
|
|
44
|
+
})) };
|
|
45
|
+
},
|
|
46
|
+
async queryStats(query) {
|
|
47
|
+
const reports = await select(query);
|
|
48
|
+
const sort = query.sort ?? "total";
|
|
49
|
+
const rows = mergeQueryShapeStats(reports.map((report) => ({
|
|
50
|
+
instance: report.instance.id,
|
|
51
|
+
shapes: report.queries
|
|
52
|
+
}))).map((shape) => ({
|
|
53
|
+
...shape,
|
|
54
|
+
p50Ms: histogramQuantile(shape.histogram, .5),
|
|
55
|
+
p95Ms: histogramQuantile(shape.histogram, .95),
|
|
56
|
+
meanMs: histogramMean(shape.histogram)
|
|
57
|
+
}));
|
|
58
|
+
const key = {
|
|
59
|
+
total: (row) => row.histogram.sumMs,
|
|
60
|
+
p95: (row) => row.p95Ms,
|
|
61
|
+
count: (row) => row.count,
|
|
62
|
+
"n+1": (row) => row.nPlusOne.requests * 1e6 + row.nPlusOne.maxPerRequest
|
|
63
|
+
};
|
|
64
|
+
const by = key[sort] ?? key.total;
|
|
65
|
+
return {
|
|
66
|
+
shapes: rows.sort((a, b) => by(b) - by(a)).slice(0, limitOf(query)),
|
|
67
|
+
sampleRate: sampleRateOf(reports),
|
|
68
|
+
instanceCount: reports.length,
|
|
69
|
+
evicted: reports.reduce((sum, report) => sum + report.capture.evictedShapes, 0)
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
async routeStats(query) {
|
|
73
|
+
const reports = await select(query);
|
|
74
|
+
const sort = query.sort ?? "total";
|
|
75
|
+
const rows = mergeRouteStats(reports.map((report) => ({
|
|
76
|
+
instance: report.instance.id,
|
|
77
|
+
routes: report.routes
|
|
78
|
+
}))).map((route) => ({
|
|
79
|
+
...route,
|
|
80
|
+
p50Ms: histogramQuantile(route.histogram, .5),
|
|
81
|
+
p95Ms: histogramQuantile(route.histogram, .95),
|
|
82
|
+
meanMs: histogramMean(route.histogram)
|
|
83
|
+
}));
|
|
84
|
+
const key = {
|
|
85
|
+
total: (row) => row.histogram.sumMs,
|
|
86
|
+
p95: (row) => row.p95Ms,
|
|
87
|
+
count: (row) => row.count,
|
|
88
|
+
errors: (row) => row.errors
|
|
89
|
+
};
|
|
90
|
+
const by = key[sort] ?? key.total;
|
|
91
|
+
return {
|
|
92
|
+
routes: rows.sort((a, b) => by(b) - by(a)).slice(0, limitOf(query)),
|
|
93
|
+
sampleRate: sampleRateOf(reports),
|
|
94
|
+
instanceCount: reports.length
|
|
95
|
+
};
|
|
96
|
+
},
|
|
97
|
+
async health(query) {
|
|
98
|
+
return { instances: (await select(query)).map((report) => ({
|
|
99
|
+
instance: infoOf(report),
|
|
100
|
+
report: report.health
|
|
101
|
+
})) };
|
|
102
|
+
},
|
|
103
|
+
async errors(query) {
|
|
104
|
+
const reports = await select(query);
|
|
105
|
+
return { groups: mergeErrorGroups(reports.map((report) => ({
|
|
106
|
+
instance: report.instance.id,
|
|
107
|
+
errors: report.errors
|
|
108
|
+
}))).slice(0, limitOf(query)) };
|
|
109
|
+
},
|
|
110
|
+
async logs(query) {
|
|
111
|
+
const reports = await select(query);
|
|
112
|
+
const rows = [];
|
|
113
|
+
for (const report of reports) for (const entry of report.logs) {
|
|
114
|
+
if (!matches(entry.level, query.level) || !matches(entry.module, query.module)) continue;
|
|
115
|
+
rows.push({
|
|
116
|
+
...entry,
|
|
117
|
+
instance: report.instance.id
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
return rows.sort((a, b) => b.at - a.at).slice(0, limitOf(query));
|
|
121
|
+
},
|
|
122
|
+
async jobs(query) {
|
|
123
|
+
return { instances: (await select(query)).map((report) => ({
|
|
124
|
+
instance: infoOf(report),
|
|
125
|
+
report: report.jobs
|
|
126
|
+
})) };
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
let currentId = "";
|
|
130
|
+
function current(reports) {
|
|
131
|
+
return currentId || reports[0]?.instance.id || "";
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
insights,
|
|
135
|
+
setCurrent(id) {
|
|
136
|
+
currentId = id;
|
|
137
|
+
}
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
/** The sample rate the counts come from: the lowest any selected instance used (1 when none). */
|
|
141
|
+
function lowestRate(reports) {
|
|
142
|
+
return reports.length === 0 ? 1 : Math.min(...reports.map((r) => r.capture.sampleRate));
|
|
143
|
+
}
|
|
144
|
+
/** Development insights: this process only. */
|
|
145
|
+
function createLocalInsights(reporter) {
|
|
146
|
+
const { insights, setCurrent } = build(async () => [await reporter.snapshot()], lowestRate);
|
|
147
|
+
setCurrent(reporter.instance.id);
|
|
148
|
+
return insights;
|
|
149
|
+
}
|
|
150
|
+
/** Production insights: merged instance reports from the store plus this process live. */
|
|
151
|
+
function createSharedInsights(input) {
|
|
152
|
+
const { store, reporter, sampleRate } = input;
|
|
153
|
+
const { insights, setCurrent } = build(async (windowMs) => {
|
|
154
|
+
const live = await reporter.snapshot();
|
|
155
|
+
let stored = [];
|
|
156
|
+
try {
|
|
157
|
+
stored = await store.reports.list(live.at - windowMs);
|
|
158
|
+
} catch {}
|
|
159
|
+
return [live, ...stored.filter((report) => report.instance.id !== live.instance.id)];
|
|
160
|
+
}, () => sampleRate);
|
|
161
|
+
setCurrent(reporter.instance.id);
|
|
162
|
+
return insights;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
export { createLocalInsights, createSharedInsights };
|
|
167
|
+
//# sourceMappingURL=insights.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"insights.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/insights/insights.ts"],"sourcesContent":["import type { DevtoolsInstanceInfo, DevtoolsInstanceReport, DevtoolsLogRow } from \"../contracts\";\nimport {\n histogramMean,\n histogramQuantile,\n mergeErrorGroups,\n mergeQueryShapeStats,\n mergeRouteStats,\n} from \"../stats\";\nimport type { DevtoolsStore } from \"../store/types\";\nimport type { DevtoolsInsightQuery, DevtoolsInsights, DevtoolsLocalReporter } from \"./types\";\n\nexport const DEFAULT_INSIGHT_LIMIT = 100;\nexport const MAX_INSIGHT_LIMIT = 500;\n\n/** Reports fresher than this are merged into the views. */\nconst FRESH_MS = 60_000;\n/** The instances list reaches back this far. */\nconst INSTANCES_MS = 5 * 60_000;\n\ntype ReportLoader = (windowMs: number) => Promise<DevtoolsInstanceReport[]>;\n\nfunction limitOf(query: DevtoolsInsightQuery): number {\n const limit = query.limit ?? DEFAULT_INSIGHT_LIMIT;\n\n return Math.min(MAX_INSIGHT_LIMIT, Math.max(1, Math.floor(limit)));\n}\n\nfunction matches(value: string, needle: string | undefined): boolean {\n return !needle || value.toLowerCase().includes(needle.toLowerCase());\n}\n\nfunction infoOf(report: DevtoolsInstanceReport): DevtoolsInstanceInfo {\n return { ...report.instance, seenAt: report.at };\n}\n\nfunction build(load: ReportLoader, sampleRateOf: (reports: DevtoolsInstanceReport[]) => number) {\n /** The fresh reports of the selected instance(s). */\n async function select(\n query: DevtoolsInsightQuery,\n windowMs = FRESH_MS,\n ): Promise<DevtoolsInstanceReport[]> {\n const reports = await load(windowMs);\n\n return query.instance === \"all\"\n ? reports\n : reports.filter((report) => report.instance.id === query.instance);\n }\n\n const insights: DevtoolsInsights = {\n async instances() {\n const reports = await load(INSTANCES_MS);\n const infos = reports.map(infoOf).sort((a, b) => b.seenAt - a.seenAt);\n\n return { current: current(reports), instances: infos };\n },\n\n async resources(query) {\n const reports = await select(query);\n\n return {\n instances: reports.map((report) => ({\n instance: infoOf(report),\n snapshot: report.resources.snapshot,\n history: report.resources.history,\n })),\n };\n },\n\n async queryStats(query) {\n const reports = await select(query);\n const sort = query.sort ?? \"total\";\n const rows = mergeQueryShapeStats(\n reports.map((report) => ({ instance: report.instance.id, shapes: report.queries })),\n ).map((shape) => ({\n ...shape,\n p50Ms: histogramQuantile(shape.histogram, 0.5),\n p95Ms: histogramQuantile(shape.histogram, 0.95),\n meanMs: histogramMean(shape.histogram),\n }));\n\n const key: Record<string, (row: (typeof rows)[number]) => number> = {\n total: (row) => row.histogram.sumMs,\n p95: (row) => row.p95Ms,\n count: (row) => row.count,\n \"n+1\": (row) => row.nPlusOne.requests * 1e6 + row.nPlusOne.maxPerRequest,\n };\n const by = key[sort] ?? key.total!;\n\n return {\n shapes: rows.sort((a, b) => by(b) - by(a)).slice(0, limitOf(query)),\n sampleRate: sampleRateOf(reports),\n instanceCount: reports.length,\n evicted: reports.reduce((sum, report) => sum + report.capture.evictedShapes, 0),\n };\n },\n\n async routeStats(query) {\n const reports = await select(query);\n const sort = query.sort ?? \"total\";\n const rows = mergeRouteStats(\n reports.map((report) => ({ instance: report.instance.id, routes: report.routes })),\n ).map((route) => ({\n ...route,\n p50Ms: histogramQuantile(route.histogram, 0.5),\n p95Ms: histogramQuantile(route.histogram, 0.95),\n meanMs: histogramMean(route.histogram),\n }));\n\n const key: Record<string, (row: (typeof rows)[number]) => number> = {\n total: (row) => row.histogram.sumMs,\n p95: (row) => row.p95Ms,\n count: (row) => row.count,\n errors: (row) => row.errors,\n };\n const by = key[sort] ?? key.total!;\n\n return {\n routes: rows.sort((a, b) => by(b) - by(a)).slice(0, limitOf(query)),\n sampleRate: sampleRateOf(reports),\n instanceCount: reports.length,\n };\n },\n\n async health(query) {\n const reports = await select(query);\n\n return {\n instances: reports.map((report) => ({ instance: infoOf(report), report: report.health })),\n };\n },\n\n async errors(query) {\n const reports = await select(query);\n const groups = mergeErrorGroups(\n reports.map((report) => ({ instance: report.instance.id, errors: report.errors })),\n );\n\n return { groups: groups.slice(0, limitOf(query)) };\n },\n\n async logs(query) {\n const reports = await select(query);\n const rows: DevtoolsLogRow[] = [];\n\n for (const report of reports) {\n for (const entry of report.logs) {\n if (!matches(entry.level, query.level) || !matches(entry.module, query.module)) continue;\n\n rows.push({ ...entry, instance: report.instance.id });\n }\n }\n\n return rows.sort((a, b) => b.at - a.at).slice(0, limitOf(query));\n },\n\n async jobs(query) {\n const reports = await select(query);\n\n return {\n instances: reports.map((report) => ({ instance: infoOf(report), report: report.jobs })),\n };\n },\n };\n\n let currentId = \"\";\n\n function current(reports: DevtoolsInstanceReport[]): string {\n return currentId || reports[0]?.instance.id || \"\";\n }\n\n return {\n insights,\n setCurrent(id: string) {\n currentId = id;\n },\n };\n}\n\n/** The sample rate the counts come from: the lowest any selected instance used (1 when none). */\nfunction lowestRate(reports: DevtoolsInstanceReport[]): number {\n return reports.length === 0 ? 1 : Math.min(...reports.map((r) => r.capture.sampleRate));\n}\n\n/** Development insights: this process only. */\nexport function createLocalInsights(reporter: DevtoolsLocalReporter): DevtoolsInsights {\n const { insights, setCurrent } = build(async () => [await reporter.snapshot()], lowestRate);\n\n setCurrent(reporter.instance.id);\n\n return insights;\n}\n\n/** Production insights: merged instance reports from the store plus this process live. */\nexport function createSharedInsights(input: {\n store: DevtoolsStore;\n reporter: DevtoolsLocalReporter;\n sampleRate: number;\n}): DevtoolsInsights {\n const { store, reporter, sampleRate } = input;\n\n const { insights, setCurrent } = build(\n async (windowMs) => {\n const live = await reporter.snapshot();\n let stored: DevtoolsInstanceReport[] = [];\n\n try {\n stored = await store.reports.list(live.at - windowMs);\n } catch {\n // The database is unreachable: show this process alone rather than nothing.\n }\n\n // The answering instance is always taken live, never from its stored row.\n return [live, ...stored.filter((report) => report.instance.id !== live.instance.id)];\n },\n () => sampleRate,\n );\n\n setCurrent(reporter.instance.id);\n\n return insights;\n}\n"],"mappings":";;;;AAWA,MAAa,wBAAwB;AACrC,MAAa,oBAAoB;;AAGjC,MAAM,WAAW;;AAEjB,MAAM,eAAe;AAIrB,SAAS,QAAQ,OAAqC;CACpD,MAAM,QAAQ,MAAM;CAEpB,OAAO,KAAK,SAAuB,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,CAAC,CAAC;AACnE;AAEA,SAAS,QAAQ,OAAe,QAAqC;CACnE,OAAO,CAAC,UAAU,MAAM,YAAY,CAAC,CAAC,SAAS,OAAO,YAAY,CAAC;AACrE;AAEA,SAAS,OAAO,QAAsD;CACpE,OAAO;EAAE,GAAG,OAAO;EAAU,QAAQ,OAAO;CAAG;AACjD;AAEA,SAAS,MAAM,MAAoB,cAA6D;;CAE9F,eAAe,OACb,OACA,WAAW,UACwB;EACnC,MAAM,UAAU,MAAM,KAAK,QAAQ;EAEnC,OAAO,MAAM,aAAa,QACtB,UACA,QAAQ,QAAQ,WAAW,OAAO,SAAS,OAAO,MAAM,QAAQ;CACtE;CAEA,MAAM,WAA6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AS,EAAE,CAAC;CACrF,SACM,UACR;CAEA,WAAW,SAAS,SAAS,EAAE;CAE/B,OAAO;AACT"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import cluster from "node:cluster";
|
|
2
|
+
import os from "node:os";
|
|
3
|
+
|
|
4
|
+
//#region ../../packages/devtools/src/production/insights/instance.ts
|
|
5
|
+
/** This process's identity (host, pid, pm2/cluster worker, start time). */
|
|
6
|
+
function createInstanceInfo(now = Date.now()) {
|
|
7
|
+
const host = os.hostname();
|
|
8
|
+
const pid = process.pid;
|
|
9
|
+
const worker = process.env.NODE_APP_INSTANCE || process.env.pm_id || (cluster.worker ? String(cluster.worker.id) : null);
|
|
10
|
+
return {
|
|
11
|
+
id: `${host}:${pid}:${now.toString(36)}`,
|
|
12
|
+
label: worker === null ? `${host} pid ${pid}` : `${host} #${worker}`,
|
|
13
|
+
host,
|
|
14
|
+
pid,
|
|
15
|
+
worker,
|
|
16
|
+
startedAt: now,
|
|
17
|
+
seenAt: now,
|
|
18
|
+
nodeVersion: process.version
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
//#endregion
|
|
23
|
+
export { createInstanceInfo };
|
|
24
|
+
//# sourceMappingURL=instance.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/insights/instance.ts"],"sourcesContent":["import cluster from \"node:cluster\";\nimport os from \"node:os\";\nimport type { DevtoolsInstanceInfo } from \"../contracts\";\n\n/** This process's identity (host, pid, pm2/cluster worker, start time). */\nexport function createInstanceInfo(now: number = Date.now()): DevtoolsInstanceInfo {\n const host = os.hostname();\n const pid = process.pid;\n const worker =\n process.env.NODE_APP_INSTANCE ||\n process.env.pm_id ||\n (cluster.worker ? String(cluster.worker.id) : null);\n\n return {\n id: `${host}:${pid}:${now.toString(36)}`,\n label: worker === null ? `${host} pid ${pid}` : `${host} #${worker}`,\n host,\n pid,\n worker,\n startedAt: now,\n seenAt: now,\n nodeVersion: process.version,\n };\n}\n"],"mappings":";;;;;AAKA,SAAgB,mBAAmB,MAAc,KAAK,IAAI,GAAyB;CACjF,MAAM,OAAO,GAAG,SAAS;CACzB,MAAM,MAAM,QAAQ;CACpB,MAAM,SACJ,QAAQ,IAAI,qBACZ,QAAQ,IAAI,UACX,QAAQ,SAAS,OAAO,QAAQ,OAAO,EAAE,IAAI;CAEhD,OAAO;EACL,IAAI,GAAG,KAAK,GAAG,IAAI,GAAG,IAAI,SAAS,EAAE;EACrC,OAAO,WAAW,OAAO,GAAG,KAAK,OAAO,QAAQ,GAAG,KAAK,IAAI;EAC5D;EACA;EACA;EACA,WAAW;EACX,QAAQ;EACR,aAAa,QAAQ;CACvB;AACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/production/insights/jobs.ts
|
|
2
|
+
const SCHEDULER_KEY = Symbol.for("warlock.scheduler.running");
|
|
3
|
+
/** Imports an optional package by name; `null` when it is not installed. */
|
|
4
|
+
async function importOptional(name) {
|
|
5
|
+
try {
|
|
6
|
+
return await import(
|
|
7
|
+
/* @vite-ignore */
|
|
8
|
+
name
|
|
9
|
+
);
|
|
10
|
+
} catch {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const defaultLoaders = {
|
|
15
|
+
async scheduler() {
|
|
16
|
+
if (!await importOptional("@warlock.js/scheduler")) return null;
|
|
17
|
+
const running = globalThis[SCHEDULER_KEY];
|
|
18
|
+
const jobs = [];
|
|
19
|
+
for (const scheduler of running ?? []) if (typeof scheduler.list === "function") jobs.push(...scheduler.list());
|
|
20
|
+
return jobs;
|
|
21
|
+
},
|
|
22
|
+
async queue() {
|
|
23
|
+
const current = (await importOptional("@warlock.js/queue"))?.currentQueueDriver;
|
|
24
|
+
const driver = current?.();
|
|
25
|
+
if (!driver || typeof driver.counts !== "function" || typeof driver.running !== "function") return null;
|
|
26
|
+
const queues = [];
|
|
27
|
+
for (const name of driver.running()) queues.push({
|
|
28
|
+
name,
|
|
29
|
+
counts: await driver.counts(name)
|
|
30
|
+
});
|
|
31
|
+
return queues;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
function readableInterval(job) {
|
|
35
|
+
const every = job.intervals?.every;
|
|
36
|
+
if (!every?.type) return null;
|
|
37
|
+
const value = every.value ?? 1;
|
|
38
|
+
const unit = every.type.replace(/s$/, "");
|
|
39
|
+
return value === 1 ? `every ${unit}` : `every ${value} ${unit}s`;
|
|
40
|
+
}
|
|
41
|
+
function toSchedule(job) {
|
|
42
|
+
return {
|
|
43
|
+
name: job.name,
|
|
44
|
+
cron: job.cronExpression ?? null,
|
|
45
|
+
interval: readableInterval(job),
|
|
46
|
+
isRunning: job.isRunning === true,
|
|
47
|
+
lastRunAt: job.lastRun ? Number(job.lastRun.valueOf()) : null,
|
|
48
|
+
nextRunAt: job.nextRun ? Number(job.nextRun.valueOf()) : null,
|
|
49
|
+
lastDurationMs: null,
|
|
50
|
+
lastError: null,
|
|
51
|
+
runs: 0,
|
|
52
|
+
failures: 0
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Reads the scheduler's jobs and the queue's counts when those packages are
|
|
57
|
+
* installed. A part that is absent or fails reports `available: false` with
|
|
58
|
+
* nothing else; the reader itself never throws.
|
|
59
|
+
*/
|
|
60
|
+
function createJobsReader(loaders = {}) {
|
|
61
|
+
const source = {
|
|
62
|
+
...defaultLoaders,
|
|
63
|
+
...loaders
|
|
64
|
+
};
|
|
65
|
+
return async () => {
|
|
66
|
+
const report = {
|
|
67
|
+
available: {
|
|
68
|
+
scheduler: false,
|
|
69
|
+
queue: false
|
|
70
|
+
},
|
|
71
|
+
schedules: [],
|
|
72
|
+
queues: []
|
|
73
|
+
};
|
|
74
|
+
try {
|
|
75
|
+
const jobs = await source.scheduler();
|
|
76
|
+
if (jobs) {
|
|
77
|
+
report.available.scheduler = true;
|
|
78
|
+
report.schedules = jobs.map(toSchedule);
|
|
79
|
+
}
|
|
80
|
+
} catch {
|
|
81
|
+
report.available.scheduler = false;
|
|
82
|
+
report.schedules = [];
|
|
83
|
+
}
|
|
84
|
+
try {
|
|
85
|
+
const queues = await source.queue();
|
|
86
|
+
if (queues) {
|
|
87
|
+
report.available.queue = true;
|
|
88
|
+
report.queues = queues;
|
|
89
|
+
}
|
|
90
|
+
} catch {
|
|
91
|
+
report.available.queue = false;
|
|
92
|
+
report.queues = [];
|
|
93
|
+
}
|
|
94
|
+
return report;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
//#endregion
|
|
99
|
+
export { createJobsReader };
|
|
100
|
+
//# sourceMappingURL=jobs.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jobs.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/insights/jobs.ts"],"sourcesContent":["import type { DevtoolsJobsReport, DevtoolsScheduleInfo } from \"../contracts\";\nimport type { DevtoolsJobsReader } from \"./types\";\n\n/** The shape of a scheduler job this reader needs (duck-typed: the packages stay optional). */\ntype SchedulerJobLike = {\n name: string;\n cronExpression?: string | null;\n intervals?: { every?: { type?: string; value?: number } };\n isRunning?: boolean;\n lastRun?: { valueOf(): number } | null;\n nextRun?: { valueOf(): number } | null;\n};\n\n/** Where the jobs come from; replaced in specs. Each returns `null` when its package is absent. */\nexport type DevtoolsJobsLoaders = {\n scheduler(): Promise<readonly SchedulerJobLike[] | null>;\n queue(): Promise<{ name: string; counts: Record<string, number> }[] | null>;\n};\n\nconst SCHEDULER_KEY = Symbol.for(\"warlock.scheduler.running\");\n\n/** Imports an optional package by name; `null` when it is not installed. */\nasync function importOptional(name: string): Promise<Record<string, unknown> | null> {\n try {\n return (await import(/* @vite-ignore */ name)) as Record<string, unknown>;\n } catch {\n return null;\n }\n}\n\nconst defaultLoaders: DevtoolsJobsLoaders = {\n async scheduler() {\n if (!(await importOptional(\"@warlock.js/scheduler\"))) return null;\n\n const running = (globalThis as Record<symbol, unknown>)[SCHEDULER_KEY] as\n | Iterable<{ list?: () => readonly SchedulerJobLike[] }>\n | undefined;\n const jobs: SchedulerJobLike[] = [];\n\n for (const scheduler of running ?? []) {\n if (typeof scheduler.list === \"function\") jobs.push(...scheduler.list());\n }\n\n return jobs;\n },\n\n async queue() {\n const queue = await importOptional(\"@warlock.js/queue\");\n const current = queue?.currentQueueDriver as (() => unknown) | undefined;\n const driver = current?.() as\n | {\n running?: () => string[];\n counts?: (queue: string) => Promise<Record<string, number>>;\n }\n | undefined;\n\n if (!driver || typeof driver.counts !== \"function\" || typeof driver.running !== \"function\") {\n return null;\n }\n\n const queues: { name: string; counts: Record<string, number> }[] = [];\n\n for (const name of driver.running()) {\n queues.push({ name, counts: await driver.counts(name) });\n }\n\n return queues;\n },\n};\n\nfunction readableInterval(job: SchedulerJobLike): string | null {\n const every = job.intervals?.every;\n\n if (!every?.type) return null;\n\n const value = every.value ?? 1;\n const unit = every.type.replace(/s$/, \"\");\n\n return value === 1 ? `every ${unit}` : `every ${value} ${unit}s`;\n}\n\nfunction toSchedule(job: SchedulerJobLike): DevtoolsScheduleInfo {\n return {\n name: job.name,\n cron: job.cronExpression ?? null,\n interval: readableInterval(job),\n isRunning: job.isRunning === true,\n lastRunAt: job.lastRun ? Number(job.lastRun.valueOf()) : null,\n nextRunAt: job.nextRun ? Number(job.nextRun.valueOf()) : null,\n // The scheduler keeps no per-run history; these stay empty.\n lastDurationMs: null,\n lastError: null,\n runs: 0,\n failures: 0,\n };\n}\n\n/**\n * Reads the scheduler's jobs and the queue's counts when those packages are\n * installed. A part that is absent or fails reports `available: false` with\n * nothing else; the reader itself never throws.\n */\nexport function createJobsReader(loaders: Partial<DevtoolsJobsLoaders> = {}): DevtoolsJobsReader {\n const source = { ...defaultLoaders, ...loaders };\n\n return async () => {\n const report: DevtoolsJobsReport = {\n available: { scheduler: false, queue: false },\n schedules: [],\n queues: [],\n };\n\n try {\n const jobs = await source.scheduler();\n\n if (jobs) {\n report.available.scheduler = true;\n report.schedules = jobs.map(toSchedule);\n }\n } catch {\n report.available.scheduler = false;\n report.schedules = [];\n }\n\n try {\n const queues = await source.queue();\n\n if (queues) {\n report.available.queue = true;\n report.queues = queues;\n }\n } catch {\n report.available.queue = false;\n report.queues = [];\n }\n\n return report;\n };\n}\n"],"mappings":";AAmBA,MAAM,gBAAgB,OAAO,IAAI,2BAA2B;;AAG5D,eAAe,eAAe,MAAuD;CACnF,IAAI;EACF,OAAQ,MAAM;;GAA0B;;CAC1C,QAAQ;EACN,OAAO;CACT;AACF;AAEA,MAAM,iBAAsC;CAC1C,MAAM,YAAY;EAChB,IAAI,CAAE,MAAM,eAAe,uBAAuB,GAAI,OAAO;EAE7D,MAAM,UAAW,WAAuC;EAGxD,MAAM,OAA2B,CAAC;EAElC,KAAK,MAAM,aAAa,WAAW,CAAC,GAClC,IAAI,OAAO,UAAU,SAAS,YAAY,KAAK,KAAK,GAAG,UAAU,KAAK,CAAC;EAGzE,OAAO;CACT;CAEA,MAAM,QAAQ;EAEZ,MAAM,WAAU,MADI,eAAe,mBAAmB,EACjC,EAAE;EACvB,MAAM,SAAS,UAAU;EAOzB,IAAI,CAAC,UAAU,OAAO,OAAO,WAAW,cAAc,OAAO,OAAO,YAAY,YAC9E,OAAO;EAGT,MAAM,SAA6D,CAAC;EAEpE,KAAK,MAAM,QAAQ,OAAO,QAAQ,GAChC,OAAO,KAAK;GAAE;GAAM,QAAQ,MAAM,OAAO,OAAO,IAAI;EAAE,CAAC;EAGzD,OAAO;CACT;AACF;AAEA,SAAS,iBAAiB,KAAsC;CAC9D,MAAM,QAAQ,IAAI,WAAW;CAE7B,IAAI,CAAC,OAAO,MAAM,OAAO;CAEzB,MAAM,QAAQ,MAAM,SAAS;CAC7B,MAAM,OAAO,MAAM,KAAK,QAAQ,MAAM,EAAE;CAExC,OAAO,UAAU,IAAI,SAAS,SAAS,SAAS,MAAM,GAAG,KAAK;AAChE;AAEA,SAAS,WAAW,KAA6C;CAC/D,OAAO;EACL,MAAM,IAAI;EACV,MAAM,IAAI,kBAAkB;EAC5B,UAAU,iBAAiB,GAAG;EAC9B,WAAW,IAAI,cAAc;EAC7B,WAAW,IAAI,UAAU,OAAO,IAAI,QAAQ,QAAQ,CAAC,IAAI;EACzD,WAAW,IAAI,UAAU,OAAO,IAAI,QAAQ,QAAQ,CAAC,IAAI;EAEzD,gBAAgB;EAChB,WAAW;EACX,MAAM;EACN,UAAU;CACZ;AACF;;;;;;AAOA,SAAgB,iBAAiB,UAAwC,CAAC,GAAuB;CAC/F,MAAM,SAAS;EAAE,GAAG;EAAgB,GAAG;CAAQ;CAE/C,OAAO,YAAY;EACjB,MAAM,SAA6B;GACjC,WAAW;IAAE,WAAW;IAAO,OAAO;GAAM;GAC5C,WAAW,CAAC;GACZ,QAAQ,CAAC;EACX;EAEA,IAAI;GACF,MAAM,OAAO,MAAM,OAAO,UAAU;GAEpC,IAAI,MAAM;IACR,OAAO,UAAU,YAAY;IAC7B,OAAO,YAAY,KAAK,IAAI,UAAU;GACxC;EACF,QAAQ;GACN,OAAO,UAAU,YAAY;GAC7B,OAAO,YAAY,CAAC;EACtB;EAEA,IAAI;GACF,MAAM,SAAS,MAAM,OAAO,MAAM;GAElC,IAAI,QAAQ;IACV,OAAO,UAAU,QAAQ;IACzB,OAAO,SAAS;GAClB;EACF,QAAQ;GACN,OAAO,UAAU,QAAQ;GACzB,OAAO,SAAS,CAAC;EACnB;EAEA,OAAO;CACT;AACF"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
//#region ../../packages/devtools/src/production/insights/reporter.ts
|
|
2
|
+
const emptyJobs = () => ({
|
|
3
|
+
available: {
|
|
4
|
+
scheduler: false,
|
|
5
|
+
queue: false
|
|
6
|
+
},
|
|
7
|
+
schedules: [],
|
|
8
|
+
queues: []
|
|
9
|
+
});
|
|
10
|
+
/** This process's report from its parts (production: from the capture; development: from the dev stats). */
|
|
11
|
+
function createLocalReporter(parts) {
|
|
12
|
+
const now = parts.now ?? Date.now;
|
|
13
|
+
return {
|
|
14
|
+
instance: parts.instance,
|
|
15
|
+
async snapshot() {
|
|
16
|
+
const at = now();
|
|
17
|
+
let jobs;
|
|
18
|
+
try {
|
|
19
|
+
jobs = await parts.jobs();
|
|
20
|
+
} catch {
|
|
21
|
+
jobs = emptyJobs();
|
|
22
|
+
}
|
|
23
|
+
const capture = parts.counters ? parts.counters() : {
|
|
24
|
+
sampleRate: 1,
|
|
25
|
+
requests: 0,
|
|
26
|
+
sampled: 0,
|
|
27
|
+
keptUnsampled: 0,
|
|
28
|
+
stored: 0,
|
|
29
|
+
droppedStored: 0,
|
|
30
|
+
evictedShapes: parts.queries.evicted(),
|
|
31
|
+
evictedRoutes: parts.routes.evicted(),
|
|
32
|
+
evictedErrors: parts.errors.evicted(),
|
|
33
|
+
droppedQueries: 0
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
instance: {
|
|
37
|
+
...parts.instance,
|
|
38
|
+
seenAt: at
|
|
39
|
+
},
|
|
40
|
+
at,
|
|
41
|
+
resources: {
|
|
42
|
+
snapshot: parts.resources.snapshot(),
|
|
43
|
+
history: parts.resources.history()
|
|
44
|
+
},
|
|
45
|
+
queries: parts.queries.snapshot(200),
|
|
46
|
+
routes: parts.routes.snapshot(200),
|
|
47
|
+
errors: parts.errors.snapshot(50),
|
|
48
|
+
logs: parts.logs.snapshot(50),
|
|
49
|
+
health: parts.health.report(),
|
|
50
|
+
jobs,
|
|
51
|
+
capture
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
export { createLocalReporter };
|
|
59
|
+
//# sourceMappingURL=reporter.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reporter.mjs","names":[],"sources":["../../../../../../../../../packages/devtools/src/production/insights/reporter.ts"],"sourcesContent":["import type {\n DevtoolsCaptureCounters,\n DevtoolsInstanceInfo,\n DevtoolsInstanceReport,\n DevtoolsJobsReport,\n} from \"../contracts\";\nimport type {\n DevtoolsErrorGroups,\n DevtoolsProductionCapture,\n DevtoolsQueryStats,\n DevtoolsRecentLogs,\n DevtoolsRouteStatsStore,\n} from \"../capture/types\";\nimport type {\n DevtoolsHealthHistory,\n DevtoolsJobsReader,\n DevtoolsLocalReporter,\n DevtoolsResourceMonitor,\n} from \"./types\";\n\nconst emptyJobs = (): DevtoolsJobsReport => ({\n available: { scheduler: false, queue: false },\n schedules: [],\n queues: [],\n});\n\n/** This process's report from its parts (production: from the capture; development: from the dev stats). */\nexport function createLocalReporter(parts: {\n instance: DevtoolsInstanceInfo;\n resources: DevtoolsResourceMonitor;\n health: DevtoolsHealthHistory;\n jobs: DevtoolsJobsReader;\n queries: DevtoolsQueryStats;\n routes: DevtoolsRouteStatsStore;\n errors: DevtoolsErrorGroups;\n logs: DevtoolsRecentLogs;\n counters: DevtoolsProductionCapture[\"counters\"] | null;\n now?: () => number;\n}): DevtoolsLocalReporter {\n const now = parts.now ?? Date.now;\n\n return {\n instance: parts.instance,\n\n async snapshot() {\n const at = now();\n let jobs: DevtoolsJobsReport;\n\n try {\n jobs = await parts.jobs();\n } catch {\n jobs = emptyJobs();\n }\n\n const capture: DevtoolsCaptureCounters = parts.counters\n ? parts.counters()\n : {\n sampleRate: 1,\n requests: 0,\n sampled: 0,\n keptUnsampled: 0,\n stored: 0,\n droppedStored: 0,\n evictedShapes: parts.queries.evicted(),\n evictedRoutes: parts.routes.evicted(),\n evictedErrors: parts.errors.evicted(),\n droppedQueries: 0,\n };\n\n const report: DevtoolsInstanceReport = {\n instance: { ...parts.instance, seenAt: at },\n at,\n resources: { snapshot: parts.resources.snapshot(), history: parts.resources.history() },\n queries: parts.queries.snapshot(200),\n routes: parts.routes.snapshot(200),\n errors: parts.errors.snapshot(50),\n logs: parts.logs.snapshot(50),\n health: parts.health.report(),\n jobs,\n capture,\n };\n\n return report;\n },\n };\n}\n"],"mappings":";AAoBA,MAAM,mBAAuC;CAC3C,WAAW;EAAE,WAAW;EAAO,OAAO;CAAM;CAC5C,WAAW,CAAC;CACZ,QAAQ,CAAC;AACX;;AAGA,SAAgB,oBAAoB,OAWV;CACxB,MAAM,MAAM,MAAM,OAAO,KAAK;CAE9B,OAAO;EACL,UAAU,MAAM;EAEhB,MAAM,WAAW;GACf,MAAM,KAAK,IAAI;GACf,IAAI;GAEJ,IAAI;IACF,OAAO,MAAM,MAAM,KAAK;GAC1B,QAAQ;IACN,OAAO,UAAU;GACnB;GAEA,MAAM,UAAmC,MAAM,WAC3C,MAAM,SAAS,IACf;IACE,YAAY;IACZ,UAAU;IACV,SAAS;IACT,eAAe;IACf,QAAQ;IACR,eAAe;IACf,eAAe,MAAM,QAAQ,QAAQ;IACrC,eAAe,MAAM,OAAO,QAAQ;IACpC,eAAe,MAAM,OAAO,QAAQ;IACpC,gBAAgB;GAClB;GAeJ,OAAO;IAZL,UAAU;KAAE,GAAG,MAAM;KAAU,QAAQ;IAAG;IAC1C;IACA,WAAW;KAAE,UAAU,MAAM,UAAU,SAAS;KAAG,SAAS,MAAM,UAAU,QAAQ;IAAE;IACtF,SAAS,MAAM,QAAQ,SAAS,GAAG;IACnC,QAAQ,MAAM,OAAO,SAAS,GAAG;IACjC,QAAQ,MAAM,OAAO,SAAS,EAAE;IAChC,MAAM,MAAM,KAAK,SAAS,EAAE;IAC5B,QAAQ,MAAM,OAAO,OAAO;IAC5B;IACA;GAGU;EACd;CACF;AACF"}
|