@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.1 → 3.8.3-ultramodern.2
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/backend-federation-security/index.js +415 -0
- package/dist/cjs/backend-federation-security/node.js +74 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +1 -1
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +4 -4
- package/dist/cjs/{contractGateAutopilot.js → contractGateSnapshotObserver.js} +14 -17
- package/dist/cjs/index.js +45 -13
- package/dist/cjs/runtime-fallback-signal/resolver.js +3 -3
- package/dist/cjs/runtimeLifecycle.js +129 -0
- package/dist/cjs/telemetry/{canaryEvaluation.js → healthEvaluation.js} +11 -13
- package/dist/cjs/telemetry/{canary.js → healthMonitor.js} +27 -44
- package/dist/cjs/telemetry/{canarySetup.js → healthSetup.js} +35 -39
- package/dist/cjs/telemetry/lifecycle.js +14 -14
- package/dist/cjs/telemetry/plugin.js +9 -9
- package/dist/cjs/telemetry/runtimeEndpoints.js +3 -3
- package/dist/cjs/telemetryCore.js +4 -4
- package/dist/esm/backend-federation-security/index.mjs +361 -0
- package/dist/esm/backend-federation-security/node.mjs +30 -0
- package/dist/esm/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm/contract-gate-snapshot-store/resolve.mjs +4 -4
- package/dist/esm/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
- package/dist/esm/index.mjs +4 -2
- package/dist/esm/runtime-fallback-signal/resolver.mjs +3 -3
- package/dist/esm/runtimeLifecycle.mjs +82 -0
- package/dist/esm/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
- package/dist/esm/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
- package/dist/esm/telemetry/healthSetup.mjs +65 -0
- package/dist/esm/telemetry/lifecycle.mjs +14 -14
- package/dist/esm/telemetry/plugin.mjs +8 -8
- package/dist/esm/telemetry/runtimeEndpoints.mjs +3 -3
- package/dist/esm/telemetryCore.mjs +1 -1
- package/dist/esm-node/backend-federation-security/index.mjs +362 -0
- package/dist/esm-node/backend-federation-security/node.mjs +31 -0
- package/dist/esm-node/contract-gate-snapshot-store/http-store.mjs +1 -1
- package/dist/esm-node/contract-gate-snapshot-store/resolve.mjs +4 -4
- package/dist/esm-node/{contractGateAutopilot.mjs → contractGateSnapshotObserver.mjs} +12 -15
- package/dist/esm-node/index.mjs +4 -2
- package/dist/esm-node/runtime-fallback-signal/resolver.mjs +3 -3
- package/dist/esm-node/runtimeLifecycle.mjs +83 -0
- package/dist/esm-node/telemetry/{canaryEvaluation.mjs → healthEvaluation.mjs} +9 -11
- package/dist/esm-node/telemetry/{canary.mjs → healthMonitor.mjs} +25 -42
- package/dist/esm-node/telemetry/healthSetup.mjs +66 -0
- package/dist/esm-node/telemetry/lifecycle.mjs +14 -14
- package/dist/esm-node/telemetry/plugin.mjs +8 -8
- package/dist/esm-node/telemetry/runtimeEndpoints.mjs +3 -3
- package/dist/esm-node/telemetryCore.mjs +1 -1
- package/dist/types/backend-federation-security/index.d.ts +68 -0
- package/dist/types/backend-federation-security/node.d.ts +3 -0
- package/dist/types/{contractGateAutopilot.d.ts → contractGateSnapshotObserver.d.ts} +7 -6
- package/dist/types/index.d.ts +4 -2
- package/dist/types/runtime-fallback-signal/resolver.d.ts +2 -2
- package/dist/types/runtimeLifecycle.d.ts +10 -0
- package/dist/types/telemetry/healthEvaluation.d.ts +20 -0
- package/dist/types/telemetry/{canary.d.ts → healthMonitor.d.ts} +31 -28
- package/dist/types/telemetry/{canarySetup.d.ts → healthSetup.d.ts} +6 -6
- package/dist/types/telemetry/lifecycle.d.ts +4 -4
- package/dist/types/telemetry/plugin.d.ts +1 -1
- package/dist/types/telemetry/runtimeEndpoints.d.ts +3 -3
- package/dist/types/telemetryCore.d.ts +1 -1
- package/package.json +46 -8
- package/src/backend-federation-security/index.ts +831 -0
- package/src/backend-federation-security/node.ts +51 -0
- package/src/contract-gate-snapshot-store/http-store.ts +1 -1
- package/src/contract-gate-snapshot-store/resolve.ts +4 -4
- package/src/{contractGateAutopilot.ts → contractGateSnapshotObserver.ts} +18 -25
- package/src/index.ts +42 -6
- package/src/runtime-fallback-signal/resolver.ts +5 -5
- package/src/runtimeLifecycle.ts +125 -0
- package/src/telemetry/{canaryEvaluation.ts → healthEvaluation.ts} +14 -17
- package/src/telemetry/{canary.ts → healthMonitor.ts} +72 -84
- package/src/telemetry/{canarySetup.ts → healthSetup.ts} +50 -53
- package/src/telemetry/lifecycle.ts +20 -20
- package/src/telemetry/plugin.ts +16 -16
- package/src/telemetry/runtimeEndpoints.ts +6 -6
- package/src/telemetryCore.ts +11 -11
- package/tests/backendFederationSecurity.test.ts +416 -0
- package/tests/{contractGateAutopilot.test.ts → contractGateSnapshotObserver.test.ts} +59 -62
- package/tests/runtimeLifecycle.test.ts +107 -0
- package/tests/telemetryHealthMonitor.test.ts +187 -0
- package/dist/esm/telemetry/canarySetup.mjs +0 -69
- package/dist/esm-node/telemetry/canarySetup.mjs +0 -70
- package/dist/types/telemetry/canaryEvaluation.d.ts +0 -20
- package/tests/telemetryCanaryOrchestrator.test.ts +0 -365
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import "node:module";
|
|
2
|
-
import { DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH, resolveContractGateSnapshotPath, resolveContractGateSnapshotStore } from "../contract-gate-snapshot-store/index.mjs";
|
|
3
|
-
import { DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS, DEFAULT_RUNTIME_FALLBACK_GATE_NAME, DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES, createRuntimeFallbackSignalRuntimeState, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, resolveRuntimeFallbackSignalEndpoint } from "../runtimeFallbackSignal.mjs";
|
|
4
|
-
import { TelemetryCanaryOrchestrator } from "../telemetryCore.mjs";
|
|
5
|
-
function emitCanaryDecisionMetric(registry, decision, action) {
|
|
6
|
-
try {
|
|
7
|
-
registry.enqueueMetric({
|
|
8
|
-
name: `telemetry.canary.${action}`,
|
|
9
|
-
value: 1,
|
|
10
|
-
unit: 'count',
|
|
11
|
-
tags: {
|
|
12
|
-
action,
|
|
13
|
-
state: decision.state,
|
|
14
|
-
failures: String(decision.failures.length)
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
} catch (_error) {}
|
|
18
|
-
}
|
|
19
|
-
const setupTelemetryCanary = ({ registry, appDirectory, canaryConfig })=>{
|
|
20
|
-
if (!canaryConfig?.enabled) return {};
|
|
21
|
-
const contractGates = canaryConfig.contractGates;
|
|
22
|
-
const canaryOrchestrator = new TelemetryCanaryOrchestrator({
|
|
23
|
-
registry,
|
|
24
|
-
evaluationIntervalMs: canaryConfig.evaluationIntervalMs,
|
|
25
|
-
minConsecutiveHealthyEvaluations: canaryConfig.minConsecutiveHealthyEvaluations,
|
|
26
|
-
rollbackConsecutiveFailures: canaryConfig.rollbackConsecutiveFailures,
|
|
27
|
-
maxQueueUtilization: canaryConfig.maxQueueUtilization,
|
|
28
|
-
maxTotalDropped: canaryConfig.maxTotalDropped,
|
|
29
|
-
maxUnhealthyExporters: canaryConfig.maxUnhealthyExporters,
|
|
30
|
-
requiredContractGates: Object.keys(contractGates || {}),
|
|
31
|
-
onPromote: (decision)=>{
|
|
32
|
-
emitCanaryDecisionMetric(registry, decision, 'promote');
|
|
33
|
-
},
|
|
34
|
-
onRollback: (decision)=>{
|
|
35
|
-
emitCanaryDecisionMetric(registry, decision, 'rollback');
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
if (contractGates) canaryOrchestrator.setContractGates(contractGates);
|
|
39
|
-
let gateSnapshotStorePromise;
|
|
40
|
-
let runtimeFallbackSignalConfig;
|
|
41
|
-
const autopilotEnabled = canaryConfig.autopilot?.enabled ?? true;
|
|
42
|
-
if (autopilotEnabled) {
|
|
43
|
-
const gateSnapshotPath = resolveContractGateSnapshotPath(appDirectory, canaryConfig.autopilot?.gateSnapshotPath);
|
|
44
|
-
gateSnapshotStorePromise = resolveContractGateSnapshotStore({
|
|
45
|
-
appDirectory,
|
|
46
|
-
gateSnapshotPath: gateSnapshotPath || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
47
|
-
stateStore: canaryConfig.autopilot?.stateStore
|
|
48
|
-
});
|
|
49
|
-
const runtimeSignalConfig = canaryConfig.autopilot?.runtimeFallbackSignal;
|
|
50
|
-
const runtimeSignalEnabled = runtimeSignalConfig?.enabled === true;
|
|
51
|
-
if (runtimeSignalEnabled && gateSnapshotStorePromise) runtimeFallbackSignalConfig = {
|
|
52
|
-
endpoint: resolveRuntimeFallbackSignalEndpoint(runtimeSignalConfig?.endpoint),
|
|
53
|
-
gateName: runtimeSignalConfig?.gateName?.trim() || DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
54
|
-
gateSnapshotStore: gateSnapshotStorePromise,
|
|
55
|
-
failureHoldMs: Math.max(1000, runtimeSignalConfig?.failureHoldMs ?? DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS),
|
|
56
|
-
maxBodyBytes: Math.max(512, runtimeSignalConfig?.maxBodyBytes ?? DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES),
|
|
57
|
-
auth: normalizeRequiredRuntimeFallbackSignalAuthConfig(runtimeSignalConfig?.auth),
|
|
58
|
-
trustPolicy: normalizeRuntimeFallbackTrustPolicy(runtimeSignalConfig?.trustPolicy),
|
|
59
|
-
runtimeState: createRuntimeFallbackSignalRuntimeState()
|
|
60
|
-
};
|
|
61
|
-
}
|
|
62
|
-
const runtimeStatusAuthConfig = runtimeFallbackSignalConfig?.auth ?? normalizeRuntimeFallbackSignalAuthConfig(canaryConfig.autopilot?.runtimeFallbackSignal?.auth);
|
|
63
|
-
return {
|
|
64
|
-
canaryOrchestrator,
|
|
65
|
-
gateSnapshotStorePromise,
|
|
66
|
-
runtimeFallbackSignalConfig,
|
|
67
|
-
runtimeStatusAuthConfig
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
export { setupTelemetryCanary };
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { TelemetryCanaryContractGateStatus, TelemetryCanaryFailure } from './canary';
|
|
2
|
-
import type { TelemetryQueueStats } from './registryTypes';
|
|
3
|
-
interface TelemetryCanaryHealthMetrics {
|
|
4
|
-
queueStats: TelemetryQueueStats;
|
|
5
|
-
unhealthyExporterCount: number;
|
|
6
|
-
requiredContractGates: readonly string[];
|
|
7
|
-
contractGates: ReadonlyMap<string, TelemetryCanaryContractGateStatus>;
|
|
8
|
-
}
|
|
9
|
-
interface TelemetryCanaryHealthThresholds {
|
|
10
|
-
maxQueueUtilization: number;
|
|
11
|
-
maxTotalDropped: number;
|
|
12
|
-
maxUnhealthyExporters: number;
|
|
13
|
-
}
|
|
14
|
-
export interface TelemetryCanaryHealthEvaluation {
|
|
15
|
-
failures: TelemetryCanaryFailure[];
|
|
16
|
-
queueStats: TelemetryQueueStats;
|
|
17
|
-
unhealthyExporterCount: number;
|
|
18
|
-
}
|
|
19
|
-
export declare const evaluateCanaryHealth: (metrics: TelemetryCanaryHealthMetrics, thresholds: TelemetryCanaryHealthThresholds) => TelemetryCanaryHealthEvaluation;
|
|
20
|
-
export {};
|
|
@@ -1,365 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
TelemetryCanaryOrchestrator,
|
|
3
|
-
type TelemetryEnvelope,
|
|
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
|
-
describe('telemetry canary orchestrator', () => {
|
|
22
|
-
test('supports dynamic required contract gate registration', async () => {
|
|
23
|
-
const registry = new TelemetryRegistry({
|
|
24
|
-
service: 'svc',
|
|
25
|
-
module: 'server',
|
|
26
|
-
environment: 'test',
|
|
27
|
-
flushIntervalMs: 60_000,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
31
|
-
registry,
|
|
32
|
-
rollbackConsecutiveFailures: 1,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
orchestrator.addRequiredContractGate('runtime-contracts');
|
|
36
|
-
const missingDecision = orchestrator.evaluate();
|
|
37
|
-
expect(missingDecision.action).toBe('rollback');
|
|
38
|
-
expect(
|
|
39
|
-
missingDecision.failures.some(
|
|
40
|
-
item =>
|
|
41
|
-
item.reason === 'contract_gate_missing' &&
|
|
42
|
-
item.gate === 'runtime-contracts',
|
|
43
|
-
),
|
|
44
|
-
).toBe(true);
|
|
45
|
-
|
|
46
|
-
orchestrator.resetToCanary();
|
|
47
|
-
orchestrator.setContractGate('runtime-contracts', true);
|
|
48
|
-
const passingDecision = orchestrator.evaluate();
|
|
49
|
-
expect(passingDecision.failures).toHaveLength(0);
|
|
50
|
-
|
|
51
|
-
await registry.shutdown();
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
test('promotes when telemetry and contract gates stay healthy', async () => {
|
|
55
|
-
const registry = new TelemetryRegistry({
|
|
56
|
-
service: 'svc',
|
|
57
|
-
module: 'server',
|
|
58
|
-
environment: 'test',
|
|
59
|
-
flushIntervalMs: 60_000,
|
|
60
|
-
});
|
|
61
|
-
await registry.register({
|
|
62
|
-
name: 'memory',
|
|
63
|
-
async emit() {
|
|
64
|
-
// noop
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
const onPromote = rs.fn();
|
|
69
|
-
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
70
|
-
registry,
|
|
71
|
-
minConsecutiveHealthyEvaluations: 2,
|
|
72
|
-
requiredContractGates: ['contracts'],
|
|
73
|
-
onPromote,
|
|
74
|
-
});
|
|
75
|
-
orchestrator.setContractGate('contracts', true);
|
|
76
|
-
|
|
77
|
-
expect(orchestrator.evaluate().action).toBe('hold');
|
|
78
|
-
const decision = orchestrator.evaluate();
|
|
79
|
-
expect(decision.action).toBe('promote');
|
|
80
|
-
expect(decision.state).toBe('promoted');
|
|
81
|
-
expect(onPromote).toHaveBeenCalledTimes(1);
|
|
82
|
-
|
|
83
|
-
await registry.shutdown();
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('rolls back after consecutive contract gate failures', async () => {
|
|
87
|
-
const registry = new TelemetryRegistry({
|
|
88
|
-
service: 'svc',
|
|
89
|
-
module: 'server',
|
|
90
|
-
environment: 'test',
|
|
91
|
-
flushIntervalMs: 60_000,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
const onRollback = rs.fn();
|
|
95
|
-
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
96
|
-
registry,
|
|
97
|
-
requiredContractGates: ['contracts'],
|
|
98
|
-
rollbackConsecutiveFailures: 2,
|
|
99
|
-
onRollback,
|
|
100
|
-
});
|
|
101
|
-
orchestrator.setContractGate('contracts', false, 'schema drift');
|
|
102
|
-
|
|
103
|
-
expect(orchestrator.evaluate().action).toBe('hold');
|
|
104
|
-
const decision = orchestrator.evaluate();
|
|
105
|
-
expect(decision.action).toBe('rollback');
|
|
106
|
-
expect(decision.state).toBe('rolled_back');
|
|
107
|
-
expect(
|
|
108
|
-
decision.failures.some(item => item.reason === 'contract_gate_failed'),
|
|
109
|
-
).toBe(true);
|
|
110
|
-
expect(onRollback).toHaveBeenCalledTimes(1);
|
|
111
|
-
|
|
112
|
-
await registry.shutdown();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
test('rolls back immediately when queue dropped budget is exceeded', async () => {
|
|
116
|
-
const registry = new TelemetryRegistry({
|
|
117
|
-
service: 'svc',
|
|
118
|
-
module: 'server',
|
|
119
|
-
environment: 'test',
|
|
120
|
-
maxQueueSize: 2,
|
|
121
|
-
flushIntervalMs: 60_000,
|
|
122
|
-
});
|
|
123
|
-
registry.enqueue(createEnvelope({ name: 'a' }));
|
|
124
|
-
registry.enqueue(createEnvelope({ name: 'b' }));
|
|
125
|
-
registry.enqueue(createEnvelope({ name: 'c' }));
|
|
126
|
-
|
|
127
|
-
const orchestrator = new TelemetryCanaryOrchestrator({
|
|
128
|
-
registry,
|
|
129
|
-
maxTotalDropped: 0,
|
|
130
|
-
rollbackConsecutiveFailures: 1,
|
|
131
|
-
});
|
|
132
|
-
const decision = orchestrator.evaluate();
|
|
133
|
-
expect(decision.action).toBe('rollback');
|
|
134
|
-
expect(
|
|
135
|
-
decision.failures.some(item => item.reason === 'queue_dropped'),
|
|
136
|
-
).toBe(true);
|
|
137
|
-
|
|
138
|
-
await registry.shutdown();
|
|
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
|
-
});
|
|
365
|
-
});
|