@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,811 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("./rolldown-runtime-Zuuoy_Rh.cjs");
|
|
2
|
+
const require_histogram = require("./histogram-BaI-PnCv.cjs");
|
|
3
|
+
let node_cluster = require("node:cluster");
|
|
4
|
+
node_cluster = require_rolldown_runtime.__toESM(node_cluster, 1);
|
|
5
|
+
let node_os = require("node:os");
|
|
6
|
+
node_os = require_rolldown_runtime.__toESM(node_os, 1);
|
|
7
|
+
let node_perf_hooks = require("node:perf_hooks");
|
|
8
|
+
let node_v8 = require("node:v8");
|
|
9
|
+
node_v8 = require_rolldown_runtime.__toESM(node_v8, 1);
|
|
10
|
+
|
|
11
|
+
//#region ../../packages/devtools/src/production/stats/merge.ts
|
|
12
|
+
/** The later of two "slowest" records. */
|
|
13
|
+
function slower(a, b) {
|
|
14
|
+
if (a === null) return b;
|
|
15
|
+
if (b === null) return a;
|
|
16
|
+
return b.durationMs > a.durationMs ? b : a;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Merges the query statistics several instances reported: one row per shape
|
|
20
|
+
* id, counts and histograms summed, the slowest example kept, `instances`
|
|
21
|
+
* listing who reported it. Order: highest total time first.
|
|
22
|
+
*/
|
|
23
|
+
function mergeQueryShapeStats(reports) {
|
|
24
|
+
const merged = /* @__PURE__ */ new Map();
|
|
25
|
+
for (const { instance, shapes } of reports) for (const shape of shapes) {
|
|
26
|
+
const current = merged.get(shape.id);
|
|
27
|
+
if (!current) {
|
|
28
|
+
merged.set(shape.id, {
|
|
29
|
+
...structuredClone(shape),
|
|
30
|
+
instances: [instance]
|
|
31
|
+
});
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
current.count += shape.count;
|
|
35
|
+
current.errors += shape.errors;
|
|
36
|
+
current.histogram = require_histogram.mergeHistograms([current.histogram, shape.histogram]);
|
|
37
|
+
current.nPlusOne = {
|
|
38
|
+
requests: current.nPlusOne.requests + shape.nPlusOne.requests,
|
|
39
|
+
maxPerRequest: Math.max(current.nPlusOne.maxPerRequest, shape.nPlusOne.maxPerRequest)
|
|
40
|
+
};
|
|
41
|
+
current.slowest = slower(current.slowest, shape.slowest);
|
|
42
|
+
current.firstSeen = Math.min(current.firstSeen, shape.firstSeen);
|
|
43
|
+
current.lastSeen = Math.max(current.lastSeen, shape.lastSeen);
|
|
44
|
+
current.explainable = current.explainable || shape.explainable;
|
|
45
|
+
if (!current.instances.includes(instance)) current.instances.push(instance);
|
|
46
|
+
}
|
|
47
|
+
return [...merged.values()].sort((a, b) => b.histogram.sumMs - a.histogram.sumMs);
|
|
48
|
+
}
|
|
49
|
+
/** Merges phase lists by name (counts and sums added, max kept), slowest total first, at most 30. */
|
|
50
|
+
function mergePhases(lists) {
|
|
51
|
+
const merged = /* @__PURE__ */ new Map();
|
|
52
|
+
for (const list of lists) for (const phase of list) {
|
|
53
|
+
const current = merged.get(phase.name);
|
|
54
|
+
if (!current) {
|
|
55
|
+
merged.set(phase.name, { ...phase });
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
current.count += phase.count;
|
|
59
|
+
current.sumMs += phase.sumMs;
|
|
60
|
+
current.maxMs = Math.max(current.maxMs, phase.maxMs);
|
|
61
|
+
}
|
|
62
|
+
return [...merged.values()].sort((a, b) => b.sumMs - a.sumMs).slice(0, 30);
|
|
63
|
+
}
|
|
64
|
+
/** Merges route statistics by key, like `mergeQueryShapeStats`. */
|
|
65
|
+
function mergeRouteStats(reports) {
|
|
66
|
+
const merged = /* @__PURE__ */ new Map();
|
|
67
|
+
for (const { instance, routes } of reports) for (const route of routes) {
|
|
68
|
+
const current = merged.get(route.key);
|
|
69
|
+
if (!current) {
|
|
70
|
+
merged.set(route.key, {
|
|
71
|
+
...structuredClone(route),
|
|
72
|
+
instances: [instance]
|
|
73
|
+
});
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
current.count += route.count;
|
|
77
|
+
current.errors += route.errors;
|
|
78
|
+
current.histogram = require_histogram.mergeHistograms([current.histogram, route.histogram]);
|
|
79
|
+
current.phases = mergePhases([current.phases, route.phases]);
|
|
80
|
+
current.slowest = slower(current.slowest, route.slowest);
|
|
81
|
+
if (!current.instances.includes(instance)) current.instances.push(instance);
|
|
82
|
+
}
|
|
83
|
+
return [...merged.values()].sort((a, b) => b.histogram.sumMs - a.histogram.sumMs);
|
|
84
|
+
}
|
|
85
|
+
/** Merges error groups by id: counts added, the newest message/stack kept. Newest first. */
|
|
86
|
+
function mergeErrorGroups(reports) {
|
|
87
|
+
const merged = /* @__PURE__ */ new Map();
|
|
88
|
+
for (const { instance, errors } of reports) for (const group of errors) {
|
|
89
|
+
const current = merged.get(group.id);
|
|
90
|
+
if (!current) {
|
|
91
|
+
merged.set(group.id, {
|
|
92
|
+
...structuredClone(group),
|
|
93
|
+
instances: [instance]
|
|
94
|
+
});
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
const newer = group.lastSeen > current.lastSeen;
|
|
98
|
+
current.count += group.count;
|
|
99
|
+
current.firstSeen = Math.min(current.firstSeen, group.firstSeen);
|
|
100
|
+
if (newer) {
|
|
101
|
+
current.lastSeen = group.lastSeen;
|
|
102
|
+
current.message = group.message;
|
|
103
|
+
current.stack = group.stack;
|
|
104
|
+
current.status = group.status;
|
|
105
|
+
current.lastRequestId = group.lastRequestId;
|
|
106
|
+
}
|
|
107
|
+
if (!current.instances.includes(instance)) current.instances.push(instance);
|
|
108
|
+
}
|
|
109
|
+
return [...merged.values()].sort((a, b) => b.lastSeen - a.lastSeen);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
//#endregion
|
|
113
|
+
//#region ../../packages/devtools/src/production/insights/cap-report.ts
|
|
114
|
+
const sizeOf = (report) => Buffer.byteLength(JSON.stringify(report), "utf8");
|
|
115
|
+
/** The lists to trim, in order, with how to cut each one to its first `keep` entries. */
|
|
116
|
+
const LISTS = [
|
|
117
|
+
{
|
|
118
|
+
length: (r) => r.logs.length,
|
|
119
|
+
cut: (r, keep) => ({
|
|
120
|
+
...r,
|
|
121
|
+
logs: r.logs.slice(0, keep)
|
|
122
|
+
})
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
length: (r) => r.errors.length,
|
|
126
|
+
cut: (r, keep) => ({
|
|
127
|
+
...r,
|
|
128
|
+
errors: r.errors.slice(0, keep)
|
|
129
|
+
})
|
|
130
|
+
},
|
|
131
|
+
{
|
|
132
|
+
length: (r) => r.routes.length,
|
|
133
|
+
cut: (r, keep) => ({
|
|
134
|
+
...r,
|
|
135
|
+
routes: r.routes.slice(0, keep)
|
|
136
|
+
})
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
length: (r) => r.queries.length,
|
|
140
|
+
cut: (r, keep) => ({
|
|
141
|
+
...r,
|
|
142
|
+
queries: r.queries.slice(0, keep)
|
|
143
|
+
})
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
length: (r) => r.resources.history.length,
|
|
147
|
+
cut: (r, keep) => ({
|
|
148
|
+
...r,
|
|
149
|
+
resources: {
|
|
150
|
+
...r.resources,
|
|
151
|
+
history: r.resources.history.slice(0, keep)
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
}
|
|
155
|
+
];
|
|
156
|
+
/**
|
|
157
|
+
* Trims a report's lists from the end until its JSON is at most `maxBytes`
|
|
158
|
+
* (default 256 KB): logs first, then errors, routes, queries and the
|
|
159
|
+
* resource history. A report that already fits is returned unchanged.
|
|
160
|
+
*/
|
|
161
|
+
function capReportSize(report, maxBytes = 262144) {
|
|
162
|
+
let current = report;
|
|
163
|
+
for (const list of LISTS) {
|
|
164
|
+
if (sizeOf(current) <= maxBytes) return current;
|
|
165
|
+
let low = 0;
|
|
166
|
+
let high = list.length(current);
|
|
167
|
+
while (low < high) {
|
|
168
|
+
const middle = Math.ceil((low + high) / 2);
|
|
169
|
+
if (sizeOf(list.cut(current, middle)) <= maxBytes) low = middle;
|
|
170
|
+
else high = middle - 1;
|
|
171
|
+
}
|
|
172
|
+
current = list.cut(current, low);
|
|
173
|
+
}
|
|
174
|
+
return current;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
//#endregion
|
|
178
|
+
//#region ../../packages/devtools/src/production/insights/health.ts
|
|
179
|
+
/** While the app boots, the first check is tried again this often. */
|
|
180
|
+
const BOOT_RETRY_MS = 1e3;
|
|
181
|
+
/** Core's readiness, imported on first use so devtools never loads core at import time. */
|
|
182
|
+
const coreReadiness = async () => {
|
|
183
|
+
const { health, Application } = await import("@warlock.js/core");
|
|
184
|
+
if (!Application.isBooted && !Application.isShuttingDown) return null;
|
|
185
|
+
return health.readiness();
|
|
186
|
+
};
|
|
187
|
+
/** Readiness checks every `intervalMs` (default 30000), 60 history entries. */
|
|
188
|
+
function createHealthHistory(options = {}) {
|
|
189
|
+
const intervalMs = options.intervalMs ?? 3e4;
|
|
190
|
+
const size = Math.max(1, options.size ?? 60);
|
|
191
|
+
const readiness = options.readiness ?? coreReadiness;
|
|
192
|
+
let status = "unknown";
|
|
193
|
+
let checkedAt = null;
|
|
194
|
+
let checks = {};
|
|
195
|
+
const history = [];
|
|
196
|
+
let timer;
|
|
197
|
+
let retry;
|
|
198
|
+
let running;
|
|
199
|
+
function report() {
|
|
200
|
+
return {
|
|
201
|
+
status,
|
|
202
|
+
checkedAt,
|
|
203
|
+
checks: { ...checks },
|
|
204
|
+
history: history.map((e) => ({
|
|
205
|
+
...e,
|
|
206
|
+
failed: [...e.failed]
|
|
207
|
+
}))
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
async function run() {
|
|
211
|
+
try {
|
|
212
|
+
const result = await readiness();
|
|
213
|
+
if (result === null) {
|
|
214
|
+
if (timer && checkedAt === null && retry === void 0) {
|
|
215
|
+
retry = setTimeout(() => {
|
|
216
|
+
retry = void 0;
|
|
217
|
+
check();
|
|
218
|
+
}, BOOT_RETRY_MS);
|
|
219
|
+
retry.unref();
|
|
220
|
+
}
|
|
221
|
+
return report();
|
|
222
|
+
}
|
|
223
|
+
const now = Date.now();
|
|
224
|
+
const failed = Object.entries(result.checks ?? {}).filter(([, passed]) => !passed).map(([name]) => name);
|
|
225
|
+
status = result.status;
|
|
226
|
+
checkedAt = now;
|
|
227
|
+
checks = { ...result.checks ?? {} };
|
|
228
|
+
history.push({
|
|
229
|
+
at: now,
|
|
230
|
+
status: result.status,
|
|
231
|
+
failed
|
|
232
|
+
});
|
|
233
|
+
if (history.length > size) history.splice(0, history.length - size);
|
|
234
|
+
} catch {
|
|
235
|
+
if (checkedAt === null) status = "unknown";
|
|
236
|
+
}
|
|
237
|
+
return report();
|
|
238
|
+
}
|
|
239
|
+
function check() {
|
|
240
|
+
running ??= run().finally(() => {
|
|
241
|
+
running = void 0;
|
|
242
|
+
});
|
|
243
|
+
return running;
|
|
244
|
+
}
|
|
245
|
+
return {
|
|
246
|
+
start() {
|
|
247
|
+
if (timer) return;
|
|
248
|
+
check();
|
|
249
|
+
timer = setInterval(() => void check(), intervalMs);
|
|
250
|
+
timer.unref();
|
|
251
|
+
},
|
|
252
|
+
stop() {
|
|
253
|
+
if (timer) clearInterval(timer);
|
|
254
|
+
if (retry) clearTimeout(retry);
|
|
255
|
+
timer = void 0;
|
|
256
|
+
retry = void 0;
|
|
257
|
+
},
|
|
258
|
+
check,
|
|
259
|
+
report
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
//#endregion
|
|
264
|
+
//#region ../../packages/devtools/src/production/insights/insights.ts
|
|
265
|
+
const DEFAULT_INSIGHT_LIMIT = 100;
|
|
266
|
+
const MAX_INSIGHT_LIMIT = 500;
|
|
267
|
+
/** Reports fresher than this are merged into the views. */
|
|
268
|
+
const FRESH_MS = 6e4;
|
|
269
|
+
/** The instances list reaches back this far. */
|
|
270
|
+
const INSTANCES_MS = 3e5;
|
|
271
|
+
function limitOf(query) {
|
|
272
|
+
const limit = query.limit ?? 100;
|
|
273
|
+
return Math.min(500, Math.max(1, Math.floor(limit)));
|
|
274
|
+
}
|
|
275
|
+
function matches(value, needle) {
|
|
276
|
+
return !needle || value.toLowerCase().includes(needle.toLowerCase());
|
|
277
|
+
}
|
|
278
|
+
function infoOf(report) {
|
|
279
|
+
return {
|
|
280
|
+
...report.instance,
|
|
281
|
+
seenAt: report.at
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function build(load, sampleRateOf) {
|
|
285
|
+
/** The fresh reports of the selected instance(s). */
|
|
286
|
+
async function select(query, windowMs = FRESH_MS) {
|
|
287
|
+
const reports = await load(windowMs);
|
|
288
|
+
return query.instance === "all" ? reports : reports.filter((report) => report.instance.id === query.instance);
|
|
289
|
+
}
|
|
290
|
+
const insights = {
|
|
291
|
+
async instances() {
|
|
292
|
+
const reports = await load(INSTANCES_MS);
|
|
293
|
+
const infos = reports.map(infoOf).sort((a, b) => b.seenAt - a.seenAt);
|
|
294
|
+
return {
|
|
295
|
+
current: current(reports),
|
|
296
|
+
instances: infos
|
|
297
|
+
};
|
|
298
|
+
},
|
|
299
|
+
async resources(query) {
|
|
300
|
+
return { instances: (await select(query)).map((report) => ({
|
|
301
|
+
instance: infoOf(report),
|
|
302
|
+
snapshot: report.resources.snapshot,
|
|
303
|
+
history: report.resources.history
|
|
304
|
+
})) };
|
|
305
|
+
},
|
|
306
|
+
async queryStats(query) {
|
|
307
|
+
const reports = await select(query);
|
|
308
|
+
const sort = query.sort ?? "total";
|
|
309
|
+
const rows = mergeQueryShapeStats(reports.map((report) => ({
|
|
310
|
+
instance: report.instance.id,
|
|
311
|
+
shapes: report.queries
|
|
312
|
+
}))).map((shape) => ({
|
|
313
|
+
...shape,
|
|
314
|
+
p50Ms: require_histogram.histogramQuantile(shape.histogram, .5),
|
|
315
|
+
p95Ms: require_histogram.histogramQuantile(shape.histogram, .95),
|
|
316
|
+
meanMs: require_histogram.histogramMean(shape.histogram)
|
|
317
|
+
}));
|
|
318
|
+
const key = {
|
|
319
|
+
total: (row) => row.histogram.sumMs,
|
|
320
|
+
p95: (row) => row.p95Ms,
|
|
321
|
+
count: (row) => row.count,
|
|
322
|
+
"n+1": (row) => row.nPlusOne.requests * 1e6 + row.nPlusOne.maxPerRequest
|
|
323
|
+
};
|
|
324
|
+
const by = key[sort] ?? key.total;
|
|
325
|
+
return {
|
|
326
|
+
shapes: rows.sort((a, b) => by(b) - by(a)).slice(0, limitOf(query)),
|
|
327
|
+
sampleRate: sampleRateOf(reports),
|
|
328
|
+
instanceCount: reports.length,
|
|
329
|
+
evicted: reports.reduce((sum, report) => sum + report.capture.evictedShapes, 0)
|
|
330
|
+
};
|
|
331
|
+
},
|
|
332
|
+
async routeStats(query) {
|
|
333
|
+
const reports = await select(query);
|
|
334
|
+
const sort = query.sort ?? "total";
|
|
335
|
+
const rows = mergeRouteStats(reports.map((report) => ({
|
|
336
|
+
instance: report.instance.id,
|
|
337
|
+
routes: report.routes
|
|
338
|
+
}))).map((route) => ({
|
|
339
|
+
...route,
|
|
340
|
+
p50Ms: require_histogram.histogramQuantile(route.histogram, .5),
|
|
341
|
+
p95Ms: require_histogram.histogramQuantile(route.histogram, .95),
|
|
342
|
+
meanMs: require_histogram.histogramMean(route.histogram)
|
|
343
|
+
}));
|
|
344
|
+
const key = {
|
|
345
|
+
total: (row) => row.histogram.sumMs,
|
|
346
|
+
p95: (row) => row.p95Ms,
|
|
347
|
+
count: (row) => row.count,
|
|
348
|
+
errors: (row) => row.errors
|
|
349
|
+
};
|
|
350
|
+
const by = key[sort] ?? key.total;
|
|
351
|
+
return {
|
|
352
|
+
routes: rows.sort((a, b) => by(b) - by(a)).slice(0, limitOf(query)),
|
|
353
|
+
sampleRate: sampleRateOf(reports),
|
|
354
|
+
instanceCount: reports.length
|
|
355
|
+
};
|
|
356
|
+
},
|
|
357
|
+
async health(query) {
|
|
358
|
+
return { instances: (await select(query)).map((report) => ({
|
|
359
|
+
instance: infoOf(report),
|
|
360
|
+
report: report.health
|
|
361
|
+
})) };
|
|
362
|
+
},
|
|
363
|
+
async errors(query) {
|
|
364
|
+
const reports = await select(query);
|
|
365
|
+
return { groups: mergeErrorGroups(reports.map((report) => ({
|
|
366
|
+
instance: report.instance.id,
|
|
367
|
+
errors: report.errors
|
|
368
|
+
}))).slice(0, limitOf(query)) };
|
|
369
|
+
},
|
|
370
|
+
async logs(query) {
|
|
371
|
+
const reports = await select(query);
|
|
372
|
+
const rows = [];
|
|
373
|
+
for (const report of reports) for (const entry of report.logs) {
|
|
374
|
+
if (!matches(entry.level, query.level) || !matches(entry.module, query.module)) continue;
|
|
375
|
+
rows.push({
|
|
376
|
+
...entry,
|
|
377
|
+
instance: report.instance.id
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
return rows.sort((a, b) => b.at - a.at).slice(0, limitOf(query));
|
|
381
|
+
},
|
|
382
|
+
async jobs(query) {
|
|
383
|
+
return { instances: (await select(query)).map((report) => ({
|
|
384
|
+
instance: infoOf(report),
|
|
385
|
+
report: report.jobs
|
|
386
|
+
})) };
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
let currentId = "";
|
|
390
|
+
function current(reports) {
|
|
391
|
+
return currentId || reports[0]?.instance.id || "";
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
insights,
|
|
395
|
+
setCurrent(id) {
|
|
396
|
+
currentId = id;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
/** The sample rate the counts come from: the lowest any selected instance used (1 when none). */
|
|
401
|
+
function lowestRate(reports) {
|
|
402
|
+
return reports.length === 0 ? 1 : Math.min(...reports.map((r) => r.capture.sampleRate));
|
|
403
|
+
}
|
|
404
|
+
/** Development insights: this process only. */
|
|
405
|
+
function createLocalInsights(reporter) {
|
|
406
|
+
const { insights, setCurrent } = build(async () => [await reporter.snapshot()], lowestRate);
|
|
407
|
+
setCurrent(reporter.instance.id);
|
|
408
|
+
return insights;
|
|
409
|
+
}
|
|
410
|
+
/** Production insights: merged instance reports from the store plus this process live. */
|
|
411
|
+
function createSharedInsights(input) {
|
|
412
|
+
const { store, reporter, sampleRate } = input;
|
|
413
|
+
const { insights, setCurrent } = build(async (windowMs) => {
|
|
414
|
+
const live = await reporter.snapshot();
|
|
415
|
+
let stored = [];
|
|
416
|
+
try {
|
|
417
|
+
stored = await store.reports.list(live.at - windowMs);
|
|
418
|
+
} catch {}
|
|
419
|
+
return [live, ...stored.filter((report) => report.instance.id !== live.instance.id)];
|
|
420
|
+
}, () => sampleRate);
|
|
421
|
+
setCurrent(reporter.instance.id);
|
|
422
|
+
return insights;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
//#endregion
|
|
426
|
+
//#region ../../packages/devtools/src/production/insights/instance.ts
|
|
427
|
+
/** This process's identity (host, pid, pm2/cluster worker, start time). */
|
|
428
|
+
function createInstanceInfo(now = Date.now()) {
|
|
429
|
+
const host = node_os.default.hostname();
|
|
430
|
+
const pid = process.pid;
|
|
431
|
+
const worker = process.env.NODE_APP_INSTANCE || process.env.pm_id || (node_cluster.default.worker ? String(node_cluster.default.worker.id) : null);
|
|
432
|
+
return {
|
|
433
|
+
id: `${host}:${pid}:${now.toString(36)}`,
|
|
434
|
+
label: worker === null ? `${host} pid ${pid}` : `${host} #${worker}`,
|
|
435
|
+
host,
|
|
436
|
+
pid,
|
|
437
|
+
worker,
|
|
438
|
+
startedAt: now,
|
|
439
|
+
seenAt: now,
|
|
440
|
+
nodeVersion: process.version
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region ../../packages/devtools/src/production/insights/jobs.ts
|
|
446
|
+
const SCHEDULER_KEY = Symbol.for("warlock.scheduler.running");
|
|
447
|
+
/** Imports an optional package by name; `null` when it is not installed. */
|
|
448
|
+
async function importOptional(name) {
|
|
449
|
+
try {
|
|
450
|
+
return await import(
|
|
451
|
+
/* @vite-ignore */
|
|
452
|
+
name
|
|
453
|
+
);
|
|
454
|
+
} catch {
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
const defaultLoaders = {
|
|
459
|
+
async scheduler() {
|
|
460
|
+
if (!await importOptional("@warlock.js/scheduler")) return null;
|
|
461
|
+
const running = globalThis[SCHEDULER_KEY];
|
|
462
|
+
const jobs = [];
|
|
463
|
+
for (const scheduler of running ?? []) if (typeof scheduler.list === "function") jobs.push(...scheduler.list());
|
|
464
|
+
return jobs;
|
|
465
|
+
},
|
|
466
|
+
async queue() {
|
|
467
|
+
const current = (await importOptional("@warlock.js/queue"))?.currentQueueDriver;
|
|
468
|
+
const driver = current?.();
|
|
469
|
+
if (!driver || typeof driver.counts !== "function" || typeof driver.running !== "function") return null;
|
|
470
|
+
const queues = [];
|
|
471
|
+
for (const name of driver.running()) queues.push({
|
|
472
|
+
name,
|
|
473
|
+
counts: await driver.counts(name)
|
|
474
|
+
});
|
|
475
|
+
return queues;
|
|
476
|
+
}
|
|
477
|
+
};
|
|
478
|
+
function readableInterval(job) {
|
|
479
|
+
const every = job.intervals?.every;
|
|
480
|
+
if (!every?.type) return null;
|
|
481
|
+
const value = every.value ?? 1;
|
|
482
|
+
const unit = every.type.replace(/s$/, "");
|
|
483
|
+
return value === 1 ? `every ${unit}` : `every ${value} ${unit}s`;
|
|
484
|
+
}
|
|
485
|
+
function toSchedule(job) {
|
|
486
|
+
return {
|
|
487
|
+
name: job.name,
|
|
488
|
+
cron: job.cronExpression ?? null,
|
|
489
|
+
interval: readableInterval(job),
|
|
490
|
+
isRunning: job.isRunning === true,
|
|
491
|
+
lastRunAt: job.lastRun ? Number(job.lastRun.valueOf()) : null,
|
|
492
|
+
nextRunAt: job.nextRun ? Number(job.nextRun.valueOf()) : null,
|
|
493
|
+
lastDurationMs: null,
|
|
494
|
+
lastError: null,
|
|
495
|
+
runs: 0,
|
|
496
|
+
failures: 0
|
|
497
|
+
};
|
|
498
|
+
}
|
|
499
|
+
/**
|
|
500
|
+
* Reads the scheduler's jobs and the queue's counts when those packages are
|
|
501
|
+
* installed. A part that is absent or fails reports `available: false` with
|
|
502
|
+
* nothing else; the reader itself never throws.
|
|
503
|
+
*/
|
|
504
|
+
function createJobsReader(loaders = {}) {
|
|
505
|
+
const source = {
|
|
506
|
+
...defaultLoaders,
|
|
507
|
+
...loaders
|
|
508
|
+
};
|
|
509
|
+
return async () => {
|
|
510
|
+
const report = {
|
|
511
|
+
available: {
|
|
512
|
+
scheduler: false,
|
|
513
|
+
queue: false
|
|
514
|
+
},
|
|
515
|
+
schedules: [],
|
|
516
|
+
queues: []
|
|
517
|
+
};
|
|
518
|
+
try {
|
|
519
|
+
const jobs = await source.scheduler();
|
|
520
|
+
if (jobs) {
|
|
521
|
+
report.available.scheduler = true;
|
|
522
|
+
report.schedules = jobs.map(toSchedule);
|
|
523
|
+
}
|
|
524
|
+
} catch {
|
|
525
|
+
report.available.scheduler = false;
|
|
526
|
+
report.schedules = [];
|
|
527
|
+
}
|
|
528
|
+
try {
|
|
529
|
+
const queues = await source.queue();
|
|
530
|
+
if (queues) {
|
|
531
|
+
report.available.queue = true;
|
|
532
|
+
report.queues = queues;
|
|
533
|
+
}
|
|
534
|
+
} catch {
|
|
535
|
+
report.available.queue = false;
|
|
536
|
+
report.queues = [];
|
|
537
|
+
}
|
|
538
|
+
return report;
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
//#endregion
|
|
543
|
+
//#region ../../packages/devtools/src/production/insights/reporter.ts
|
|
544
|
+
const emptyJobs = () => ({
|
|
545
|
+
available: {
|
|
546
|
+
scheduler: false,
|
|
547
|
+
queue: false
|
|
548
|
+
},
|
|
549
|
+
schedules: [],
|
|
550
|
+
queues: []
|
|
551
|
+
});
|
|
552
|
+
/** This process's report from its parts (production: from the capture; development: from the dev stats). */
|
|
553
|
+
function createLocalReporter(parts) {
|
|
554
|
+
const now = parts.now ?? Date.now;
|
|
555
|
+
return {
|
|
556
|
+
instance: parts.instance,
|
|
557
|
+
async snapshot() {
|
|
558
|
+
const at = now();
|
|
559
|
+
let jobs;
|
|
560
|
+
try {
|
|
561
|
+
jobs = await parts.jobs();
|
|
562
|
+
} catch {
|
|
563
|
+
jobs = emptyJobs();
|
|
564
|
+
}
|
|
565
|
+
const capture = parts.counters ? parts.counters() : {
|
|
566
|
+
sampleRate: 1,
|
|
567
|
+
requests: 0,
|
|
568
|
+
sampled: 0,
|
|
569
|
+
keptUnsampled: 0,
|
|
570
|
+
stored: 0,
|
|
571
|
+
droppedStored: 0,
|
|
572
|
+
evictedShapes: parts.queries.evicted(),
|
|
573
|
+
evictedRoutes: parts.routes.evicted(),
|
|
574
|
+
evictedErrors: parts.errors.evicted(),
|
|
575
|
+
droppedQueries: 0
|
|
576
|
+
};
|
|
577
|
+
return {
|
|
578
|
+
instance: {
|
|
579
|
+
...parts.instance,
|
|
580
|
+
seenAt: at
|
|
581
|
+
},
|
|
582
|
+
at,
|
|
583
|
+
resources: {
|
|
584
|
+
snapshot: parts.resources.snapshot(),
|
|
585
|
+
history: parts.resources.history()
|
|
586
|
+
},
|
|
587
|
+
queries: parts.queries.snapshot(200),
|
|
588
|
+
routes: parts.routes.snapshot(200),
|
|
589
|
+
errors: parts.errors.snapshot(50),
|
|
590
|
+
logs: parts.logs.snapshot(50),
|
|
591
|
+
health: parts.health.report(),
|
|
592
|
+
jobs,
|
|
593
|
+
capture
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
//#endregion
|
|
600
|
+
//#region ../../packages/devtools/src/production/insights/resources.ts
|
|
601
|
+
function gcKindName(kind) {
|
|
602
|
+
if (kind === node_perf_hooks.constants.NODE_PERFORMANCE_GC_MAJOR) return "major";
|
|
603
|
+
if (kind === node_perf_hooks.constants.NODE_PERFORMANCE_GC_INCREMENTAL) return "incremental";
|
|
604
|
+
if (kind === node_perf_hooks.constants.NODE_PERFORMANCE_GC_WEAKCB) return "weakcb";
|
|
605
|
+
return "minor";
|
|
606
|
+
}
|
|
607
|
+
const defaultSources = {
|
|
608
|
+
now: () => Date.now(),
|
|
609
|
+
memoryUsage: () => process.memoryUsage(),
|
|
610
|
+
cpuUsage: () => process.cpuUsage(),
|
|
611
|
+
heapLimit: () => node_v8.default.getHeapStatistics().heap_size_limit,
|
|
612
|
+
uptime: () => process.uptime(),
|
|
613
|
+
eventLoopDelay: () => (0, node_perf_hooks.monitorEventLoopDelay)({ resolution: 20 }),
|
|
614
|
+
eventLoopUtilization: () => node_perf_hooks.performance.eventLoopUtilization(),
|
|
615
|
+
observeGc(onGc) {
|
|
616
|
+
const observer = new node_perf_hooks.PerformanceObserver((list) => {
|
|
617
|
+
for (const entry of list.getEntries()) onGc(gcKindName(entry.detail?.kind ?? entry.kind), entry.duration);
|
|
618
|
+
});
|
|
619
|
+
observer.observe({ entryTypes: ["gc"] });
|
|
620
|
+
return () => observer.disconnect();
|
|
621
|
+
}
|
|
622
|
+
};
|
|
623
|
+
/** Nanoseconds to milliseconds; a histogram with no samples reports 0. */
|
|
624
|
+
function nsToMs(value) {
|
|
625
|
+
return Number.isFinite(value) && value > 0 && value < 0x38d7ea4c68000 ? value / 1e6 : 0;
|
|
626
|
+
}
|
|
627
|
+
/** Resource sampling every `intervalMs` (default 5000), `historySize` points (default 120). */
|
|
628
|
+
function createResourceMonitor(options = {}) {
|
|
629
|
+
const intervalMs = options.intervalMs ?? 5e3;
|
|
630
|
+
const historySize = Math.max(1, options.historySize ?? 120);
|
|
631
|
+
const sources = {
|
|
632
|
+
...defaultSources,
|
|
633
|
+
...options.sources
|
|
634
|
+
};
|
|
635
|
+
const loopDelay = sources.eventLoopDelay();
|
|
636
|
+
const points = [];
|
|
637
|
+
const gcByKind = {
|
|
638
|
+
minor: {
|
|
639
|
+
count: 0,
|
|
640
|
+
pauseMs: 0
|
|
641
|
+
},
|
|
642
|
+
major: {
|
|
643
|
+
count: 0,
|
|
644
|
+
pauseMs: 0
|
|
645
|
+
},
|
|
646
|
+
incremental: {
|
|
647
|
+
count: 0,
|
|
648
|
+
pauseMs: 0
|
|
649
|
+
},
|
|
650
|
+
weakcb: {
|
|
651
|
+
count: 0,
|
|
652
|
+
pauseMs: 0
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
let gcCountSince = 0;
|
|
656
|
+
let gcPauseSince = 0;
|
|
657
|
+
let lastAt = sources.now();
|
|
658
|
+
let lastCpu = sources.cpuUsage();
|
|
659
|
+
let lastElu = sources.eventLoopUtilization();
|
|
660
|
+
let timer;
|
|
661
|
+
let stopGc;
|
|
662
|
+
function sample() {
|
|
663
|
+
const at = sources.now();
|
|
664
|
+
const memory = sources.memoryUsage();
|
|
665
|
+
const cpu = sources.cpuUsage();
|
|
666
|
+
const elu = sources.eventLoopUtilization();
|
|
667
|
+
const wallMs = at - lastAt;
|
|
668
|
+
const cpuMs = (cpu.user + cpu.system - lastCpu.user - lastCpu.system) / 1e3;
|
|
669
|
+
const active = elu.active - lastElu.active;
|
|
670
|
+
const idle = elu.idle - lastElu.idle;
|
|
671
|
+
const point = {
|
|
672
|
+
at,
|
|
673
|
+
rssBytes: memory.rss,
|
|
674
|
+
heapUsedBytes: memory.heapUsed,
|
|
675
|
+
heapTotalBytes: memory.heapTotal,
|
|
676
|
+
externalBytes: memory.external,
|
|
677
|
+
cpuPercent: wallMs > 0 ? Math.max(0, cpuMs / wallMs * 100) : 0,
|
|
678
|
+
eventLoopDelayP50Ms: nsToMs(loopDelay.percentile(50)),
|
|
679
|
+
eventLoopDelayP99Ms: nsToMs(loopDelay.percentile(99)),
|
|
680
|
+
eventLoopDelayMaxMs: nsToMs(loopDelay.max),
|
|
681
|
+
eventLoopUtilization: active + idle > 0 ? active / (active + idle) : 0,
|
|
682
|
+
gcCount: gcCountSince,
|
|
683
|
+
gcPauseMs: gcPauseSince
|
|
684
|
+
};
|
|
685
|
+
loopDelay.reset();
|
|
686
|
+
lastAt = at;
|
|
687
|
+
lastCpu = cpu;
|
|
688
|
+
lastElu = elu;
|
|
689
|
+
gcCountSince = 0;
|
|
690
|
+
gcPauseSince = 0;
|
|
691
|
+
points.push(point);
|
|
692
|
+
if (points.length > historySize) points.splice(0, points.length - historySize);
|
|
693
|
+
return { ...point };
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
start() {
|
|
697
|
+
if (timer) return;
|
|
698
|
+
lastAt = sources.now();
|
|
699
|
+
lastCpu = sources.cpuUsage();
|
|
700
|
+
lastElu = sources.eventLoopUtilization();
|
|
701
|
+
loopDelay.enable();
|
|
702
|
+
stopGc = sources.observeGc((kind, durationMs) => {
|
|
703
|
+
gcCountSince++;
|
|
704
|
+
gcPauseSince += durationMs;
|
|
705
|
+
gcByKind[kind].count++;
|
|
706
|
+
gcByKind[kind].pauseMs += durationMs;
|
|
707
|
+
});
|
|
708
|
+
timer = setInterval(sample, intervalMs);
|
|
709
|
+
timer.unref();
|
|
710
|
+
},
|
|
711
|
+
stop() {
|
|
712
|
+
if (timer) clearInterval(timer);
|
|
713
|
+
timer = void 0;
|
|
714
|
+
stopGc?.();
|
|
715
|
+
stopGc = void 0;
|
|
716
|
+
loopDelay.disable();
|
|
717
|
+
},
|
|
718
|
+
sample,
|
|
719
|
+
snapshot() {
|
|
720
|
+
return {
|
|
721
|
+
...points[points.length - 1] ?? sample(),
|
|
722
|
+
heapLimitBytes: sources.heapLimit(),
|
|
723
|
+
uptimeSeconds: sources.uptime(),
|
|
724
|
+
gcByKind: structuredClone(gcByKind)
|
|
725
|
+
};
|
|
726
|
+
},
|
|
727
|
+
history() {
|
|
728
|
+
return points.map((point) => ({ ...point }));
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
//#endregion
|
|
734
|
+
//#region ../../packages/devtools/src/production/insights/writer.ts
|
|
735
|
+
const HOUSEKEEPING_INTERVAL_MS = 6e5;
|
|
736
|
+
const REPORT_MAX_AGE_MS = 3e5;
|
|
737
|
+
const WARN_EVERY_MS = 6e4;
|
|
738
|
+
/**
|
|
739
|
+
* Writes the report every `production.reportIntervalMs`, and every 10
|
|
740
|
+
* minutes prunes: reports unseen for 5 minutes, samples older than
|
|
741
|
+
* `requestRetentionHours`, expired sessions and invites, audit entries older
|
|
742
|
+
* than `auditRetentionDays`. Timers are `unref`ed; a failed write is logged
|
|
743
|
+
* once per minute, never thrown.
|
|
744
|
+
*/
|
|
745
|
+
function startReportWriter(input) {
|
|
746
|
+
const { reporter, store, production, warn } = input;
|
|
747
|
+
let stopped = false;
|
|
748
|
+
let lastWarnAt = Number.NEGATIVE_INFINITY;
|
|
749
|
+
let pending = Promise.resolve();
|
|
750
|
+
function fail(what, error) {
|
|
751
|
+
const now = Date.now();
|
|
752
|
+
if (!warn || now - lastWarnAt < WARN_EVERY_MS) return;
|
|
753
|
+
lastWarnAt = now;
|
|
754
|
+
const reason = error instanceof Error ? error.message : String(error);
|
|
755
|
+
warn(`Devtools could not ${what}: ${reason}. It will try again.`);
|
|
756
|
+
}
|
|
757
|
+
async function write() {
|
|
758
|
+
if (stopped) return;
|
|
759
|
+
try {
|
|
760
|
+
await store.reports.write(capReportSize(await reporter.snapshot()));
|
|
761
|
+
} catch (error) {
|
|
762
|
+
fail("write this instance's report to the database", error);
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
async function housekeeping() {
|
|
766
|
+
if (stopped) return;
|
|
767
|
+
const now = Date.now();
|
|
768
|
+
const steps = [
|
|
769
|
+
["remove old instance reports", () => store.reports.prune(now - REPORT_MAX_AGE_MS)],
|
|
770
|
+
["remove old request samples", () => store.samples.prune(now - production.requestRetentionHours * 36e5)],
|
|
771
|
+
["remove expired sessions", () => store.sessions.removeExpired(now)],
|
|
772
|
+
["remove expired invites", () => store.invites.removeExpired(now)],
|
|
773
|
+
["remove old audit entries", () => store.audit.prune(now - production.auditRetentionDays * 864e5)]
|
|
774
|
+
];
|
|
775
|
+
for (const [what, step] of steps) try {
|
|
776
|
+
await step();
|
|
777
|
+
} catch (error) {
|
|
778
|
+
fail(what, error);
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
function enqueue(task) {
|
|
782
|
+
pending = pending.then(task);
|
|
783
|
+
return pending;
|
|
784
|
+
}
|
|
785
|
+
const writeTimer = setInterval(() => void enqueue(write), production.reportIntervalMs);
|
|
786
|
+
const housekeepingTimer = setInterval(() => void enqueue(housekeeping), HOUSEKEEPING_INTERVAL_MS);
|
|
787
|
+
writeTimer.unref();
|
|
788
|
+
housekeepingTimer.unref();
|
|
789
|
+
enqueue(write);
|
|
790
|
+
return {
|
|
791
|
+
writeNow: () => enqueue(write),
|
|
792
|
+
async stop() {
|
|
793
|
+
stopped = true;
|
|
794
|
+
clearInterval(writeTimer);
|
|
795
|
+
clearInterval(housekeepingTimer);
|
|
796
|
+
await pending;
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
//#endregion
|
|
802
|
+
exports.capReportSize = capReportSize;
|
|
803
|
+
exports.createHealthHistory = createHealthHistory;
|
|
804
|
+
exports.createInstanceInfo = createInstanceInfo;
|
|
805
|
+
exports.createJobsReader = createJobsReader;
|
|
806
|
+
exports.createLocalInsights = createLocalInsights;
|
|
807
|
+
exports.createLocalReporter = createLocalReporter;
|
|
808
|
+
exports.createResourceMonitor = createResourceMonitor;
|
|
809
|
+
exports.createSharedInsights = createSharedInsights;
|
|
810
|
+
exports.startReportWriter = startReportWriter;
|
|
811
|
+
//# sourceMappingURL=insights-BKtqxdnP.cjs.map
|