@foxford/den 4.0.0 → 4.2.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/README.mdx +43 -4
- package/adapter.cjs +2 -3
- package/adapter.js +1 -2
- package/bin/den.cjs +31 -51
- package/bin/den.js +31 -51
- package/builder/index.cjs +2 -3
- package/builder/index.d.cts +3 -2
- package/builder/index.d.ts +3 -2
- package/builder/index.js +1 -2
- package/{chunk-E56BKBQZ.js → chunk-AS6ZNCUY.js} +7 -7
- package/{chunk-H5DKRHHQ.cjs → chunk-BFRLBMH2.cjs} +8 -8
- package/chunk-ETO2T2TA.cjs +503 -0
- package/{chunk-E23E2VUC.js → chunk-HWDDAFGV.js} +1 -1
- package/{chunk-XQ7EHXHG.js → chunk-JW24N6O4.js} +47 -55
- package/{chunk-2P5TAWRW.cjs → chunk-MH2WIOTQ.cjs} +65 -60
- package/{chunk-XOJ2VWX4.cjs → chunk-MWDNN7Q4.cjs} +1 -1
- package/{chunk-QTWJTYZW.cjs → chunk-NOI7FSBX.cjs} +47 -55
- package/{chunk-DUU4MQ4B.js → chunk-VCIMVMHG.js} +64 -59
- package/{chunk-WBHHHICS.js → chunk-WKCIOQOY.js} +1 -1
- package/{chunk-C7BM4DGX.cjs → chunk-Y7DGFJFA.cjs} +1 -1
- package/chunk-YWWRJMWN.js +503 -0
- package/define.cjs +3 -4
- package/define.js +2 -3
- package/index.cjs +54 -71
- package/index.js +53 -70
- package/island/index.cjs +5 -8
- package/island/index.js +4 -7
- package/ops/index.cjs +2 -3
- package/ops/index.js +1 -2
- package/package.json +17 -18
- package/serve/index.cjs +294 -108
- package/serve/index.d.cts +11 -1
- package/serve/index.d.ts +11 -1
- package/serve/index.js +293 -107
- package/chunk-6FNC3XMI.js +0 -45
- package/chunk-FMRORLLE.js +0 -558
- package/chunk-OC4LQ2CK.cjs +0 -558
- package/chunk-T5QVCXVB.cjs +0 -45
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
-
|
|
3
|
-
var _chunkT5QVCXVBcjs = require('./chunk-T5QVCXVB.cjs');
|
|
4
|
-
|
|
5
|
-
// src/ops/index.ts
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/ops/index.ts
|
|
6
2
|
var _http = require('http');
|
|
7
3
|
var _client = require('@prometheus-io/client');
|
|
8
4
|
|
|
@@ -11,17 +7,30 @@ var _client = require('@prometheus-io/client');
|
|
|
11
7
|
|
|
12
8
|
// src/ops/runtime.ts
|
|
13
9
|
var _cluster = require('cluster'); var _cluster2 = _interopRequireDefault(_cluster);
|
|
10
|
+
var _perf_hooks = require('perf_hooks');
|
|
14
11
|
|
|
15
12
|
function collectRuntime(registry, appName) {
|
|
16
13
|
registry.setDefaultLabels({ app: appName, process_role: _cluster2.default.isWorker ? "worker" : "main" });
|
|
17
14
|
_client.collectDefaultMetrics.call(void 0, { register: registry });
|
|
15
|
+
let previousElu = _perf_hooks.performance.eventLoopUtilization();
|
|
16
|
+
new (0, _client.Gauge)({
|
|
17
|
+
aggregator: "max",
|
|
18
|
+
collect() {
|
|
19
|
+
const current = _perf_hooks.performance.eventLoopUtilization();
|
|
20
|
+
this.set(_perf_hooks.performance.eventLoopUtilization(current, previousElu).utilization);
|
|
21
|
+
previousElu = current;
|
|
22
|
+
},
|
|
23
|
+
help: "Event loop utilization since the last scrape; maximum across workers",
|
|
24
|
+
name: "nodejs_eventloop_utilization_ratio",
|
|
25
|
+
registers: [registry]
|
|
26
|
+
});
|
|
18
27
|
let previousCpu = process.cpuUsage();
|
|
19
|
-
let previousTime = performance.now();
|
|
28
|
+
let previousTime = _perf_hooks.performance.now();
|
|
20
29
|
new (0, _client.Gauge)({
|
|
21
30
|
aggregator: "sum",
|
|
22
31
|
collect() {
|
|
23
32
|
const currentCpu = process.cpuUsage();
|
|
24
|
-
const currentTime = performance.now();
|
|
33
|
+
const currentTime = _perf_hooks.performance.now();
|
|
25
34
|
const elapsed = currentTime - previousTime;
|
|
26
35
|
this.set(
|
|
27
36
|
elapsed > 0 ? (currentCpu.user - previousCpu.user + currentCpu.system - previousCpu.system) / (elapsed * 1e3) : 0
|
|
@@ -70,8 +79,8 @@ function collectRuntime(registry, appName) {
|
|
|
70
79
|
collect() {
|
|
71
80
|
this.set(process.resourceUsage()[field]);
|
|
72
81
|
},
|
|
73
|
-
help:
|
|
74
|
-
name:
|
|
82
|
+
help: "Process ".concat(name, " since startup"),
|
|
83
|
+
name: "process_".concat(name, "_total"),
|
|
75
84
|
registers: [registry]
|
|
76
85
|
});
|
|
77
86
|
}
|
|
@@ -156,64 +165,60 @@ function clusterMetrics(metrics = getProcessMetrics()) {
|
|
|
156
165
|
shutdown: () => lifecycle.shutdown()
|
|
157
166
|
};
|
|
158
167
|
}
|
|
159
|
-
function startOpsServer() {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
async function startOpsServer(options = {}) {
|
|
169
|
+
var _a;
|
|
170
|
+
const metrics = (_a = options.metrics) != null ? _a : getProcessMetrics();
|
|
171
|
+
const server = _http.createServer.call(void 0, (req, res) => {
|
|
172
|
+
var _a2, _b, _c, _d;
|
|
173
|
+
const path = (_a2 = req.url) == null ? void 0 : _a2.split("?")[0];
|
|
174
|
+
res.setHeader("cache-control", "no-store");
|
|
175
|
+
if (req.method !== "GET" || !["/healthz", "/livez", "/metrics"].includes(path != null ? path : "")) {
|
|
176
|
+
res.writeHead(404).end();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (path !== "/metrics") {
|
|
180
|
+
res.writeHead(path === "/livez" && ((_b = options.isLive) == null ? void 0 : _b.call(options)) === false ? 503 : 200, {
|
|
181
|
+
"content-type": "text/plain; charset=utf-8"
|
|
182
|
+
}).end("ok");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
void ((_d = (_c = options.collect) == null ? void 0 : _c.call(options)) != null ? _d : metrics.registry.metrics()).then((body) => {
|
|
186
|
+
var _a3;
|
|
187
|
+
if (!res.destroyed) {
|
|
188
|
+
res.writeHead(200, { "content-type": (_a3 = options.contentType) != null ? _a3 : metrics.registry.contentType }).end(body);
|
|
170
189
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}).end("ok");
|
|
175
|
-
return;
|
|
190
|
+
}).catch(() => {
|
|
191
|
+
if (!res.destroyed) {
|
|
192
|
+
res.writeHead(503).end("metrics unavailable");
|
|
176
193
|
}
|
|
177
|
-
void ((_d = (_c = options.collect) == null ? void 0 : _c.call(options)) != null ? _d : metrics.registry.metrics()).then((body) => {
|
|
178
|
-
var _a3;
|
|
179
|
-
if (!res.destroyed) {
|
|
180
|
-
res.writeHead(200, { "content-type": (_a3 = options.contentType) != null ? _a3 : metrics.registry.contentType }).end(body);
|
|
181
|
-
}
|
|
182
|
-
}).catch(() => {
|
|
183
|
-
if (!res.destroyed) {
|
|
184
|
-
res.writeHead(503).end("metrics unavailable");
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
194
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
});
|
|
196
|
+
await new Promise((resolve, reject) => {
|
|
197
|
+
var _a2, _b;
|
|
198
|
+
server.once("error", reject);
|
|
199
|
+
server.listen((_a2 = options.port) != null ? _a2 : 9090, (_b = options.host) != null ? _b : "0.0.0.0", () => {
|
|
200
|
+
server.removeListener("error", reject);
|
|
201
|
+
resolve();
|
|
195
202
|
});
|
|
196
|
-
return server;
|
|
197
203
|
});
|
|
204
|
+
return server;
|
|
198
205
|
}
|
|
199
|
-
function closeHttpServer(server, timeoutMs = 5e3) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
server.closeIdleConnections();
|
|
206
|
+
async function closeHttpServer(server, timeoutMs = 5e3) {
|
|
207
|
+
if (!server.listening) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await new Promise((resolve, reject) => {
|
|
211
|
+
const timer = setTimeout(() => server.closeAllConnections(), timeoutMs);
|
|
212
|
+
timer.unref();
|
|
213
|
+
server.close((error) => {
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
if (error) {
|
|
216
|
+
reject(error);
|
|
217
|
+
} else {
|
|
218
|
+
resolve();
|
|
219
|
+
}
|
|
216
220
|
});
|
|
221
|
+
server.closeIdleConnections();
|
|
217
222
|
});
|
|
218
223
|
}
|
|
219
224
|
|
|
@@ -14,7 +14,7 @@ function viewAdapterOf(layer) {
|
|
|
14
14
|
function adapterOfConfig(config) {
|
|
15
15
|
if (!isViewAdapter(config.adapter)) {
|
|
16
16
|
throw new Error(
|
|
17
|
-
|
|
17
|
+
"den/island: view-\u0441\u043B\u043E\u0439 \xAB".concat(config.name, "\xBB \u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D \u0431\u0435\u0437 \u0430\u0434\u0430\u043F\u0442\u0435\u0440\u0430 \u2014 ") + "\u043E\u0436\u0438\u0434\u0430\u0435\u0442\u0441\u044F ViewAdapter (type + createIsland + renderIsland + installResolver), \u043D\u0430\u043F\u0440\u0438\u043C\u0435\u0440 reactAdapter()"
|
|
18
18
|
);
|
|
19
19
|
}
|
|
20
20
|
return config.adapter;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkMWDNN7Q4cjs = require('./chunk-MWDNN7Q4.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk6QV4L6R2cjs = require('./chunk-6QV4L6R2.cjs');
|
|
@@ -10,10 +10,6 @@ var _chunk6QV4L6R2cjs = require('./chunk-6QV4L6R2.cjs');
|
|
|
10
10
|
|
|
11
11
|
var _chunkA6ZPAM6Zcjs = require('./chunk-A6ZPAM6Z.cjs');
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _chunkT5QVCXVBcjs = require('./chunk-T5QVCXVB.cjs');
|
|
16
|
-
|
|
17
13
|
// src/island/document.ts
|
|
18
14
|
function isDocumentSource(value) {
|
|
19
15
|
return typeof value === "object" && value !== null && typeof value.describeDocument === "function";
|
|
@@ -39,7 +35,7 @@ function installRuntime(container, extensions) {
|
|
|
39
35
|
unit.register(container);
|
|
40
36
|
}
|
|
41
37
|
installed.push(extension);
|
|
42
|
-
((_a = _chunkA6ZPAM6Zcjs.logger.getLogger("island:runtime")) != null ? _a : _chunkA6ZPAM6Zcjs.logger).debug(
|
|
38
|
+
((_a = _chunkA6ZPAM6Zcjs.logger.getLogger("island:runtime")) != null ? _a : _chunkA6ZPAM6Zcjs.logger).debug("\u0440\u0430\u0441\u0448\u0438\u0440\u0435\u043D\u0438\u0435 \u0440\u0430\u043D\u0442\u0430\u0439\u043C\u0430 \xAB".concat(extension.name, "\xBB \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D\u043E"));
|
|
43
39
|
}
|
|
44
40
|
}
|
|
45
41
|
function bindInstalled(container) {
|
|
@@ -120,7 +116,7 @@ function registerIslandParts(container, descriptor, islandLog) {
|
|
|
120
116
|
const viewModels = (_b = descriptor.viewModels) != null ? _b : [];
|
|
121
117
|
const slots = Object.entries((_c = descriptor.slots) != null ? _c : {});
|
|
122
118
|
islandLog.info(
|
|
123
|
-
|
|
119
|
+
"\u043E\u0441\u0442\u0440\u043E\u0432: \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440 \u0441\u043E\u0437\u0434\u0430\u043D (units=".concat(descriptor.units.length, ", vms=").concat(viewModels.length, ", slots=").concat(slots.length, ")")
|
|
124
120
|
);
|
|
125
121
|
for (const unit of descriptor.units) {
|
|
126
122
|
unit.register(container);
|
|
@@ -160,18 +156,16 @@ function hydrateIslandState(container, descriptor, denState) {
|
|
|
160
156
|
}
|
|
161
157
|
}
|
|
162
158
|
}
|
|
163
|
-
function activateIslandViewModels(
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
);
|
|
174
|
-
});
|
|
159
|
+
async function activateIslandViewModels(container, descriptor, route = EMPTY_ROUTE) {
|
|
160
|
+
var _a;
|
|
161
|
+
await Promise.all(
|
|
162
|
+
((_a = descriptor.viewModels) != null ? _a : []).map(async (vm) => {
|
|
163
|
+
var _a2;
|
|
164
|
+
const instance = container.resolve(vm.token);
|
|
165
|
+
_chunkA6ZPAM6Zcjs.unitLogger.call(void 0, container, vm.token.description).debug("\u0430\u043A\u0442\u0438\u0432\u0430\u0446\u0438\u044F VM (".concat(route.pathname || "\u2014", ")"));
|
|
166
|
+
await ((_a2 = instance.activate) == null ? void 0 : _a2.call(instance, route));
|
|
167
|
+
})
|
|
168
|
+
);
|
|
175
169
|
}
|
|
176
170
|
function collectIslandState(container, descriptor) {
|
|
177
171
|
var _a, _b;
|
|
@@ -194,10 +188,10 @@ function collectDocumentContribution(container, descriptor) {
|
|
|
194
188
|
}
|
|
195
189
|
const part = instance.describeDocument();
|
|
196
190
|
if (part.head) {
|
|
197
|
-
contribution.head =
|
|
191
|
+
contribution.head = { ...contribution.head, ...part.head };
|
|
198
192
|
}
|
|
199
193
|
if (part.data) {
|
|
200
|
-
contribution.data =
|
|
194
|
+
contribution.data = { ...contribution.data, ...part.data };
|
|
201
195
|
}
|
|
202
196
|
if (part.assets && contribution.assets === void 0) {
|
|
203
197
|
contribution.assets = part.assets;
|
|
@@ -238,41 +232,39 @@ function setupOnce(descriptor) {
|
|
|
238
232
|
}
|
|
239
233
|
return started;
|
|
240
234
|
}
|
|
241
|
-
function renderApp(descriptor, request) {
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
235
|
+
async function renderApp(descriptor, request) {
|
|
236
|
+
var _a, _b, _c;
|
|
237
|
+
await setupOnce(descriptor);
|
|
238
|
+
const route = {
|
|
239
|
+
params: (_a = request.params) != null ? _a : {},
|
|
240
|
+
pathname: request.pathname,
|
|
241
|
+
search: (_b = request.search) != null ? _b : ""
|
|
242
|
+
};
|
|
243
|
+
const inputs = islandInputsOf(descriptor, request.inputs);
|
|
244
|
+
const container = createIslandContainer(descriptor, { context: request.context, inputs, parent: request.parent });
|
|
245
|
+
if (container === null) {
|
|
246
|
+
throw new Error("den/island: \u043F\u0440\u0438\u043B\u043E\u0436\u0435\u043D\u0438\u0435 \xAB".concat(descriptor.name, "\xBB \u043D\u0435 \u0441\u043E\u0431\u0440\u0430\u043B\u043E\u0441\u044C \u2014 \u0440\u0435\u043D\u0434\u0435\u0440 \u043D\u0435\u0432\u043E\u0437\u043C\u043E\u0436\u0435\u043D"));
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
await activateIslandViewModels(container, descriptor, route);
|
|
250
|
+
const contribution = collectDocumentContribution(container, descriptor);
|
|
251
|
+
const { data, head, redirect, status = STATUS_OK } = contribution;
|
|
252
|
+
if (status !== STATUS_OK) {
|
|
253
|
+
return { data, head, html: "", redirect, state: {}, status };
|
|
254
254
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
if (status !== STATUS_OK) {
|
|
260
|
-
return { data, head, html: "", redirect, state: {}, status };
|
|
261
|
-
}
|
|
262
|
-
const assets = (_c = contribution.assets) != null ? _c : descriptor.assets;
|
|
263
|
-
const state = _chunkT5QVCXVBcjs.__spreadValues.call(void 0, _chunkT5QVCXVBcjs.__spreadValues.call(void 0, {}, inputs), collectIslandState(container, descriptor));
|
|
264
|
-
if (descriptor.view === void 0 || descriptor.viewLayer === void 0) {
|
|
265
|
-
return { assets, data, head, html: "", state, status };
|
|
266
|
-
}
|
|
267
|
-
const rendered = _chunkXOJ2VWX4cjs.resolveViewAdapter.call(void 0, container).renderIsland(descriptor, {
|
|
268
|
-
container,
|
|
269
|
-
slots: request.slots
|
|
270
|
-
});
|
|
271
|
-
return { assets, data, head, headHtml: rendered.head, html: rendered.html, state, status };
|
|
272
|
-
} finally {
|
|
273
|
-
yield container.dispose();
|
|
255
|
+
const assets = (_c = contribution.assets) != null ? _c : descriptor.assets;
|
|
256
|
+
const state = { ...inputs, ...collectIslandState(container, descriptor) };
|
|
257
|
+
if (descriptor.view === void 0 || descriptor.viewLayer === void 0) {
|
|
258
|
+
return { assets, data, head, html: "", state, status };
|
|
274
259
|
}
|
|
275
|
-
|
|
260
|
+
const rendered = _chunkMWDNN7Q4cjs.resolveViewAdapter.call(void 0, container).renderIsland(descriptor, {
|
|
261
|
+
container,
|
|
262
|
+
slots: request.slots
|
|
263
|
+
});
|
|
264
|
+
return { assets, data, head, headHtml: rendered.head, html: rendered.html, state, status };
|
|
265
|
+
} finally {
|
|
266
|
+
await container.dispose();
|
|
267
|
+
}
|
|
276
268
|
}
|
|
277
269
|
|
|
278
270
|
// src/island/routes.ts
|
|
@@ -305,7 +297,7 @@ function decodeParams(groups) {
|
|
|
305
297
|
var REGEXP_SPECIALS = /[.*+?^${}()|[\]\\]/g;
|
|
306
298
|
var PARAM_SEGMENT = /\/:([A-Za-z_$][\w$]*)/g;
|
|
307
299
|
function pathPattern(pattern) {
|
|
308
|
-
return
|
|
300
|
+
return "^".concat(pattern.replace(REGEXP_SPECIALS, "\\$&").replace(PARAM_SEGMENT, "/(?<$1>[^/]+)"), "$");
|
|
309
301
|
}
|
|
310
302
|
|
|
311
303
|
|
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__async
|
|
3
|
-
} from "./chunk-6FNC3XMI.js";
|
|
4
|
-
|
|
5
1
|
// src/ops/index.ts
|
|
6
2
|
import { createServer } from "http";
|
|
7
3
|
import { ClusterRegistry } from "@prometheus-io/client";
|
|
@@ -11,17 +7,30 @@ import { Counter, Gauge as Gauge2, Histogram, Registry } from "@prometheus-io/cl
|
|
|
11
7
|
|
|
12
8
|
// src/ops/runtime.ts
|
|
13
9
|
import cluster from "cluster";
|
|
10
|
+
import { performance as performance2 } from "perf_hooks";
|
|
14
11
|
import { collectDefaultMetrics, Gauge } from "@prometheus-io/client";
|
|
15
12
|
function collectRuntime(registry, appName) {
|
|
16
13
|
registry.setDefaultLabels({ app: appName, process_role: cluster.isWorker ? "worker" : "main" });
|
|
17
14
|
collectDefaultMetrics({ register: registry });
|
|
15
|
+
let previousElu = performance2.eventLoopUtilization();
|
|
16
|
+
new Gauge({
|
|
17
|
+
aggregator: "max",
|
|
18
|
+
collect() {
|
|
19
|
+
const current = performance2.eventLoopUtilization();
|
|
20
|
+
this.set(performance2.eventLoopUtilization(current, previousElu).utilization);
|
|
21
|
+
previousElu = current;
|
|
22
|
+
},
|
|
23
|
+
help: "Event loop utilization since the last scrape; maximum across workers",
|
|
24
|
+
name: "nodejs_eventloop_utilization_ratio",
|
|
25
|
+
registers: [registry]
|
|
26
|
+
});
|
|
18
27
|
let previousCpu = process.cpuUsage();
|
|
19
|
-
let previousTime =
|
|
28
|
+
let previousTime = performance2.now();
|
|
20
29
|
new Gauge({
|
|
21
30
|
aggregator: "sum",
|
|
22
31
|
collect() {
|
|
23
32
|
const currentCpu = process.cpuUsage();
|
|
24
|
-
const currentTime =
|
|
33
|
+
const currentTime = performance2.now();
|
|
25
34
|
const elapsed = currentTime - previousTime;
|
|
26
35
|
this.set(
|
|
27
36
|
elapsed > 0 ? (currentCpu.user - previousCpu.user + currentCpu.system - previousCpu.system) / (elapsed * 1e3) : 0
|
|
@@ -70,8 +79,8 @@ function collectRuntime(registry, appName) {
|
|
|
70
79
|
collect() {
|
|
71
80
|
this.set(process.resourceUsage()[field]);
|
|
72
81
|
},
|
|
73
|
-
help:
|
|
74
|
-
name:
|
|
82
|
+
help: "Process ".concat(name, " since startup"),
|
|
83
|
+
name: "process_".concat(name, "_total"),
|
|
75
84
|
registers: [registry]
|
|
76
85
|
});
|
|
77
86
|
}
|
|
@@ -156,64 +165,60 @@ function clusterMetrics(metrics = getProcessMetrics()) {
|
|
|
156
165
|
shutdown: () => lifecycle.shutdown()
|
|
157
166
|
};
|
|
158
167
|
}
|
|
159
|
-
function startOpsServer() {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
async function startOpsServer(options = {}) {
|
|
169
|
+
var _a;
|
|
170
|
+
const metrics = (_a = options.metrics) != null ? _a : getProcessMetrics();
|
|
171
|
+
const server = createServer((req, res) => {
|
|
172
|
+
var _a2, _b, _c, _d;
|
|
173
|
+
const path = (_a2 = req.url) == null ? void 0 : _a2.split("?")[0];
|
|
174
|
+
res.setHeader("cache-control", "no-store");
|
|
175
|
+
if (req.method !== "GET" || !["/healthz", "/livez", "/metrics"].includes(path != null ? path : "")) {
|
|
176
|
+
res.writeHead(404).end();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
if (path !== "/metrics") {
|
|
180
|
+
res.writeHead(path === "/livez" && ((_b = options.isLive) == null ? void 0 : _b.call(options)) === false ? 503 : 200, {
|
|
181
|
+
"content-type": "text/plain; charset=utf-8"
|
|
182
|
+
}).end("ok");
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
void ((_d = (_c = options.collect) == null ? void 0 : _c.call(options)) != null ? _d : metrics.registry.metrics()).then((body) => {
|
|
186
|
+
var _a3;
|
|
187
|
+
if (!res.destroyed) {
|
|
188
|
+
res.writeHead(200, { "content-type": (_a3 = options.contentType) != null ? _a3 : metrics.registry.contentType }).end(body);
|
|
170
189
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}).end("ok");
|
|
175
|
-
return;
|
|
190
|
+
}).catch(() => {
|
|
191
|
+
if (!res.destroyed) {
|
|
192
|
+
res.writeHead(503).end("metrics unavailable");
|
|
176
193
|
}
|
|
177
|
-
void ((_d = (_c = options.collect) == null ? void 0 : _c.call(options)) != null ? _d : metrics.registry.metrics()).then((body) => {
|
|
178
|
-
var _a3;
|
|
179
|
-
if (!res.destroyed) {
|
|
180
|
-
res.writeHead(200, { "content-type": (_a3 = options.contentType) != null ? _a3 : metrics.registry.contentType }).end(body);
|
|
181
|
-
}
|
|
182
|
-
}).catch(() => {
|
|
183
|
-
if (!res.destroyed) {
|
|
184
|
-
res.writeHead(503).end("metrics unavailable");
|
|
185
|
-
}
|
|
186
|
-
});
|
|
187
194
|
});
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
});
|
|
196
|
+
await new Promise((resolve, reject) => {
|
|
197
|
+
var _a2, _b;
|
|
198
|
+
server.once("error", reject);
|
|
199
|
+
server.listen((_a2 = options.port) != null ? _a2 : 9090, (_b = options.host) != null ? _b : "0.0.0.0", () => {
|
|
200
|
+
server.removeListener("error", reject);
|
|
201
|
+
resolve();
|
|
195
202
|
});
|
|
196
|
-
return server;
|
|
197
203
|
});
|
|
204
|
+
return server;
|
|
198
205
|
}
|
|
199
|
-
function closeHttpServer(server, timeoutMs = 5e3) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
server.closeIdleConnections();
|
|
206
|
+
async function closeHttpServer(server, timeoutMs = 5e3) {
|
|
207
|
+
if (!server.listening) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
await new Promise((resolve, reject) => {
|
|
211
|
+
const timer = setTimeout(() => server.closeAllConnections(), timeoutMs);
|
|
212
|
+
timer.unref();
|
|
213
|
+
server.close((error) => {
|
|
214
|
+
clearTimeout(timer);
|
|
215
|
+
if (error) {
|
|
216
|
+
reject(error);
|
|
217
|
+
} else {
|
|
218
|
+
resolve();
|
|
219
|
+
}
|
|
216
220
|
});
|
|
221
|
+
server.closeIdleConnections();
|
|
217
222
|
});
|
|
218
223
|
}
|
|
219
224
|
|
|
@@ -6,7 +6,7 @@ function installResolver(resolver) {
|
|
|
6
6
|
function resolveDefinition(token) {
|
|
7
7
|
if (activeResolver === null) {
|
|
8
8
|
throw new Error(
|
|
9
|
-
|
|
9
|
+
"den/adapter: \u0440\u0435\u0437\u043E\u043B\u0432\u0435\u0440 \u043D\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D \u0434\u043B\u044F \xAB".concat(token.description, "\xBB \u2014 ") + "\u043D\u0438 \u043E\u0434\u0438\u043D host-\u0430\u0434\u0430\u043F\u0442\u0435\u0440 \u043D\u0435 \u0432\u044B\u0437\u0432\u0430\u043B installResolver()"
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
return activeResolver(token);
|
|
@@ -6,7 +6,7 @@ function installResolver(resolver) {
|
|
|
6
6
|
function resolveDefinition(token) {
|
|
7
7
|
if (activeResolver === null) {
|
|
8
8
|
throw new Error(
|
|
9
|
-
|
|
9
|
+
"den/adapter: \u0440\u0435\u0437\u043E\u043B\u0432\u0435\u0440 \u043D\u0435 \u0443\u0441\u0442\u0430\u043D\u043E\u0432\u043B\u0435\u043D \u0434\u043B\u044F \xAB".concat(token.description, "\xBB \u2014 ") + "\u043D\u0438 \u043E\u0434\u0438\u043D host-\u0430\u0434\u0430\u043F\u0442\u0435\u0440 \u043D\u0435 \u0432\u044B\u0437\u0432\u0430\u043B installResolver()"
|
|
10
10
|
);
|
|
11
11
|
}
|
|
12
12
|
return activeResolver(token);
|