@bleedingdev/modern-js-server-runtime-extensions 3.8.3-ultramodern.1 → 3.8.3-ultramodern.3
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,5 +1,5 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
const
|
|
2
|
+
const evaluateTelemetryHealth = (metrics, thresholds)=>{
|
|
3
3
|
const failures = [];
|
|
4
4
|
const { queueStats, unhealthyExporterCount } = metrics;
|
|
5
5
|
if (queueStats.utilization > thresholds.maxQueueUtilization) failures.push({
|
|
@@ -19,18 +19,16 @@ const evaluateCanaryHealth = (metrics, thresholds)=>{
|
|
|
19
19
|
});
|
|
20
20
|
for (const gateName of metrics.requiredContractGates){
|
|
21
21
|
const gate = metrics.contractGates.get(gateName);
|
|
22
|
-
if (
|
|
23
|
-
failures.push({
|
|
24
|
-
reason: '
|
|
22
|
+
if (gate) {
|
|
23
|
+
if (!gate.passed) failures.push({
|
|
24
|
+
reason: 'contract_gate_failed',
|
|
25
25
|
gate: gateName,
|
|
26
|
-
message: `Contract gate "${gateName}" is
|
|
26
|
+
message: gate.reason || `Contract gate "${gateName}" is not passing`
|
|
27
27
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
if (!gate.passed) failures.push({
|
|
31
|
-
reason: 'contract_gate_failed',
|
|
28
|
+
} else failures.push({
|
|
29
|
+
reason: 'contract_gate_missing',
|
|
32
30
|
gate: gateName,
|
|
33
|
-
message:
|
|
31
|
+
message: `Contract gate "${gateName}" is missing`
|
|
34
32
|
});
|
|
35
33
|
}
|
|
36
34
|
return {
|
|
@@ -39,4 +37,4 @@ const evaluateCanaryHealth = (metrics, thresholds)=>{
|
|
|
39
37
|
unhealthyExporterCount
|
|
40
38
|
};
|
|
41
39
|
};
|
|
42
|
-
export {
|
|
40
|
+
export { evaluateTelemetryHealth };
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
import { evaluateCanaryHealth } from "./canaryEvaluation.mjs";
|
|
3
2
|
import { clamp } from "./envelope.mjs";
|
|
4
|
-
|
|
3
|
+
import { evaluateTelemetryHealth } from "./healthEvaluation.mjs";
|
|
4
|
+
class TelemetryHealthMonitor {
|
|
5
5
|
setRequiredContractGates(gates) {
|
|
6
6
|
this.requiredContractGates = Array.from(new Set(gates.map((item)=>item.trim()).filter(Boolean)));
|
|
7
7
|
}
|
|
8
8
|
addRequiredContractGate(name) {
|
|
9
9
|
const normalizedName = name.trim();
|
|
10
|
-
if (!normalizedName)
|
|
11
|
-
if (!this.requiredContractGates.includes(normalizedName)) this.requiredContractGates.push(normalizedName);
|
|
10
|
+
if (normalizedName && !this.requiredContractGates.includes(normalizedName)) this.requiredContractGates.push(normalizedName);
|
|
12
11
|
}
|
|
13
12
|
setContractGate(name, passed, reason) {
|
|
14
13
|
this.contractGates.set(name, {
|
|
@@ -19,23 +18,13 @@ class TelemetryCanaryOrchestrator {
|
|
|
19
18
|
});
|
|
20
19
|
}
|
|
21
20
|
setContractGates(gates) {
|
|
22
|
-
for (const [name, value] of Object.entries(gates))
|
|
23
|
-
|
|
24
|
-
this.setContractGate(name, value);
|
|
25
|
-
continue;
|
|
26
|
-
}
|
|
27
|
-
this.setContractGate(name, value.passed, value.reason);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
resetToCanary() {
|
|
31
|
-
this.state = 'canary';
|
|
32
|
-
this.consecutiveHealthy = 0;
|
|
33
|
-
this.consecutiveFailures = 0;
|
|
21
|
+
for (const [name, value] of Object.entries(gates))if ('boolean' == typeof value) this.setContractGate(name, value);
|
|
22
|
+
else this.setContractGate(name, value.passed, value.reason);
|
|
34
23
|
}
|
|
35
24
|
collectFailures() {
|
|
36
25
|
const queueStats = this.registry.getQueueStats();
|
|
37
26
|
const unhealthyExporterCount = this.registry.getExporterHealth().filter((item)=>!item.healthy).length;
|
|
38
|
-
return
|
|
27
|
+
return evaluateTelemetryHealth({
|
|
39
28
|
queueStats,
|
|
40
29
|
unhealthyExporterCount,
|
|
41
30
|
requiredContractGates: this.requiredContractGates,
|
|
@@ -47,27 +36,26 @@ class TelemetryCanaryOrchestrator {
|
|
|
47
36
|
});
|
|
48
37
|
}
|
|
49
38
|
evaluate() {
|
|
50
|
-
const now = Date.now();
|
|
51
39
|
const { failures, queueStats, unhealthyExporterCount } = this.collectFailures();
|
|
52
|
-
let
|
|
40
|
+
let transition = 'none';
|
|
53
41
|
if (failures.length > 0) {
|
|
54
42
|
this.consecutiveHealthy = 0;
|
|
55
43
|
this.consecutiveFailures += 1;
|
|
56
|
-
if ('
|
|
57
|
-
this.state = '
|
|
58
|
-
|
|
44
|
+
if ('unhealthy' !== this.state && this.consecutiveFailures >= this.minConsecutiveFailedEvaluations) {
|
|
45
|
+
this.state = 'unhealthy';
|
|
46
|
+
transition = 'became_unhealthy';
|
|
59
47
|
}
|
|
60
48
|
} else {
|
|
61
49
|
this.consecutiveFailures = 0;
|
|
62
50
|
this.consecutiveHealthy += 1;
|
|
63
|
-
if ('
|
|
64
|
-
this.state = '
|
|
65
|
-
|
|
51
|
+
if ('healthy' !== this.state && this.consecutiveHealthy >= this.minConsecutiveHealthyEvaluations) {
|
|
52
|
+
this.state = 'healthy';
|
|
53
|
+
transition = 'became_healthy';
|
|
66
54
|
}
|
|
67
55
|
}
|
|
68
|
-
const
|
|
69
|
-
timestamp: now,
|
|
70
|
-
|
|
56
|
+
const evaluation = {
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
transition,
|
|
71
59
|
state: this.state,
|
|
72
60
|
consecutiveHealthy: this.consecutiveHealthy,
|
|
73
61
|
consecutiveFailures: this.consecutiveFailures,
|
|
@@ -79,21 +67,17 @@ class TelemetryCanaryOrchestrator {
|
|
|
79
67
|
}))
|
|
80
68
|
};
|
|
81
69
|
try {
|
|
82
|
-
this.onEvaluate?.(
|
|
83
|
-
} catch (_error) {}
|
|
84
|
-
if ('promote' === action) try {
|
|
85
|
-
this.onPromote?.(decision);
|
|
70
|
+
this.onEvaluate?.(evaluation);
|
|
86
71
|
} catch (_error) {}
|
|
87
|
-
if ('
|
|
88
|
-
this.
|
|
72
|
+
if ('none' !== transition) try {
|
|
73
|
+
this.onTransition?.(evaluation);
|
|
89
74
|
} catch (_error) {}
|
|
90
|
-
return
|
|
75
|
+
return evaluation;
|
|
91
76
|
}
|
|
92
77
|
getStatusSnapshot() {
|
|
93
|
-
const now = Date.now();
|
|
94
78
|
const { failures, queueStats, unhealthyExporterCount } = this.collectFailures();
|
|
95
79
|
return {
|
|
96
|
-
timestamp: now,
|
|
80
|
+
timestamp: Date.now(),
|
|
97
81
|
state: this.state,
|
|
98
82
|
consecutiveHealthy: this.consecutiveHealthy,
|
|
99
83
|
consecutiveFailures: this.consecutiveFailures,
|
|
@@ -124,20 +108,19 @@ class TelemetryCanaryOrchestrator {
|
|
|
124
108
|
constructor(options){
|
|
125
109
|
this.requiredContractGates = [];
|
|
126
110
|
this.contractGates = new Map();
|
|
127
|
-
this.state = '
|
|
111
|
+
this.state = 'pending';
|
|
128
112
|
this.consecutiveHealthy = 0;
|
|
129
113
|
this.consecutiveFailures = 0;
|
|
130
114
|
this.registry = options.registry;
|
|
131
115
|
this.evaluationIntervalMs = Math.max(250, options.evaluationIntervalMs ?? 15000);
|
|
132
116
|
this.minConsecutiveHealthyEvaluations = Math.max(1, options.minConsecutiveHealthyEvaluations ?? 3);
|
|
133
|
-
this.
|
|
117
|
+
this.minConsecutiveFailedEvaluations = Math.max(1, options.minConsecutiveFailedEvaluations ?? 2);
|
|
134
118
|
this.maxQueueUtilization = clamp(options.maxQueueUtilization ?? 0.8, 0, 1);
|
|
135
119
|
this.maxTotalDropped = Math.max(0, options.maxTotalDropped ?? 0);
|
|
136
120
|
this.maxUnhealthyExporters = Math.max(0, options.maxUnhealthyExporters ?? 0);
|
|
137
121
|
this.setRequiredContractGates(options.requiredContractGates || []);
|
|
138
122
|
this.onEvaluate = options.onEvaluate;
|
|
139
|
-
this.
|
|
140
|
-
this.onRollback = options.onRollback;
|
|
123
|
+
this.onTransition = options.onTransition;
|
|
141
124
|
}
|
|
142
125
|
}
|
|
143
|
-
export {
|
|
126
|
+
export { TelemetryHealthMonitor };
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { TelemetryHealthMonitor } from "../telemetryCore.mjs";
|
|
5
|
+
function emitHealthTransitionMetric(registry, evaluation) {
|
|
6
|
+
try {
|
|
7
|
+
registry.enqueueMetric({
|
|
8
|
+
name: 'telemetry.health.transition',
|
|
9
|
+
value: 1,
|
|
10
|
+
unit: 'count',
|
|
11
|
+
tags: {
|
|
12
|
+
transition: evaluation.transition,
|
|
13
|
+
state: evaluation.state,
|
|
14
|
+
failures: String(evaluation.failures.length)
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
} catch (_error) {}
|
|
18
|
+
}
|
|
19
|
+
const setupTelemetryHealthMonitoring = ({ registry, appDirectory, legacyHealthConfig })=>{
|
|
20
|
+
if (!legacyHealthConfig?.enabled) return {};
|
|
21
|
+
const contractGates = legacyHealthConfig.contractGates;
|
|
22
|
+
const healthMonitor = new TelemetryHealthMonitor({
|
|
23
|
+
registry,
|
|
24
|
+
evaluationIntervalMs: legacyHealthConfig.evaluationIntervalMs,
|
|
25
|
+
minConsecutiveHealthyEvaluations: legacyHealthConfig.minConsecutiveHealthyEvaluations,
|
|
26
|
+
minConsecutiveFailedEvaluations: legacyHealthConfig.rollbackConsecutiveFailures,
|
|
27
|
+
maxQueueUtilization: legacyHealthConfig.maxQueueUtilization,
|
|
28
|
+
maxTotalDropped: legacyHealthConfig.maxTotalDropped,
|
|
29
|
+
maxUnhealthyExporters: legacyHealthConfig.maxUnhealthyExporters,
|
|
30
|
+
requiredContractGates: Object.keys(contractGates || {}),
|
|
31
|
+
onTransition: (evaluation)=>{
|
|
32
|
+
emitHealthTransitionMetric(registry, evaluation);
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
if (contractGates) healthMonitor.setContractGates(contractGates);
|
|
36
|
+
let gateSnapshotStorePromise;
|
|
37
|
+
let runtimeFallbackSignalConfig;
|
|
38
|
+
const snapshotObservationEnabled = legacyHealthConfig.autopilot?.enabled ?? true;
|
|
39
|
+
if (snapshotObservationEnabled) {
|
|
40
|
+
const gateSnapshotPath = resolveContractGateSnapshotPath(appDirectory, legacyHealthConfig.autopilot?.gateSnapshotPath);
|
|
41
|
+
gateSnapshotStorePromise = resolveContractGateSnapshotStore({
|
|
42
|
+
appDirectory,
|
|
43
|
+
gateSnapshotPath: gateSnapshotPath || DEFAULT_CONTRACT_GATE_SNAPSHOT_PATH,
|
|
44
|
+
stateStore: legacyHealthConfig.autopilot?.stateStore
|
|
45
|
+
});
|
|
46
|
+
const runtimeSignalConfig = legacyHealthConfig.autopilot?.runtimeFallbackSignal;
|
|
47
|
+
if (runtimeSignalConfig?.enabled === true) runtimeFallbackSignalConfig = {
|
|
48
|
+
endpoint: resolveRuntimeFallbackSignalEndpoint(runtimeSignalConfig.endpoint),
|
|
49
|
+
gateName: runtimeSignalConfig.gateName?.trim() || DEFAULT_RUNTIME_FALLBACK_GATE_NAME,
|
|
50
|
+
gateSnapshotStore: gateSnapshotStorePromise,
|
|
51
|
+
failureHoldMs: Math.max(1000, runtimeSignalConfig.failureHoldMs ?? DEFAULT_RUNTIME_FALLBACK_FAILURE_HOLD_MS),
|
|
52
|
+
maxBodyBytes: Math.max(512, runtimeSignalConfig.maxBodyBytes ?? DEFAULT_RUNTIME_FALLBACK_MAX_BODY_BYTES),
|
|
53
|
+
auth: normalizeRequiredRuntimeFallbackSignalAuthConfig(runtimeSignalConfig.auth),
|
|
54
|
+
trustPolicy: normalizeRuntimeFallbackTrustPolicy(runtimeSignalConfig.trustPolicy),
|
|
55
|
+
runtimeState: createRuntimeFallbackSignalRuntimeState()
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
const runtimeStatusAuthConfig = runtimeFallbackSignalConfig?.auth ?? normalizeRuntimeFallbackSignalAuthConfig(legacyHealthConfig.autopilot?.runtimeFallbackSignal?.auth);
|
|
59
|
+
return {
|
|
60
|
+
healthMonitor,
|
|
61
|
+
gateSnapshotStorePromise,
|
|
62
|
+
runtimeFallbackSignalConfig,
|
|
63
|
+
runtimeStatusAuthConfig
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
export { setupTelemetryHealthMonitoring };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "node:module";
|
|
2
2
|
import { resolveContractGateSnapshotPath } from "../contract-gate-snapshot-store/index.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { ContractGateSnapshotObserver } from "../contractGateSnapshotObserver.mjs";
|
|
4
4
|
import { createOtlpTelemetryExporter, createVictoriaMetricsTelemetryExporter, maybeWarnLegacyOtlpEndpoint } from "../telemetryCore.mjs";
|
|
5
5
|
const activeTelemetryLaneClosers = new Set();
|
|
6
6
|
let telemetryBeforeExitHookInstalled = false;
|
|
@@ -13,15 +13,15 @@ const ensureTelemetryBeforeExitHook = ()=>{
|
|
|
13
13
|
])close();
|
|
14
14
|
});
|
|
15
15
|
};
|
|
16
|
-
const registerTelemetryLifecycle = ({ api, registry, telemetryConfig,
|
|
17
|
-
let
|
|
16
|
+
const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, legacyHealthConfig, healthMonitor, gateSnapshotStorePromise, appDirectory })=>{
|
|
17
|
+
let contractGateSnapshotObserver;
|
|
18
18
|
let telemetryLaneClosed = false;
|
|
19
19
|
const closeTelemetryLane = async ()=>{
|
|
20
20
|
if (telemetryLaneClosed) return;
|
|
21
21
|
telemetryLaneClosed = true;
|
|
22
22
|
activeTelemetryLaneClosers.delete(closeTelemetryLane);
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
contractGateSnapshotObserver?.stop();
|
|
24
|
+
healthMonitor?.stop();
|
|
25
25
|
await registry.shutdown();
|
|
26
26
|
};
|
|
27
27
|
let prepared = false;
|
|
@@ -42,20 +42,20 @@ const registerTelemetryLifecycle = ({ api, registry, telemetryConfig, canaryConf
|
|
|
42
42
|
await registry.startupHealthCheck({
|
|
43
43
|
failLoud: telemetryConfig.failLoudStartup ?? true
|
|
44
44
|
});
|
|
45
|
-
if (!
|
|
46
|
-
|
|
45
|
+
if (!healthMonitor) return;
|
|
46
|
+
healthMonitor.start();
|
|
47
47
|
if (gateSnapshotStorePromise) {
|
|
48
48
|
const gateSnapshotStore = await gateSnapshotStorePromise;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
gateSnapshotPath: resolveContractGateSnapshotPath(appDirectory,
|
|
49
|
+
contractGateSnapshotObserver = new ContractGateSnapshotObserver({
|
|
50
|
+
monitor: healthMonitor,
|
|
51
|
+
gateSnapshotPath: resolveContractGateSnapshotPath(appDirectory, legacyHealthConfig?.autopilot?.gateSnapshotPath),
|
|
52
52
|
gateSnapshotStore,
|
|
53
|
-
pollIntervalMs:
|
|
54
|
-
gateStaleAfterMs:
|
|
53
|
+
pollIntervalMs: legacyHealthConfig?.autopilot?.pollIntervalMs,
|
|
54
|
+
gateStaleAfterMs: legacyHealthConfig?.autopilot?.gateStaleAfterMs
|
|
55
55
|
});
|
|
56
56
|
}
|
|
57
|
-
if (
|
|
58
|
-
|
|
57
|
+
if (contractGateSnapshotObserver) await contractGateSnapshotObserver.start();
|
|
58
|
+
healthMonitor.evaluate();
|
|
59
59
|
});
|
|
60
60
|
};
|
|
61
61
|
export { registerTelemetryLifecycle };
|
|
@@ -2,8 +2,8 @@ import "node:module";
|
|
|
2
2
|
import { parseTraceparent } from "@modern-js/create-request/server";
|
|
3
3
|
import { logger } from "@modern-js/utils";
|
|
4
4
|
import { parseServerRuntimeExtensionsEnv } from "../env.mjs";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { TelemetryHealthMonitor, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, toTelemetryEnvelope } from "../telemetryCore.mjs";
|
|
6
|
+
import { setupTelemetryHealthMonitoring } from "./healthSetup.mjs";
|
|
7
7
|
import { registerTelemetryLifecycle } from "./lifecycle.mjs";
|
|
8
8
|
import { createRuntimeFallbackSignalMiddleware, createRuntimeStatusMiddleware } from "./runtimeEndpoints.mjs";
|
|
9
9
|
const hasEnabledTelemetryExporters = (config)=>Boolean(config?.exporters?.otlp?.enabled || config?.exporters?.victoriaMetrics?.enabled);
|
|
@@ -37,15 +37,15 @@ const injectTelemetryPlugin = ()=>({
|
|
|
37
37
|
redactionKeys: telemetryConfig.redactionKeys,
|
|
38
38
|
slo: resolveTelemetrySloOptions(telemetryConfig.slo)
|
|
39
39
|
});
|
|
40
|
-
const {
|
|
40
|
+
const { healthMonitor, gateSnapshotStorePromise, runtimeFallbackSignalConfig, runtimeStatusAuthConfig } = setupTelemetryHealthMonitoring({
|
|
41
41
|
registry,
|
|
42
42
|
appDirectory,
|
|
43
|
-
|
|
43
|
+
legacyHealthConfig: telemetryConfig.canary
|
|
44
44
|
});
|
|
45
45
|
if (runtimeFallbackSignalConfig) middlewares.push(createRuntimeFallbackSignalMiddleware(runtimeFallbackSignalConfig));
|
|
46
46
|
middlewares.push(createRuntimeStatusMiddleware({
|
|
47
47
|
registry,
|
|
48
|
-
|
|
48
|
+
healthMonitor,
|
|
49
49
|
runtimeFallbackSignalConfig,
|
|
50
50
|
runtimeStatusAuthConfig
|
|
51
51
|
}));
|
|
@@ -77,12 +77,12 @@ const injectTelemetryPlugin = ()=>({
|
|
|
77
77
|
api,
|
|
78
78
|
registry,
|
|
79
79
|
telemetryConfig,
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
legacyHealthConfig: telemetryConfig.canary,
|
|
81
|
+
healthMonitor,
|
|
82
82
|
gateSnapshotStorePromise,
|
|
83
83
|
appDirectory
|
|
84
84
|
});
|
|
85
85
|
}
|
|
86
86
|
});
|
|
87
87
|
export { DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, parseRuntimeFallbackSignalPayloadFromRawBody, resolveRuntimeFallbackSignalEndpoint } from "../runtimeFallbackSignal.mjs";
|
|
88
|
-
export {
|
|
88
|
+
export { TelemetryHealthMonitor, TelemetryRegistry, TelemetryStartupHealthError, createOtlpTelemetryExporter, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, hasEnabledTelemetryExporters, injectTelemetryPlugin, resolveTelemetrySloOptions };
|
|
@@ -35,7 +35,7 @@ const createRuntimeFallbackSignalMiddleware = (signalConfig)=>({
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
});
|
|
38
|
-
const createRuntimeStatusMiddleware = ({ registry,
|
|
38
|
+
const createRuntimeStatusMiddleware = ({ registry, healthMonitor, runtimeFallbackSignalConfig, runtimeStatusAuthConfig })=>({
|
|
39
39
|
name: 'telemetry-runtime-status',
|
|
40
40
|
path: DEFAULT_RUNTIME_STATUS_ENDPOINT,
|
|
41
41
|
method: 'get',
|
|
@@ -54,9 +54,9 @@ const createRuntimeStatusMiddleware = ({ registry, canaryOrchestrator, runtimeFa
|
|
|
54
54
|
queueStats: registry.getQueueStats(),
|
|
55
55
|
exporterHealth: registry.getExporterHealth()
|
|
56
56
|
},
|
|
57
|
-
|
|
57
|
+
health: healthMonitor ? {
|
|
58
58
|
enabled: true,
|
|
59
|
-
...
|
|
59
|
+
...healthMonitor.getStatusSnapshot()
|
|
60
60
|
} : {
|
|
61
61
|
enabled: false
|
|
62
62
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "node:module";
|
|
2
|
-
export { TelemetryCanaryOrchestrator } from "./telemetry/canary.mjs";
|
|
3
2
|
export { toTelemetryEnvelope } from "./telemetry/envelope.mjs";
|
|
4
3
|
export { createOtlpTelemetryExporter, createVictoriaMetricsTelemetryExporter, maybeWarnLegacyOtlpEndpoint } from "./telemetry/exporters.mjs";
|
|
4
|
+
export { TelemetryHealthMonitor } from "./telemetry/healthMonitor.mjs";
|
|
5
5
|
export { createTelemetryAwareMetrics } from "./telemetry/metrics.mjs";
|
|
6
6
|
export { TelemetryRegistry } from "./telemetry/registry.mjs";
|
|
7
7
|
export { TelemetryStartupHealthError } from "./telemetry/registryTypes.mjs";
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
export type BackendFederationRemoteEntryErrorCode = 'aborted' | 'byte_length_mismatch' | 'entry_too_large' | 'fetch_failed' | 'identity_mismatch' | 'integrity_mismatch' | 'invalid_verification' | 'redirect_mismatch' | 'timeout' | 'unsupported_entry';
|
|
2
|
+
export declare class BackendFederationRemoteEntryError extends Error {
|
|
3
|
+
readonly code: BackendFederationRemoteEntryErrorCode;
|
|
4
|
+
readonly details?: Record<string, unknown>;
|
|
5
|
+
constructor(code: BackendFederationRemoteEntryErrorCode, message: string, options?: {
|
|
6
|
+
cause?: unknown;
|
|
7
|
+
details?: Record<string, unknown>;
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
export type BackendFederationEntryIntegrity = {
|
|
11
|
+
byteLength: number;
|
|
12
|
+
sha256: string;
|
|
13
|
+
};
|
|
14
|
+
export type BackendFederationRemoteEntryVerification = BackendFederationEntryIntegrity & {
|
|
15
|
+
buildMarker?: string;
|
|
16
|
+
entryUrl: string;
|
|
17
|
+
remoteName: string;
|
|
18
|
+
unitId?: string;
|
|
19
|
+
};
|
|
20
|
+
export type BackendFederationRemoteEntryExpectation = Partial<BackendFederationRemoteEntryVerification>;
|
|
21
|
+
export type BackendFederationRemoteEntry = {
|
|
22
|
+
entry: string;
|
|
23
|
+
name: string;
|
|
24
|
+
type?: string;
|
|
25
|
+
};
|
|
26
|
+
export type BackendFederationEntryExports = {
|
|
27
|
+
get: (id: string) => (() => Promise<unknown> | unknown) | Promise<() => Promise<unknown> | unknown>;
|
|
28
|
+
init?: (...args: unknown[]) => void | Promise<void>;
|
|
29
|
+
};
|
|
30
|
+
export type BackendFederationResourceResponse = {
|
|
31
|
+
body?: ReadableStream<Uint8Array> | null;
|
|
32
|
+
headers?: {
|
|
33
|
+
get(name: string): string | null;
|
|
34
|
+
};
|
|
35
|
+
ok: boolean;
|
|
36
|
+
status: number;
|
|
37
|
+
statusText?: string;
|
|
38
|
+
text?: () => Promise<string>;
|
|
39
|
+
url?: string;
|
|
40
|
+
};
|
|
41
|
+
export type BackendFederationResourceFetch = (url: string, init?: RequestInit) => Promise<BackendFederationResourceResponse>;
|
|
42
|
+
export type BackendFederationRemoteEntryFetch = BackendFederationResourceFetch;
|
|
43
|
+
export type BackendFederationResourcePolicy = {
|
|
44
|
+
allowInsecureHttp?: boolean;
|
|
45
|
+
fetch?: BackendFederationResourceFetch;
|
|
46
|
+
maxBytes?: number;
|
|
47
|
+
signal?: AbortSignal;
|
|
48
|
+
timeoutMs?: number;
|
|
49
|
+
};
|
|
50
|
+
export type BackendFederationCommonJsEvaluator = (source: string, context: {
|
|
51
|
+
remote: BackendFederationRemoteEntry;
|
|
52
|
+
}) => unknown;
|
|
53
|
+
export type BackendFederationRemoteEntryPolicy = BackendFederationResourcePolicy & {
|
|
54
|
+
evaluateCommonJs?: BackendFederationCommonJsEvaluator;
|
|
55
|
+
expected?: BackendFederationRemoteEntryExpectation;
|
|
56
|
+
};
|
|
57
|
+
export type LoadVerifiedBackendFederationEntryOptions = BackendFederationRemoteEntryPolicy & {
|
|
58
|
+
remote: BackendFederationRemoteEntry;
|
|
59
|
+
verification?: BackendFederationRemoteEntryVerification;
|
|
60
|
+
};
|
|
61
|
+
export type LoadBoundedBackendFederationResourceOptions = BackendFederationResourcePolicy & {
|
|
62
|
+
kind?: 'entry' | 'manifest';
|
|
63
|
+
};
|
|
64
|
+
export declare function resolveBackendFederationRemoteEntryVerification(manifest: unknown): BackendFederationRemoteEntryVerification | undefined;
|
|
65
|
+
export declare function redactBackendFederationUrl(value: string): string;
|
|
66
|
+
export declare function loadBoundedBackendFederationResource(resourceUrl: string, options?: LoadBoundedBackendFederationResourceOptions): Promise<Uint8Array<ArrayBuffer>>;
|
|
67
|
+
export declare const evaluateBackendFederationCommonJsEntry: (remote: BackendFederationRemoteEntry, bytes: Uint8Array, evaluator?: BackendFederationCommonJsEvaluator) => BackendFederationEntryExports;
|
|
68
|
+
export declare function loadVerifiedBackendFederationEntry(options: LoadVerifiedBackendFederationEntryOptions): Promise<BackendFederationEntryExports>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type BackendFederationCommonJsEvaluator, type BackendFederationEntryIntegrity } from './index';
|
|
2
|
+
export declare function createBackendFederationEntryIntegrity(value: string | Uint8Array): BackendFederationEntryIntegrity;
|
|
3
|
+
export declare const evaluateNodeBackendFederationCommonJs: BackendFederationCommonJsEvaluator;
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
import type { ContractGateSnapshotStore } from './contract-gate-snapshot-store/types';
|
|
2
|
-
import type {
|
|
2
|
+
import type { TelemetryHealthMonitor } from './telemetry/healthMonitor';
|
|
3
3
|
type LoggerLike = {
|
|
4
4
|
info?: (message: string) => void;
|
|
5
5
|
warn?: (message: string) => void;
|
|
6
6
|
};
|
|
7
|
-
export type
|
|
8
|
-
|
|
7
|
+
export type ContractGateSnapshotObserverOptions = {
|
|
8
|
+
monitor: TelemetryHealthMonitor;
|
|
9
9
|
gateSnapshotPath?: string;
|
|
10
10
|
gateSnapshotStore?: ContractGateSnapshotStore;
|
|
11
11
|
pollIntervalMs?: number;
|
|
12
12
|
gateStaleAfterMs?: number;
|
|
13
13
|
logger?: LoggerLike;
|
|
14
14
|
};
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
/** Polls contract-gate snapshots and exposes them to telemetry health checks. */
|
|
16
|
+
export declare class ContractGateSnapshotObserver {
|
|
17
|
+
private readonly monitor;
|
|
17
18
|
private readonly gateSnapshotStore;
|
|
18
19
|
private readonly gateSnapshotPath?;
|
|
19
20
|
private readonly pollIntervalMs;
|
|
@@ -22,7 +23,7 @@ export declare class ContractGateAutopilot {
|
|
|
22
23
|
private poller?;
|
|
23
24
|
private syncGeneration;
|
|
24
25
|
private readonly appliedGateFingerprints;
|
|
25
|
-
constructor(options:
|
|
26
|
+
constructor(options: ContractGateSnapshotObserverOptions);
|
|
26
27
|
start(): Promise<void>;
|
|
27
28
|
stop(): void;
|
|
28
29
|
syncOnce(): Promise<number>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { type BackendFederationCommonJsEvaluator, type BackendFederationEntryExports, type BackendFederationEntryIntegrity, type BackendFederationRemoteEntry, BackendFederationRemoteEntryError, type BackendFederationRemoteEntryErrorCode, type BackendFederationRemoteEntryExpectation, type BackendFederationRemoteEntryFetch, type BackendFederationRemoteEntryPolicy, type BackendFederationRemoteEntryVerification, type BackendFederationResourceFetch, type BackendFederationResourcePolicy, type BackendFederationResourceResponse, evaluateBackendFederationCommonJsEntry, type LoadBoundedBackendFederationResourceOptions, type LoadVerifiedBackendFederationEntryOptions, loadBoundedBackendFederationResource, loadVerifiedBackendFederationEntry, redactBackendFederationUrl, resolveBackendFederationRemoteEntryVerification, } from './backend-federation-security';
|
|
2
|
+
export { ContractGateSnapshotObserver, type ContractGateSnapshotObserverOptions, } from './contractGateSnapshotObserver';
|
|
2
3
|
export { DEFAULT_ENVIRONMENT_NAME, parseServerRuntimeExtensionsEnv, type ServerRuntimeExtensionsEnv, } from './env';
|
|
3
4
|
export { getRequestPathname, injectMfAssetCacheHeadersPlugin, isMfManifestAsset, isMfRemoteEntryAsset, resolveMfAssetCacheHeaders, } from './mfCache';
|
|
4
5
|
export { type CollectDirectRemoteModuleFederationCssOptions, collectDirectRemoteModuleFederationCss, collectDirectRemoteModuleFederationCssWithMeta, collectModuleFederationManifestCss, createModuleFederationCssCollector, injectModuleFederationCssPlugin, type ModuleFederationCssCollectorOptions, type ModuleFederationCssPluginOptions, type ModuleFederationManifest, type RemoteModuleFederationCssCollection, } from './module-federation-css';
|
|
5
|
-
export {
|
|
6
|
+
export { createDisposableServerRuntimeHandle, type DisposableServerRuntimeHandle, disposeServerRuntime, initializeDisposableServerRuntime, registerServerRuntimeDisposer, type ServerRuntimeHandle, } from './runtimeLifecycle';
|
|
7
|
+
export { createOtlpTelemetryExporter, createRuntimeFallbackSignalRuntimeState, createRuntimeSignalError, createTelemetryAwareMetrics, createVictoriaMetricsTelemetryExporter, DEFAULT_RUNTIME_FALLBACK_SIGNAL_ENDPOINT, DEFAULT_RUNTIME_STATUS_ENDPOINT, enforceRuntimeFallbackSignalAuthToken, enforceRuntimeFallbackSignalTrustPolicy, getRuntimeSignalErrorStatusCode, hasEnabledTelemetryExporters, injectTelemetryPlugin, normalizeRequiredRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackSignalAuthConfig, normalizeRuntimeFallbackTrustPolicy, type OtlpExporterOptions, parseRuntimeFallbackSignalPayloadFromRawBody, type RuntimeFallbackSignalAuthConfig, type RuntimeFallbackSignalRuntimeState, type RuntimeFallbackSignalSource, type RuntimeFallbackSignalTrustContext, type RuntimeFallbackSignalTrustPolicy, type RuntimeSignalError, type RuntimeSignalErrorCode, resolveRuntimeFallbackSignalEndpoint, resolveTelemetrySloOptions, type TelemetryContractGateStatus, type TelemetryEnvelope, type TelemetryExporter, type TelemetryHealthEvaluation, type TelemetryHealthFailure, type TelemetryHealthFailureReason, TelemetryHealthMonitor, type TelemetryHealthMonitorOptions, type TelemetryHealthState, type TelemetryHealthStatusSnapshot, type TelemetryHealthTransition, type TelemetryQueueStats, TelemetryRegistry, type TelemetryRegistryOptions, type TelemetrySignalType, type TelemetrySloAlert, TelemetryStartupHealthError, type VictoriaMetricsExporterOptions, } from './telemetry';
|
|
@@ -9,8 +9,8 @@ export declare function normalizeRuntimeFallbackSignalAuthConfig(configured: {
|
|
|
9
9
|
} | undefined): RuntimeFallbackSignalAuthConfig;
|
|
10
10
|
/**
|
|
11
11
|
* Normalizes auth config for the runtime fallback signal endpoint when the
|
|
12
|
-
* endpoint itself is enabled. The endpoint
|
|
13
|
-
*
|
|
12
|
+
* endpoint itself is enabled. The endpoint records observed failing contract
|
|
13
|
+
* gates, so it always requires a token.
|
|
14
14
|
*/
|
|
15
15
|
export declare function normalizeRequiredRuntimeFallbackSignalAuthConfig(configured: Parameters<typeof normalizeRuntimeFallbackSignalAuthConfig>[0]): RuntimeFallbackSignalAuthConfig;
|
|
16
16
|
export declare function enforceRuntimeFallbackSignalAuthToken(token: string | undefined, authConfig: RuntimeFallbackSignalAuthConfig): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type ServerRuntimeHandle = (request: Request, ...args: any[]) => Response | Promise<Response>;
|
|
2
|
+
export type DisposableServerRuntimeHandle = ServerRuntimeHandle & {
|
|
3
|
+
dispose: () => Promise<void>;
|
|
4
|
+
};
|
|
5
|
+
type RuntimeDisposer = () => void | Promise<void>;
|
|
6
|
+
export declare const registerServerRuntimeDisposer: (owner: object, disposer: RuntimeDisposer) => () => void;
|
|
7
|
+
export declare const disposeServerRuntime: (owner: object) => Promise<void>;
|
|
8
|
+
export declare const createDisposableServerRuntimeHandle: (owner: object, handle: ServerRuntimeHandle) => DisposableServerRuntimeHandle;
|
|
9
|
+
export declare const initializeDisposableServerRuntime: (owner: object, handle: ServerRuntimeHandle, initialize: () => Promise<void>) => Promise<DisposableServerRuntimeHandle>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { TelemetryContractGateStatus, TelemetryHealthFailure } from './healthMonitor';
|
|
2
|
+
import type { TelemetryQueueStats } from './registryTypes';
|
|
3
|
+
interface TelemetryHealthMetrics {
|
|
4
|
+
queueStats: TelemetryQueueStats;
|
|
5
|
+
unhealthyExporterCount: number;
|
|
6
|
+
requiredContractGates: readonly string[];
|
|
7
|
+
contractGates: ReadonlyMap<string, TelemetryContractGateStatus>;
|
|
8
|
+
}
|
|
9
|
+
interface TelemetryHealthThresholds {
|
|
10
|
+
maxQueueUtilization: number;
|
|
11
|
+
maxTotalDropped: number;
|
|
12
|
+
maxUnhealthyExporters: number;
|
|
13
|
+
}
|
|
14
|
+
export interface TelemetryHealthEvaluationResult {
|
|
15
|
+
failures: TelemetryHealthFailure[];
|
|
16
|
+
queueStats: TelemetryQueueStats;
|
|
17
|
+
unhealthyExporterCount: number;
|
|
18
|
+
}
|
|
19
|
+
export declare const evaluateTelemetryHealth: (metrics: TelemetryHealthMetrics, thresholds: TelemetryHealthThresholds) => TelemetryHealthEvaluationResult;
|
|
20
|
+
export {};
|