@bleedingdev/modern-js-server-runtime-extensions 3.8.2-ultramodern.9 → 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,97 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
evaluateCanaryHealth,
|
|
3
|
-
type TelemetryCanaryHealthEvaluation,
|
|
4
|
-
} from './canaryEvaluation';
|
|
5
1
|
import { clamp } from './envelope';
|
|
2
|
+
import {
|
|
3
|
+
evaluateTelemetryHealth,
|
|
4
|
+
type TelemetryHealthEvaluationResult,
|
|
5
|
+
} from './healthEvaluation';
|
|
6
6
|
|
|
7
7
|
import type { TelemetryRegistry } from './registry';
|
|
8
|
-
|
|
9
8
|
import type { TelemetryQueueStats } from './registryTypes';
|
|
10
9
|
|
|
11
|
-
export type
|
|
12
|
-
export type
|
|
13
|
-
|
|
10
|
+
export type TelemetryHealthState = 'pending' | 'healthy' | 'unhealthy';
|
|
11
|
+
export type TelemetryHealthTransition =
|
|
12
|
+
| 'none'
|
|
13
|
+
| 'became_healthy'
|
|
14
|
+
| 'became_unhealthy';
|
|
15
|
+
export type TelemetryHealthFailureReason =
|
|
14
16
|
| 'queue_utilization'
|
|
15
17
|
| 'queue_dropped'
|
|
16
18
|
| 'unhealthy_exporter'
|
|
17
19
|
| 'contract_gate_missing'
|
|
18
20
|
| 'contract_gate_failed';
|
|
19
21
|
|
|
20
|
-
export interface
|
|
21
|
-
reason:
|
|
22
|
+
export interface TelemetryHealthFailure {
|
|
23
|
+
reason: TelemetryHealthFailureReason;
|
|
22
24
|
gate?: string;
|
|
23
25
|
message?: string;
|
|
24
26
|
threshold?: number;
|
|
25
27
|
value?: number;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
export interface
|
|
30
|
+
export interface TelemetryContractGateStatus {
|
|
29
31
|
name: string;
|
|
30
32
|
passed: boolean;
|
|
31
33
|
reason?: string;
|
|
32
34
|
updatedAt: number;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
|
-
export interface
|
|
37
|
+
export interface TelemetryHealthEvaluation {
|
|
36
38
|
timestamp: number;
|
|
37
|
-
|
|
38
|
-
state:
|
|
39
|
+
transition: TelemetryHealthTransition;
|
|
40
|
+
state: TelemetryHealthState;
|
|
39
41
|
consecutiveHealthy: number;
|
|
40
42
|
consecutiveFailures: number;
|
|
41
|
-
failures:
|
|
43
|
+
failures: TelemetryHealthFailure[];
|
|
42
44
|
queueStats: TelemetryQueueStats;
|
|
43
45
|
unhealthyExporterCount: number;
|
|
44
|
-
contractGates:
|
|
46
|
+
contractGates: TelemetryContractGateStatus[];
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
export interface
|
|
49
|
+
export interface TelemetryHealthStatusSnapshot {
|
|
48
50
|
timestamp: number;
|
|
49
|
-
state:
|
|
51
|
+
state: TelemetryHealthState;
|
|
50
52
|
consecutiveHealthy: number;
|
|
51
53
|
consecutiveFailures: number;
|
|
52
54
|
queueStats: TelemetryQueueStats;
|
|
53
55
|
unhealthyExporterCount: number;
|
|
54
56
|
requiredContractGates: string[];
|
|
55
|
-
contractGates:
|
|
56
|
-
failurePreview:
|
|
57
|
+
contractGates: TelemetryContractGateStatus[];
|
|
58
|
+
failurePreview: TelemetryHealthFailure[];
|
|
57
59
|
}
|
|
58
60
|
|
|
59
|
-
export interface
|
|
61
|
+
export interface TelemetryHealthMonitorOptions {
|
|
60
62
|
registry: TelemetryRegistry;
|
|
61
63
|
evaluationIntervalMs?: number;
|
|
62
64
|
minConsecutiveHealthyEvaluations?: number;
|
|
63
|
-
|
|
65
|
+
minConsecutiveFailedEvaluations?: number;
|
|
64
66
|
maxQueueUtilization?: number;
|
|
65
67
|
maxTotalDropped?: number;
|
|
66
68
|
maxUnhealthyExporters?: number;
|
|
67
69
|
requiredContractGates?: string[];
|
|
68
|
-
onEvaluate?: (
|
|
69
|
-
|
|
70
|
-
onRollback?: (decision: TelemetryCanaryDecision) => void;
|
|
70
|
+
onEvaluate?: (evaluation: TelemetryHealthEvaluation) => void;
|
|
71
|
+
onTransition?: (evaluation: TelemetryHealthEvaluation) => void;
|
|
71
72
|
}
|
|
72
73
|
|
|
73
|
-
|
|
74
|
+
/**
|
|
75
|
+
* Observes telemetry and contract-gate health with hysteresis.
|
|
76
|
+
*
|
|
77
|
+
* This class reports health only. It does not deploy, promote, route, or roll
|
|
78
|
+
* back application revisions.
|
|
79
|
+
*/
|
|
80
|
+
export class TelemetryHealthMonitor {
|
|
74
81
|
private readonly registry: TelemetryRegistry;
|
|
75
82
|
private readonly evaluationIntervalMs: number;
|
|
76
83
|
private readonly minConsecutiveHealthyEvaluations: number;
|
|
77
|
-
private readonly
|
|
84
|
+
private readonly minConsecutiveFailedEvaluations: number;
|
|
78
85
|
private readonly maxQueueUtilization: number;
|
|
79
86
|
private readonly maxTotalDropped: number;
|
|
80
87
|
private readonly maxUnhealthyExporters: number;
|
|
81
88
|
private requiredContractGates: string[] = [];
|
|
82
|
-
private readonly onEvaluate?: (
|
|
83
|
-
private readonly
|
|
84
|
-
|
|
89
|
+
private readonly onEvaluate?: (evaluation: TelemetryHealthEvaluation) => void;
|
|
90
|
+
private readonly onTransition?: (
|
|
91
|
+
evaluation: TelemetryHealthEvaluation,
|
|
92
|
+
) => void;
|
|
85
93
|
private readonly contractGates = new Map<
|
|
86
94
|
string,
|
|
87
|
-
|
|
95
|
+
TelemetryContractGateStatus
|
|
88
96
|
>();
|
|
89
|
-
private state:
|
|
97
|
+
private state: TelemetryHealthState = 'pending';
|
|
90
98
|
private consecutiveHealthy = 0;
|
|
91
99
|
private consecutiveFailures = 0;
|
|
92
100
|
private evaluationTimer?: ReturnType<typeof setInterval>;
|
|
93
101
|
|
|
94
|
-
constructor(options:
|
|
102
|
+
constructor(options: TelemetryHealthMonitorOptions) {
|
|
95
103
|
this.registry = options.registry;
|
|
96
104
|
this.evaluationIntervalMs = Math.max(
|
|
97
105
|
250,
|
|
@@ -101,9 +109,9 @@ export class TelemetryCanaryOrchestrator {
|
|
|
101
109
|
1,
|
|
102
110
|
options.minConsecutiveHealthyEvaluations ?? 3,
|
|
103
111
|
);
|
|
104
|
-
this.
|
|
112
|
+
this.minConsecutiveFailedEvaluations = Math.max(
|
|
105
113
|
1,
|
|
106
|
-
options.
|
|
114
|
+
options.minConsecutiveFailedEvaluations ?? 2,
|
|
107
115
|
);
|
|
108
116
|
this.maxQueueUtilization = clamp(options.maxQueueUtilization ?? 0.8, 0, 1);
|
|
109
117
|
this.maxTotalDropped = Math.max(0, options.maxTotalDropped ?? 0);
|
|
@@ -113,8 +121,7 @@ export class TelemetryCanaryOrchestrator {
|
|
|
113
121
|
);
|
|
114
122
|
this.setRequiredContractGates(options.requiredContractGates || []);
|
|
115
123
|
this.onEvaluate = options.onEvaluate;
|
|
116
|
-
this.
|
|
117
|
-
this.onRollback = options.onRollback;
|
|
124
|
+
this.onTransition = options.onTransition;
|
|
118
125
|
}
|
|
119
126
|
|
|
120
127
|
setRequiredContractGates(gates: string[]) {
|
|
@@ -125,11 +132,10 @@ export class TelemetryCanaryOrchestrator {
|
|
|
125
132
|
|
|
126
133
|
addRequiredContractGate(name: string) {
|
|
127
134
|
const normalizedName = name.trim();
|
|
128
|
-
if (
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
if (!this.requiredContractGates.includes(normalizedName)) {
|
|
135
|
+
if (
|
|
136
|
+
normalizedName &&
|
|
137
|
+
!this.requiredContractGates.includes(normalizedName)
|
|
138
|
+
) {
|
|
133
139
|
this.requiredContractGates.push(normalizedName);
|
|
134
140
|
}
|
|
135
141
|
}
|
|
@@ -149,26 +155,19 @@ export class TelemetryCanaryOrchestrator {
|
|
|
149
155
|
for (const [name, value] of Object.entries(gates)) {
|
|
150
156
|
if (typeof value === 'boolean') {
|
|
151
157
|
this.setContractGate(name, value);
|
|
152
|
-
|
|
158
|
+
} else {
|
|
159
|
+
this.setContractGate(name, value.passed, value.reason);
|
|
153
160
|
}
|
|
154
|
-
|
|
155
|
-
this.setContractGate(name, value.passed, value.reason);
|
|
156
161
|
}
|
|
157
162
|
}
|
|
158
163
|
|
|
159
|
-
|
|
160
|
-
this.state = 'canary';
|
|
161
|
-
this.consecutiveHealthy = 0;
|
|
162
|
-
this.consecutiveFailures = 0;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
private collectFailures(): TelemetryCanaryHealthEvaluation {
|
|
164
|
+
private collectFailures(): TelemetryHealthEvaluationResult {
|
|
166
165
|
const queueStats = this.registry.getQueueStats();
|
|
167
166
|
const unhealthyExporterCount = this.registry
|
|
168
167
|
.getExporterHealth()
|
|
169
168
|
.filter(item => !item.healthy).length;
|
|
170
169
|
|
|
171
|
-
return
|
|
170
|
+
return evaluateTelemetryHealth(
|
|
172
171
|
{
|
|
173
172
|
queueStats,
|
|
174
173
|
unhealthyExporterCount,
|
|
@@ -183,38 +182,36 @@ export class TelemetryCanaryOrchestrator {
|
|
|
183
182
|
);
|
|
184
183
|
}
|
|
185
184
|
|
|
186
|
-
evaluate():
|
|
187
|
-
const now = Date.now();
|
|
185
|
+
evaluate(): TelemetryHealthEvaluation {
|
|
188
186
|
const { failures, queueStats, unhealthyExporterCount } =
|
|
189
187
|
this.collectFailures();
|
|
190
|
-
let
|
|
188
|
+
let transition: TelemetryHealthTransition = 'none';
|
|
191
189
|
|
|
192
190
|
if (failures.length > 0) {
|
|
193
191
|
this.consecutiveHealthy = 0;
|
|
194
192
|
this.consecutiveFailures += 1;
|
|
195
|
-
|
|
196
193
|
if (
|
|
197
|
-
this.state !== '
|
|
198
|
-
this.consecutiveFailures >= this.
|
|
194
|
+
this.state !== 'unhealthy' &&
|
|
195
|
+
this.consecutiveFailures >= this.minConsecutiveFailedEvaluations
|
|
199
196
|
) {
|
|
200
|
-
this.state = '
|
|
201
|
-
|
|
197
|
+
this.state = 'unhealthy';
|
|
198
|
+
transition = 'became_unhealthy';
|
|
202
199
|
}
|
|
203
200
|
} else {
|
|
204
201
|
this.consecutiveFailures = 0;
|
|
205
202
|
this.consecutiveHealthy += 1;
|
|
206
203
|
if (
|
|
207
|
-
this.state
|
|
204
|
+
this.state !== 'healthy' &&
|
|
208
205
|
this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations
|
|
209
206
|
) {
|
|
210
|
-
this.state = '
|
|
211
|
-
|
|
207
|
+
this.state = 'healthy';
|
|
208
|
+
transition = 'became_healthy';
|
|
212
209
|
}
|
|
213
210
|
}
|
|
214
211
|
|
|
215
|
-
const
|
|
216
|
-
timestamp: now,
|
|
217
|
-
|
|
212
|
+
const evaluation: TelemetryHealthEvaluation = {
|
|
213
|
+
timestamp: Date.now(),
|
|
214
|
+
transition,
|
|
218
215
|
state: this.state,
|
|
219
216
|
consecutiveHealthy: this.consecutiveHealthy,
|
|
220
217
|
consecutiveFailures: this.consecutiveFailures,
|
|
@@ -227,36 +224,27 @@ export class TelemetryCanaryOrchestrator {
|
|
|
227
224
|
};
|
|
228
225
|
|
|
229
226
|
try {
|
|
230
|
-
this.onEvaluate?.(
|
|
227
|
+
this.onEvaluate?.(evaluation);
|
|
231
228
|
} catch (_error) {
|
|
232
|
-
//
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
if (action === 'promote') {
|
|
236
|
-
try {
|
|
237
|
-
this.onPromote?.(decision);
|
|
238
|
-
} catch (_error) {
|
|
239
|
-
// canary observer hooks must never crash server.
|
|
240
|
-
}
|
|
229
|
+
// Health observers must never crash the server.
|
|
241
230
|
}
|
|
242
231
|
|
|
243
|
-
if (
|
|
232
|
+
if (transition !== 'none') {
|
|
244
233
|
try {
|
|
245
|
-
this.
|
|
234
|
+
this.onTransition?.(evaluation);
|
|
246
235
|
} catch (_error) {
|
|
247
|
-
//
|
|
236
|
+
// Health observers must never crash the server.
|
|
248
237
|
}
|
|
249
238
|
}
|
|
250
239
|
|
|
251
|
-
return
|
|
240
|
+
return evaluation;
|
|
252
241
|
}
|
|
253
242
|
|
|
254
|
-
getStatusSnapshot():
|
|
255
|
-
const now = Date.now();
|
|
243
|
+
getStatusSnapshot(): TelemetryHealthStatusSnapshot {
|
|
256
244
|
const { failures, queueStats, unhealthyExporterCount } =
|
|
257
245
|
this.collectFailures();
|
|
258
246
|
return {
|
|
259
|
-
timestamp: now,
|
|
247
|
+
timestamp: Date.now(),
|
|
260
248
|
state: this.state,
|
|
261
249
|
consecutiveHealthy: this.consecutiveHealthy,
|
|
262
250
|
consecutiveFailures: this.consecutiveFailures,
|
|
@@ -18,141 +18,138 @@ import {
|
|
|
18
18
|
resolveRuntimeFallbackSignalEndpoint,
|
|
19
19
|
} from '../runtimeFallbackSignal';
|
|
20
20
|
import {
|
|
21
|
-
type
|
|
22
|
-
|
|
21
|
+
type TelemetryHealthEvaluation,
|
|
22
|
+
TelemetryHealthMonitor,
|
|
23
23
|
TelemetryRegistry,
|
|
24
24
|
} from '../telemetryCore';
|
|
25
25
|
|
|
26
|
-
type
|
|
26
|
+
type SetupTelemetryHealthMonitoringOptions = {
|
|
27
27
|
registry: TelemetryRegistry;
|
|
28
28
|
appDirectory: string;
|
|
29
|
-
|
|
29
|
+
legacyHealthConfig: ServerTelemetryUserConfig['canary'] | undefined;
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
-
type
|
|
33
|
-
|
|
32
|
+
type SetupTelemetryHealthMonitoringResult = {
|
|
33
|
+
healthMonitor?: TelemetryHealthMonitor;
|
|
34
34
|
gateSnapshotStorePromise?: Promise<ContractGateSnapshotStore>;
|
|
35
35
|
runtimeFallbackSignalConfig?: RuntimeFallbackSignalConfig;
|
|
36
36
|
runtimeStatusAuthConfig?: RuntimeFallbackSignalAuthConfig;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
function
|
|
39
|
+
function emitHealthTransitionMetric(
|
|
40
40
|
registry: TelemetryRegistry,
|
|
41
|
-
|
|
42
|
-
action: 'promote' | 'rollback',
|
|
41
|
+
evaluation: TelemetryHealthEvaluation,
|
|
43
42
|
) {
|
|
44
43
|
try {
|
|
45
44
|
registry.enqueueMetric({
|
|
46
|
-
name:
|
|
45
|
+
name: 'telemetry.health.transition',
|
|
47
46
|
value: 1,
|
|
48
47
|
unit: 'count',
|
|
49
48
|
tags: {
|
|
50
|
-
|
|
51
|
-
state:
|
|
52
|
-
failures: String(
|
|
49
|
+
transition: evaluation.transition,
|
|
50
|
+
state: evaluation.state,
|
|
51
|
+
failures: String(evaluation.failures.length),
|
|
53
52
|
},
|
|
54
53
|
});
|
|
55
54
|
} catch (_error) {
|
|
56
|
-
//
|
|
55
|
+
// Health transition metrics are best-effort and must not break requests.
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
|
|
60
|
-
export const
|
|
59
|
+
export const setupTelemetryHealthMonitoring = ({
|
|
61
60
|
registry,
|
|
62
61
|
appDirectory,
|
|
63
|
-
|
|
64
|
-
}:
|
|
65
|
-
if (!
|
|
62
|
+
legacyHealthConfig,
|
|
63
|
+
}: SetupTelemetryHealthMonitoringOptions): SetupTelemetryHealthMonitoringResult => {
|
|
64
|
+
if (!legacyHealthConfig?.enabled) {
|
|
66
65
|
return {};
|
|
67
66
|
}
|
|
68
67
|
|
|
69
|
-
const contractGates =
|
|
68
|
+
const contractGates = legacyHealthConfig.contractGates as
|
|
70
69
|
| Record<string, boolean | { passed: boolean; reason?: string }>
|
|
71
70
|
| undefined;
|
|
72
71
|
|
|
73
|
-
const
|
|
72
|
+
const healthMonitor = new TelemetryHealthMonitor({
|
|
74
73
|
registry,
|
|
75
|
-
evaluationIntervalMs:
|
|
74
|
+
evaluationIntervalMs: legacyHealthConfig.evaluationIntervalMs,
|
|
76
75
|
minConsecutiveHealthyEvaluations:
|
|
77
|
-
|
|
78
|
-
rollbackConsecutiveFailures
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
legacyHealthConfig.minConsecutiveHealthyEvaluations,
|
|
77
|
+
// `rollbackConsecutiveFailures` is the legacy public config key. It now
|
|
78
|
+
// controls health-state hysteresis and never triggers a deployment action.
|
|
79
|
+
minConsecutiveFailedEvaluations:
|
|
80
|
+
legacyHealthConfig.rollbackConsecutiveFailures,
|
|
81
|
+
maxQueueUtilization: legacyHealthConfig.maxQueueUtilization,
|
|
82
|
+
maxTotalDropped: legacyHealthConfig.maxTotalDropped,
|
|
83
|
+
maxUnhealthyExporters: legacyHealthConfig.maxUnhealthyExporters,
|
|
82
84
|
requiredContractGates: Object.keys(contractGates || {}),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
},
|
|
86
|
-
onRollback: decision => {
|
|
87
|
-
emitCanaryDecisionMetric(registry, decision, 'rollback');
|
|
85
|
+
onTransition: evaluation => {
|
|
86
|
+
emitHealthTransitionMetric(registry, evaluation);
|
|
88
87
|
},
|
|
89
88
|
});
|
|
90
89
|
|
|
91
90
|
if (contractGates) {
|
|
92
|
-
|
|
91
|
+
healthMonitor.setContractGates(contractGates);
|
|
93
92
|
}
|
|
94
93
|
|
|
95
94
|
let gateSnapshotStorePromise: Promise<ContractGateSnapshotStore> | undefined;
|
|
96
95
|
let runtimeFallbackSignalConfig: RuntimeFallbackSignalConfig | undefined;
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
97
|
+
// `autopilot` is retained only as the legacy config key for snapshot input.
|
|
98
|
+
const snapshotObservationEnabled =
|
|
99
|
+
legacyHealthConfig.autopilot?.enabled ?? true;
|
|
100
|
+
if (snapshotObservationEnabled) {
|
|
100
101
|
const gateSnapshotPath = resolveContractGateSnapshotPath(
|
|
101
102
|
appDirectory,
|
|
102
|
-
|
|
103
|
+
legacyHealthConfig.autopilot?.gateSnapshotPath,
|
|
103
104
|
);
|
|
104
105
|
gateSnapshotStorePromise = resolveContractGateSnapshotStore({
|
|
105
106
|
appDirectory,
|
|
106
107
|
gateSnapshotPath: gateSnapshotPath || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
107
|
-
stateStore:
|
|
108
|
+
stateStore: legacyHealthConfig.autopilot?.stateStore,
|
|
108
109
|
});
|
|
109
110
|
|
|
110
|
-
const runtimeSignalConfig =
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
// OFF) and requires a configured auth token when enabled.
|
|
114
|
-
const runtimeSignalEnabled = runtimeSignalConfig?.enabled === true;
|
|
115
|
-
if (runtimeSignalEnabled && gateSnapshotStorePromise) {
|
|
111
|
+
const runtimeSignalConfig =
|
|
112
|
+
legacyHealthConfig.autopilot?.runtimeFallbackSignal;
|
|
113
|
+
if (runtimeSignalConfig?.enabled === true) {
|
|
116
114
|
runtimeFallbackSignalConfig = {
|
|
117
115
|
endpoint: resolveRuntimeFallbackSignalEndpoint(
|
|
118
|
-
runtimeSignalConfig
|
|
116
|
+
runtimeSignalConfig.endpoint,
|
|
119
117
|
),
|
|
120
118
|
gateName:
|
|
121
|
-
runtimeSignalConfig
|
|
119
|
+
runtimeSignalConfig.gateName?.trim() ||
|
|
122
120
|
DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
123
121
|
gateSnapshotStore: gateSnapshotStorePromise,
|
|
124
122
|
failureHoldMs: Math.max(
|
|
125
123
|
1_000,
|
|
126
|
-
runtimeSignalConfig
|
|
124
|
+
runtimeSignalConfig.failureHoldMs ??
|
|
127
125
|
DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS,
|
|
128
126
|
),
|
|
129
127
|
maxBodyBytes: Math.max(
|
|
130
128
|
512,
|
|
131
|
-
runtimeSignalConfig
|
|
129
|
+
runtimeSignalConfig.maxBodyBytes ??
|
|
132
130
|
DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES,
|
|
133
131
|
),
|
|
134
132
|
auth: normalizeRequiredRuntimeFallbackSignalAuthConfig(
|
|
135
|
-
runtimeSignalConfig
|
|
133
|
+
runtimeSignalConfig.auth,
|
|
136
134
|
),
|
|
137
135
|
trustPolicy: normalizeRuntimeFallbackTrustPolicy(
|
|
138
|
-
runtimeSignalConfig
|
|
136
|
+
runtimeSignalConfig.trustPolicy,
|
|
139
137
|
),
|
|
140
138
|
runtimeState: createRuntimeFallbackSignalRuntimeState(),
|
|
141
139
|
};
|
|
142
140
|
}
|
|
143
141
|
}
|
|
144
142
|
|
|
145
|
-
//
|
|
146
|
-
//
|
|
147
|
-
// even when the signal endpoint itself stays disabled.
|
|
143
|
+
// Detailed runtime status stays authenticated even when signal ingestion is
|
|
144
|
+
// disabled. The auth source remains the legacy config path for compatibility.
|
|
148
145
|
const runtimeStatusAuthConfig =
|
|
149
146
|
runtimeFallbackSignalConfig?.auth ??
|
|
150
147
|
normalizeRuntimeFallbackSignalAuthConfig(
|
|
151
|
-
|
|
148
|
+
legacyHealthConfig.autopilot?.runtimeFallbackSignal?.auth,
|
|
152
149
|
);
|
|
153
150
|
|
|
154
151
|
return {
|
|
155
|
-
|
|
152
|
+
healthMonitor,
|
|
156
153
|
gateSnapshotStorePromise,
|
|
157
154
|
runtimeFallbackSignalConfig,
|
|
158
155
|
runtimeStatusAuthConfig,
|
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
type ContractGateSnapshotStore,
|
|
4
4
|
resolveContractGateSnapshotPath,
|
|
5
5
|
} from '../contract-gate-snapshot-store';
|
|
6
|
-
import {
|
|
6
|
+
import { ContractGateSnapshotObserver } from '../contractGateSnapshotObserver';
|
|
7
7
|
import {
|
|
8
8
|
createOtlpTelemetryExporter,
|
|
9
9
|
createVictoriaMetricsTelemetryExporter,
|
|
10
10
|
maybeWarnLegacyOtlpEndpoint,
|
|
11
|
-
|
|
11
|
+
TelemetryHealthMonitor,
|
|
12
12
|
TelemetryRegistry,
|
|
13
13
|
} from '../telemetryCore';
|
|
14
14
|
|
|
@@ -21,8 +21,8 @@ type RegisterTelemetryLifecycleOptions = {
|
|
|
21
21
|
api: TelemetryLifecycleApi;
|
|
22
22
|
registry: TelemetryRegistry;
|
|
23
23
|
telemetryConfig: ServerTelemetryUserConfig;
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
legacyHealthConfig: ServerTelemetryUserConfig['canary'] | undefined;
|
|
25
|
+
healthMonitor?: TelemetryHealthMonitor;
|
|
26
26
|
gateSnapshotStorePromise?: Promise<ContractGateSnapshotStore>;
|
|
27
27
|
appDirectory: string;
|
|
28
28
|
};
|
|
@@ -50,12 +50,12 @@ export const registerTelemetryLifecycle = ({
|
|
|
50
50
|
api,
|
|
51
51
|
registry,
|
|
52
52
|
telemetryConfig,
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
legacyHealthConfig,
|
|
54
|
+
healthMonitor,
|
|
55
55
|
gateSnapshotStorePromise,
|
|
56
56
|
appDirectory,
|
|
57
57
|
}: RegisterTelemetryLifecycleOptions) => {
|
|
58
|
-
let
|
|
58
|
+
let contractGateSnapshotObserver: ContractGateSnapshotObserver | undefined;
|
|
59
59
|
let telemetryLaneClosed = false;
|
|
60
60
|
const closeTelemetryLane = async () => {
|
|
61
61
|
if (telemetryLaneClosed) {
|
|
@@ -63,8 +63,8 @@ export const registerTelemetryLifecycle = ({
|
|
|
63
63
|
}
|
|
64
64
|
telemetryLaneClosed = true;
|
|
65
65
|
activeTelemetryLaneClosers.delete(closeTelemetryLane);
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
contractGateSnapshotObserver?.stop();
|
|
67
|
+
healthMonitor?.stop();
|
|
68
68
|
await registry.shutdown();
|
|
69
69
|
};
|
|
70
70
|
|
|
@@ -76,7 +76,7 @@ export const registerTelemetryLifecycle = ({
|
|
|
76
76
|
prepared = true;
|
|
77
77
|
|
|
78
78
|
// Shutdown path for the telemetry lane: flush pending envelopes and
|
|
79
|
-
// stop
|
|
79
|
+
// stop health/snapshot pollers when the node server closes (this also
|
|
80
80
|
// covers dev-server restarts, which close the previous node server
|
|
81
81
|
// before assembling a new one), with process beforeExit as the
|
|
82
82
|
// final-flush floor when no node server handle exists.
|
|
@@ -112,27 +112,27 @@ export const registerTelemetryLifecycle = ({
|
|
|
112
112
|
failLoud: telemetryConfig.failLoudStartup ?? true,
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
if (!
|
|
115
|
+
if (!healthMonitor) {
|
|
116
116
|
return;
|
|
117
117
|
}
|
|
118
118
|
|
|
119
|
-
|
|
119
|
+
healthMonitor.start();
|
|
120
120
|
if (gateSnapshotStorePromise) {
|
|
121
121
|
const gateSnapshotStore = await gateSnapshotStorePromise;
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
contractGateSnapshotObserver = new ContractGateSnapshotObserver({
|
|
123
|
+
monitor: healthMonitor,
|
|
124
124
|
gateSnapshotPath: resolveContractGateSnapshotPath(
|
|
125
125
|
appDirectory,
|
|
126
|
-
|
|
126
|
+
legacyHealthConfig?.autopilot?.gateSnapshotPath,
|
|
127
127
|
),
|
|
128
128
|
gateSnapshotStore,
|
|
129
|
-
pollIntervalMs:
|
|
130
|
-
gateStaleAfterMs:
|
|
129
|
+
pollIntervalMs: legacyHealthConfig?.autopilot?.pollIntervalMs,
|
|
130
|
+
gateStaleAfterMs: legacyHealthConfig?.autopilot?.gateStaleAfterMs,
|
|
131
131
|
});
|
|
132
132
|
}
|
|
133
|
-
if (
|
|
134
|
-
await
|
|
133
|
+
if (contractGateSnapshotObserver) {
|
|
134
|
+
await contractGateSnapshotObserver.start();
|
|
135
135
|
}
|
|
136
|
-
|
|
136
|
+
healthMonitor.evaluate();
|
|
137
137
|
});
|
|
138
138
|
};
|
package/src/telemetry/plugin.ts
CHANGED
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
type TelemetryRegistryOptions,
|
|
15
15
|
toTelemetryEnvelope,
|
|
16
16
|
} from '../telemetryCore';
|
|
17
|
-
import {
|
|
17
|
+
import { setupTelemetryHealthMonitoring } from './healthSetup';
|
|
18
18
|
import { registerTelemetryLifecycle } from './lifecycle';
|
|
19
19
|
import {
|
|
20
20
|
createRuntimeFallbackSignalMiddleware,
|
|
@@ -47,18 +47,18 @@ export {
|
|
|
47
47
|
createTelemetryAwareMetrics,
|
|
48
48
|
createVictoriaMetricsTelemetryExporter,
|
|
49
49
|
type OtlpExporterOptions,
|
|
50
|
-
type
|
|
51
|
-
type TelemetryCanaryContractGateStatus,
|
|
52
|
-
type TelemetryCanaryDecision,
|
|
53
|
-
type TelemetryCanaryFailure,
|
|
54
|
-
type TelemetryCanaryFailureReason,
|
|
55
|
-
TelemetryCanaryOrchestrator,
|
|
56
|
-
type TelemetryCanaryOrchestratorOptions,
|
|
57
|
-
type TelemetryCanaryState,
|
|
58
|
-
type TelemetryCanaryStatusSnapshot,
|
|
50
|
+
type TelemetryContractGateStatus,
|
|
59
51
|
type TelemetryEnvelope,
|
|
60
52
|
type TelemetryExporter,
|
|
61
53
|
type TelemetryExporterHealthStatus,
|
|
54
|
+
type TelemetryHealthEvaluation,
|
|
55
|
+
type TelemetryHealthFailure,
|
|
56
|
+
type TelemetryHealthFailureReason,
|
|
57
|
+
TelemetryHealthMonitor,
|
|
58
|
+
type TelemetryHealthMonitorOptions,
|
|
59
|
+
type TelemetryHealthState,
|
|
60
|
+
type TelemetryHealthStatusSnapshot,
|
|
61
|
+
type TelemetryHealthTransition,
|
|
62
62
|
type TelemetryQueueStats,
|
|
63
63
|
TelemetryRegistry,
|
|
64
64
|
type TelemetryRegistryOptions,
|
|
@@ -132,14 +132,14 @@ export const injectTelemetryPlugin = (): ServerPlugin => ({
|
|
|
132
132
|
});
|
|
133
133
|
|
|
134
134
|
const {
|
|
135
|
-
|
|
135
|
+
healthMonitor,
|
|
136
136
|
gateSnapshotStorePromise,
|
|
137
137
|
runtimeFallbackSignalConfig,
|
|
138
138
|
runtimeStatusAuthConfig,
|
|
139
|
-
} =
|
|
139
|
+
} = setupTelemetryHealthMonitoring({
|
|
140
140
|
registry,
|
|
141
141
|
appDirectory,
|
|
142
|
-
|
|
142
|
+
legacyHealthConfig: telemetryConfig.canary,
|
|
143
143
|
});
|
|
144
144
|
|
|
145
145
|
if (runtimeFallbackSignalConfig) {
|
|
@@ -150,7 +150,7 @@ export const injectTelemetryPlugin = (): ServerPlugin => ({
|
|
|
150
150
|
middlewares.push(
|
|
151
151
|
createRuntimeStatusMiddleware({
|
|
152
152
|
registry,
|
|
153
|
-
|
|
153
|
+
healthMonitor,
|
|
154
154
|
runtimeFallbackSignalConfig,
|
|
155
155
|
runtimeStatusAuthConfig,
|
|
156
156
|
}),
|
|
@@ -188,8 +188,8 @@ export const injectTelemetryPlugin = (): ServerPlugin => ({
|
|
|
188
188
|
api,
|
|
189
189
|
registry,
|
|
190
190
|
telemetryConfig,
|
|
191
|
-
|
|
192
|
-
|
|
191
|
+
legacyHealthConfig: telemetryConfig.canary,
|
|
192
|
+
healthMonitor,
|
|
193
193
|
gateSnapshotStorePromise,
|
|
194
194
|
appDirectory,
|
|
195
195
|
});
|