@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.6 → 3.5.0-ultramodern.76
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/dist/cjs/contract-gate-snapshot-normalization.js +122 -0
- package/dist/cjs/contract-gate-snapshot-store/file-store.js +102 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +133 -0
- package/dist/cjs/contract-gate-snapshot-store/index.js +58 -0
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +124 -0
- package/dist/cjs/contract-gate-snapshot-store/types.js +44 -0
- package/dist/cjs/contractGateAutopilot.js +22 -70
- package/dist/cjs/index.js +6 -25
- package/dist/cjs/mfCache.js +2 -2
- package/dist/cjs/module-federation-css/collector.js +79 -0
- package/dist/cjs/module-federation-css/index.js +55 -0
- package/dist/cjs/module-federation-css/manifest.js +129 -0
- package/dist/cjs/module-federation-css/plugin.js +71 -0
- package/dist/cjs/module-federation-css/remote.js +133 -0
- package/dist/cjs/runtime-fallback-signal/index.js +93 -0
- package/dist/cjs/runtime-fallback-signal/model.js +157 -0
- package/dist/cjs/runtime-fallback-signal/resolver.js +163 -0
- package/dist/cjs/runtime-fallback-signal/store.js +83 -0
- package/dist/cjs/runtimeFallbackSignal.js +32 -281
- package/dist/cjs/telemetry/canary.js +180 -0
- package/dist/cjs/telemetry/canaryEvaluation.js +79 -0
- package/dist/cjs/telemetry/canarySetup.js +107 -0
- package/dist/cjs/telemetry/envelope.js +223 -0
- package/dist/cjs/telemetry/exporters.js +148 -0
- package/dist/cjs/telemetry/lifecycle.js +98 -0
- package/dist/cjs/telemetry/metrics.js +115 -0
- package/dist/cjs/telemetry/plugin.js +185 -0
- package/dist/cjs/telemetry/registry.js +296 -0
- package/dist/cjs/telemetry/registryTypes.js +46 -0
- package/dist/cjs/telemetry/runtimeEndpoints.js +135 -0
- package/dist/cjs/telemetry.js +32 -343
- package/dist/cjs/telemetryCore.js +14 -767
- package/dist/esm/contract-gate-snapshot-normalization.mjs +81 -0
- package/dist/esm/contract-gate-snapshot-store/file-store.mjs +51 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +92 -0
- package/dist/esm/contract-gate-snapshot-store/index.mjs +4 -0
- package/dist/esm/contract-gate-snapshot-store/resolve.mjs +70 -0
- package/dist/esm/contract-gate-snapshot-store/types.mjs +3 -0
- package/dist/esm/contractGateAutopilot.mjs +21 -69
- package/dist/esm/index.mjs +1 -2
- package/dist/esm/mfCache.mjs +2 -2
- package/dist/esm/module-federation-css/collector.mjs +38 -0
- package/dist/esm/module-federation-css/index.mjs +4 -0
- package/dist/esm/module-federation-css/manifest.mjs +69 -0
- package/dist/esm/module-federation-css/plugin.mjs +33 -0
- package/dist/esm/module-federation-css/remote.mjs +92 -0
- package/dist/esm/runtime-fallback-signal/index.mjs +3 -0
- package/dist/esm/runtime-fallback-signal/model.mjs +73 -0
- package/dist/esm/runtime-fallback-signal/resolver.mjs +107 -0
- package/dist/esm/runtime-fallback-signal/store.mjs +39 -0
- package/dist/esm/runtimeFallbackSignal.mjs +1 -222
- package/dist/esm/telemetry/canary.mjs +142 -0
- package/dist/esm/telemetry/canaryEvaluation.mjs +41 -0
- package/dist/esm/telemetry/canarySetup.mjs +69 -0
- package/dist/esm/telemetry/envelope.mjs +164 -0
- package/dist/esm/telemetry/exporters.mjs +104 -0
- package/dist/esm/telemetry/lifecycle.mjs +60 -0
- package/dist/esm/telemetry/metrics.mjs +77 -0
- package/dist/esm/telemetry/plugin.mjs +87 -0
- package/dist/esm/telemetry/registry.mjs +258 -0
- package/dist/esm/telemetry/registryTypes.mjs +8 -0
- package/dist/esm/telemetry/runtimeEndpoints.mjs +94 -0
- package/dist/esm/telemetry.mjs +1 -275
- package/dist/esm/telemetryCore.mjs +6 -759
- package/dist/esm-node/contract-gate-snapshot-normalization.mjs +82 -0
- package/dist/esm-node/contract-gate-snapshot-store/file-store.mjs +52 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +93 -0
- package/dist/esm-node/contract-gate-snapshot-store/index.mjs +5 -0
- package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +71 -0
- package/dist/esm-node/contract-gate-snapshot-store/types.mjs +4 -0
- package/dist/esm-node/contractGateAutopilot.mjs +21 -69
- package/dist/esm-node/index.mjs +1 -2
- package/dist/esm-node/mfCache.mjs +2 -2
- package/dist/esm-node/module-federation-css/collector.mjs +39 -0
- package/dist/esm-node/module-federation-css/index.mjs +5 -0
- package/dist/esm-node/module-federation-css/manifest.mjs +70 -0
- package/dist/esm-node/module-federation-css/plugin.mjs +34 -0
- package/dist/esm-node/module-federation-css/remote.mjs +93 -0
- package/dist/esm-node/runtime-fallback-signal/index.mjs +4 -0
- package/dist/esm-node/runtime-fallback-signal/model.mjs +74 -0
- package/dist/esm-node/runtime-fallback-signal/resolver.mjs +108 -0
- package/dist/esm-node/runtime-fallback-signal/store.mjs +40 -0
- package/dist/esm-node/runtimeFallbackSignal.mjs +1 -222
- package/dist/esm-node/telemetry/canary.mjs +143 -0
- package/dist/esm-node/telemetry/canaryEvaluation.mjs +42 -0
- package/dist/esm-node/telemetry/canarySetup.mjs +70 -0
- package/dist/esm-node/telemetry/envelope.mjs +165 -0
- package/dist/esm-node/telemetry/exporters.mjs +105 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +61 -0
- package/dist/esm-node/telemetry/metrics.mjs +78 -0
- package/dist/esm-node/telemetry/plugin.mjs +88 -0
- package/dist/esm-node/telemetry/registry.mjs +259 -0
- package/dist/esm-node/telemetry/registryTypes.mjs +9 -0
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +95 -0
- package/dist/esm-node/telemetry.mjs +1 -275
- package/dist/esm-node/telemetryCore.mjs +6 -759
- package/dist/types/contract-gate-snapshot-normalization.d.ts +15 -0
- package/dist/types/contract-gate-snapshot-store/file-store.d.ts +3 -0
- package/dist/types/contract-gate-snapshot-store/http-store.d.ts +5 -0
- package/dist/types/contract-gate-snapshot-store/index.d.ts +5 -0
- package/dist/types/contract-gate-snapshot-store/resolve.d.ts +9 -0
- package/dist/types/{contractGateSnapshotStore.d.ts → contract-gate-snapshot-store/types.d.ts} +1 -11
- package/dist/types/contractGateAutopilot.d.ts +3 -6
- package/dist/types/index.d.ts +1 -2
- package/dist/types/module-federation-css/collector.d.ts +25 -0
- package/dist/types/module-federation-css/index.d.ts +8 -0
- package/dist/types/module-federation-css/manifest.d.ts +28 -0
- package/dist/types/module-federation-css/plugin.d.ts +23 -0
- package/dist/types/module-federation-css/remote.d.ts +20 -0
- package/dist/types/runtime-fallback-signal/index.d.ts +4 -0
- package/dist/types/runtime-fallback-signal/model.d.ts +70 -0
- package/dist/types/runtime-fallback-signal/resolver.d.ts +29 -0
- package/dist/types/runtime-fallback-signal/store.d.ts +4 -0
- package/dist/types/runtimeFallbackSignal.d.ts +1 -94
- package/dist/types/telemetry/canary.d.ts +85 -0
- package/dist/types/telemetry/canaryEvaluation.d.ts +20 -0
- package/dist/types/telemetry/canarySetup.d.ts +17 -0
- package/dist/types/telemetry/envelope.d.ts +55 -0
- package/dist/types/telemetry/exporters.d.ts +12 -0
- package/dist/types/telemetry/lifecycle.d.ts +18 -0
- package/dist/types/telemetry/metrics.d.ts +3 -0
- package/dist/types/telemetry/plugin.d.ts +12 -0
- package/dist/types/telemetry/registry.d.ts +69 -0
- package/dist/types/telemetry/registryTypes.d.ts +50 -0
- package/dist/types/telemetry/runtimeEndpoints.d.ts +35 -0
- package/dist/types/telemetry.d.ts +1 -12
- package/dist/types/telemetryCore.d.ts +6 -257
- package/package.json +11 -13
- package/src/contract-gate-snapshot-normalization.ts +155 -0
- package/src/contract-gate-snapshot-store/file-store.ts +83 -0
- package/src/contract-gate-snapshot-store/http-store.ts +159 -0
- package/src/contract-gate-snapshot-store/index.ts +20 -0
- package/src/contract-gate-snapshot-store/resolve.ts +179 -0
- package/src/contract-gate-snapshot-store/types.ts +64 -0
- package/src/contractGateAutopilot.ts +39 -131
- package/src/index.ts +1 -17
- package/src/mfCache.ts +3 -1
- package/src/module-federation-css/collector.ts +82 -0
- package/src/module-federation-css/index.ts +14 -0
- package/src/module-federation-css/manifest.ts +163 -0
- package/src/module-federation-css/plugin.ts +86 -0
- package/src/module-federation-css/remote.ts +165 -0
- package/src/runtime-fallback-signal/index.ts +34 -0
- package/src/runtime-fallback-signal/model.ts +230 -0
- package/src/runtime-fallback-signal/resolver.ts +304 -0
- package/src/runtime-fallback-signal/store.ts +78 -0
- package/src/runtimeFallbackSignal.ts +1 -584
- package/src/telemetry/canary.ts +291 -0
- package/src/telemetry/canaryEvaluation.ts +83 -0
- package/src/telemetry/canarySetup.ts +160 -0
- package/src/telemetry/envelope.ts +277 -0
- package/src/telemetry/exporters.ts +165 -0
- package/src/telemetry/lifecycle.ts +138 -0
- package/src/telemetry/metrics.ts +141 -0
- package/src/telemetry/plugin.ts +197 -0
- package/src/telemetry/registry.ts +424 -0
- package/src/telemetry/registryTypes.ts +63 -0
- package/src/telemetry/runtimeEndpoints.ts +172 -0
- package/src/telemetry.ts +1 -554
- package/src/telemetryCore.ts +34 -1332
- package/tests/contractGateAutopilot.test.ts +205 -0
- package/tests/contractGateSnapshotStore.test.ts +54 -1
- package/tests/helpers.ts +1 -0
- package/tests/moduleFederationCss.test.ts +1 -1
- package/tests/registration.test.ts +1 -1
- package/tests/telemetry.test.ts +51 -0
- package/tests/telemetryAutopilot.test.ts +141 -0
- package/tests/telemetryCanaryOrchestrator.test.ts +225 -0
- package/tests/telemetryLifecycle.test.ts +253 -2
- package/tests/telemetryRegistryQueueMatrix.test.ts +227 -0
- package/dist/cjs/contractGateSnapshotStore.js +0 -253
- package/dist/cjs/moduleFederationCss.js +0 -285
- package/dist/esm/contractGateSnapshotStore.mjs +0 -190
- package/dist/esm/moduleFederationCss.mjs +0 -225
- package/dist/esm-node/contractGateSnapshotStore.mjs +0 -192
- package/dist/esm-node/moduleFederationCss.mjs +0 -226
- package/dist/types/moduleFederationCss.d.ts +0 -87
- package/src/contractGateSnapshotStore.ts +0 -420
- package/src/moduleFederationCss.ts +0 -473
|
@@ -137,4 +137,229 @@ describe('telemetry canary orchestrator', () => {
|
|
|
137
137
|
|
|
138
138
|
await registry.shutdown();
|
|
139
139
|
});
|
|
140
|
+
|
|
141
|
+
test('stays canary below the healthy threshold and promotes after consecutive healthy evaluations', async () => {
|
|
142
|
+
const registry = new TelemetryRegistry({
|
|
143
|
+
service: 'svc',
|
|
144
|
+
module: 'server',
|
|
145
|
+
environment: 'test',
|
|
146
|
+
flushIntervalMs: 60_000,
|
|
147
|
+
});
|
|
148
|
+
const onEvaluate = rs.fn();
|
|
149
|
+
const onPromote = rs.fn();
|
|
150
|
+
const onRollback = rs.fn();
|
|
151
|
+
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
152
|
+
registry,
|
|
153
|
+
minConsecutiveHealthyEvaluations: 3,
|
|
154
|
+
onEvaluate,
|
|
155
|
+
onPromote,
|
|
156
|
+
onRollback,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
const first = orchestrator.evaluate();
|
|
160
|
+
expect(first.action).toBe('hold');
|
|
161
|
+
expect(first.state).toBe('canary');
|
|
162
|
+
expect(first.consecutiveHealthy).toBe(1);
|
|
163
|
+
|
|
164
|
+
const second = orchestrator.evaluate();
|
|
165
|
+
expect(second.action).toBe('hold');
|
|
166
|
+
expect(second.state).toBe('canary');
|
|
167
|
+
expect(second.consecutiveHealthy).toBe(2);
|
|
168
|
+
expect(onPromote).not.toHaveBeenCalled();
|
|
169
|
+
|
|
170
|
+
const third = orchestrator.evaluate();
|
|
171
|
+
expect(third.action).toBe('promote');
|
|
172
|
+
expect(third.state).toBe('promoted');
|
|
173
|
+
expect(third.consecutiveHealthy).toBe(3);
|
|
174
|
+
|
|
175
|
+
expect(onEvaluate).toHaveBeenCalledTimes(3);
|
|
176
|
+
expect(onEvaluate).toHaveBeenNthCalledWith(1, first);
|
|
177
|
+
expect(onEvaluate).toHaveBeenNthCalledWith(2, second);
|
|
178
|
+
expect(onEvaluate).toHaveBeenNthCalledWith(3, third);
|
|
179
|
+
expect(onPromote).toHaveBeenCalledTimes(1);
|
|
180
|
+
expect(onPromote).toHaveBeenCalledWith(third);
|
|
181
|
+
expect(onRollback).not.toHaveBeenCalled();
|
|
182
|
+
|
|
183
|
+
await registry.shutdown();
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
test('rolls back after consecutive failures and stays rolled back until reset', async () => {
|
|
187
|
+
const registry = new TelemetryRegistry({
|
|
188
|
+
service: 'svc',
|
|
189
|
+
module: 'server',
|
|
190
|
+
environment: 'test',
|
|
191
|
+
flushIntervalMs: 60_000,
|
|
192
|
+
});
|
|
193
|
+
const onEvaluate = rs.fn();
|
|
194
|
+
const onPromote = rs.fn();
|
|
195
|
+
const onRollback = rs.fn();
|
|
196
|
+
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
197
|
+
registry,
|
|
198
|
+
minConsecutiveHealthyEvaluations: 1,
|
|
199
|
+
rollbackConsecutiveFailures: 2,
|
|
200
|
+
requiredContractGates: ['contracts'],
|
|
201
|
+
onEvaluate,
|
|
202
|
+
onPromote,
|
|
203
|
+
onRollback,
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
orchestrator.setContractGate('contracts', false, 'schema drift');
|
|
207
|
+
|
|
208
|
+
const firstFailure = orchestrator.evaluate();
|
|
209
|
+
expect(firstFailure.action).toBe('hold');
|
|
210
|
+
expect(firstFailure.state).toBe('canary');
|
|
211
|
+
expect(firstFailure.consecutiveFailures).toBe(1);
|
|
212
|
+
expect(onRollback).not.toHaveBeenCalled();
|
|
213
|
+
|
|
214
|
+
const secondFailure = orchestrator.evaluate();
|
|
215
|
+
expect(secondFailure.action).toBe('rollback');
|
|
216
|
+
expect(secondFailure.state).toBe('rolled_back');
|
|
217
|
+
expect(secondFailure.consecutiveFailures).toBe(2);
|
|
218
|
+
expect(onRollback).toHaveBeenCalledTimes(1);
|
|
219
|
+
expect(onRollback).toHaveBeenCalledWith(secondFailure);
|
|
220
|
+
|
|
221
|
+
orchestrator.setContractGate('contracts', true);
|
|
222
|
+
const healthyWhileRolledBack = orchestrator.evaluate();
|
|
223
|
+
expect(healthyWhileRolledBack.action).toBe('hold');
|
|
224
|
+
expect(healthyWhileRolledBack.state).toBe('rolled_back');
|
|
225
|
+
expect(healthyWhileRolledBack.consecutiveHealthy).toBe(1);
|
|
226
|
+
expect(onPromote).not.toHaveBeenCalled();
|
|
227
|
+
expect(onRollback).toHaveBeenCalledTimes(1);
|
|
228
|
+
|
|
229
|
+
orchestrator.resetToCanary();
|
|
230
|
+
expect(orchestrator.getStatusSnapshot().state).toBe('canary');
|
|
231
|
+
|
|
232
|
+
const promotedAfterReset = orchestrator.evaluate();
|
|
233
|
+
expect(promotedAfterReset.action).toBe('promote');
|
|
234
|
+
expect(promotedAfterReset.state).toBe('promoted');
|
|
235
|
+
expect(onEvaluate).toHaveBeenCalledTimes(4);
|
|
236
|
+
expect(onPromote).toHaveBeenCalledTimes(1);
|
|
237
|
+
expect(onPromote).toHaveBeenCalledWith(promotedAfterReset);
|
|
238
|
+
|
|
239
|
+
await registry.shutdown();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
test('blocks promotion until required contract gates pass', async () => {
|
|
243
|
+
const registry = new TelemetryRegistry({
|
|
244
|
+
service: 'svc',
|
|
245
|
+
module: 'server',
|
|
246
|
+
environment: 'test',
|
|
247
|
+
flushIntervalMs: 60_000,
|
|
248
|
+
});
|
|
249
|
+
const onPromote = rs.fn();
|
|
250
|
+
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
251
|
+
registry,
|
|
252
|
+
minConsecutiveHealthyEvaluations: 1,
|
|
253
|
+
rollbackConsecutiveFailures: 10,
|
|
254
|
+
requiredContractGates: ['contracts', 'runtime'],
|
|
255
|
+
onPromote,
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
orchestrator.setContractGate('contracts', true);
|
|
259
|
+
const missingGateDecision = orchestrator.evaluate();
|
|
260
|
+
expect(missingGateDecision.action).toBe('hold');
|
|
261
|
+
expect(missingGateDecision.state).toBe('canary');
|
|
262
|
+
expect(missingGateDecision.consecutiveHealthy).toBe(0);
|
|
263
|
+
expect(missingGateDecision.failures).toEqual(
|
|
264
|
+
expect.arrayContaining([
|
|
265
|
+
expect.objectContaining({
|
|
266
|
+
reason: 'contract_gate_missing',
|
|
267
|
+
gate: 'runtime',
|
|
268
|
+
}),
|
|
269
|
+
]),
|
|
270
|
+
);
|
|
271
|
+
expect(onPromote).not.toHaveBeenCalled();
|
|
272
|
+
|
|
273
|
+
orchestrator.setContractGate('runtime', false, 'runtime contract failed');
|
|
274
|
+
const failedGateDecision = orchestrator.evaluate();
|
|
275
|
+
expect(failedGateDecision.action).toBe('hold');
|
|
276
|
+
expect(failedGateDecision.state).toBe('canary');
|
|
277
|
+
expect(failedGateDecision.failures).toEqual(
|
|
278
|
+
expect.arrayContaining([
|
|
279
|
+
expect.objectContaining({
|
|
280
|
+
reason: 'contract_gate_failed',
|
|
281
|
+
gate: 'runtime',
|
|
282
|
+
}),
|
|
283
|
+
]),
|
|
284
|
+
);
|
|
285
|
+
expect(onPromote).not.toHaveBeenCalled();
|
|
286
|
+
|
|
287
|
+
orchestrator.setContractGate('runtime', true);
|
|
288
|
+
const passingGateDecision = orchestrator.evaluate();
|
|
289
|
+
expect(passingGateDecision.action).toBe('promote');
|
|
290
|
+
expect(passingGateDecision.state).toBe('promoted');
|
|
291
|
+
expect(passingGateDecision.failures).toHaveLength(0);
|
|
292
|
+
expect(onPromote).toHaveBeenCalledTimes(1);
|
|
293
|
+
expect(onPromote).toHaveBeenCalledWith(passingGateDecision);
|
|
294
|
+
|
|
295
|
+
await registry.shutdown();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
test('observer hook failures do not escape or block later hooks', async () => {
|
|
299
|
+
const promotingRegistry = new TelemetryRegistry({
|
|
300
|
+
service: 'svc',
|
|
301
|
+
module: 'server',
|
|
302
|
+
environment: 'test',
|
|
303
|
+
flushIntervalMs: 60_000,
|
|
304
|
+
});
|
|
305
|
+
const onPromoteEvaluate = rs.fn(() => {
|
|
306
|
+
throw new Error('evaluate promote failed');
|
|
307
|
+
});
|
|
308
|
+
const onPromote = rs.fn(() => {
|
|
309
|
+
throw new Error('promote failed');
|
|
310
|
+
});
|
|
311
|
+
const promotingOrchestrator = new TelemetryCanaryOrchestrator({
|
|
312
|
+
registry: promotingRegistry,
|
|
313
|
+
minConsecutiveHealthyEvaluations: 1,
|
|
314
|
+
onEvaluate: onPromoteEvaluate,
|
|
315
|
+
onPromote,
|
|
316
|
+
});
|
|
317
|
+
let promotedDecision:
|
|
318
|
+
| ReturnType<TelemetryCanaryOrchestrator['evaluate']>
|
|
319
|
+
| undefined;
|
|
320
|
+
|
|
321
|
+
expect(() => {
|
|
322
|
+
promotedDecision = promotingOrchestrator.evaluate();
|
|
323
|
+
}).not.toThrow();
|
|
324
|
+
|
|
325
|
+
expect(promotedDecision?.action).toBe('promote');
|
|
326
|
+
expect(promotedDecision?.state).toBe('promoted');
|
|
327
|
+
expect(onPromoteEvaluate).toHaveBeenCalledTimes(1);
|
|
328
|
+
expect(onPromote).toHaveBeenCalledTimes(1);
|
|
329
|
+
|
|
330
|
+
const rollbackRegistry = new TelemetryRegistry({
|
|
331
|
+
service: 'svc',
|
|
332
|
+
module: 'server',
|
|
333
|
+
environment: 'test',
|
|
334
|
+
flushIntervalMs: 60_000,
|
|
335
|
+
});
|
|
336
|
+
const onRollbackEvaluate = rs.fn(() => {
|
|
337
|
+
throw new Error('evaluate rollback failed');
|
|
338
|
+
});
|
|
339
|
+
const onRollback = rs.fn(() => {
|
|
340
|
+
throw new Error('rollback failed');
|
|
341
|
+
});
|
|
342
|
+
const rollbackOrchestrator = new TelemetryCanaryOrchestrator({
|
|
343
|
+
registry: rollbackRegistry,
|
|
344
|
+
rollbackConsecutiveFailures: 1,
|
|
345
|
+
requiredContractGates: ['contracts'],
|
|
346
|
+
onEvaluate: onRollbackEvaluate,
|
|
347
|
+
onRollback,
|
|
348
|
+
});
|
|
349
|
+
let rollbackDecision:
|
|
350
|
+
| ReturnType<TelemetryCanaryOrchestrator['evaluate']>
|
|
351
|
+
| undefined;
|
|
352
|
+
|
|
353
|
+
expect(() => {
|
|
354
|
+
rollbackDecision = rollbackOrchestrator.evaluate();
|
|
355
|
+
}).not.toThrow();
|
|
356
|
+
|
|
357
|
+
expect(rollbackDecision?.action).toBe('rollback');
|
|
358
|
+
expect(rollbackDecision?.state).toBe('rolled_back');
|
|
359
|
+
expect(onRollbackEvaluate).toHaveBeenCalledTimes(1);
|
|
360
|
+
expect(onRollback).toHaveBeenCalledTimes(1);
|
|
361
|
+
|
|
362
|
+
await promotingRegistry.shutdown();
|
|
363
|
+
await rollbackRegistry.shutdown();
|
|
364
|
+
});
|
|
140
365
|
});
|
|
@@ -5,6 +5,9 @@ import {
|
|
|
5
5
|
type ServerPlugin,
|
|
6
6
|
} from '@modern-js/server-core';
|
|
7
7
|
import { logger } from '@modern-js/utils';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import os from 'os';
|
|
10
|
+
import path from 'path';
|
|
8
11
|
import { injectTelemetryPlugin } from '../src/telemetry';
|
|
9
12
|
import { getDefaultAppContext, getDefaultConfig } from './helpers';
|
|
10
13
|
|
|
@@ -32,9 +35,12 @@ const emitMonitorEventsPlugin = (input: {
|
|
|
32
35
|
},
|
|
33
36
|
});
|
|
34
37
|
|
|
35
|
-
const waitFor = async (
|
|
38
|
+
const waitFor = async (
|
|
39
|
+
predicate: () => boolean | Promise<boolean>,
|
|
40
|
+
timeoutMs = 2_000,
|
|
41
|
+
) => {
|
|
36
42
|
const startedAt = Date.now();
|
|
37
|
-
while (!predicate()) {
|
|
43
|
+
while (!(await predicate())) {
|
|
38
44
|
if (Date.now() - startedAt > timeoutMs) {
|
|
39
45
|
throw new Error('waitFor timed out');
|
|
40
46
|
}
|
|
@@ -93,6 +99,251 @@ describe('telemetry plugin lifecycle', () => {
|
|
|
93
99
|
}
|
|
94
100
|
});
|
|
95
101
|
|
|
102
|
+
test('boots canary autopilot lane and exports rollback telemetry', async () => {
|
|
103
|
+
const tempDir = fs.mkdtempSync(
|
|
104
|
+
path.join(os.tmpdir(), 'modern-telemetry-lifecycle-'),
|
|
105
|
+
);
|
|
106
|
+
const gateName = 'runtime-mf-fallback-health';
|
|
107
|
+
const signalToken = 'canary-lifecycle-token';
|
|
108
|
+
const snapshotPath = path.join(tempDir, '.modern/contract-gates.json');
|
|
109
|
+
const otlpEndpoint = 'http://127.0.0.1:4318/v1/logs';
|
|
110
|
+
const fetchCalls: Array<{
|
|
111
|
+
url: string;
|
|
112
|
+
body: string;
|
|
113
|
+
headers: HeadersInit | undefined;
|
|
114
|
+
}> = [];
|
|
115
|
+
const fetchMock = rs.fn(async (url: any, init?: RequestInit) => {
|
|
116
|
+
fetchCalls.push({
|
|
117
|
+
url: String(url),
|
|
118
|
+
body: String(init?.body ?? ''),
|
|
119
|
+
headers: init?.headers,
|
|
120
|
+
});
|
|
121
|
+
return new Response('{}', { status: 200 });
|
|
122
|
+
});
|
|
123
|
+
const warnSpy = rs.spyOn(logger, 'warn').mockImplementation(() => {});
|
|
124
|
+
const originalFetch = globalThis.fetch;
|
|
125
|
+
globalThis.fetch = fetchMock as typeof fetch;
|
|
126
|
+
|
|
127
|
+
const nodeServerStub = new EventEmitter();
|
|
128
|
+
const stubNodeServerPlugin: ServerPlugin = {
|
|
129
|
+
name: 'stub-node-server',
|
|
130
|
+
setup(api) {
|
|
131
|
+
api.updateServerContext({ nodeServer: nodeServerStub } as any);
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
try {
|
|
136
|
+
fs.mkdirSync(path.dirname(snapshotPath), { recursive: true });
|
|
137
|
+
fs.writeFileSync(
|
|
138
|
+
snapshotPath,
|
|
139
|
+
JSON.stringify({
|
|
140
|
+
schemaVersion: 1,
|
|
141
|
+
updatedAt: Date.now(),
|
|
142
|
+
gates: {
|
|
143
|
+
[gateName]: {
|
|
144
|
+
passed: true,
|
|
145
|
+
updatedAt: Date.now(),
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
}),
|
|
149
|
+
'utf8',
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
const config = getDefaultConfig();
|
|
153
|
+
config.server = {
|
|
154
|
+
telemetry: {
|
|
155
|
+
enabled: true,
|
|
156
|
+
service: 'runtime-extensions-test',
|
|
157
|
+
module: 'telemetry-lifecycle',
|
|
158
|
+
environment: 'test',
|
|
159
|
+
maxQueueSize: 64,
|
|
160
|
+
maxBatchSize: 100,
|
|
161
|
+
flushIntervalMs: 60_000,
|
|
162
|
+
slo: {
|
|
163
|
+
queueUtilizationWarnThreshold: 0.01,
|
|
164
|
+
alertCooldownMs: 0,
|
|
165
|
+
},
|
|
166
|
+
exporters: {
|
|
167
|
+
otlp: {
|
|
168
|
+
enabled: true,
|
|
169
|
+
endpoint: otlpEndpoint,
|
|
170
|
+
headers: {
|
|
171
|
+
'x-modernjs-test': 'canary-autopilot',
|
|
172
|
+
},
|
|
173
|
+
timeoutMs: 200,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
canary: {
|
|
177
|
+
enabled: true,
|
|
178
|
+
evaluationIntervalMs: 250,
|
|
179
|
+
minConsecutiveHealthyEvaluations: 1,
|
|
180
|
+
rollbackConsecutiveFailures: 1,
|
|
181
|
+
maxQueueUtilization: 1,
|
|
182
|
+
maxTotalDropped: 0,
|
|
183
|
+
maxUnhealthyExporters: 0,
|
|
184
|
+
contractGates: {
|
|
185
|
+
[gateName]: true,
|
|
186
|
+
},
|
|
187
|
+
autopilot: {
|
|
188
|
+
enabled: true,
|
|
189
|
+
gateSnapshotPath: snapshotPath,
|
|
190
|
+
pollIntervalMs: 250,
|
|
191
|
+
gateStaleAfterMs: 60_000,
|
|
192
|
+
runtimeFallbackSignal: {
|
|
193
|
+
enabled: true,
|
|
194
|
+
endpoint: '/_modern/contract-gates/runtime-fallback',
|
|
195
|
+
gateName,
|
|
196
|
+
failureHoldMs: 5_000,
|
|
197
|
+
maxBodyBytes: 4_096,
|
|
198
|
+
auth: {
|
|
199
|
+
expectedValue: signalToken,
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
} as any;
|
|
206
|
+
|
|
207
|
+
const server = createServerBase({
|
|
208
|
+
config,
|
|
209
|
+
pwd: tempDir,
|
|
210
|
+
appContext: getDefaultAppContext(),
|
|
211
|
+
});
|
|
212
|
+
server.addPlugins([
|
|
213
|
+
...createDefaultPlugins({ logger: false }),
|
|
214
|
+
stubNodeServerPlugin,
|
|
215
|
+
injectTelemetryPlugin(),
|
|
216
|
+
emitMonitorEventsPlugin({
|
|
217
|
+
path: '/emit',
|
|
218
|
+
message: 'canary-request',
|
|
219
|
+
count: 2,
|
|
220
|
+
}),
|
|
221
|
+
]);
|
|
222
|
+
await server.init();
|
|
223
|
+
|
|
224
|
+
const statusHeaders = new Headers({
|
|
225
|
+
'x-modernjs-runtime-signal-token': signalToken,
|
|
226
|
+
});
|
|
227
|
+
let statusPayload: any;
|
|
228
|
+
|
|
229
|
+
await waitFor(async () => {
|
|
230
|
+
const status = await server.request(
|
|
231
|
+
'/_modern/runtime/status',
|
|
232
|
+
{
|
|
233
|
+
method: 'GET',
|
|
234
|
+
headers: statusHeaders,
|
|
235
|
+
},
|
|
236
|
+
{},
|
|
237
|
+
);
|
|
238
|
+
expect(status.status).toBe(200);
|
|
239
|
+
statusPayload = await status.json();
|
|
240
|
+
return (
|
|
241
|
+
statusPayload.canary?.state === 'promoted' &&
|
|
242
|
+
statusPayload.canary?.contractGates?.some(
|
|
243
|
+
(gate: any) => gate.name === gateName && gate.passed === true,
|
|
244
|
+
)
|
|
245
|
+
);
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
const emitResponse = await server.request('/emit', {}, {});
|
|
249
|
+
expect(emitResponse.status).toBe(200);
|
|
250
|
+
|
|
251
|
+
const signalResponse = await server.request(
|
|
252
|
+
'/_modern/contract-gates/runtime-fallback',
|
|
253
|
+
{
|
|
254
|
+
method: 'POST',
|
|
255
|
+
headers: new Headers({
|
|
256
|
+
'content-type': 'application/json',
|
|
257
|
+
'x-modernjs-runtime-signal-token': signalToken,
|
|
258
|
+
}),
|
|
259
|
+
body: JSON.stringify({
|
|
260
|
+
reason: 'remote_load_failed',
|
|
261
|
+
phase: 'load',
|
|
262
|
+
appName: 'crm',
|
|
263
|
+
entry: 'https://remote.example.com/remoteEntry.js',
|
|
264
|
+
}),
|
|
265
|
+
},
|
|
266
|
+
{},
|
|
267
|
+
);
|
|
268
|
+
expect(signalResponse.status).toBe(202);
|
|
269
|
+
|
|
270
|
+
const persistedSnapshot = JSON.parse(
|
|
271
|
+
fs.readFileSync(snapshotPath, 'utf8'),
|
|
272
|
+
) as {
|
|
273
|
+
gates?: Record<
|
|
274
|
+
string,
|
|
275
|
+
{
|
|
276
|
+
expiresAt?: number;
|
|
277
|
+
passed?: boolean;
|
|
278
|
+
reason?: string;
|
|
279
|
+
}
|
|
280
|
+
>;
|
|
281
|
+
};
|
|
282
|
+
expect(persistedSnapshot.gates?.[gateName]?.passed).toBe(false);
|
|
283
|
+
expect(persistedSnapshot.gates?.[gateName]?.expiresAt).toBeGreaterThan(
|
|
284
|
+
Date.now(),
|
|
285
|
+
);
|
|
286
|
+
|
|
287
|
+
await waitFor(async () => {
|
|
288
|
+
const status = await server.request(
|
|
289
|
+
'/_modern/runtime/status',
|
|
290
|
+
{
|
|
291
|
+
method: 'GET',
|
|
292
|
+
headers: statusHeaders,
|
|
293
|
+
},
|
|
294
|
+
{},
|
|
295
|
+
);
|
|
296
|
+
expect(status.status).toBe(200);
|
|
297
|
+
statusPayload = await status.json();
|
|
298
|
+
return (
|
|
299
|
+
statusPayload.canary?.state === 'rolled_back' &&
|
|
300
|
+
statusPayload.canary?.contractGates?.some(
|
|
301
|
+
(gate: any) =>
|
|
302
|
+
gate.name === gateName &&
|
|
303
|
+
gate.passed === false &&
|
|
304
|
+
String(gate.reason).includes('remote_load_failed'),
|
|
305
|
+
)
|
|
306
|
+
);
|
|
307
|
+
}, 4_000);
|
|
308
|
+
|
|
309
|
+
expect(statusPayload.telemetry?.exporterHealth).toContainEqual(
|
|
310
|
+
expect.objectContaining({
|
|
311
|
+
name: 'otlp',
|
|
312
|
+
healthy: true,
|
|
313
|
+
}),
|
|
314
|
+
);
|
|
315
|
+
expect(
|
|
316
|
+
fetchCalls.some(
|
|
317
|
+
call =>
|
|
318
|
+
call.url === otlpEndpoint &&
|
|
319
|
+
(call.headers as Record<string, string>)['x-modernjs-test'] ===
|
|
320
|
+
'canary-autopilot',
|
|
321
|
+
),
|
|
322
|
+
).toBe(true);
|
|
323
|
+
expect(
|
|
324
|
+
warnSpy.mock.calls.some(call =>
|
|
325
|
+
String(call[0]).includes('[telemetry.slo] queue.utilization'),
|
|
326
|
+
),
|
|
327
|
+
).toBe(true);
|
|
328
|
+
|
|
329
|
+
nodeServerStub.emit('close');
|
|
330
|
+
|
|
331
|
+
await waitFor(() =>
|
|
332
|
+
fetchCalls.some(call =>
|
|
333
|
+
call.body.includes('telemetry.canary.rollback'),
|
|
334
|
+
),
|
|
335
|
+
);
|
|
336
|
+
const exportedBodies = fetchCalls.map(call => call.body).join('\n');
|
|
337
|
+
expect(exportedBodies).toContain('telemetry.canary.rollback');
|
|
338
|
+
expect(exportedBodies).toContain('canary-request-0');
|
|
339
|
+
} finally {
|
|
340
|
+
nodeServerStub.emit('close');
|
|
341
|
+
globalThis.fetch = originalFetch;
|
|
342
|
+
warnSpy.mockRestore();
|
|
343
|
+
fs.rmSync(tempDir, { recursive: true, force: true });
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
|
|
96
347
|
test('flushes pending envelopes when the node server closes', async () => {
|
|
97
348
|
const fetchCalls: Array<{ url: string; body: string }> = [];
|
|
98
349
|
const fetchMock = rs.fn(async (url: any, init?: any) => {
|