@bleedingdev/modern-js-server-runtime-extensions 3.5.0-ultramodern.30 → 3.5.0-ultramodern.31
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-store/file-store.js +102 -0
- package/dist/cjs/contract-gate-snapshot-store/http-store.js +142 -0
- package/dist/cjs/contract-gate-snapshot-store/index.js +58 -0
- package/dist/cjs/contract-gate-snapshot-store/resolve.js +122 -0
- package/dist/cjs/contract-gate-snapshot-store/types.js +44 -0
- package/dist/cjs/contractGateAutopilot.js +27 -6
- package/dist/cjs/index.js +13 -13
- 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 +144 -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/auth.js +87 -0
- package/dist/cjs/runtime-fallback-signal/constants.js +72 -0
- package/dist/cjs/runtime-fallback-signal/contract-gate.js +64 -0
- package/dist/cjs/runtime-fallback-signal/endpoint.js +50 -0
- package/dist/cjs/runtime-fallback-signal/errors.js +44 -0
- package/dist/cjs/runtime-fallback-signal/index.js +99 -0
- package/dist/cjs/runtime-fallback-signal/payload.js +72 -0
- package/dist/cjs/runtime-fallback-signal/source.js +66 -0
- package/dist/cjs/runtime-fallback-signal/state.js +57 -0
- package/dist/cjs/runtime-fallback-signal/status.js +47 -0
- package/dist/cjs/runtime-fallback-signal/trust-policy.js +108 -0
- package/dist/cjs/runtime-fallback-signal/types.js +18 -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 +148 -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 +348 -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-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 +68 -0
- package/dist/esm/contract-gate-snapshot-store/types.mjs +3 -0
- package/dist/esm/contractGateAutopilot.mjs +26 -5
- package/dist/esm/index.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/auth.mjs +40 -0
- package/dist/esm/runtime-fallback-signal/constants.mjs +10 -0
- package/dist/esm/runtime-fallback-signal/contract-gate.mjs +26 -0
- package/dist/esm/runtime-fallback-signal/endpoint.mjs +12 -0
- package/dist/esm/runtime-fallback-signal/errors.mjs +6 -0
- package/dist/esm/runtime-fallback-signal/index.mjs +9 -0
- package/dist/esm/runtime-fallback-signal/payload.mjs +31 -0
- package/dist/esm/runtime-fallback-signal/source.mjs +22 -0
- package/dist/esm/runtime-fallback-signal/state.mjs +16 -0
- package/dist/esm/runtime-fallback-signal/status.mjs +9 -0
- package/dist/esm/runtime-fallback-signal/trust-policy.mjs +67 -0
- package/dist/esm/runtime-fallback-signal/types.mjs +0 -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 +101 -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 +310 -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-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 +70 -0
- package/dist/esm-node/contract-gate-snapshot-store/types.mjs +4 -0
- package/dist/esm-node/contractGateAutopilot.mjs +26 -5
- package/dist/esm-node/index.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/auth.mjs +41 -0
- package/dist/esm-node/runtime-fallback-signal/constants.mjs +11 -0
- package/dist/esm-node/runtime-fallback-signal/contract-gate.mjs +27 -0
- package/dist/esm-node/runtime-fallback-signal/endpoint.mjs +13 -0
- package/dist/esm-node/runtime-fallback-signal/errors.mjs +7 -0
- package/dist/esm-node/runtime-fallback-signal/index.mjs +10 -0
- package/dist/esm-node/runtime-fallback-signal/payload.mjs +32 -0
- package/dist/esm-node/runtime-fallback-signal/source.mjs +23 -0
- package/dist/esm-node/runtime-fallback-signal/state.mjs +17 -0
- package/dist/esm-node/runtime-fallback-signal/status.mjs +10 -0
- package/dist/esm-node/runtime-fallback-signal/trust-policy.mjs +68 -0
- package/dist/esm-node/runtime-fallback-signal/types.mjs +1 -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 +102 -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 +311 -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-store/file-store.d.ts +3 -0
- package/dist/types/contract-gate-snapshot-store/http-store.d.ts +11 -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 +4 -2
- package/dist/types/index.d.ts +2 -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 +33 -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/auth.d.ts +18 -0
- package/dist/types/runtime-fallback-signal/constants.d.ts +9 -0
- package/dist/types/runtime-fallback-signal/contract-gate.d.ts +2 -0
- package/dist/types/runtime-fallback-signal/endpoint.d.ts +1 -0
- package/dist/types/runtime-fallback-signal/errors.d.ts +2 -0
- package/dist/types/runtime-fallback-signal/index.d.ts +10 -0
- package/dist/types/runtime-fallback-signal/payload.d.ts +6 -0
- package/dist/types/runtime-fallback-signal/source.d.ts +3 -0
- package/dist/types/runtime-fallback-signal/state.d.ts +3 -0
- package/dist/types/runtime-fallback-signal/status.d.ts +2 -0
- package/dist/types/runtime-fallback-signal/trust-policy.d.ts +13 -0
- package/dist/types/runtime-fallback-signal/types.d.ts +50 -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 +19 -0
- package/dist/types/telemetry/canarySetup.d.ts +17 -0
- package/dist/types/telemetry/envelope.d.ts +45 -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 +72 -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 +6 -6
- package/src/contract-gate-snapshot-store/file-store.ts +85 -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 +175 -0
- package/src/contract-gate-snapshot-store/types.ts +64 -0
- package/src/contractGateAutopilot.ts +45 -9
- package/src/index.ts +6 -6
- 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 +166 -0
- package/src/module-federation-css/plugin.ts +86 -0
- package/src/module-federation-css/remote.ts +165 -0
- package/src/runtime-fallback-signal/auth.ts +117 -0
- package/src/runtime-fallback-signal/constants.ts +19 -0
- package/src/runtime-fallback-signal/contract-gate.ts +43 -0
- package/src/runtime-fallback-signal/endpoint.ts +22 -0
- package/src/runtime-fallback-signal/errors.ts +10 -0
- package/src/runtime-fallback-signal/index.ts +36 -0
- package/src/runtime-fallback-signal/payload.ts +79 -0
- package/src/runtime-fallback-signal/source.ts +49 -0
- package/src/runtime-fallback-signal/state.ts +34 -0
- package/src/runtime-fallback-signal/status.ts +22 -0
- package/src/runtime-fallback-signal/trust-policy.ts +179 -0
- package/src/runtime-fallback-signal/types.ts +66 -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 +189 -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 +467 -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 +40 -0
- package/tests/telemetryLifecycle.test.ts +253 -2
- 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
|
@@ -0,0 +1,291 @@
|
|
|
1
|
+
import {
|
|
2
|
+
evaluateCanaryHealth,
|
|
3
|
+
type TelemetryCanaryHealthEvaluation,
|
|
4
|
+
} from './canaryEvaluation';
|
|
5
|
+
import { clamp } from './envelope';
|
|
6
|
+
|
|
7
|
+
import type { TelemetryRegistry } from './registry';
|
|
8
|
+
|
|
9
|
+
import type { TelemetryQueueStats } from './registryTypes';
|
|
10
|
+
|
|
11
|
+
export type TelemetryCanaryState = 'canary' | 'promoted' | 'rolled_back';
|
|
12
|
+
export type TelemetryCanaryAction = 'hold' | 'promote' | 'rollback';
|
|
13
|
+
export type TelemetryCanaryFailureReason =
|
|
14
|
+
| 'queue_utilization'
|
|
15
|
+
| 'queue_dropped'
|
|
16
|
+
| 'unhealthy_exporter'
|
|
17
|
+
| 'contract_gate_missing'
|
|
18
|
+
| 'contract_gate_failed';
|
|
19
|
+
|
|
20
|
+
export interface TelemetryCanaryFailure {
|
|
21
|
+
reason: TelemetryCanaryFailureReason;
|
|
22
|
+
gate?: string;
|
|
23
|
+
message?: string;
|
|
24
|
+
threshold?: number;
|
|
25
|
+
value?: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface TelemetryCanaryContractGateStatus {
|
|
29
|
+
name: string;
|
|
30
|
+
passed: boolean;
|
|
31
|
+
reason?: string;
|
|
32
|
+
updatedAt: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface TelemetryCanaryDecision {
|
|
36
|
+
timestamp: number;
|
|
37
|
+
action: TelemetryCanaryAction;
|
|
38
|
+
state: TelemetryCanaryState;
|
|
39
|
+
consecutiveHealthy: number;
|
|
40
|
+
consecutiveFailures: number;
|
|
41
|
+
failures: TelemetryCanaryFailure[];
|
|
42
|
+
queueStats: TelemetryQueueStats;
|
|
43
|
+
unhealthyExporterCount: number;
|
|
44
|
+
contractGates: TelemetryCanaryContractGateStatus[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface TelemetryCanaryStatusSnapshot {
|
|
48
|
+
timestamp: number;
|
|
49
|
+
state: TelemetryCanaryState;
|
|
50
|
+
consecutiveHealthy: number;
|
|
51
|
+
consecutiveFailures: number;
|
|
52
|
+
queueStats: TelemetryQueueStats;
|
|
53
|
+
unhealthyExporterCount: number;
|
|
54
|
+
requiredContractGates: string[];
|
|
55
|
+
contractGates: TelemetryCanaryContractGateStatus[];
|
|
56
|
+
failurePreview: TelemetryCanaryFailure[];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export interface TelemetryCanaryOrchestratorOptions {
|
|
60
|
+
registry: TelemetryRegistry;
|
|
61
|
+
evaluationIntervalMs?: number;
|
|
62
|
+
minConsecutiveHealthyEvaluations?: number;
|
|
63
|
+
rollbackConsecutiveFailures?: number;
|
|
64
|
+
maxQueueUtilization?: number;
|
|
65
|
+
maxTotalDropped?: number;
|
|
66
|
+
maxUnhealthyExporters?: number;
|
|
67
|
+
requiredContractGates?: string[];
|
|
68
|
+
onEvaluate?: (decision: TelemetryCanaryDecision) => void;
|
|
69
|
+
onPromote?: (decision: TelemetryCanaryDecision) => void;
|
|
70
|
+
onRollback?: (decision: TelemetryCanaryDecision) => void;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export class TelemetryCanaryOrchestrator {
|
|
74
|
+
private readonly registry: TelemetryRegistry;
|
|
75
|
+
private readonly evaluationIntervalMs: number;
|
|
76
|
+
private readonly minConsecutiveHealthyEvaluations: number;
|
|
77
|
+
private readonly rollbackConsecutiveFailures: number;
|
|
78
|
+
private readonly maxQueueUtilization: number;
|
|
79
|
+
private readonly maxTotalDropped: number;
|
|
80
|
+
private readonly maxUnhealthyExporters: number;
|
|
81
|
+
private requiredContractGates: string[] = [];
|
|
82
|
+
private readonly onEvaluate?: (decision: TelemetryCanaryDecision) => void;
|
|
83
|
+
private readonly onPromote?: (decision: TelemetryCanaryDecision) => void;
|
|
84
|
+
private readonly onRollback?: (decision: TelemetryCanaryDecision) => void;
|
|
85
|
+
private readonly contractGates = new Map<
|
|
86
|
+
string,
|
|
87
|
+
TelemetryCanaryContractGateStatus
|
|
88
|
+
>();
|
|
89
|
+
private state: TelemetryCanaryState = 'canary';
|
|
90
|
+
private consecutiveHealthy = 0;
|
|
91
|
+
private consecutiveFailures = 0;
|
|
92
|
+
private evaluationTimer?: ReturnType<typeof setInterval>;
|
|
93
|
+
|
|
94
|
+
constructor(options: TelemetryCanaryOrchestratorOptions) {
|
|
95
|
+
this.registry = options.registry;
|
|
96
|
+
this.evaluationIntervalMs = Math.max(
|
|
97
|
+
250,
|
|
98
|
+
options.evaluationIntervalMs ?? 15_000,
|
|
99
|
+
);
|
|
100
|
+
this.minConsecutiveHealthyEvaluations = Math.max(
|
|
101
|
+
1,
|
|
102
|
+
options.minConsecutiveHealthyEvaluations ?? 3,
|
|
103
|
+
);
|
|
104
|
+
this.rollbackConsecutiveFailures = Math.max(
|
|
105
|
+
1,
|
|
106
|
+
options.rollbackConsecutiveFailures ?? 2,
|
|
107
|
+
);
|
|
108
|
+
this.maxQueueUtilization = clamp(options.maxQueueUtilization ?? 0.8, 0, 1);
|
|
109
|
+
this.maxTotalDropped = Math.max(0, options.maxTotalDropped ?? 0);
|
|
110
|
+
this.maxUnhealthyExporters = Math.max(
|
|
111
|
+
0,
|
|
112
|
+
options.maxUnhealthyExporters ?? 0,
|
|
113
|
+
);
|
|
114
|
+
this.setRequiredContractGates(options.requiredContractGates || []);
|
|
115
|
+
this.onEvaluate = options.onEvaluate;
|
|
116
|
+
this.onPromote = options.onPromote;
|
|
117
|
+
this.onRollback = options.onRollback;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
setRequiredContractGates(gates: string[]) {
|
|
121
|
+
this.requiredContractGates = Array.from(
|
|
122
|
+
new Set(gates.map(item => item.trim()).filter(Boolean)),
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
addRequiredContractGate(name: string) {
|
|
127
|
+
const normalizedName = name.trim();
|
|
128
|
+
if (!normalizedName) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
if (!this.requiredContractGates.includes(normalizedName)) {
|
|
133
|
+
this.requiredContractGates.push(normalizedName);
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
setContractGate(name: string, passed: boolean, reason?: string) {
|
|
138
|
+
this.contractGates.set(name, {
|
|
139
|
+
name,
|
|
140
|
+
passed,
|
|
141
|
+
reason,
|
|
142
|
+
updatedAt: Date.now(),
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
setContractGates(
|
|
147
|
+
gates: Record<string, boolean | { passed: boolean; reason?: string }>,
|
|
148
|
+
) {
|
|
149
|
+
for (const [name, value] of Object.entries(gates)) {
|
|
150
|
+
if (typeof value === 'boolean') {
|
|
151
|
+
this.setContractGate(name, value);
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
this.setContractGate(name, value.passed, value.reason);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
resetToCanary() {
|
|
160
|
+
this.state = 'canary';
|
|
161
|
+
this.consecutiveHealthy = 0;
|
|
162
|
+
this.consecutiveFailures = 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
private collectFailures(): TelemetryCanaryHealthEvaluation {
|
|
166
|
+
const queueStats = this.registry.getQueueStats();
|
|
167
|
+
const unhealthyExporterCount = this.registry
|
|
168
|
+
.getExporterHealth()
|
|
169
|
+
.filter(item => !item.healthy).length;
|
|
170
|
+
|
|
171
|
+
return evaluateCanaryHealth(
|
|
172
|
+
{
|
|
173
|
+
queueStats,
|
|
174
|
+
unhealthyExporterCount,
|
|
175
|
+
requiredContractGates: this.requiredContractGates,
|
|
176
|
+
contractGates: this.contractGates,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
maxQueueUtilization: this.maxQueueUtilization,
|
|
180
|
+
maxTotalDropped: this.maxTotalDropped,
|
|
181
|
+
maxUnhealthyExporters: this.maxUnhealthyExporters,
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
evaluate(): TelemetryCanaryDecision {
|
|
187
|
+
const now = Date.now();
|
|
188
|
+
const { failures, queueStats, unhealthyExporterCount } =
|
|
189
|
+
this.collectFailures();
|
|
190
|
+
let action: TelemetryCanaryAction = 'hold';
|
|
191
|
+
|
|
192
|
+
if (failures.length > 0) {
|
|
193
|
+
this.consecutiveHealthy = 0;
|
|
194
|
+
this.consecutiveFailures += 1;
|
|
195
|
+
|
|
196
|
+
if (
|
|
197
|
+
this.state !== 'rolled_back' &&
|
|
198
|
+
this.consecutiveFailures >= this.rollbackConsecutiveFailures
|
|
199
|
+
) {
|
|
200
|
+
this.state = 'rolled_back';
|
|
201
|
+
action = 'rollback';
|
|
202
|
+
}
|
|
203
|
+
} else {
|
|
204
|
+
this.consecutiveFailures = 0;
|
|
205
|
+
this.consecutiveHealthy += 1;
|
|
206
|
+
if (
|
|
207
|
+
this.state === 'canary' &&
|
|
208
|
+
this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations
|
|
209
|
+
) {
|
|
210
|
+
this.state = 'promoted';
|
|
211
|
+
action = 'promote';
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const decision: TelemetryCanaryDecision = {
|
|
216
|
+
timestamp: now,
|
|
217
|
+
action,
|
|
218
|
+
state: this.state,
|
|
219
|
+
consecutiveHealthy: this.consecutiveHealthy,
|
|
220
|
+
consecutiveFailures: this.consecutiveFailures,
|
|
221
|
+
failures,
|
|
222
|
+
queueStats,
|
|
223
|
+
unhealthyExporterCount,
|
|
224
|
+
contractGates: Array.from(this.contractGates.values()).map(item => ({
|
|
225
|
+
...item,
|
|
226
|
+
})),
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
try {
|
|
230
|
+
this.onEvaluate?.(decision);
|
|
231
|
+
} catch (_error) {
|
|
232
|
+
// canary observer hooks must never crash server.
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
if (action === 'promote') {
|
|
236
|
+
try {
|
|
237
|
+
this.onPromote?.(decision);
|
|
238
|
+
} catch (_error) {
|
|
239
|
+
// canary observer hooks must never crash server.
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (action === 'rollback') {
|
|
244
|
+
try {
|
|
245
|
+
this.onRollback?.(decision);
|
|
246
|
+
} catch (_error) {
|
|
247
|
+
// canary observer hooks must never crash server.
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
return decision;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
getStatusSnapshot(): TelemetryCanaryStatusSnapshot {
|
|
255
|
+
const now = Date.now();
|
|
256
|
+
const { failures, queueStats, unhealthyExporterCount } =
|
|
257
|
+
this.collectFailures();
|
|
258
|
+
return {
|
|
259
|
+
timestamp: now,
|
|
260
|
+
state: this.state,
|
|
261
|
+
consecutiveHealthy: this.consecutiveHealthy,
|
|
262
|
+
consecutiveFailures: this.consecutiveFailures,
|
|
263
|
+
queueStats,
|
|
264
|
+
unhealthyExporterCount,
|
|
265
|
+
requiredContractGates: [...this.requiredContractGates],
|
|
266
|
+
contractGates: Array.from(this.contractGates.values()).map(item => ({
|
|
267
|
+
...item,
|
|
268
|
+
})),
|
|
269
|
+
failurePreview: failures,
|
|
270
|
+
};
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
start() {
|
|
274
|
+
if (this.evaluationTimer) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
this.evaluationTimer = setInterval(() => {
|
|
278
|
+
this.evaluate();
|
|
279
|
+
}, this.evaluationIntervalMs);
|
|
280
|
+
if (typeof (this.evaluationTimer as NodeJS.Timeout).unref === 'function') {
|
|
281
|
+
(this.evaluationTimer as NodeJS.Timeout).unref();
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
stop() {
|
|
286
|
+
if (this.evaluationTimer) {
|
|
287
|
+
clearInterval(this.evaluationTimer);
|
|
288
|
+
this.evaluationTimer = undefined;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
TelemetryCanaryContractGateStatus,
|
|
3
|
+
TelemetryCanaryFailure,
|
|
4
|
+
} from './canary';
|
|
5
|
+
|
|
6
|
+
import type { TelemetryQueueStats } from './registryTypes';
|
|
7
|
+
|
|
8
|
+
export interface TelemetryCanaryHealthMetrics {
|
|
9
|
+
queueStats: TelemetryQueueStats;
|
|
10
|
+
unhealthyExporterCount: number;
|
|
11
|
+
requiredContractGates: readonly string[];
|
|
12
|
+
contractGates: ReadonlyMap<string, TelemetryCanaryContractGateStatus>;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface TelemetryCanaryHealthThresholds {
|
|
16
|
+
maxQueueUtilization: number;
|
|
17
|
+
maxTotalDropped: number;
|
|
18
|
+
maxUnhealthyExporters: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface TelemetryCanaryHealthEvaluation {
|
|
22
|
+
failures: TelemetryCanaryFailure[];
|
|
23
|
+
queueStats: TelemetryQueueStats;
|
|
24
|
+
unhealthyExporterCount: number;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const evaluateCanaryHealth = (
|
|
28
|
+
metrics: TelemetryCanaryHealthMetrics,
|
|
29
|
+
thresholds: TelemetryCanaryHealthThresholds,
|
|
30
|
+
): TelemetryCanaryHealthEvaluation => {
|
|
31
|
+
const failures: TelemetryCanaryFailure[] = [];
|
|
32
|
+
const { queueStats, unhealthyExporterCount } = metrics;
|
|
33
|
+
|
|
34
|
+
if (queueStats.utilization > thresholds.maxQueueUtilization) {
|
|
35
|
+
failures.push({
|
|
36
|
+
reason: 'queue_utilization',
|
|
37
|
+
threshold: thresholds.maxQueueUtilization,
|
|
38
|
+
value: queueStats.utilization,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (queueStats.totalDropped > thresholds.maxTotalDropped) {
|
|
43
|
+
failures.push({
|
|
44
|
+
reason: 'queue_dropped',
|
|
45
|
+
threshold: thresholds.maxTotalDropped,
|
|
46
|
+
value: queueStats.totalDropped,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (unhealthyExporterCount > thresholds.maxUnhealthyExporters) {
|
|
51
|
+
failures.push({
|
|
52
|
+
reason: 'unhealthy_exporter',
|
|
53
|
+
threshold: thresholds.maxUnhealthyExporters,
|
|
54
|
+
value: unhealthyExporterCount,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
for (const gateName of metrics.requiredContractGates) {
|
|
59
|
+
const gate = metrics.contractGates.get(gateName);
|
|
60
|
+
if (!gate) {
|
|
61
|
+
failures.push({
|
|
62
|
+
reason: 'contract_gate_missing',
|
|
63
|
+
gate: gateName,
|
|
64
|
+
message: `Contract gate "${gateName}" is missing`,
|
|
65
|
+
});
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (!gate.passed) {
|
|
70
|
+
failures.push({
|
|
71
|
+
reason: 'contract_gate_failed',
|
|
72
|
+
gate: gateName,
|
|
73
|
+
message: gate.reason || `Contract gate "${gateName}" is not passing`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
failures,
|
|
80
|
+
queueStats,
|
|
81
|
+
unhealthyExporterCount,
|
|
82
|
+
};
|
|
83
|
+
};
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import type { ServerTelemetryUserConfig } from '@modern-js/server-core';
|
|
2
|
+
import {
|
|
3
|
+
type ContractGateSnapshotStore,
|
|
4
|
+
DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
5
|
+
resolveContractGateSnapshotPath,
|
|
6
|
+
resolveContractGateSnapshotStore,
|
|
7
|
+
} from '../contract-gate-snapshot-store';
|
|
8
|
+
import {
|
|
9
|
+
createRuntimeFallbackSignalRuntimeState,
|
|
10
|
+
DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
|
|
11
|
+
DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
12
|
+
DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
|
|
13
|
+
normalizeRequiredRuntimeFallbackSignalAuthConfig,
|
|
14
|
+
normalizeRuntimeFallbackSignalAuthConfig,
|
|
15
|
+
normalizeRuntimeFallbackTrustPolicy,
|
|
16
|
+
type RuntimeFallbackSignalAuthConfig,
|
|
17
|
+
type RuntimeFallbackSignalConfig,
|
|
18
|
+
resolveRuntimeFallbackSignalEndpoint,
|
|
19
|
+
} from '../runtimeFallbackSignal';
|
|
20
|
+
import {
|
|
21
|
+
type TelemetryCanaryDecision,
|
|
22
|
+
TelemetryCanaryOrchestrator,
|
|
23
|
+
TelemetryRegistry,
|
|
24
|
+
} from '../telemetryCore';
|
|
25
|
+
|
|
26
|
+
type SetupTelemetryCanaryOptions = {
|
|
27
|
+
registry: TelemetryRegistry;
|
|
28
|
+
appDirectory: string;
|
|
29
|
+
canaryConfig: ServerTelemetryUserConfig['canary'] | undefined;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type SetupTelemetryCanaryResult = {
|
|
33
|
+
canaryOrchestrator?: TelemetryCanaryOrchestrator;
|
|
34
|
+
gateSnapshotStorePromise?: Promise<ContractGateSnapshotStore>;
|
|
35
|
+
runtimeFallbackSignalConfig?: RuntimeFallbackSignalConfig;
|
|
36
|
+
runtimeStatusAuthConfig?: RuntimeFallbackSignalAuthConfig;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
function emitCanaryDecisionMetric(
|
|
40
|
+
registry: TelemetryRegistry,
|
|
41
|
+
decision: TelemetryCanaryDecision,
|
|
42
|
+
action: 'promote' | 'rollback',
|
|
43
|
+
) {
|
|
44
|
+
try {
|
|
45
|
+
registry.enqueueMetric({
|
|
46
|
+
name: `telemetry.canary.${action}`,
|
|
47
|
+
value: 1,
|
|
48
|
+
unit: 'count',
|
|
49
|
+
tags: {
|
|
50
|
+
action,
|
|
51
|
+
state: decision.state,
|
|
52
|
+
failures: String(decision.failures.length),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
} catch (_error) {
|
|
56
|
+
// Canary decision metrics are best-effort and must never break request flow.
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export const setupTelemetryCanary = ({
|
|
61
|
+
registry,
|
|
62
|
+
appDirectory,
|
|
63
|
+
canaryConfig,
|
|
64
|
+
}: SetupTelemetryCanaryOptions): SetupTelemetryCanaryResult => {
|
|
65
|
+
if (!canaryConfig?.enabled) {
|
|
66
|
+
return {};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const contractGates = canaryConfig.contractGates as
|
|
70
|
+
| Record<string, boolean | { passed: boolean; reason?: string }>
|
|
71
|
+
| undefined;
|
|
72
|
+
|
|
73
|
+
const canaryOrchestrator = new TelemetryCanaryOrchestrator({
|
|
74
|
+
registry,
|
|
75
|
+
evaluationIntervalMs: canaryConfig.evaluationIntervalMs,
|
|
76
|
+
minConsecutiveHealthyEvaluations:
|
|
77
|
+
canaryConfig.minConsecutiveHealthyEvaluations,
|
|
78
|
+
rollbackConsecutiveFailures: canaryConfig.rollbackConsecutiveFailures,
|
|
79
|
+
maxQueueUtilization: canaryConfig.maxQueueUtilization,
|
|
80
|
+
maxTotalDropped: canaryConfig.maxTotalDropped,
|
|
81
|
+
maxUnhealthyExporters: canaryConfig.maxUnhealthyExporters,
|
|
82
|
+
requiredContractGates: Object.keys(contractGates || {}),
|
|
83
|
+
onPromote: decision => {
|
|
84
|
+
emitCanaryDecisionMetric(registry, decision, 'promote');
|
|
85
|
+
},
|
|
86
|
+
onRollback: decision => {
|
|
87
|
+
emitCanaryDecisionMetric(registry, decision, 'rollback');
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
if (contractGates) {
|
|
92
|
+
canaryOrchestrator.setContractGates(contractGates);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
let gateSnapshotStorePromise: Promise<ContractGateSnapshotStore> | undefined;
|
|
96
|
+
let runtimeFallbackSignalConfig: RuntimeFallbackSignalConfig | undefined;
|
|
97
|
+
|
|
98
|
+
const autopilotEnabled = canaryConfig.autopilot?.enabled ?? true;
|
|
99
|
+
if (autopilotEnabled) {
|
|
100
|
+
const gateSnapshotPath = resolveContractGateSnapshotPath(
|
|
101
|
+
appDirectory,
|
|
102
|
+
canaryConfig.autopilot?.gateSnapshotPath,
|
|
103
|
+
);
|
|
104
|
+
gateSnapshotStorePromise = resolveContractGateSnapshotStore({
|
|
105
|
+
appDirectory,
|
|
106
|
+
gateSnapshotPath: gateSnapshotPath || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
107
|
+
stateStore: canaryConfig.autopilot?.stateStore,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
const runtimeSignalConfig = canaryConfig.autopilot?.runtimeFallbackSignal;
|
|
111
|
+
// The signal endpoint can persist failing contract gates and force
|
|
112
|
+
// canary orchestrator into rollback, so it is opt-in (default
|
|
113
|
+
// OFF) and requires a configured auth token when enabled.
|
|
114
|
+
const runtimeSignalEnabled = runtimeSignalConfig?.enabled === true;
|
|
115
|
+
if (runtimeSignalEnabled && gateSnapshotStorePromise) {
|
|
116
|
+
runtimeFallbackSignalConfig = {
|
|
117
|
+
endpoint: resolveRuntimeFallbackSignalEndpoint(
|
|
118
|
+
runtimeSignalConfig?.endpoint,
|
|
119
|
+
),
|
|
120
|
+
gateName:
|
|
121
|
+
runtimeSignalConfig?.gateName?.trim() ||
|
|
122
|
+
DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
123
|
+
gateSnapshotStore: gateSnapshotStorePromise,
|
|
124
|
+
failureHoldMs: Math.max(
|
|
125
|
+
1_000,
|
|
126
|
+
runtimeSignalConfig?.failureHoldMs ??
|
|
127
|
+
DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
|
|
128
|
+
),
|
|
129
|
+
maxBodyBytes: Math.max(
|
|
130
|
+
512,
|
|
131
|
+
runtimeSignalConfig?.maxBodyBytes ??
|
|
132
|
+
DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
|
|
133
|
+
),
|
|
134
|
+
auth: normalizeRequiredRuntimeFallbackSignalAuthConfig(
|
|
135
|
+
runtimeSignalConfig?.auth,
|
|
136
|
+
),
|
|
137
|
+
trustPolicy: normalizeRuntimeFallbackTrustPolicy(
|
|
138
|
+
runtimeSignalConfig?.trustPolicy,
|
|
139
|
+
),
|
|
140
|
+
runtimeState: createRuntimeFallbackSignalRuntimeState(),
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// The runtime status endpoint exposes detail only to authenticated
|
|
146
|
+
// callers. Auth can be configured through runtimeFallbackSignal.auth
|
|
147
|
+
// even when the signal endpoint itself stays disabled.
|
|
148
|
+
const runtimeStatusAuthConfig =
|
|
149
|
+
runtimeFallbackSignalConfig?.auth ??
|
|
150
|
+
normalizeRuntimeFallbackSignalAuthConfig(
|
|
151
|
+
canaryConfig.autopilot?.runtimeFallbackSignal?.auth,
|
|
152
|
+
);
|
|
153
|
+
|
|
154
|
+
return {
|
|
155
|
+
canaryOrchestrator,
|
|
156
|
+
gateSnapshotStorePromise,
|
|
157
|
+
runtimeFallbackSignalConfig,
|
|
158
|
+
runtimeStatusAuthConfig,
|
|
159
|
+
};
|
|
160
|
+
};
|