@bleedingdev/modern-js-server-runtime-extensions 3.9.0-ultramodern.9 → 3.9.3-ultramodern.1
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 +3 -1
- package/dist/cjs/backend-federation-security/index.js +73 -152
- package/dist/cjs/bff-policy/index.js +7 -0
- package/dist/cjs/bff-policy/node.js +20 -4
- package/dist/cjs/bff-policy/operationContracts.js +150 -135
- package/dist/cjs/bff-policy/operationIdentity.js +81 -0
- package/dist/cjs/bff-policy/producer.js +79 -0
- package/dist/cjs/localisedLoader.js +65 -0
- package/dist/cjs/localisedLoaderPlugin.js +2 -2
- package/dist/cjs/module-federation-css/remote.js +2 -1
- package/dist/cjs/static-serving/staticModuleFederation.js +49 -12
- package/dist/esm/backend-federation-security/index.mjs +73 -152
- package/dist/esm/bff-policy/index.mjs +1 -0
- package/dist/esm/bff-policy/operationIdentity.mjs +30 -0
- package/dist/esm/bff-policy/producer.mjs +31 -0
- package/dist/esm/localisedLoader.mjs +24 -0
- package/dist/esm/localisedLoaderPlugin.mjs +2 -2
- package/dist/esm/module-federation-css/remote.mjs +2 -1
- package/dist/esm-node/backend-federation-security/index.mjs +73 -152
- package/dist/esm-node/bff-policy/index.mjs +1 -0
- package/dist/esm-node/bff-policy/node.mjs +1 -0
- package/dist/esm-node/bff-policy/operationContracts.mjs +5 -27
- package/dist/esm-node/bff-policy/operationIdentity.mjs +31 -0
- package/dist/esm-node/bff-policy/producer.mjs +32 -0
- package/dist/esm-node/localisedLoader.mjs +25 -0
- package/dist/esm-node/localisedLoaderPlugin.mjs +2 -2
- package/dist/esm-node/module-federation-css/remote.mjs +2 -1
- package/dist/esm-node/static-serving/staticModuleFederation.mjs +49 -12
- package/dist/types/backend-federation-security/node.d.ts +1 -1
- package/dist/types/bff-policy/index.d.ts +1 -0
- package/dist/types/bff-policy/node.d.ts +1 -0
- package/dist/types/bff-policy/operationContracts.d.ts +2 -41
- package/dist/types/bff-policy/operationIdentity.d.ts +34 -0
- package/dist/types/bff-policy/producer.d.ts +10 -0
- package/dist/types/localisedLoader.d.ts +15 -0
- package/dist/types/module-federation-css/remote.d.ts +2 -0
- package/dist/types-esm/backend-federation-security/node.d.mts +1 -1
- package/dist/types-esm/bff-policy/index.d.mts +1 -0
- package/dist/types-esm/bff-policy/node.d.mts +1 -0
- package/dist/types-esm/bff-policy/operationContracts.d.mts +2 -41
- package/dist/types-esm/bff-policy/operationIdentity.d.mts +34 -0
- package/dist/types-esm/bff-policy/producer.d.mts +10 -0
- package/dist/types-esm/localisedLoader.d.mts +15 -0
- package/dist/types-esm/module-federation-css/remote.d.mts +2 -0
- package/package.json +47 -19
- package/src/backend-federation-security/index.ts +151 -318
- package/src/backend-federation-security/node.ts +24 -22
- package/src/bff-policy/index.ts +1 -0
- package/src/bff-policy/node.ts +1 -0
- package/src/bff-policy/operationContracts.ts +13 -86
- package/src/bff-policy/operationIdentity.ts +90 -0
- package/src/bff-policy/producer.ts +40 -0
- package/src/contract-gate-snapshot-store/resolve.ts +0 -1
- package/src/localisedLoader.ts +50 -0
- package/src/localisedLoaderPlugin.ts +6 -7
- package/src/module-federation-css/remote.ts +3 -1
- package/src/static-serving/staticModuleFederation.ts +127 -22
- package/rslib.config.mts +0 -38
- package/rstest.config.mts +0 -18
- package/tests/backendFederationSecurity.test.ts +0 -416
- package/tests/bff-policy/crossProjectPolicy.matrix.test.ts +0 -450
- package/tests/bff-policy/crossProjectPolicy.test.ts +0 -197
- package/tests/bff-policy/operationContracts.test.ts +0 -221
- package/tests/bff-policy/optionalZodPeer.test.ts +0 -30
- package/tests/bff-policy/resolveCrossProjectPolicy.test.ts +0 -76
- package/tests/contractGateSnapshotObserver.test.ts +0 -347
- package/tests/contractGateSnapshotStore.test.ts +0 -225
- package/tests/env.test.ts +0 -54
- package/tests/helpers.ts +0 -20
- package/tests/localisedLoader.test.ts +0 -120
- package/tests/mfCache.test.ts +0 -63
- package/tests/moduleFederationCss.test.ts +0 -348
- package/tests/nativeErrorResponse.test.ts +0 -118
- package/tests/nativeServerAssembly.test.ts +0 -385
- package/tests/runtimeLifecycle.test.ts +0 -159
- package/tests/static-serving/ordering.test.ts +0 -214
- package/tests/static-serving/static.test.ts +0 -411
- package/tests/telemetry.test.ts +0 -248
- package/tests/telemetryHealthMonitor.test.ts +0 -183
- package/tests/telemetryHealthObservation.test.ts +0 -302
- package/tests/telemetryLifecycle.test.ts +0 -123
- package/tests/telemetryRegistryQueueMatrix.test.ts +0 -130
- package/tests/telemetryTraceparent.test.ts +0 -167
- package/tests/tsconfig.json +0 -11
- package/tsconfig.json +0 -10
package/tests/telemetry.test.ts
DELETED
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
createOtlpTelemetryExporter,
|
|
3
|
-
createTelemetryAwareMetrics,
|
|
4
|
-
createVictoriaMetricsTelemetryExporter,
|
|
5
|
-
type TelemetryEnvelope,
|
|
6
|
-
TelemetryRegistry,
|
|
7
|
-
TelemetryStartupHealthError,
|
|
8
|
-
} from '../src/telemetry';
|
|
9
|
-
|
|
10
|
-
const createEnvelope = (partial: Record<string, unknown> = {}) => ({
|
|
11
|
-
timestamp: Date.now(),
|
|
12
|
-
service: 'svc',
|
|
13
|
-
module: 'server',
|
|
14
|
-
environment: 'test',
|
|
15
|
-
signalType: 'metric' as const,
|
|
16
|
-
name: 'server.handle.request',
|
|
17
|
-
value: 10,
|
|
18
|
-
unit: 'ms',
|
|
19
|
-
...partial,
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
describe('telemetry registry', () => {
|
|
23
|
-
test('redacts configured keys recursively', async () => {
|
|
24
|
-
const batches: unknown[] = [];
|
|
25
|
-
const registry = new TelemetryRegistry({
|
|
26
|
-
service: 'svc',
|
|
27
|
-
module: 'server',
|
|
28
|
-
environment: 'test',
|
|
29
|
-
flushIntervalMs: 60_000,
|
|
30
|
-
redactionKeys: ['token'],
|
|
31
|
-
});
|
|
32
|
-
await registry.register({
|
|
33
|
-
name: 'memory',
|
|
34
|
-
async emit(batch) {
|
|
35
|
-
batches.push(...batch);
|
|
36
|
-
},
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
registry.enqueue(
|
|
40
|
-
createEnvelope({
|
|
41
|
-
name: 'sensitive',
|
|
42
|
-
attributes: {
|
|
43
|
-
token: 'secret',
|
|
44
|
-
nested: {
|
|
45
|
-
token: 'inner-secret',
|
|
46
|
-
keep: true,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
}),
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
await registry.flush();
|
|
53
|
-
await registry.shutdown();
|
|
54
|
-
|
|
55
|
-
const item = batches.find(
|
|
56
|
-
entry => (entry as { name?: string }).name === 'sensitive',
|
|
57
|
-
) as
|
|
58
|
-
| {
|
|
59
|
-
attributes?: {
|
|
60
|
-
token?: string;
|
|
61
|
-
nested?: {
|
|
62
|
-
token?: string;
|
|
63
|
-
keep?: boolean;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
| undefined;
|
|
68
|
-
expect(item).toBeDefined();
|
|
69
|
-
expect(item?.attributes?.token).toBe('[REDACTED]');
|
|
70
|
-
expect(item?.attributes?.nested?.token).toBe('[REDACTED]');
|
|
71
|
-
expect(item?.attributes?.nested?.keep).toBe(true);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
test('wraps metrics and preserves trace tags in envelopes', async () => {
|
|
75
|
-
const emitted: TelemetryEnvelope[] = [];
|
|
76
|
-
const registry = new TelemetryRegistry({
|
|
77
|
-
service: 'svc',
|
|
78
|
-
module: 'server',
|
|
79
|
-
environment: 'test',
|
|
80
|
-
flushIntervalMs: 60_000,
|
|
81
|
-
});
|
|
82
|
-
await registry.register({
|
|
83
|
-
name: 'memory',
|
|
84
|
-
async emit(batch) {
|
|
85
|
-
emitted.push(...batch);
|
|
86
|
-
},
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
const base = {
|
|
90
|
-
gauges: rs.fn(),
|
|
91
|
-
emitCounter: rs.fn(),
|
|
92
|
-
emitTimer: rs.fn(),
|
|
93
|
-
};
|
|
94
|
-
const metrics = createTelemetryAwareMetrics(base as any, registry);
|
|
95
|
-
metrics.emitCounter('server.request.count', 1, {
|
|
96
|
-
pathname: '/foo',
|
|
97
|
-
trace_id: '11112222333344445555666677778888',
|
|
98
|
-
});
|
|
99
|
-
metrics.emitTimer('server.request.cost', 25, {
|
|
100
|
-
pathname: '/foo',
|
|
101
|
-
span_id: '1111222233334444',
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
await registry.flush();
|
|
105
|
-
await registry.shutdown();
|
|
106
|
-
|
|
107
|
-
expect(base.emitCounter).toHaveBeenCalledTimes(1);
|
|
108
|
-
expect(base.emitTimer).toHaveBeenCalledTimes(1);
|
|
109
|
-
|
|
110
|
-
const countEnvelope = emitted.find(
|
|
111
|
-
item => item.name === 'server.request.count',
|
|
112
|
-
)!;
|
|
113
|
-
const timerEnvelope = emitted.find(
|
|
114
|
-
item => item.name === 'server.request.cost',
|
|
115
|
-
)!;
|
|
116
|
-
|
|
117
|
-
expect(countEnvelope.unit).toBe('count');
|
|
118
|
-
expect(countEnvelope.traceId).toBe('11112222333344445555666677778888');
|
|
119
|
-
expect(timerEnvelope.unit).toBe('ms');
|
|
120
|
-
expect(timerEnvelope.spanId).toBe('1111222233334444');
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
test('startup health check fails loud by default when exporter is unhealthy', async () => {
|
|
124
|
-
const registry = new TelemetryRegistry({
|
|
125
|
-
service: 'svc',
|
|
126
|
-
module: 'server',
|
|
127
|
-
environment: 'test',
|
|
128
|
-
flushIntervalMs: 60_000,
|
|
129
|
-
});
|
|
130
|
-
await registry.register({
|
|
131
|
-
name: 'failing',
|
|
132
|
-
async emit() {
|
|
133
|
-
throw new Error('connection refused');
|
|
134
|
-
},
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
await expect(registry.startupHealthCheck()).rejects.toBeInstanceOf(
|
|
138
|
-
TelemetryStartupHealthError,
|
|
139
|
-
);
|
|
140
|
-
const health = registry.getExporterHealth();
|
|
141
|
-
expect(health).toHaveLength(1);
|
|
142
|
-
expect(health[0].healthy).toBe(false);
|
|
143
|
-
expect(health[0].failures).toBeGreaterThan(0);
|
|
144
|
-
await registry.shutdown();
|
|
145
|
-
});
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
describe('telemetry exporters', () => {
|
|
149
|
-
const originalFetch = globalThis.fetch;
|
|
150
|
-
|
|
151
|
-
afterEach(() => {
|
|
152
|
-
globalThis.fetch = originalFetch;
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('otlp exporter sends envelope batch with JSON body', async () => {
|
|
156
|
-
const mockFetch = rs.fn(async () => new Response('ok', { status: 200 }));
|
|
157
|
-
globalThis.fetch = mockFetch as typeof fetch;
|
|
158
|
-
|
|
159
|
-
const exporter = createOtlpTelemetryExporter({
|
|
160
|
-
endpoint: 'http://localhost:4318/v1/logs',
|
|
161
|
-
});
|
|
162
|
-
await exporter.emit([
|
|
163
|
-
createEnvelope({
|
|
164
|
-
signalType: 'log',
|
|
165
|
-
name: 'hello',
|
|
166
|
-
level: 'info',
|
|
167
|
-
}),
|
|
168
|
-
]);
|
|
169
|
-
|
|
170
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
171
|
-
const [url, init] = mockFetch.mock.calls[0] as unknown as [
|
|
172
|
-
string,
|
|
173
|
-
RequestInit,
|
|
174
|
-
];
|
|
175
|
-
expect(url).toBe('http://localhost:4318/v1/logs');
|
|
176
|
-
expect(init.method).toBe('POST');
|
|
177
|
-
expect(new Headers(init.headers).get('content-type')).toBe(
|
|
178
|
-
'application/json',
|
|
179
|
-
);
|
|
180
|
-
const payload = JSON.parse(String(init.body)) as {
|
|
181
|
-
resource: {
|
|
182
|
-
service: string;
|
|
183
|
-
module: string;
|
|
184
|
-
environment: string;
|
|
185
|
-
};
|
|
186
|
-
emittedAt: number;
|
|
187
|
-
events: unknown[];
|
|
188
|
-
};
|
|
189
|
-
expect(payload.resource).toEqual({
|
|
190
|
-
service: 'svc',
|
|
191
|
-
module: 'server',
|
|
192
|
-
environment: 'test',
|
|
193
|
-
});
|
|
194
|
-
expect(payload.emittedAt).toEqual(expect.any(Number));
|
|
195
|
-
expect(payload.events).toHaveLength(1);
|
|
196
|
-
expect(payload.events[0]).toMatchObject({
|
|
197
|
-
service: 'svc',
|
|
198
|
-
module: 'server',
|
|
199
|
-
environment: 'test',
|
|
200
|
-
signalType: 'log',
|
|
201
|
-
name: 'hello',
|
|
202
|
-
level: 'info',
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test('victoria metrics exporter emits prometheus lines', async () => {
|
|
207
|
-
const mockFetch = rs.fn(async () => new Response('ok', { status: 200 }));
|
|
208
|
-
globalThis.fetch = mockFetch as typeof fetch;
|
|
209
|
-
|
|
210
|
-
const exporter = createVictoriaMetricsTelemetryExporter({
|
|
211
|
-
endpoint: 'http://localhost:8428/api/v1/import/prometheus',
|
|
212
|
-
metricPrefix: 'modernjs',
|
|
213
|
-
});
|
|
214
|
-
await exporter.emit([
|
|
215
|
-
createEnvelope({
|
|
216
|
-
signalType: 'metric',
|
|
217
|
-
name: 'server.handle.request',
|
|
218
|
-
value: 42,
|
|
219
|
-
}),
|
|
220
|
-
createEnvelope({
|
|
221
|
-
signalType: 'log',
|
|
222
|
-
name: 'request.error',
|
|
223
|
-
level: 'error',
|
|
224
|
-
}),
|
|
225
|
-
]);
|
|
226
|
-
|
|
227
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
228
|
-
const [url, init] = mockFetch.mock.calls[0] as unknown as [
|
|
229
|
-
string,
|
|
230
|
-
RequestInit,
|
|
231
|
-
];
|
|
232
|
-
expect(url).toBe('http://localhost:8428/api/v1/import/prometheus');
|
|
233
|
-
expect(init.method).toBe('POST');
|
|
234
|
-
expect(new Headers(init.headers).get('content-type')).toBe(
|
|
235
|
-
'text/plain; version=0.0.4',
|
|
236
|
-
);
|
|
237
|
-
const body = String(init.body);
|
|
238
|
-
expect(body.endsWith('\n')).toBe(true);
|
|
239
|
-
const lines = body.trimEnd().split('\n');
|
|
240
|
-
expect(lines).toHaveLength(2);
|
|
241
|
-
expect(lines[0]).toMatch(
|
|
242
|
-
/^modernjs_metric_server_handle_request\{environment="test",module="server",service="svc"\} 42 \d+$/,
|
|
243
|
-
);
|
|
244
|
-
expect(lines[1]).toMatch(
|
|
245
|
-
/^modernjs_log_request_error\{environment="test",level="error",module="server",service="svc"\} 10 \d+$/,
|
|
246
|
-
);
|
|
247
|
-
});
|
|
248
|
-
});
|
|
@@ -1,183 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type TelemetryEnvelope,
|
|
3
|
-
TelemetryHealthMonitor,
|
|
4
|
-
TelemetryRegistry,
|
|
5
|
-
} from '../src/telemetry';
|
|
6
|
-
|
|
7
|
-
const createEnvelope = (
|
|
8
|
-
partial: Partial<TelemetryEnvelope> = {},
|
|
9
|
-
): TelemetryEnvelope => ({
|
|
10
|
-
timestamp: Date.now(),
|
|
11
|
-
service: 'svc',
|
|
12
|
-
module: 'server',
|
|
13
|
-
environment: 'test',
|
|
14
|
-
signalType: 'metric',
|
|
15
|
-
name: 'server.handle.request',
|
|
16
|
-
value: 10,
|
|
17
|
-
unit: 'ms',
|
|
18
|
-
...partial,
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
const createRegistry = (maxQueueSize = 1_000) =>
|
|
22
|
-
new TelemetryRegistry({
|
|
23
|
-
service: 'svc',
|
|
24
|
-
module: 'server',
|
|
25
|
-
environment: 'test',
|
|
26
|
-
maxQueueSize,
|
|
27
|
-
flushIntervalMs: 60_000,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
describe('telemetry health monitor', () => {
|
|
31
|
-
test('reports hysteretic health transitions without deployment actions', async () => {
|
|
32
|
-
const registry = createRegistry();
|
|
33
|
-
const onEvaluate = rs.fn();
|
|
34
|
-
const onTransition = rs.fn();
|
|
35
|
-
const monitor = new TelemetryHealthMonitor({
|
|
36
|
-
registry,
|
|
37
|
-
minConsecutiveHealthyEvaluations: 2,
|
|
38
|
-
minConsecutiveFailedEvaluations: 2,
|
|
39
|
-
requiredContractGates: ['contracts'],
|
|
40
|
-
onEvaluate,
|
|
41
|
-
onTransition,
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
monitor.setContractGate('contracts', false, 'schema drift');
|
|
45
|
-
const firstFailure = monitor.evaluate();
|
|
46
|
-
const unhealthy = monitor.evaluate();
|
|
47
|
-
const stillUnhealthy = monitor.evaluate();
|
|
48
|
-
|
|
49
|
-
expect(firstFailure).toMatchObject({
|
|
50
|
-
state: 'pending',
|
|
51
|
-
transition: 'none',
|
|
52
|
-
consecutiveFailures: 1,
|
|
53
|
-
});
|
|
54
|
-
expect(unhealthy).toMatchObject({
|
|
55
|
-
state: 'unhealthy',
|
|
56
|
-
transition: 'became_unhealthy',
|
|
57
|
-
consecutiveFailures: 2,
|
|
58
|
-
});
|
|
59
|
-
expect(stillUnhealthy).toMatchObject({
|
|
60
|
-
state: 'unhealthy',
|
|
61
|
-
transition: 'none',
|
|
62
|
-
consecutiveFailures: 3,
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
monitor.setContractGate('contracts', true);
|
|
66
|
-
const firstRecovery = monitor.evaluate();
|
|
67
|
-
const recovered = monitor.evaluate();
|
|
68
|
-
const stillHealthy = monitor.evaluate();
|
|
69
|
-
|
|
70
|
-
expect(firstRecovery).toMatchObject({
|
|
71
|
-
state: 'unhealthy',
|
|
72
|
-
transition: 'none',
|
|
73
|
-
consecutiveHealthy: 1,
|
|
74
|
-
});
|
|
75
|
-
expect(recovered).toMatchObject({
|
|
76
|
-
state: 'healthy',
|
|
77
|
-
transition: 'became_healthy',
|
|
78
|
-
consecutiveHealthy: 2,
|
|
79
|
-
});
|
|
80
|
-
expect(stillHealthy).toMatchObject({
|
|
81
|
-
state: 'healthy',
|
|
82
|
-
transition: 'none',
|
|
83
|
-
consecutiveHealthy: 3,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
expect(onTransition).toHaveBeenNthCalledWith(1, unhealthy);
|
|
87
|
-
expect(onTransition).toHaveBeenNthCalledWith(2, recovered);
|
|
88
|
-
|
|
89
|
-
await registry.shutdown();
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('observes missing and failed required contract gates', async () => {
|
|
93
|
-
const registry = createRegistry();
|
|
94
|
-
const monitor = new TelemetryHealthMonitor({
|
|
95
|
-
registry,
|
|
96
|
-
minConsecutiveHealthyEvaluations: 1,
|
|
97
|
-
minConsecutiveFailedEvaluations: 1,
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
monitor.addRequiredContractGate('runtime-contracts');
|
|
101
|
-
const missing = monitor.evaluate();
|
|
102
|
-
expect(missing.state).toBe('unhealthy');
|
|
103
|
-
expect(missing.failures).toContainEqual(
|
|
104
|
-
expect.objectContaining({
|
|
105
|
-
reason: 'contract_gate_missing',
|
|
106
|
-
gate: 'runtime-contracts',
|
|
107
|
-
}),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
monitor.setContractGate('runtime-contracts', false, 'incompatible schema');
|
|
111
|
-
const failed = monitor.evaluate();
|
|
112
|
-
expect(failed.failures).toContainEqual(
|
|
113
|
-
expect.objectContaining({
|
|
114
|
-
reason: 'contract_gate_failed',
|
|
115
|
-
gate: 'runtime-contracts',
|
|
116
|
-
message: 'incompatible schema',
|
|
117
|
-
}),
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
monitor.setContractGate('runtime-contracts', true);
|
|
121
|
-
const healthy = monitor.evaluate();
|
|
122
|
-
expect(healthy).toMatchObject({
|
|
123
|
-
state: 'healthy',
|
|
124
|
-
transition: 'became_healthy',
|
|
125
|
-
failures: [],
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
await registry.shutdown();
|
|
129
|
-
});
|
|
130
|
-
|
|
131
|
-
test('observes telemetry queue drops', async () => {
|
|
132
|
-
const registry = createRegistry(2);
|
|
133
|
-
registry.enqueue(createEnvelope({ name: 'a' }));
|
|
134
|
-
registry.enqueue(createEnvelope({ name: 'b' }));
|
|
135
|
-
registry.enqueue(createEnvelope({ name: 'c' }));
|
|
136
|
-
|
|
137
|
-
const monitor = new TelemetryHealthMonitor({
|
|
138
|
-
registry,
|
|
139
|
-
maxTotalDropped: 0,
|
|
140
|
-
minConsecutiveFailedEvaluations: 1,
|
|
141
|
-
});
|
|
142
|
-
const evaluation = monitor.evaluate();
|
|
143
|
-
|
|
144
|
-
expect(evaluation).toMatchObject({
|
|
145
|
-
state: 'unhealthy',
|
|
146
|
-
transition: 'became_unhealthy',
|
|
147
|
-
});
|
|
148
|
-
expect(evaluation.failures).toContainEqual(
|
|
149
|
-
expect.objectContaining({ reason: 'queue_dropped' }),
|
|
150
|
-
);
|
|
151
|
-
|
|
152
|
-
await registry.shutdown();
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('isolates health observer failures from the server path', async () => {
|
|
156
|
-
const registry = createRegistry();
|
|
157
|
-
const onEvaluate = rs.fn(() => {
|
|
158
|
-
throw new Error('evaluate observer failed');
|
|
159
|
-
});
|
|
160
|
-
const onTransition = rs.fn(() => {
|
|
161
|
-
throw new Error('transition observer failed');
|
|
162
|
-
});
|
|
163
|
-
const monitor = new TelemetryHealthMonitor({
|
|
164
|
-
registry,
|
|
165
|
-
minConsecutiveHealthyEvaluations: 1,
|
|
166
|
-
onEvaluate,
|
|
167
|
-
onTransition,
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
let evaluation: ReturnType<TelemetryHealthMonitor['evaluate']> | undefined;
|
|
171
|
-
expect(() => {
|
|
172
|
-
evaluation = monitor.evaluate();
|
|
173
|
-
}).not.toThrow();
|
|
174
|
-
expect(evaluation).toMatchObject({
|
|
175
|
-
state: 'healthy',
|
|
176
|
-
transition: 'became_healthy',
|
|
177
|
-
});
|
|
178
|
-
expect(onEvaluate).toHaveBeenCalledTimes(1);
|
|
179
|
-
expect(onTransition).toHaveBeenCalledTimes(1);
|
|
180
|
-
|
|
181
|
-
await registry.shutdown();
|
|
182
|
-
});
|
|
183
|
-
});
|