@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.6 → 3.9.0-ultramodern.7
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/package.json +10 -10
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +0 -37
- package/tests/bff-policy/crossProjectPolicy.test.ts +26 -799
- package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +0 -58
- package/tests/contractGateSnapshotStore.test.ts +0 -51
- package/tests/nativeErrorResponse.test.ts +0 -81
- package/tests/nativeServerAssembly.test.ts +30 -47
- package/tests/static-serving/static.test.ts +31 -20
- package/tests/telemetry.test.ts +0 -97
- package/tests/telemetryHealthMonitor.test.ts +0 -2
- package/tests/telemetryHealthObservation.test.ts +226 -919
- package/tests/telemetryLifecycle.test.ts +0 -54
- package/tests/telemetryRegistryQueueMatrix.test.ts +14 -110
- package/tests/registration.test.ts +0 -27
- package/tests/static-serving/provider.test.ts +0 -83
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
createServerBase,
|
|
5
5
|
type ServerPlugin,
|
|
6
6
|
} from '@modern-js/server-core';
|
|
7
|
-
import { logger } from '@modern-js/utils';
|
|
8
7
|
import { injectTelemetryPlugin } from '../src/telemetry';
|
|
9
8
|
import { getDefaultAppContext, getDefaultConfig } from './helpers';
|
|
10
9
|
|
|
@@ -46,59 +45,6 @@ const waitFor = async (
|
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
describe('telemetry plugin lifecycle', () => {
|
|
49
|
-
test('wires server.telemetry.slo through to alert emission', async () => {
|
|
50
|
-
const warnSpy = rs.spyOn(logger, 'warn').mockImplementation(() => {});
|
|
51
|
-
|
|
52
|
-
let server: ReturnType<typeof createServerBase> | undefined;
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
const config = getDefaultConfig();
|
|
56
|
-
config.server = {
|
|
57
|
-
telemetry: {
|
|
58
|
-
enabled: true,
|
|
59
|
-
maxQueueSize: 2,
|
|
60
|
-
maxBatchSize: 500,
|
|
61
|
-
flushIntervalMs: 60_000,
|
|
62
|
-
slo: {
|
|
63
|
-
queueUtilizationWarnThreshold: 0.5,
|
|
64
|
-
queueDroppedWarnThreshold: 1,
|
|
65
|
-
alertCooldownMs: 0,
|
|
66
|
-
},
|
|
67
|
-
},
|
|
68
|
-
} as any;
|
|
69
|
-
|
|
70
|
-
server = createServerBase({
|
|
71
|
-
config,
|
|
72
|
-
pwd: process.cwd(),
|
|
73
|
-
appContext: getDefaultAppContext(),
|
|
74
|
-
});
|
|
75
|
-
server.addPlugins([
|
|
76
|
-
...createDefaultPlugins({ logger: false }),
|
|
77
|
-
injectTelemetryPlugin(),
|
|
78
|
-
emitMonitorEventsPlugin({
|
|
79
|
-
path: '/emit',
|
|
80
|
-
message: 'slo-probe',
|
|
81
|
-
count: 6,
|
|
82
|
-
}),
|
|
83
|
-
]);
|
|
84
|
-
await server.init();
|
|
85
|
-
|
|
86
|
-
const response = await server.request('/emit', {}, {});
|
|
87
|
-
expect(response.status).toBe(200);
|
|
88
|
-
|
|
89
|
-
const sloWarnings = warnSpy.mock.calls.filter(call =>
|
|
90
|
-
String(call[0]).includes('[telemetry.slo]'),
|
|
91
|
-
);
|
|
92
|
-
expect(sloWarnings.length).toBeGreaterThan(0);
|
|
93
|
-
expect(
|
|
94
|
-
sloWarnings.some(call => String(call[0]).includes('queue.drop')),
|
|
95
|
-
).toBe(true);
|
|
96
|
-
} finally {
|
|
97
|
-
await server?.dispose();
|
|
98
|
-
warnSpy.mockRestore();
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
|
|
102
48
|
test('flushes pending envelopes when the native runtime is disposed', async () => {
|
|
103
49
|
const fetchCalls: Array<{ url: string; body: string }> = [];
|
|
104
50
|
const fetchMock = rs.fn(async (url: any, init?: any) => {
|
|
@@ -41,104 +41,6 @@ const createMemoryExporter = (
|
|
|
41
41
|
});
|
|
42
42
|
|
|
43
43
|
describe('telemetry registry queue matrix', () => {
|
|
44
|
-
test.each([
|
|
45
|
-
{
|
|
46
|
-
name: 'below-threshold drops remain window-scoped across flushes',
|
|
47
|
-
dropsPerWindow: [1, 1],
|
|
48
|
-
expectedDropAlertValues: [],
|
|
49
|
-
expectedDropAlertTotals: [],
|
|
50
|
-
},
|
|
51
|
-
{
|
|
52
|
-
name: 'threshold drops alert once per window with lifetime totals attached',
|
|
53
|
-
dropsPerWindow: [2, 2],
|
|
54
|
-
expectedDropAlertValues: [2, 2],
|
|
55
|
-
expectedDropAlertTotals: [2, 4],
|
|
56
|
-
},
|
|
57
|
-
])('$name', async ({
|
|
58
|
-
dropsPerWindow,
|
|
59
|
-
expectedDropAlertValues,
|
|
60
|
-
expectedDropAlertTotals,
|
|
61
|
-
}) => {
|
|
62
|
-
const alerts: TelemetrySloAlert[] = [];
|
|
63
|
-
const batches: TelemetryEnvelope[][] = [];
|
|
64
|
-
const registry = createRegistry({
|
|
65
|
-
maxQueueSize: 2,
|
|
66
|
-
slo: {
|
|
67
|
-
queueUtilizationWarnThreshold: 1,
|
|
68
|
-
queueDroppedWarnThreshold: 2,
|
|
69
|
-
alertCooldownMs: 0,
|
|
70
|
-
onAlert(alert) {
|
|
71
|
-
alerts.push(alert);
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
});
|
|
75
|
-
await registry.register(createMemoryExporter(batches));
|
|
76
|
-
|
|
77
|
-
let totalDropped = 0;
|
|
78
|
-
for (const [windowIndex, dropCount] of dropsPerWindow.entries()) {
|
|
79
|
-
for (let index = 0; index < 2 + dropCount; index++) {
|
|
80
|
-
registry.enqueue(
|
|
81
|
-
createEnvelope({
|
|
82
|
-
name: `window.${windowIndex}.event.${index}`,
|
|
83
|
-
}),
|
|
84
|
-
);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
totalDropped += dropCount;
|
|
88
|
-
expect(registry.getQueueStats()).toEqual({
|
|
89
|
-
depth: 2,
|
|
90
|
-
capacity: 2,
|
|
91
|
-
utilization: 1,
|
|
92
|
-
pendingDropped: dropCount,
|
|
93
|
-
totalDropped,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
await registry.flush();
|
|
97
|
-
expect(registry.getQueueStats()).toEqual({
|
|
98
|
-
depth: 0,
|
|
99
|
-
capacity: 2,
|
|
100
|
-
utilization: 0,
|
|
101
|
-
pendingDropped: 0,
|
|
102
|
-
totalDropped,
|
|
103
|
-
});
|
|
104
|
-
expect(batches).toHaveLength(windowIndex + 1);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const emitted = batches.flat();
|
|
108
|
-
expect(
|
|
109
|
-
emitted
|
|
110
|
-
.filter(item => item.name === 'telemetry.queue.dropped')
|
|
111
|
-
.map(item => item.value),
|
|
112
|
-
).toEqual(dropsPerWindow);
|
|
113
|
-
expect(
|
|
114
|
-
emitted
|
|
115
|
-
.filter(item => item.name === 'telemetry.queue.depth')
|
|
116
|
-
.map(item => item.value),
|
|
117
|
-
).toEqual([2, 2]);
|
|
118
|
-
expect(
|
|
119
|
-
emitted
|
|
120
|
-
.filter(item => item.name === 'telemetry.queue.utilization')
|
|
121
|
-
.map(item => item.value),
|
|
122
|
-
).toEqual([1, 1]);
|
|
123
|
-
|
|
124
|
-
const utilizationAlerts = alerts.filter(
|
|
125
|
-
alert => alert.type === 'queue.utilization',
|
|
126
|
-
);
|
|
127
|
-
expect(utilizationAlerts.length).toBeGreaterThan(0);
|
|
128
|
-
expect(utilizationAlerts.every(alert => alert.value === 1)).toBe(true);
|
|
129
|
-
|
|
130
|
-
const dropAlerts = alerts.filter(alert => alert.type === 'queue.drop');
|
|
131
|
-
expect(dropAlerts.map(alert => alert.value)).toEqual(
|
|
132
|
-
expectedDropAlertValues,
|
|
133
|
-
);
|
|
134
|
-
expect(dropAlerts.map(alert => alert.totalDropped)).toEqual(
|
|
135
|
-
expectedDropAlertTotals,
|
|
136
|
-
);
|
|
137
|
-
expect(dropAlerts.every(alert => alert.threshold === 2)).toBe(true);
|
|
138
|
-
|
|
139
|
-
await registry.shutdown();
|
|
140
|
-
});
|
|
141
|
-
|
|
142
44
|
test('aggregates exporter health across successful and failed emitters', async () => {
|
|
143
45
|
const batches: TelemetryEnvelope[][] = [];
|
|
144
46
|
const registry = createRegistry({ maxQueueSize: 4 });
|
|
@@ -175,8 +77,9 @@ describe('telemetry registry queue matrix', () => {
|
|
|
175
77
|
expect(healthByName.get('failing')?.lastFailureAt).toEqual(
|
|
176
78
|
expect.any(Number),
|
|
177
79
|
);
|
|
178
|
-
expect(batches).
|
|
179
|
-
|
|
80
|
+
expect(batches.flat().some(item => item.name === 'health.sample')).toBe(
|
|
81
|
+
true,
|
|
82
|
+
);
|
|
180
83
|
|
|
181
84
|
await registry.shutdown();
|
|
182
85
|
});
|
|
@@ -210,16 +113,17 @@ describe('telemetry registry queue matrix', () => {
|
|
|
210
113
|
const utilizationAlerts = alerts.filter(
|
|
211
114
|
alert => alert.type === 'queue.utilization',
|
|
212
115
|
);
|
|
213
|
-
expect(utilizationAlerts).
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
116
|
+
expect(utilizationAlerts).toEqual([
|
|
117
|
+
expect.objectContaining({
|
|
118
|
+
type: 'queue.utilization',
|
|
119
|
+
value: 1,
|
|
120
|
+
threshold: 1,
|
|
121
|
+
queueDepth: 2,
|
|
122
|
+
queueCapacity: 2,
|
|
123
|
+
queueUtilization: 1,
|
|
124
|
+
totalDropped: 0,
|
|
125
|
+
}),
|
|
126
|
+
]);
|
|
223
127
|
|
|
224
128
|
await registry.shutdown();
|
|
225
129
|
});
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createDefaultPlugins, createServerBase } from '@modern-js/server-core';
|
|
2
|
-
import { getDefaultAppContext, getDefaultConfig } from './helpers';
|
|
3
|
-
|
|
4
|
-
describe('plugin registration', () => {
|
|
5
|
-
test('bare server-core ignores telemetry config without explicit registration', async () => {
|
|
6
|
-
const config = getDefaultConfig();
|
|
7
|
-
config.server = {
|
|
8
|
-
telemetry: {
|
|
9
|
-
enabled: true,
|
|
10
|
-
health: {
|
|
11
|
-
enabled: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
} as any;
|
|
15
|
-
|
|
16
|
-
const server = createServerBase({
|
|
17
|
-
config,
|
|
18
|
-
pwd: process.cwd(),
|
|
19
|
-
appContext: getDefaultAppContext(),
|
|
20
|
-
});
|
|
21
|
-
server.addPlugins([...createDefaultPlugins({ logger: false })]);
|
|
22
|
-
await server.init();
|
|
23
|
-
|
|
24
|
-
const response = await server.request('/_modern/runtime/status', {}, {});
|
|
25
|
-
expect(response.status).toBe(404);
|
|
26
|
-
});
|
|
27
|
-
});
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
import { mkdir, mkdtemp, rm, writeFile } from 'node:fs/promises';
|
|
2
|
-
import os from 'node:os';
|
|
3
|
-
import path from 'node:path';
|
|
4
|
-
import { brotliCompressSync, gzipSync } from 'node:zlib';
|
|
5
|
-
import { compatPlugin, createServerBase } from '@modern-js/server-core';
|
|
6
|
-
import { serverStaticPlugin } from '@modern-js/server-core/node';
|
|
7
|
-
import type { ServerRoute } from '@modern-js/types';
|
|
8
|
-
import staticServingExtensionsPlugin from '../../src/static-serving/plugin';
|
|
9
|
-
import { getDefaultAppContext, getDefaultConfig } from '../helpers';
|
|
10
|
-
|
|
11
|
-
const roots: string[] = [];
|
|
12
|
-
afterEach(async () => {
|
|
13
|
-
await Promise.all(roots.splice(0).map(root => rm(root, { recursive: true })));
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
it.each([
|
|
17
|
-
['*;q=0.8', 'br'],
|
|
18
|
-
['*;q=0.8, identity;q=0.9', null],
|
|
19
|
-
['*;q=0.8, identity;q=0', 'br'],
|
|
20
|
-
['br;q=0, *;q=0.8, identity;q=0', 'gzip'],
|
|
21
|
-
['br;q=0.2, gzip;q=1', 'gzip'],
|
|
22
|
-
['br;q=0.8', null],
|
|
23
|
-
['br;q=0.8, identity;q=0', 'br'],
|
|
24
|
-
['br;q=0, gzip;q=0, identity;q=0', 'denied'],
|
|
25
|
-
])('consumes native selected assets for %s', async (acceptEncoding, encoding) => {
|
|
26
|
-
const pwd = await mkdtemp(
|
|
27
|
-
path.join(os.tmpdir(), 'private-static-consumption-'),
|
|
28
|
-
);
|
|
29
|
-
roots.push(pwd);
|
|
30
|
-
const original = Buffer.from('native response body');
|
|
31
|
-
const br = brotliCompressSync(original);
|
|
32
|
-
const gzip = gzipSync(original);
|
|
33
|
-
for (const directory of ['static', 'public']) {
|
|
34
|
-
const filename = path.join(pwd, directory, 'asset.txt');
|
|
35
|
-
await mkdir(path.dirname(filename));
|
|
36
|
-
await writeFile(filename, original);
|
|
37
|
-
await writeFile(`${filename}.br`, br);
|
|
38
|
-
await writeFile(`${filename}.gz`, gzip);
|
|
39
|
-
}
|
|
40
|
-
const server = createServerBase({
|
|
41
|
-
config: getDefaultConfig(),
|
|
42
|
-
appContext: getDefaultAppContext(),
|
|
43
|
-
pwd,
|
|
44
|
-
routes: [
|
|
45
|
-
{
|
|
46
|
-
urlPath: '/document',
|
|
47
|
-
entryPath: 'public/asset.txt',
|
|
48
|
-
isSSR: false,
|
|
49
|
-
responseHeaders: { 'x-route': 'retained' },
|
|
50
|
-
},
|
|
51
|
-
] as ServerRoute[],
|
|
52
|
-
});
|
|
53
|
-
server.addPlugins([
|
|
54
|
-
compatPlugin(),
|
|
55
|
-
staticServingExtensionsPlugin(),
|
|
56
|
-
serverStaticPlugin(),
|
|
57
|
-
]);
|
|
58
|
-
await server.init();
|
|
59
|
-
for (const url of ['/static/asset.txt', '/document']) {
|
|
60
|
-
const response = await server.request(url, {
|
|
61
|
-
headers: { 'accept-encoding': acceptEncoding },
|
|
62
|
-
});
|
|
63
|
-
expect(response.headers.get('vary')).toContain('Accept-Encoding');
|
|
64
|
-
if (encoding === 'denied') {
|
|
65
|
-
expect(response.status).toBe(406);
|
|
66
|
-
expect(await response.text()).toBe('');
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
expect(response.status).toBe(200);
|
|
70
|
-
expect(response.headers.get('content-encoding')).toBe(encoding);
|
|
71
|
-
expect(response.headers.get('content-type')).toContain('text/plain');
|
|
72
|
-
const expected =
|
|
73
|
-
encoding === 'br' ? br : encoding === 'gzip' ? gzip : original;
|
|
74
|
-
expect(Buffer.from(await response.arrayBuffer())).toEqual(expected);
|
|
75
|
-
if (url === '/document') {
|
|
76
|
-
expect(response.headers.get('x-route')).toBe('retained');
|
|
77
|
-
} else {
|
|
78
|
-
expect(response.headers.get('content-length')).toBe(
|
|
79
|
-
String(expected.length),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
});
|