@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.5 → 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/README.md +5 -5
- package/dist/cjs/bff-policy/crossProjectPolicy.js +1 -11
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -8
- package/dist/cjs/telemetry/exporters.js +4 -4
- package/dist/cjs/telemetry/healthSetup.js +14 -18
- package/dist/cjs/telemetry/lifecycle.js +5 -5
- package/dist/cjs/telemetry/plugin.js +3 -4
- package/dist/cjs/telemetry/runtimeEndpoints.js +1 -7
- package/dist/cjs/telemetryCore.js +5 -5
- package/dist/esm/bff-policy/crossProjectPolicy.mjs +1 -11
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm/telemetry/exporters.mjs +2 -2
- package/dist/esm/telemetry/healthSetup.mjs +14 -18
- package/dist/esm/telemetry/lifecycle.mjs +6 -6
- package/dist/esm/telemetry/plugin.mjs +3 -4
- package/dist/esm/telemetry/runtimeEndpoints.mjs +1 -7
- package/dist/esm/telemetryCore.mjs +1 -1
- package/dist/esm-node/bff-policy/crossProjectPolicy.mjs +1 -11
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -8
- package/dist/esm-node/telemetry/exporters.mjs +2 -2
- package/dist/esm-node/telemetry/healthSetup.mjs +14 -18
- package/dist/esm-node/telemetry/lifecycle.mjs +6 -6
- package/dist/esm-node/telemetry/plugin.mjs +3 -4
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +1 -7
- package/dist/esm-node/telemetryCore.mjs +1 -1
- package/dist/types/bff-policy/crossProjectPolicy.d.ts +2 -11
- package/dist/types/telemetry/exporters.d.ts +1 -1
- package/dist/types/telemetry/healthSetup.d.ts +2 -4
- package/dist/types/telemetry/lifecycle.d.ts +2 -2
- package/dist/types/telemetry/runtimeEndpoints.d.ts +1 -3
- package/dist/types/telemetryCore.d.ts +1 -1
- package/dist/types-esm/bff-policy/crossProjectPolicy.d.mts +2 -11
- package/dist/types-esm/telemetry/exporters.d.mts +1 -1
- package/dist/types-esm/telemetry/healthSetup.d.mts +2 -4
- package/dist/types-esm/telemetry/lifecycle.d.mts +2 -2
- package/dist/types-esm/telemetry/runtimeEndpoints.d.mts +1 -3
- package/dist/types-esm/telemetryCore.d.mts +1 -1
- package/package.json +10 -10
- package/src/bff-policy/crossProjectPolicy.ts +7 -34
- package/src/contract-gate-snapshot-store/http-store.ts +1 -11
- package/src/telemetry/exporters.ts +1 -1
- package/src/telemetry/healthSetup.ts +16 -27
- package/src/telemetry/lifecycle.ts +7 -7
- package/src/telemetry/plugin.ts +2 -4
- package/src/telemetry/runtimeEndpoints.ts +0 -10
- package/src/telemetryCore.ts +1 -1
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +0 -37
- package/tests/bff-policy/crossProjectPolicy.test.ts +26 -833
- 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 +34 -51
- 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 +302 -0
- package/tests/telemetryLifecycle.test.ts +0 -54
- package/tests/telemetryRegistryQueueMatrix.test.ts +14 -110
- package/dist/cjs/telemetry/canaryCompatibility.js +0 -73
- package/dist/esm/telemetry/canaryCompatibility.mjs +0 -35
- package/dist/esm-node/telemetry/canaryCompatibility.mjs +0 -36
- package/dist/types/telemetry/canaryCompatibility.d.ts +0 -19
- package/dist/types-esm/telemetry/canaryCompatibility.d.mts +0 -19
- package/src/telemetry/canaryCompatibility.ts +0 -55
- package/tests/registration.test.ts +0 -27
- package/tests/static-serving/provider.test.ts +0 -83
- package/tests/telemetryAutopilot.test.ts +0 -993
- package/tests/telemetryCanaryCompatibility.test.ts +0 -152
|
@@ -0,0 +1,302 @@
|
|
|
1
|
+
import { createDefaultPlugins, createServerBase } from '@modern-js/server-core';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import os from 'os';
|
|
4
|
+
import path from 'path';
|
|
5
|
+
import { injectTelemetryPlugin } from '../src/telemetry';
|
|
6
|
+
import { getDefaultAppContext, getDefaultConfig } from './helpers';
|
|
7
|
+
|
|
8
|
+
type ServerBase = ReturnType<typeof createServerBase>;
|
|
9
|
+
|
|
10
|
+
const SIGNAL_ENDPOINT = '/_modern/contract-gates/runtime-fallback';
|
|
11
|
+
const TOKEN_HEADER = 'x-modernjs-runtime-signal-token';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Boots a real server with the telemetry plugin and the given snapshot-
|
|
15
|
+
* observation
|
|
16
|
+
* config, then tears the temp workspace down. `server.init()` is left to the
|
|
17
|
+
* caller so fail-closed init can be asserted.
|
|
18
|
+
*/
|
|
19
|
+
const withHealthObservation = async (
|
|
20
|
+
snapshotObservation: Record<string, unknown>,
|
|
21
|
+
run: (server: ServerBase, snapshotPath: string) => Promise<void>,
|
|
22
|
+
) => {
|
|
23
|
+
const tempDir = fs.mkdtempSync(
|
|
24
|
+
path.join(os.tmpdir(), 'modern-telemetry-health-observation-'),
|
|
25
|
+
);
|
|
26
|
+
const snapshotPath = path.join(tempDir, '.modern/contract-gates.json');
|
|
27
|
+
try {
|
|
28
|
+
const config = getDefaultConfig();
|
|
29
|
+
config.server = {
|
|
30
|
+
telemetry: {
|
|
31
|
+
enabled: true,
|
|
32
|
+
health: {
|
|
33
|
+
enabled: true,
|
|
34
|
+
minConsecutiveFailedEvaluations: 1,
|
|
35
|
+
snapshotObservation: {
|
|
36
|
+
enabled: true,
|
|
37
|
+
gateSnapshotPath: snapshotPath,
|
|
38
|
+
...snapshotObservation,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
} as any;
|
|
43
|
+
|
|
44
|
+
const server = createServerBase({
|
|
45
|
+
config,
|
|
46
|
+
pwd: tempDir,
|
|
47
|
+
appContext: getDefaultAppContext(),
|
|
48
|
+
});
|
|
49
|
+
server.addPlugins([
|
|
50
|
+
...createDefaultPlugins({ logger: false }),
|
|
51
|
+
injectTelemetryPlugin(),
|
|
52
|
+
]);
|
|
53
|
+
|
|
54
|
+
await run(server, snapshotPath);
|
|
55
|
+
} finally {
|
|
56
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const postSignal = (server: ServerBase, token: string | null, body: unknown) =>
|
|
61
|
+
server.request(
|
|
62
|
+
SIGNAL_ENDPOINT,
|
|
63
|
+
{
|
|
64
|
+
method: 'POST',
|
|
65
|
+
headers: new Headers({
|
|
66
|
+
'content-type': 'application/json',
|
|
67
|
+
...(token ? { [TOKEN_HEADER]: token } : {}),
|
|
68
|
+
}),
|
|
69
|
+
body: JSON.stringify(body),
|
|
70
|
+
},
|
|
71
|
+
{},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
describe('telemetry health observation runtime signal', () => {
|
|
75
|
+
test('rejects oversized runtime fallback signal payload', async () => {
|
|
76
|
+
await withHealthObservation(
|
|
77
|
+
{
|
|
78
|
+
runtimeFallbackSignal: {
|
|
79
|
+
enabled: true,
|
|
80
|
+
endpoint: SIGNAL_ENDPOINT,
|
|
81
|
+
maxBodyBytes: 16,
|
|
82
|
+
auth: { expectedValue: 'oversize-signal-token' },
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
async server => {
|
|
86
|
+
await server.init();
|
|
87
|
+
const response = await postSignal(server, 'oversize-signal-token', {
|
|
88
|
+
reason: 'x'.repeat(2_048),
|
|
89
|
+
});
|
|
90
|
+
expect(response.status).toBe(413);
|
|
91
|
+
const payload = (await response.json()) as { error?: string };
|
|
92
|
+
expect(String(payload.error)).toContain('payload too large');
|
|
93
|
+
},
|
|
94
|
+
);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('requires runtime fallback auth token when configured', async () => {
|
|
98
|
+
await withHealthObservation(
|
|
99
|
+
{
|
|
100
|
+
runtimeFallbackSignal: {
|
|
101
|
+
enabled: true,
|
|
102
|
+
endpoint: SIGNAL_ENDPOINT,
|
|
103
|
+
auth: {
|
|
104
|
+
enabled: true,
|
|
105
|
+
headerName: TOKEN_HEADER,
|
|
106
|
+
expectedValue: 'top-secret-token',
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
async (server, snapshotPath) => {
|
|
111
|
+
await server.init();
|
|
112
|
+
const signal = {
|
|
113
|
+
reason: 'remote_load_failed',
|
|
114
|
+
phase: 'load',
|
|
115
|
+
appName: 'crm',
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const rejected = await postSignal(server, null, signal);
|
|
119
|
+
expect(rejected.status).toBe(401);
|
|
120
|
+
expect(fs.existsSync(snapshotPath)).toBe(false);
|
|
121
|
+
|
|
122
|
+
const accepted = await postSignal(server, 'top-secret-token', signal);
|
|
123
|
+
expect(accepted.status).toBe(202);
|
|
124
|
+
expect(fs.existsSync(snapshotPath)).toBe(true);
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
test('enforces runtime fallback trust policy before mutating gate snapshots', async () => {
|
|
130
|
+
await withHealthObservation(
|
|
131
|
+
{
|
|
132
|
+
runtimeFallbackSignal: {
|
|
133
|
+
enabled: true,
|
|
134
|
+
endpoint: SIGNAL_ENDPOINT,
|
|
135
|
+
auth: { expectedValue: 'trust-policy-token' },
|
|
136
|
+
trustPolicy: {
|
|
137
|
+
allowedApps: ['crm-shell'],
|
|
138
|
+
allowedEntryOrigins: ['https://erp.example.com'],
|
|
139
|
+
expectedRuntimeDigests: { 'crm-shell': 'digest-crm-v1' },
|
|
140
|
+
enforceRuntimeDigest: true,
|
|
141
|
+
},
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
async (server, snapshotPath) => {
|
|
145
|
+
await server.init();
|
|
146
|
+
const base = {
|
|
147
|
+
reason: 'remote_load_failed',
|
|
148
|
+
phase: 'load',
|
|
149
|
+
appName: 'crm-shell',
|
|
150
|
+
entry: 'https://erp.example.com/remoteEntry.js',
|
|
151
|
+
runtimeDigest: 'digest-crm-v1',
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const untrustedApp = await postSignal(server, 'trust-policy-token', {
|
|
155
|
+
...base,
|
|
156
|
+
appName: 'unknown-app',
|
|
157
|
+
});
|
|
158
|
+
expect(untrustedApp.status).toBe(403);
|
|
159
|
+
|
|
160
|
+
const digestMismatch = await postSignal(server, 'trust-policy-token', {
|
|
161
|
+
...base,
|
|
162
|
+
runtimeDigest: 'digest-wrong',
|
|
163
|
+
});
|
|
164
|
+
expect(digestMismatch.status).toBe(403);
|
|
165
|
+
|
|
166
|
+
const trusted = await postSignal(server, 'trust-policy-token', {
|
|
167
|
+
...base,
|
|
168
|
+
metadata: {
|
|
169
|
+
compatibility: { '@tanstack/react-router': '1.170.15' },
|
|
170
|
+
},
|
|
171
|
+
});
|
|
172
|
+
expect(trusted.status).toBe(202);
|
|
173
|
+
|
|
174
|
+
const snapshot = JSON.parse(fs.readFileSync(snapshotPath, 'utf8')) as {
|
|
175
|
+
gates?: Record<string, any>;
|
|
176
|
+
};
|
|
177
|
+
const gate = snapshot.gates?.['runtime-mf-fallback-health'];
|
|
178
|
+
expect(gate?.passed).toBe(false);
|
|
179
|
+
expect(
|
|
180
|
+
gate?.metadata?.metadata?.compatibility?.['@tanstack/react-router'],
|
|
181
|
+
).toBe('1.170.15');
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('dedupes repeated fallback events and rate limits rotated identities', async () => {
|
|
187
|
+
await withHealthObservation(
|
|
188
|
+
{
|
|
189
|
+
runtimeFallbackSignal: {
|
|
190
|
+
enabled: true,
|
|
191
|
+
endpoint: SIGNAL_ENDPOINT,
|
|
192
|
+
auth: { expectedValue: 'rate-limit-token' },
|
|
193
|
+
trustPolicy: {
|
|
194
|
+
dedupeWindowMs: 60_000,
|
|
195
|
+
maxSignalsPerWindow: 1,
|
|
196
|
+
windowMs: 60_000,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
async server => {
|
|
201
|
+
await server.init();
|
|
202
|
+
const sendSignal = (appName: string) =>
|
|
203
|
+
postSignal(server, 'rate-limit-token', {
|
|
204
|
+
reason: 'remote_mount_failed',
|
|
205
|
+
phase: 'mount',
|
|
206
|
+
appName,
|
|
207
|
+
entry: `https://${appName}.example.com/remoteEntry.js`,
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
expect((await sendSignal('app-a')).status).toBe(202);
|
|
211
|
+
|
|
212
|
+
const duplicate = await sendSignal('app-a');
|
|
213
|
+
expect(duplicate.status).toBe(202);
|
|
214
|
+
expect(((await duplicate.json()) as any).deduped).toBe(true);
|
|
215
|
+
|
|
216
|
+
// A rotated appName/entry pair used to mint a fresh rate-limit bucket;
|
|
217
|
+
// the limiter is now keyed on connection identity instead.
|
|
218
|
+
expect((await sendSignal('app-b')).status).toBe(429);
|
|
219
|
+
},
|
|
220
|
+
);
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
test('keeps the runtime fallback signal endpoint disabled unless explicitly enabled', async () => {
|
|
224
|
+
// no runtimeFallbackSignal config: the health kill switch must stay OFF.
|
|
225
|
+
await withHealthObservation({}, async (server, snapshotPath) => {
|
|
226
|
+
await server.init();
|
|
227
|
+
const response = await postSignal(server, null, {
|
|
228
|
+
reason: 'remote_load_failed',
|
|
229
|
+
phase: 'load',
|
|
230
|
+
appName: 'dashboard',
|
|
231
|
+
});
|
|
232
|
+
expect(response.status).toBe(404);
|
|
233
|
+
expect(fs.existsSync(snapshotPath)).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
test('refuses to enable the runtime fallback signal endpoint without an auth token', async () => {
|
|
238
|
+
await withHealthObservation(
|
|
239
|
+
// enabled with no auth token configured: init must fail closed.
|
|
240
|
+
{ runtimeFallbackSignal: { enabled: true } },
|
|
241
|
+
async server => {
|
|
242
|
+
await expect(server.init()).rejects.toThrow(
|
|
243
|
+
/requires an auth token|auth\.expectedValue/,
|
|
244
|
+
);
|
|
245
|
+
},
|
|
246
|
+
);
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
test('runtime status endpoint stays a bare health probe without configured auth', async () => {
|
|
250
|
+
await withHealthObservation({}, async server => {
|
|
251
|
+
await server.init();
|
|
252
|
+
const response = await server.request('/_modern/runtime/status', {}, {});
|
|
253
|
+
expect(response.status).toBe(200);
|
|
254
|
+
const payload = (await response.json()) as Record<string, unknown>;
|
|
255
|
+
expect(payload.ok).toBe(true);
|
|
256
|
+
// No telemetry/health/trust internals are disclosed without auth.
|
|
257
|
+
expect(payload.telemetry).toBeUndefined();
|
|
258
|
+
expect(payload.health).toBeUndefined();
|
|
259
|
+
expect(payload.runtimeFallbackSignal).toBeUndefined();
|
|
260
|
+
});
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
test('runtime status auth works even when the signal endpoint stays disabled', async () => {
|
|
264
|
+
await withHealthObservation(
|
|
265
|
+
{
|
|
266
|
+
runtimeFallbackSignal: {
|
|
267
|
+
// endpoint stays disabled, but its auth config still guards the
|
|
268
|
+
// status endpoint detail view.
|
|
269
|
+
auth: { enabled: true, expectedValue: 'status-only-token' },
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
async server => {
|
|
273
|
+
await server.init();
|
|
274
|
+
|
|
275
|
+
const signalResponse = await postSignal(server, 'status-only-token', {
|
|
276
|
+
appName: 'dashboard',
|
|
277
|
+
});
|
|
278
|
+
expect(signalResponse.status).toBe(404);
|
|
279
|
+
|
|
280
|
+
const unauthorized = await server.request(
|
|
281
|
+
'/_modern/runtime/status',
|
|
282
|
+
{},
|
|
283
|
+
{},
|
|
284
|
+
);
|
|
285
|
+
expect(unauthorized.status).toBe(401);
|
|
286
|
+
|
|
287
|
+
const authorized = await server.request(
|
|
288
|
+
'/_modern/runtime/status',
|
|
289
|
+
{
|
|
290
|
+
method: 'GET',
|
|
291
|
+
headers: new Headers({ [TOKEN_HEADER]: 'status-only-token' }),
|
|
292
|
+
},
|
|
293
|
+
{},
|
|
294
|
+
);
|
|
295
|
+
expect(authorized.status).toBe(200);
|
|
296
|
+
const payload = (await authorized.json()) as Record<string, any>;
|
|
297
|
+
expect(payload.health?.enabled).toBe(true);
|
|
298
|
+
expect(payload.runtimeFallbackSignal?.enabled).toBe(false);
|
|
299
|
+
},
|
|
300
|
+
);
|
|
301
|
+
});
|
|
302
|
+
});
|
|
@@ -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,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __webpack_require__ = {};
|
|
3
|
-
(()=>{
|
|
4
|
-
__webpack_require__.d = (exports1, getters, values)=>{
|
|
5
|
-
var define = (defs, kind)=>{
|
|
6
|
-
for(var key in defs)if (__webpack_require__.o(defs, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
[kind]: defs[key]
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
define(getters, "get");
|
|
12
|
-
define(values, "value");
|
|
13
|
-
};
|
|
14
|
-
})();
|
|
15
|
-
(()=>{
|
|
16
|
-
__webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
|
|
17
|
-
})();
|
|
18
|
-
(()=>{
|
|
19
|
-
__webpack_require__.r = (exports1)=>{
|
|
20
|
-
if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
|
|
21
|
-
value: 'Module'
|
|
22
|
-
});
|
|
23
|
-
Object.defineProperty(exports1, '__esModule', {
|
|
24
|
-
value: true
|
|
25
|
-
});
|
|
26
|
-
};
|
|
27
|
-
})();
|
|
28
|
-
var __webpack_exports__ = {};
|
|
29
|
-
__webpack_require__.r(__webpack_exports__);
|
|
30
|
-
const createTelemetryCanaryCompatibility = (registry)=>{
|
|
31
|
-
let state = 'canary';
|
|
32
|
-
return {
|
|
33
|
-
observe (evaluation) {
|
|
34
|
-
let action;
|
|
35
|
-
if ('became_healthy' === evaluation.transition && 'canary' === state) {
|
|
36
|
-
state = 'promoted';
|
|
37
|
-
action = 'promote';
|
|
38
|
-
} else {
|
|
39
|
-
if ('became_unhealthy' !== evaluation.transition || 'rolled_back' === state) return;
|
|
40
|
-
state = 'rolled_back';
|
|
41
|
-
action = 'rollback';
|
|
42
|
-
}
|
|
43
|
-
try {
|
|
44
|
-
registry.enqueueMetric({
|
|
45
|
-
name: `telemetry.canary.${action}`,
|
|
46
|
-
value: 1,
|
|
47
|
-
unit: 'count',
|
|
48
|
-
tags: {
|
|
49
|
-
action,
|
|
50
|
-
state,
|
|
51
|
-
failures: String(evaluation.failures.length)
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
} catch (_error) {}
|
|
55
|
-
},
|
|
56
|
-
getStatusSnapshot (snapshot) {
|
|
57
|
-
return {
|
|
58
|
-
...snapshot,
|
|
59
|
-
state
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
};
|
|
64
|
-
__webpack_require__.d(__webpack_exports__, {}, {
|
|
65
|
-
createTelemetryCanaryCompatibility: createTelemetryCanaryCompatibility
|
|
66
|
-
});
|
|
67
|
-
exports.createTelemetryCanaryCompatibility = __webpack_exports__.createTelemetryCanaryCompatibility;
|
|
68
|
-
for(var __rspack_i in __webpack_exports__)if (-1 === [
|
|
69
|
-
"createTelemetryCanaryCompatibility"
|
|
70
|
-
].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
|
|
71
|
-
Object.defineProperty(exports, '__esModule', {
|
|
72
|
-
value: true
|
|
73
|
-
});
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
const createTelemetryCanaryCompatibility = (registry)=>{
|
|
2
|
-
let state = 'canary';
|
|
3
|
-
return {
|
|
4
|
-
observe (evaluation) {
|
|
5
|
-
let action;
|
|
6
|
-
if ('became_healthy' === evaluation.transition && 'canary' === state) {
|
|
7
|
-
state = 'promoted';
|
|
8
|
-
action = 'promote';
|
|
9
|
-
} else {
|
|
10
|
-
if ('became_unhealthy' !== evaluation.transition || 'rolled_back' === state) return;
|
|
11
|
-
state = 'rolled_back';
|
|
12
|
-
action = 'rollback';
|
|
13
|
-
}
|
|
14
|
-
try {
|
|
15
|
-
registry.enqueueMetric({
|
|
16
|
-
name: `telemetry.canary.${action}`,
|
|
17
|
-
value: 1,
|
|
18
|
-
unit: 'count',
|
|
19
|
-
tags: {
|
|
20
|
-
action,
|
|
21
|
-
state,
|
|
22
|
-
failures: String(evaluation.failures.length)
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
} catch (_error) {}
|
|
26
|
-
},
|
|
27
|
-
getStatusSnapshot (snapshot) {
|
|
28
|
-
return {
|
|
29
|
-
...snapshot,
|
|
30
|
-
state
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export { createTelemetryCanaryCompatibility };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
const createTelemetryCanaryCompatibility = (registry)=>{
|
|
3
|
-
let state = 'canary';
|
|
4
|
-
return {
|
|
5
|
-
observe (evaluation) {
|
|
6
|
-
let action;
|
|
7
|
-
if ('became_healthy' === evaluation.transition && 'canary' === state) {
|
|
8
|
-
state = 'promoted';
|
|
9
|
-
action = 'promote';
|
|
10
|
-
} else {
|
|
11
|
-
if ('became_unhealthy' !== evaluation.transition || 'rolled_back' === state) return;
|
|
12
|
-
state = 'rolled_back';
|
|
13
|
-
action = 'rollback';
|
|
14
|
-
}
|
|
15
|
-
try {
|
|
16
|
-
registry.enqueueMetric({
|
|
17
|
-
name: `telemetry.canary.${action}`,
|
|
18
|
-
value: 1,
|
|
19
|
-
unit: 'count',
|
|
20
|
-
tags: {
|
|
21
|
-
action,
|
|
22
|
-
state,
|
|
23
|
-
failures: String(evaluation.failures.length)
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
} catch (_error) {}
|
|
27
|
-
},
|
|
28
|
-
getStatusSnapshot (snapshot) {
|
|
29
|
-
return {
|
|
30
|
-
...snapshot,
|
|
31
|
-
state
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
export { createTelemetryCanaryCompatibility };
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { TelemetryHealthEvaluation, TelemetryHealthStatusSnapshot } from './healthMonitor.js';
|
|
2
|
-
import type { TelemetryRegistry } from './registry.js';
|
|
3
|
-
type CanaryState = 'canary' | 'promoted' | 'rolled_back';
|
|
4
|
-
export declare const createTelemetryCanaryCompatibility: (registry: TelemetryRegistry) => {
|
|
5
|
-
observe(evaluation: TelemetryHealthEvaluation): void;
|
|
6
|
-
getStatusSnapshot(snapshot: TelemetryHealthStatusSnapshot): {
|
|
7
|
-
timestamp: number;
|
|
8
|
-
consecutiveHealthy: number;
|
|
9
|
-
consecutiveFailures: number;
|
|
10
|
-
queueStats: import("./registryTypes.js").TelemetryQueueStats;
|
|
11
|
-
unhealthyExporterCount: number;
|
|
12
|
-
requiredContractGates: string[];
|
|
13
|
-
contractGates: import("./healthMonitor.js").TelemetryContractGateStatus[];
|
|
14
|
-
failurePreview: import("./healthMonitor.js").TelemetryHealthFailure[];
|
|
15
|
-
state: CanaryState;
|
|
16
|
-
};
|
|
17
|
-
};
|
|
18
|
-
export type TelemetryCanaryCompatibility = ReturnType<typeof createTelemetryCanaryCompatibility>;
|
|
19
|
-
export {};
|