viberadar 0.3.209 → 0.3.211
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/server/index.d.ts.map +1 -1
- package/dist/server/index.js +110 -25
- package/dist/server/index.js.map +1 -1
- package/dist/ui/dashboard.html +99 -6
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,OAAO,EAAE,UAAU,EAA4H,MAAM,YAAY,CAAC;AAOlK,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AA0vED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAO7B,OAAO,EAAE,UAAU,EAA4H,MAAM,YAAY,CAAC;AAOlK,UAAU,aAAa;IACrB,IAAI,EAAE,UAAU,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC;CACrB;AA0vED,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,WAAW,EAAE,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAs1G1G"}
|
package/dist/server/index.js
CHANGED
|
@@ -2216,6 +2216,13 @@ function startServer({ data: initialData, port, projectRoot }) {
|
|
|
2216
2216
|
}
|
|
2217
2217
|
return out;
|
|
2218
2218
|
}
|
|
2219
|
+
function sanitizeLoadEnvName(value, fallback) {
|
|
2220
|
+
const raw = typeof value === 'string' && value.trim() ? value.trim() : fallback;
|
|
2221
|
+
return /^[A-Za-z_][A-Za-z0-9_]*$/.test(raw) ? raw : fallback;
|
|
2222
|
+
}
|
|
2223
|
+
function detectK6Scenarios(script) {
|
|
2224
|
+
return /\bscenarios\s*:/.test(script) || /export\s+const\s+options[\s\S]*\bscenarios\b/.test(script);
|
|
2225
|
+
}
|
|
2219
2226
|
function redactLoadEnvVars(envVars) {
|
|
2220
2227
|
const out = {};
|
|
2221
2228
|
for (const key of Object.keys(envVars)) {
|
|
@@ -2223,18 +2230,77 @@ function startServer({ data: initialData, port, projectRoot }) {
|
|
|
2223
2230
|
}
|
|
2224
2231
|
return out;
|
|
2225
2232
|
}
|
|
2226
|
-
function
|
|
2233
|
+
function resolveLoadLocalPath(value) {
|
|
2234
|
+
if (typeof value !== 'string' || !value.trim())
|
|
2235
|
+
return undefined;
|
|
2236
|
+
const raw = value.trim();
|
|
2237
|
+
return path.resolve(path.isAbsolute(raw) ? raw : path.join(projectRoot, raw));
|
|
2238
|
+
}
|
|
2239
|
+
function copyLoadDataFiles(sourcePath, workDir) {
|
|
2240
|
+
if (!sourcePath || !fs.existsSync(sourcePath))
|
|
2241
|
+
return 0;
|
|
2242
|
+
const stat = fs.statSync(sourcePath);
|
|
2243
|
+
let copied = 0;
|
|
2244
|
+
const copyOne = (src, dst) => {
|
|
2245
|
+
const st = fs.statSync(src);
|
|
2246
|
+
if (st.isDirectory()) {
|
|
2247
|
+
fs.mkdirSync(dst, { recursive: true });
|
|
2248
|
+
for (const name of fs.readdirSync(src)) {
|
|
2249
|
+
if (name === '.git' || name === 'node_modules' || name === 'dist')
|
|
2250
|
+
continue;
|
|
2251
|
+
copyOne(path.join(src, name), path.join(dst, name));
|
|
2252
|
+
}
|
|
2253
|
+
return;
|
|
2254
|
+
}
|
|
2255
|
+
if (!st.isFile())
|
|
2256
|
+
return;
|
|
2257
|
+
fs.mkdirSync(path.dirname(dst), { recursive: true });
|
|
2258
|
+
fs.copyFileSync(src, dst);
|
|
2259
|
+
copied++;
|
|
2260
|
+
};
|
|
2261
|
+
if (stat.isDirectory()) {
|
|
2262
|
+
for (const name of fs.readdirSync(sourcePath)) {
|
|
2263
|
+
if (name === '.git' || name === 'node_modules' || name === 'dist')
|
|
2264
|
+
continue;
|
|
2265
|
+
copyOne(path.join(sourcePath, name), path.join(workDir, name));
|
|
2266
|
+
}
|
|
2267
|
+
}
|
|
2268
|
+
else if (stat.isFile()) {
|
|
2269
|
+
copyOne(sourcePath, path.join(workDir, path.basename(sourcePath)));
|
|
2270
|
+
}
|
|
2271
|
+
return copied;
|
|
2272
|
+
}
|
|
2273
|
+
function buildLoadConfig(cfg, paths) {
|
|
2227
2274
|
const envVars = sanitizeLoadEnvVars(cfg.envVars);
|
|
2228
2275
|
const baseUrl = typeof cfg.baseUrl === 'string' && cfg.baseUrl.trim() ? cfg.baseUrl.trim() : 'http://localhost:5000';
|
|
2276
|
+
const dataDir = resolveLoadLocalPath(cfg.dataDir);
|
|
2277
|
+
const resultDir = resolveLoadLocalPath(cfg.resultDir);
|
|
2278
|
+
const executionMode = cfg.executionMode === 'script' ? 'script' : 'cli';
|
|
2279
|
+
const vusEnvName = sanitizeLoadEnvName(cfg.vusEnvName, 'SMOKE_VUS');
|
|
2280
|
+
const durationEnvName = sanitizeLoadEnvName(cfg.durationEnvName, 'SMOKE_DURATION');
|
|
2229
2281
|
envVars.BASE_URL = baseUrl;
|
|
2230
2282
|
const config = {
|
|
2231
2283
|
vus: normalizeLoadVus(cfg.vus),
|
|
2232
2284
|
duration: normalizeLoadDuration(cfg.duration),
|
|
2233
2285
|
baseUrl,
|
|
2234
2286
|
scriptName: sanitizeLoadScriptName(cfg.scriptName),
|
|
2287
|
+
executionMode,
|
|
2288
|
+
vusEnvName,
|
|
2289
|
+
durationEnvName,
|
|
2290
|
+
dataDir,
|
|
2291
|
+
resultDir,
|
|
2292
|
+
runDir: paths?.runDir,
|
|
2293
|
+
workDir: paths?.workDir,
|
|
2294
|
+
resultPath: paths?.resultPath,
|
|
2295
|
+
dataFilesCopied: paths?.dataFilesCopied,
|
|
2235
2296
|
envVars: redactLoadEnvVars(envVars),
|
|
2236
2297
|
};
|
|
2237
|
-
|
|
2298
|
+
if (executionMode === 'script') {
|
|
2299
|
+
envVars[vusEnvName] = String(config.vus);
|
|
2300
|
+
envVars[durationEnvName] = config.duration;
|
|
2301
|
+
config.envVars = redactLoadEnvVars(envVars);
|
|
2302
|
+
}
|
|
2303
|
+
return { config, envVars, dataDir, resultDir };
|
|
2238
2304
|
}
|
|
2239
2305
|
function flattenK6Checks(group) {
|
|
2240
2306
|
let passes = 0;
|
|
@@ -2334,6 +2400,10 @@ function startServer({ data: initialData, port, projectRoot }) {
|
|
|
2334
2400
|
fs.unlinkSync(path.join(loadRunsDir, `${old.runId}.json`));
|
|
2335
2401
|
}
|
|
2336
2402
|
catch { }
|
|
2403
|
+
try {
|
|
2404
|
+
fs.rmSync(path.join(loadRunsDir, old.runId), { recursive: true, force: true });
|
|
2405
|
+
}
|
|
2406
|
+
catch { }
|
|
2337
2407
|
}
|
|
2338
2408
|
}
|
|
2339
2409
|
function loadLastRunIntoState() {
|
|
@@ -5045,7 +5115,7 @@ a{color:var(--blue)}
|
|
|
5045
5115
|
req.on('data', (d) => { body += d; });
|
|
5046
5116
|
req.on('end', () => {
|
|
5047
5117
|
try {
|
|
5048
|
-
const { name, script, vus, duration, baseUrl } = JSON.parse(body);
|
|
5118
|
+
const { name, script, vus, duration, baseUrl, dataDir, resultDir, executionMode, vusEnvName, durationEnvName } = JSON.parse(body);
|
|
5049
5119
|
if (!name || !script) {
|
|
5050
5120
|
res.writeHead(400, jsonH);
|
|
5051
5121
|
res.end(JSON.stringify({ error: 'name and script required' }));
|
|
@@ -5063,6 +5133,11 @@ a{color:var(--blue)}
|
|
|
5063
5133
|
vus: normalizeLoadVus(vus),
|
|
5064
5134
|
duration: normalizeLoadDuration(duration),
|
|
5065
5135
|
baseUrl: typeof baseUrl === 'string' && baseUrl.trim() ? baseUrl.trim() : 'http://localhost:5000',
|
|
5136
|
+
executionMode: executionMode === 'script' ? 'script' : 'cli',
|
|
5137
|
+
vusEnvName: sanitizeLoadEnvName(vusEnvName, 'SMOKE_VUS'),
|
|
5138
|
+
durationEnvName: sanitizeLoadEnvName(durationEnvName, 'SMOKE_DURATION'),
|
|
5139
|
+
dataDir: resolveLoadLocalPath(dataDir),
|
|
5140
|
+
resultDir: resolveLoadLocalPath(resultDir),
|
|
5066
5141
|
};
|
|
5067
5142
|
// overwrite if same name exists
|
|
5068
5143
|
const existing = fs.readdirSync(scriptsDir).find(f => {
|
|
@@ -5220,12 +5295,24 @@ a{color:var(--blue)}
|
|
|
5220
5295
|
res.end(JSON.stringify({ error: 'No script provided' }));
|
|
5221
5296
|
return;
|
|
5222
5297
|
}
|
|
5223
|
-
const { config: loadConfig, envVars } = buildLoadConfig(cfg);
|
|
5224
5298
|
const runId = `load-${Date.now()}-${Math.random().toString(36).slice(2, 8)}`;
|
|
5225
|
-
const
|
|
5226
|
-
const
|
|
5227
|
-
const
|
|
5299
|
+
const runDir = path.join(loadRunsDir, runId);
|
|
5300
|
+
const workDir = path.join(runDir, 'work');
|
|
5301
|
+
const defaultResultDir = path.join(runDir, 'results');
|
|
5302
|
+
const effectiveCfg = { ...cfg };
|
|
5303
|
+
if (!effectiveCfg.executionMode) {
|
|
5304
|
+
effectiveCfg.executionMode = detectK6Scenarios(script) ? 'script' : 'cli';
|
|
5305
|
+
}
|
|
5306
|
+
const initial = buildLoadConfig(effectiveCfg);
|
|
5307
|
+
const resultPath = initial.resultDir ? path.join(initial.resultDir, runId) : defaultResultDir;
|
|
5308
|
+
const scriptPath = path.join(workDir, 'script.js');
|
|
5309
|
+
const jsonOutPath = path.join(resultPath, 'metrics.ndjson');
|
|
5310
|
+
const summaryPath = path.join(resultPath, 'summary.json');
|
|
5311
|
+
let dataFilesCopied = 0;
|
|
5228
5312
|
try {
|
|
5313
|
+
fs.mkdirSync(workDir, { recursive: true });
|
|
5314
|
+
fs.mkdirSync(resultPath, { recursive: true });
|
|
5315
|
+
dataFilesCopied = copyLoadDataFiles(initial.dataDir, workDir);
|
|
5229
5316
|
fs.writeFileSync(scriptPath, script, 'utf-8');
|
|
5230
5317
|
}
|
|
5231
5318
|
catch (e) {
|
|
@@ -5233,6 +5320,12 @@ a{color:var(--blue)}
|
|
|
5233
5320
|
res.end(JSON.stringify({ error: e.message }));
|
|
5234
5321
|
return;
|
|
5235
5322
|
}
|
|
5323
|
+
const { config: loadConfig, envVars } = buildLoadConfig(effectiveCfg, {
|
|
5324
|
+
runDir,
|
|
5325
|
+
workDir,
|
|
5326
|
+
resultPath,
|
|
5327
|
+
dataFilesCopied,
|
|
5328
|
+
});
|
|
5236
5329
|
loadRunning = true;
|
|
5237
5330
|
loadState = {
|
|
5238
5331
|
runId, status: 'running', startTime: Date.now(), buckets: [], totalRequests: 0,
|
|
@@ -5246,17 +5339,13 @@ a{color:var(--blue)}
|
|
|
5246
5339
|
if (k && v !== undefined && v !== '')
|
|
5247
5340
|
envFlags.push('--env', `${k}=${v}`);
|
|
5248
5341
|
}
|
|
5249
|
-
const args = [
|
|
5250
|
-
|
|
5251
|
-
'--vus', String(loadConfig.vus),
|
|
5252
|
-
|
|
5253
|
-
|
|
5254
|
-
'--summary-export', summaryPath,
|
|
5255
|
-
'--out', `json=${jsonOutPath}`,
|
|
5256
|
-
scriptPath,
|
|
5257
|
-
];
|
|
5342
|
+
const args = ['run'];
|
|
5343
|
+
if (loadConfig.executionMode !== 'script') {
|
|
5344
|
+
args.push('--vus', String(loadConfig.vus), '--duration', loadConfig.duration);
|
|
5345
|
+
}
|
|
5346
|
+
args.push(...envFlags, '--summary-export', summaryPath, '--out', `json=${jsonOutPath}`, scriptPath);
|
|
5258
5347
|
loadProc = (0, child_process_1.spawn)('k6', args, {
|
|
5259
|
-
cwd:
|
|
5348
|
+
cwd: workDir, env: { ...process.env }, shell: WIN, stdio: 'pipe',
|
|
5260
5349
|
});
|
|
5261
5350
|
const addLog = (line) => {
|
|
5262
5351
|
loadState.logs.push(line);
|
|
@@ -5353,15 +5442,11 @@ a{color:var(--blue)}
|
|
|
5353
5442
|
saveLoadRun();
|
|
5354
5443
|
broadcast('load-done', { runId: loadState.runId, status: loadState.status, summary: loadState.summary });
|
|
5355
5444
|
try {
|
|
5356
|
-
fs.
|
|
5357
|
-
}
|
|
5358
|
-
catch { }
|
|
5359
|
-
try {
|
|
5360
|
-
fs.unlinkSync(jsonOutPath);
|
|
5445
|
+
fs.writeFileSync(path.join(resultPath, 'k6.log'), loadState.logs.join('\n'), 'utf-8');
|
|
5361
5446
|
}
|
|
5362
5447
|
catch { }
|
|
5363
5448
|
try {
|
|
5364
|
-
fs.
|
|
5449
|
+
fs.writeFileSync(path.join(resultPath, 'config.json'), JSON.stringify(loadState.config, null, 2), 'utf-8');
|
|
5365
5450
|
}
|
|
5366
5451
|
catch { }
|
|
5367
5452
|
});
|
|
@@ -5376,11 +5461,11 @@ a{color:var(--blue)}
|
|
|
5376
5461
|
saveLoadRun();
|
|
5377
5462
|
broadcast('load-done', { runId: loadState.runId, status: 'error', summary: loadState.summary });
|
|
5378
5463
|
try {
|
|
5379
|
-
fs.
|
|
5464
|
+
fs.writeFileSync(path.join(resultPath, 'k6.log'), loadState.logs.join('\n'), 'utf-8');
|
|
5380
5465
|
}
|
|
5381
5466
|
catch { }
|
|
5382
5467
|
try {
|
|
5383
|
-
fs.
|
|
5468
|
+
fs.writeFileSync(path.join(resultPath, 'config.json'), JSON.stringify(loadState.config, null, 2), 'utf-8');
|
|
5384
5469
|
}
|
|
5385
5470
|
catch { }
|
|
5386
5471
|
});
|