@devilsdev/rag-pipeline-utils 2.2.1 → 2.3.0
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/README.md +244 -11
- package/contracts/contract-schema.json +189 -0
- package/dist/index.cjs +19 -0
- package/dist/index.mjs +15 -1
- package/package.json +3 -2
- package/src/cli/commands/wizard.js +627 -0
- package/src/cli/input-sanitization-middleware.js +356 -0
- package/src/cli/templates/development.template.json +64 -0
- package/src/cli/templates/minimal.template.json +33 -0
- package/src/cli/templates/production.template.json +104 -0
- package/src/cli/templates/testing.template.json +45 -0
- package/src/config/connection-pool-config.json +259 -0
- package/src/config/memory-optimization.js +414 -0
- package/src/config/redaction-patterns.json +150 -0
- package/src/config/sanitization-rules.json +323 -0
- package/src/core/plugin-registry.js +266 -20
- package/src/dag/core/error-context.js +391 -0
- package/src/dag/core/execution-scheduler.js +350 -0
- package/src/dag/core/topology-validation.js +415 -0
- package/src/dag/dag-engine.js +26 -424
- package/src/dev/README.md +126 -0
- package/src/dev/dev-server.js +356 -0
- package/src/dev/examples/hot-reload-usage.js +355 -0
- package/src/dev/hot-reload.js +807 -0
- package/src/enterprise/sso-integration.js +67 -25
- package/src/index.js +19 -0
- package/src/observability/event-logger.js +62 -2
- package/src/plugins/optimized-openai-embedder.js +169 -0
- package/src/security/jwt-config.js +431 -0
- package/src/security/jwt-validator.js +701 -0
- package/src/utils/api-client-pool-integration.js +436 -0
- package/src/utils/batch-processor.js +710 -0
- package/src/utils/connection-pool.js +605 -0
- package/src/utils/contract-validator.js +460 -0
- package/src/utils/error-formatter.js +603 -0
- package/src/utils/examples/error-formatter-usage.js +351 -0
- package/src/utils/input-sanitizer.js +967 -0
- package/src/utils/memory-monitor.js +800 -0
- package/src/utils/secure-logger-config.js +352 -0
- package/src/utils/secure-logger.js +576 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "http://json-schema.org/draft-07/schema#",
|
|
3
|
+
"title": "Connection Pool Configuration",
|
|
4
|
+
"description": "HTTP/HTTPS connection pooling configuration for external API calls",
|
|
5
|
+
"type": "object",
|
|
6
|
+
"properties": {
|
|
7
|
+
"enabled": {
|
|
8
|
+
"type": "boolean",
|
|
9
|
+
"description": "Enable connection pooling globally",
|
|
10
|
+
"default": true
|
|
11
|
+
},
|
|
12
|
+
"maxSockets": {
|
|
13
|
+
"type": "integer",
|
|
14
|
+
"description": "Maximum total sockets across all hosts",
|
|
15
|
+
"default": 50,
|
|
16
|
+
"minimum": 1,
|
|
17
|
+
"maximum": 1000
|
|
18
|
+
},
|
|
19
|
+
"maxFreeSockets": {
|
|
20
|
+
"type": "integer",
|
|
21
|
+
"description": "Maximum idle sockets to keep in pool",
|
|
22
|
+
"default": 10,
|
|
23
|
+
"minimum": 0,
|
|
24
|
+
"maximum": 100
|
|
25
|
+
},
|
|
26
|
+
"maxSocketsPerHost": {
|
|
27
|
+
"type": "integer",
|
|
28
|
+
"description": "Maximum sockets per host",
|
|
29
|
+
"default": 10,
|
|
30
|
+
"minimum": 1,
|
|
31
|
+
"maximum": 100
|
|
32
|
+
},
|
|
33
|
+
"timeout": {
|
|
34
|
+
"type": "integer",
|
|
35
|
+
"description": "Socket timeout in milliseconds",
|
|
36
|
+
"default": 30000,
|
|
37
|
+
"minimum": 1000,
|
|
38
|
+
"maximum": 300000
|
|
39
|
+
},
|
|
40
|
+
"freeSocketTimeout": {
|
|
41
|
+
"type": "integer",
|
|
42
|
+
"description": "Idle socket timeout in milliseconds",
|
|
43
|
+
"default": 15000,
|
|
44
|
+
"minimum": 1000,
|
|
45
|
+
"maximum": 60000
|
|
46
|
+
},
|
|
47
|
+
"keepAliveTimeout": {
|
|
48
|
+
"type": "integer",
|
|
49
|
+
"description": "Keep-alive timeout in milliseconds",
|
|
50
|
+
"default": 60000,
|
|
51
|
+
"minimum": 5000,
|
|
52
|
+
"maximum": 300000
|
|
53
|
+
},
|
|
54
|
+
"keepAlive": {
|
|
55
|
+
"type": "boolean",
|
|
56
|
+
"description": "Enable keep-alive for connections",
|
|
57
|
+
"default": true
|
|
58
|
+
},
|
|
59
|
+
"keepAliveMsecs": {
|
|
60
|
+
"type": "integer",
|
|
61
|
+
"description": "Keep-alive probe interval in milliseconds",
|
|
62
|
+
"default": 1000,
|
|
63
|
+
"minimum": 100,
|
|
64
|
+
"maximum": 60000
|
|
65
|
+
},
|
|
66
|
+
"scheduling": {
|
|
67
|
+
"type": "string",
|
|
68
|
+
"description": "Socket scheduling algorithm",
|
|
69
|
+
"enum": ["lifo", "fifo"],
|
|
70
|
+
"default": "lifo"
|
|
71
|
+
},
|
|
72
|
+
"trackMetrics": {
|
|
73
|
+
"type": "boolean",
|
|
74
|
+
"description": "Enable metrics tracking",
|
|
75
|
+
"default": true
|
|
76
|
+
},
|
|
77
|
+
"metricsInterval": {
|
|
78
|
+
"type": "integer",
|
|
79
|
+
"description": "Metrics collection interval in milliseconds",
|
|
80
|
+
"default": 60000,
|
|
81
|
+
"minimum": 1000,
|
|
82
|
+
"maximum": 600000
|
|
83
|
+
},
|
|
84
|
+
"perHostPools": {
|
|
85
|
+
"type": "object",
|
|
86
|
+
"description": "Per-host connection pool configurations",
|
|
87
|
+
"properties": {
|
|
88
|
+
"openai": {
|
|
89
|
+
"type": "object",
|
|
90
|
+
"properties": {
|
|
91
|
+
"maxSockets": {
|
|
92
|
+
"type": "integer",
|
|
93
|
+
"default": 20
|
|
94
|
+
},
|
|
95
|
+
"maxFreeSockets": {
|
|
96
|
+
"type": "integer",
|
|
97
|
+
"default": 5
|
|
98
|
+
},
|
|
99
|
+
"timeout": {
|
|
100
|
+
"type": "integer",
|
|
101
|
+
"default": 60000
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
"anthropic": {
|
|
106
|
+
"type": "object",
|
|
107
|
+
"properties": {
|
|
108
|
+
"maxSockets": {
|
|
109
|
+
"type": "integer",
|
|
110
|
+
"default": 20
|
|
111
|
+
},
|
|
112
|
+
"maxFreeSockets": {
|
|
113
|
+
"type": "integer",
|
|
114
|
+
"default": 5
|
|
115
|
+
},
|
|
116
|
+
"timeout": {
|
|
117
|
+
"type": "integer",
|
|
118
|
+
"default": 60000
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
"pinecone": {
|
|
123
|
+
"type": "object",
|
|
124
|
+
"properties": {
|
|
125
|
+
"maxSockets": {
|
|
126
|
+
"type": "integer",
|
|
127
|
+
"default": 15
|
|
128
|
+
},
|
|
129
|
+
"maxFreeSockets": {
|
|
130
|
+
"type": "integer",
|
|
131
|
+
"default": 5
|
|
132
|
+
},
|
|
133
|
+
"timeout": {
|
|
134
|
+
"type": "integer",
|
|
135
|
+
"default": 30000
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
"environments": {
|
|
142
|
+
"type": "object",
|
|
143
|
+
"description": "Environment-specific configurations",
|
|
144
|
+
"properties": {
|
|
145
|
+
"development": {
|
|
146
|
+
"type": "object",
|
|
147
|
+
"properties": {
|
|
148
|
+
"enabled": {
|
|
149
|
+
"type": "boolean",
|
|
150
|
+
"default": true
|
|
151
|
+
},
|
|
152
|
+
"maxSockets": {
|
|
153
|
+
"type": "integer",
|
|
154
|
+
"default": 20
|
|
155
|
+
},
|
|
156
|
+
"trackMetrics": {
|
|
157
|
+
"type": "boolean",
|
|
158
|
+
"default": true
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
},
|
|
162
|
+
"production": {
|
|
163
|
+
"type": "object",
|
|
164
|
+
"properties": {
|
|
165
|
+
"enabled": {
|
|
166
|
+
"type": "boolean",
|
|
167
|
+
"default": true
|
|
168
|
+
},
|
|
169
|
+
"maxSockets": {
|
|
170
|
+
"type": "integer",
|
|
171
|
+
"default": 100
|
|
172
|
+
},
|
|
173
|
+
"maxFreeSockets": {
|
|
174
|
+
"type": "integer",
|
|
175
|
+
"default": 20
|
|
176
|
+
},
|
|
177
|
+
"trackMetrics": {
|
|
178
|
+
"type": "boolean",
|
|
179
|
+
"default": true
|
|
180
|
+
},
|
|
181
|
+
"metricsInterval": {
|
|
182
|
+
"type": "integer",
|
|
183
|
+
"default": 30000
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
"test": {
|
|
188
|
+
"type": "object",
|
|
189
|
+
"properties": {
|
|
190
|
+
"enabled": {
|
|
191
|
+
"type": "boolean",
|
|
192
|
+
"default": true
|
|
193
|
+
},
|
|
194
|
+
"maxSockets": {
|
|
195
|
+
"type": "integer",
|
|
196
|
+
"default": 10
|
|
197
|
+
},
|
|
198
|
+
"trackMetrics": {
|
|
199
|
+
"type": "boolean",
|
|
200
|
+
"default": false
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
"examples": [
|
|
208
|
+
{
|
|
209
|
+
"enabled": true,
|
|
210
|
+
"maxSockets": 100,
|
|
211
|
+
"maxFreeSockets": 20,
|
|
212
|
+
"maxSocketsPerHost": 15,
|
|
213
|
+
"timeout": 30000,
|
|
214
|
+
"freeSocketTimeout": 15000,
|
|
215
|
+
"keepAliveTimeout": 60000,
|
|
216
|
+
"keepAlive": true,
|
|
217
|
+
"keepAliveMsecs": 1000,
|
|
218
|
+
"scheduling": "lifo",
|
|
219
|
+
"trackMetrics": true,
|
|
220
|
+
"metricsInterval": 60000,
|
|
221
|
+
"perHostPools": {
|
|
222
|
+
"openai": {
|
|
223
|
+
"maxSockets": 30,
|
|
224
|
+
"maxFreeSockets": 10,
|
|
225
|
+
"timeout": 60000
|
|
226
|
+
},
|
|
227
|
+
"anthropic": {
|
|
228
|
+
"maxSockets": 30,
|
|
229
|
+
"maxFreeSockets": 10,
|
|
230
|
+
"timeout": 60000
|
|
231
|
+
},
|
|
232
|
+
"pinecone": {
|
|
233
|
+
"maxSockets": 20,
|
|
234
|
+
"maxFreeSockets": 5,
|
|
235
|
+
"timeout": 30000
|
|
236
|
+
}
|
|
237
|
+
},
|
|
238
|
+
"environments": {
|
|
239
|
+
"development": {
|
|
240
|
+
"enabled": true,
|
|
241
|
+
"maxSockets": 20,
|
|
242
|
+
"trackMetrics": true
|
|
243
|
+
},
|
|
244
|
+
"production": {
|
|
245
|
+
"enabled": true,
|
|
246
|
+
"maxSockets": 100,
|
|
247
|
+
"maxFreeSockets": 20,
|
|
248
|
+
"trackMetrics": true,
|
|
249
|
+
"metricsInterval": 30000
|
|
250
|
+
},
|
|
251
|
+
"test": {
|
|
252
|
+
"enabled": true,
|
|
253
|
+
"maxSockets": 10,
|
|
254
|
+
"trackMetrics": false
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
}
|
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Memory Optimization Configuration Profiles
|
|
5
|
+
*
|
|
6
|
+
* Provides pre-configured profiles for different use cases,
|
|
7
|
+
* from minimal overhead monitoring to comprehensive production debugging.
|
|
8
|
+
*
|
|
9
|
+
* @module config/memory-optimization
|
|
10
|
+
* @since 2.3.0
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Light Profile
|
|
15
|
+
*
|
|
16
|
+
* Minimal overhead monitoring for development and testing.
|
|
17
|
+
* Focuses on basic memory tracking with infrequent sampling.
|
|
18
|
+
*
|
|
19
|
+
* Use when:
|
|
20
|
+
* - Running in development environment
|
|
21
|
+
* - Performance is critical
|
|
22
|
+
* - Basic memory awareness is sufficient
|
|
23
|
+
*/
|
|
24
|
+
const LIGHT_PROFILE = {
|
|
25
|
+
// Memory limits
|
|
26
|
+
maxMemoryMB: 512,
|
|
27
|
+
|
|
28
|
+
// Sampling intervals (infrequent for low overhead)
|
|
29
|
+
samplingInterval: 5000, // 5 seconds
|
|
30
|
+
snapshotInterval: 60000, // 1 minute
|
|
31
|
+
|
|
32
|
+
// Thresholds (higher to avoid frequent alerts)
|
|
33
|
+
warningThreshold: 0.8,
|
|
34
|
+
criticalThreshold: 0.95,
|
|
35
|
+
|
|
36
|
+
// History tracking (minimal)
|
|
37
|
+
historySize: 50,
|
|
38
|
+
|
|
39
|
+
// Features
|
|
40
|
+
leakDetectionEnabled: false,
|
|
41
|
+
gcHintsEnabled: false,
|
|
42
|
+
autoGC: false,
|
|
43
|
+
|
|
44
|
+
// Leak detection config (disabled but configured)
|
|
45
|
+
leakThreshold: 10,
|
|
46
|
+
leakRateThreshold: 0.1,
|
|
47
|
+
|
|
48
|
+
// GC config (conservative)
|
|
49
|
+
gcThreshold: 0.9,
|
|
50
|
+
minGCInterval: 60000, // 1 minute
|
|
51
|
+
|
|
52
|
+
// Backpressure (conservative)
|
|
53
|
+
backpressure: {
|
|
54
|
+
enabled: false,
|
|
55
|
+
pauseThreshold: 0.85,
|
|
56
|
+
resumeThreshold: 0.7,
|
|
57
|
+
maxPauseDuration: 30000, // 30 seconds
|
|
58
|
+
},
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Standard Profile (Default)
|
|
63
|
+
*
|
|
64
|
+
* Balanced monitoring suitable for most production workloads.
|
|
65
|
+
* Provides good visibility with acceptable overhead.
|
|
66
|
+
*
|
|
67
|
+
* Use when:
|
|
68
|
+
* - Running in production
|
|
69
|
+
* - Need reliable memory monitoring
|
|
70
|
+
* - Can tolerate <1% overhead
|
|
71
|
+
* - Want leak detection and GC hints
|
|
72
|
+
*/
|
|
73
|
+
const STANDARD_PROFILE = {
|
|
74
|
+
// Memory limits
|
|
75
|
+
maxMemoryMB: 512,
|
|
76
|
+
|
|
77
|
+
// Sampling intervals (balanced)
|
|
78
|
+
samplingInterval: 1000, // 1 second
|
|
79
|
+
snapshotInterval: 30000, // 30 seconds
|
|
80
|
+
|
|
81
|
+
// Thresholds (standard)
|
|
82
|
+
warningThreshold: 0.75,
|
|
83
|
+
criticalThreshold: 0.9,
|
|
84
|
+
|
|
85
|
+
// History tracking (good coverage)
|
|
86
|
+
historySize: 100,
|
|
87
|
+
|
|
88
|
+
// Features
|
|
89
|
+
leakDetectionEnabled: true,
|
|
90
|
+
gcHintsEnabled: true,
|
|
91
|
+
autoGC: false,
|
|
92
|
+
|
|
93
|
+
// Leak detection config
|
|
94
|
+
leakThreshold: 5,
|
|
95
|
+
leakRateThreshold: 0.05,
|
|
96
|
+
|
|
97
|
+
// GC config
|
|
98
|
+
gcThreshold: 0.85,
|
|
99
|
+
minGCInterval: 30000, // 30 seconds
|
|
100
|
+
|
|
101
|
+
// Backpressure
|
|
102
|
+
backpressure: {
|
|
103
|
+
enabled: true,
|
|
104
|
+
pauseThreshold: 0.85,
|
|
105
|
+
resumeThreshold: 0.7,
|
|
106
|
+
maxPauseDuration: 10000, // 10 seconds
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Heavy Profile
|
|
112
|
+
*
|
|
113
|
+
* Comprehensive monitoring for debugging and optimization.
|
|
114
|
+
* High frequency sampling with all features enabled.
|
|
115
|
+
*
|
|
116
|
+
* Use when:
|
|
117
|
+
* - Debugging memory issues
|
|
118
|
+
* - Optimizing memory usage
|
|
119
|
+
* - Need detailed memory analytics
|
|
120
|
+
* - Overhead is acceptable (1-5%)
|
|
121
|
+
* - Running performance testing
|
|
122
|
+
*/
|
|
123
|
+
const HEAVY_PROFILE = {
|
|
124
|
+
// Memory limits
|
|
125
|
+
maxMemoryMB: 512,
|
|
126
|
+
|
|
127
|
+
// Sampling intervals (high frequency)
|
|
128
|
+
samplingInterval: 200, // 200ms
|
|
129
|
+
snapshotInterval: 10000, // 10 seconds
|
|
130
|
+
|
|
131
|
+
// Thresholds (sensitive)
|
|
132
|
+
warningThreshold: 0.7,
|
|
133
|
+
criticalThreshold: 0.85,
|
|
134
|
+
|
|
135
|
+
// History tracking (comprehensive)
|
|
136
|
+
historySize: 200,
|
|
137
|
+
|
|
138
|
+
// Features (all enabled)
|
|
139
|
+
leakDetectionEnabled: true,
|
|
140
|
+
gcHintsEnabled: true,
|
|
141
|
+
autoGC: false, // Manual control preferred in debugging
|
|
142
|
+
|
|
143
|
+
// Leak detection config (sensitive)
|
|
144
|
+
leakThreshold: 3,
|
|
145
|
+
leakRateThreshold: 0.03,
|
|
146
|
+
|
|
147
|
+
// GC config (aggressive)
|
|
148
|
+
gcThreshold: 0.8,
|
|
149
|
+
minGCInterval: 15000, // 15 seconds
|
|
150
|
+
|
|
151
|
+
// Backpressure (aggressive)
|
|
152
|
+
backpressure: {
|
|
153
|
+
enabled: true,
|
|
154
|
+
pauseThreshold: 0.8,
|
|
155
|
+
resumeThreshold: 0.65,
|
|
156
|
+
maxPauseDuration: 5000, // 5 seconds
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Custom Profile Template
|
|
162
|
+
*
|
|
163
|
+
* Starting point for custom configurations.
|
|
164
|
+
* Copy and modify as needed for specific requirements.
|
|
165
|
+
*/
|
|
166
|
+
const CUSTOM_PROFILE_TEMPLATE = {
|
|
167
|
+
// Memory limits
|
|
168
|
+
maxMemoryMB: 512,
|
|
169
|
+
|
|
170
|
+
// Sampling intervals
|
|
171
|
+
samplingInterval: 1000,
|
|
172
|
+
snapshotInterval: 30000,
|
|
173
|
+
|
|
174
|
+
// Thresholds
|
|
175
|
+
warningThreshold: 0.75,
|
|
176
|
+
criticalThreshold: 0.9,
|
|
177
|
+
|
|
178
|
+
// History tracking
|
|
179
|
+
historySize: 100,
|
|
180
|
+
|
|
181
|
+
// Features
|
|
182
|
+
leakDetectionEnabled: true,
|
|
183
|
+
gcHintsEnabled: true,
|
|
184
|
+
autoGC: false,
|
|
185
|
+
|
|
186
|
+
// Leak detection config
|
|
187
|
+
leakThreshold: 5,
|
|
188
|
+
leakRateThreshold: 0.05,
|
|
189
|
+
|
|
190
|
+
// GC config
|
|
191
|
+
gcThreshold: 0.85,
|
|
192
|
+
minGCInterval: 30000,
|
|
193
|
+
|
|
194
|
+
// Backpressure
|
|
195
|
+
backpressure: {
|
|
196
|
+
enabled: true,
|
|
197
|
+
pauseThreshold: 0.85,
|
|
198
|
+
resumeThreshold: 0.7,
|
|
199
|
+
maxPauseDuration: 10000,
|
|
200
|
+
},
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Profile Selection Guide
|
|
205
|
+
*
|
|
206
|
+
* Helps choose the right profile based on requirements.
|
|
207
|
+
*/
|
|
208
|
+
const PROFILE_GUIDE = {
|
|
209
|
+
light: {
|
|
210
|
+
overhead: "<0.5%",
|
|
211
|
+
sampling: "Infrequent (5s)",
|
|
212
|
+
features: "Basic",
|
|
213
|
+
useCase: "Development, testing, performance-critical",
|
|
214
|
+
},
|
|
215
|
+
standard: {
|
|
216
|
+
overhead: "<1%",
|
|
217
|
+
sampling: "Regular (1s)",
|
|
218
|
+
features: "Leak detection, GC hints",
|
|
219
|
+
useCase: "Production, general monitoring",
|
|
220
|
+
},
|
|
221
|
+
heavy: {
|
|
222
|
+
overhead: "1-5%",
|
|
223
|
+
sampling: "High frequency (200ms)",
|
|
224
|
+
features: "All features, detailed analytics",
|
|
225
|
+
useCase: "Debugging, optimization, testing",
|
|
226
|
+
},
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
/**
|
|
230
|
+
* Environment-based profile selection
|
|
231
|
+
*
|
|
232
|
+
* Automatically selects appropriate profile based on NODE_ENV
|
|
233
|
+
* and other environment variables.
|
|
234
|
+
*
|
|
235
|
+
* @returns {Object} Selected profile configuration
|
|
236
|
+
*/
|
|
237
|
+
function selectProfileByEnvironment() {
|
|
238
|
+
const env = process.env.NODE_ENV || "development";
|
|
239
|
+
const memoryProfile = process.env.MEMORY_PROFILE;
|
|
240
|
+
|
|
241
|
+
// Explicit profile override
|
|
242
|
+
if (memoryProfile) {
|
|
243
|
+
switch (memoryProfile.toLowerCase()) {
|
|
244
|
+
case "light":
|
|
245
|
+
return LIGHT_PROFILE;
|
|
246
|
+
case "heavy":
|
|
247
|
+
return HEAVY_PROFILE;
|
|
248
|
+
case "standard":
|
|
249
|
+
return STANDARD_PROFILE;
|
|
250
|
+
default:
|
|
251
|
+
console.warn(
|
|
252
|
+
`Unknown MEMORY_PROFILE: ${memoryProfile}, using STANDARD`,
|
|
253
|
+
);
|
|
254
|
+
return STANDARD_PROFILE;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Environment-based defaults
|
|
259
|
+
switch (env) {
|
|
260
|
+
case "production":
|
|
261
|
+
return STANDARD_PROFILE;
|
|
262
|
+
case "test":
|
|
263
|
+
return LIGHT_PROFILE;
|
|
264
|
+
case "development":
|
|
265
|
+
return LIGHT_PROFILE;
|
|
266
|
+
default:
|
|
267
|
+
return STANDARD_PROFILE;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
/**
|
|
272
|
+
* Merge custom configuration with profile
|
|
273
|
+
*
|
|
274
|
+
* Allows overriding specific settings while keeping profile defaults.
|
|
275
|
+
*
|
|
276
|
+
* @param {Object} profile - Base profile
|
|
277
|
+
* @param {Object} overrides - Custom settings
|
|
278
|
+
* @returns {Object} Merged configuration
|
|
279
|
+
*/
|
|
280
|
+
function mergeConfig(profile, overrides = {}) {
|
|
281
|
+
return {
|
|
282
|
+
...profile,
|
|
283
|
+
...overrides,
|
|
284
|
+
backpressure: {
|
|
285
|
+
...profile.backpressure,
|
|
286
|
+
...(overrides.backpressure || {}),
|
|
287
|
+
},
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Validate configuration
|
|
293
|
+
*
|
|
294
|
+
* Ensures configuration values are within acceptable ranges.
|
|
295
|
+
*
|
|
296
|
+
* @param {Object} config - Configuration to validate
|
|
297
|
+
* @returns {Object} Validation result with errors if any
|
|
298
|
+
*/
|
|
299
|
+
function validateConfig(config) {
|
|
300
|
+
const errors = [];
|
|
301
|
+
|
|
302
|
+
// Memory limits
|
|
303
|
+
if (config.maxMemoryMB < 64) {
|
|
304
|
+
errors.push("maxMemoryMB must be at least 64 MB");
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
// Sampling intervals
|
|
308
|
+
if (config.samplingInterval < 50) {
|
|
309
|
+
errors.push("samplingInterval must be at least 50ms");
|
|
310
|
+
}
|
|
311
|
+
if (config.snapshotInterval < config.samplingInterval) {
|
|
312
|
+
errors.push("snapshotInterval must be >= samplingInterval");
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// Thresholds
|
|
316
|
+
if (config.warningThreshold >= config.criticalThreshold) {
|
|
317
|
+
errors.push("warningThreshold must be < criticalThreshold");
|
|
318
|
+
}
|
|
319
|
+
if (config.warningThreshold < 0.5 || config.warningThreshold > 1.0) {
|
|
320
|
+
errors.push("warningThreshold must be between 0.5 and 1.0");
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// Leak detection
|
|
324
|
+
if (config.leakThreshold < 2) {
|
|
325
|
+
errors.push("leakThreshold must be at least 2");
|
|
326
|
+
}
|
|
327
|
+
if (config.leakRateThreshold < 0 || config.leakRateThreshold > 1) {
|
|
328
|
+
errors.push("leakRateThreshold must be between 0 and 1");
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
// GC config
|
|
332
|
+
if (config.gcThreshold < 0.5 || config.gcThreshold > 1.0) {
|
|
333
|
+
errors.push("gcThreshold must be between 0.5 and 1.0");
|
|
334
|
+
}
|
|
335
|
+
if (config.minGCInterval < 5000) {
|
|
336
|
+
errors.push("minGCInterval must be at least 5000ms");
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Backpressure
|
|
340
|
+
if (config.backpressure) {
|
|
341
|
+
if (
|
|
342
|
+
config.backpressure.pauseThreshold <= config.backpressure.resumeThreshold
|
|
343
|
+
) {
|
|
344
|
+
errors.push("pauseThreshold must be > resumeThreshold");
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
return {
|
|
349
|
+
valid: errors.length === 0,
|
|
350
|
+
errors,
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Get recommended configuration based on workload characteristics
|
|
356
|
+
*
|
|
357
|
+
* @param {Object} workload - Workload characteristics
|
|
358
|
+
* @returns {Object} Recommended configuration
|
|
359
|
+
*/
|
|
360
|
+
function getRecommendedConfig(workload = {}) {
|
|
361
|
+
const {
|
|
362
|
+
expectedMemoryMB = 512,
|
|
363
|
+
streamingIntensive = false,
|
|
364
|
+
longRunning = false,
|
|
365
|
+
performanceCritical = false,
|
|
366
|
+
} = workload;
|
|
367
|
+
|
|
368
|
+
// Start with standard profile
|
|
369
|
+
let config = { ...STANDARD_PROFILE };
|
|
370
|
+
|
|
371
|
+
// Adjust memory limit
|
|
372
|
+
config.maxMemoryMB = expectedMemoryMB;
|
|
373
|
+
|
|
374
|
+
// Streaming intensive workloads need more frequent monitoring
|
|
375
|
+
if (streamingIntensive) {
|
|
376
|
+
config.samplingInterval = 500;
|
|
377
|
+
config.backpressure.enabled = true;
|
|
378
|
+
config.backpressure.pauseThreshold = 0.8;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
// Long-running workloads need leak detection
|
|
382
|
+
if (longRunning) {
|
|
383
|
+
config.leakDetectionEnabled = true;
|
|
384
|
+
config.leakThreshold = 5;
|
|
385
|
+
config.historySize = 200;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
// Performance critical workloads need minimal overhead
|
|
389
|
+
if (performanceCritical) {
|
|
390
|
+
config.samplingInterval = 5000;
|
|
391
|
+
config.snapshotInterval = 60000;
|
|
392
|
+
config.leakDetectionEnabled = false;
|
|
393
|
+
config.historySize = 50;
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
return config;
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
module.exports = {
|
|
400
|
+
// Profiles
|
|
401
|
+
LIGHT_PROFILE,
|
|
402
|
+
STANDARD_PROFILE,
|
|
403
|
+
HEAVY_PROFILE,
|
|
404
|
+
CUSTOM_PROFILE_TEMPLATE,
|
|
405
|
+
|
|
406
|
+
// Profile metadata
|
|
407
|
+
PROFILE_GUIDE,
|
|
408
|
+
|
|
409
|
+
// Utilities
|
|
410
|
+
selectProfileByEnvironment,
|
|
411
|
+
mergeConfig,
|
|
412
|
+
validateConfig,
|
|
413
|
+
getRecommendedConfig,
|
|
414
|
+
};
|