@innovatorved/code-lab 0.1.12 → 0.1.13
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/ARCHITECTURE.md +5 -5
- package/README.md +6 -6
- package/dist/code-lab.css +165 -0
- package/dist/code-lab.d.ts +1 -1
- package/dist/code-lab.esm.js +2016 -430
- package/dist/code-lab.js +2014 -429
- package/dist/preview-sw.js +1 -1
- package/dist/runtime.d.ts +1 -0
- package/dist/runtime.esm.js +966 -401
- package/dist/runtime.js +964 -401
- package/dist/shell.esm.js +806 -1
- package/dist/shell.js +806 -1
- package/dist/terminal.esm.js +1 -1
- package/dist/terminal.js +1 -1
- package/package.json +1 -1
- package/src/code-lab.css +165 -0
- package/src/runtime.ts +964 -400
- package/src/shell.ts +805 -0
- package/src/workbench.ts +238 -22
package/src/workbench.ts
CHANGED
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
|
|
58
58
|
// The bundler rewrites this literal from package.json at build time. Keeping
|
|
59
59
|
// the fallback in sync lets tests require src/workbench.js directly.
|
|
60
|
-
const CODELAB_VERSION = '0.1.
|
|
60
|
+
const CODELAB_VERSION = '0.1.13';
|
|
61
61
|
|
|
62
62
|
// Ambient TypeScript declarations for Node.js built-ins inside Monaco
|
|
63
63
|
const NODE_AMBIENT_DTS = `
|
|
@@ -1581,6 +1581,7 @@ declare module 'bun:sqlite' {
|
|
|
1581
1581
|
this.logger.debug('Could not parse portTable dispatch URL.', err);
|
|
1582
1582
|
}
|
|
1583
1583
|
const method = String((init && init.method) || 'GET').toUpperCase();
|
|
1584
|
+
const fromPort = (init && init._fromPort) ? Number(init._fromPort) : null;
|
|
1584
1585
|
try {
|
|
1585
1586
|
const res = await origDispatch(url, init);
|
|
1586
1587
|
const durationMs = Math.max(0.1, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - t0);
|
|
@@ -1606,8 +1607,9 @@ declare module 'bun:sqlite' {
|
|
|
1606
1607
|
try {
|
|
1607
1608
|
formattedBody = JSON.stringify(JSON.parse(bodyText), null, 2);
|
|
1608
1609
|
} catch (err) {
|
|
1609
|
-
|
|
1610
|
+
this.logger.debug('Response body is not JSON.', err);
|
|
1610
1611
|
}
|
|
1612
|
+
const chaosEffect = (res && res._chaosEffect) || responseHeaders['x-codelab-chaos'] || null;
|
|
1611
1613
|
if (!Array.isArray(this.lastHttpTrace)) this.lastHttpTrace = [];
|
|
1612
1614
|
this.lastHttpTrace.push({
|
|
1613
1615
|
id: 'trace_' + Date.now() + '_' + Math.random().toString(36).slice(2, 6),
|
|
@@ -1616,6 +1618,8 @@ declare module 'bun:sqlite' {
|
|
|
1616
1618
|
url: reqPath,
|
|
1617
1619
|
fullUrl,
|
|
1618
1620
|
port: parsedPort,
|
|
1621
|
+
fromPort,
|
|
1622
|
+
chaosEffect,
|
|
1619
1623
|
status: (res && res.status) || 200,
|
|
1620
1624
|
statusText: (res && res.statusText) || 'OK',
|
|
1621
1625
|
durationMs,
|
|
@@ -1626,8 +1630,34 @@ declare module 'bun:sqlite' {
|
|
|
1626
1630
|
responseBody: bodyText,
|
|
1627
1631
|
formattedBody
|
|
1628
1632
|
});
|
|
1633
|
+
const netPill = this.container ? this.container.querySelector('#cl-network-pill') : null;
|
|
1634
|
+
if (netPill) netPill.textContent = `${this.lastHttpTrace.length} reqs`;
|
|
1629
1635
|
return res;
|
|
1630
1636
|
} catch (err) {
|
|
1637
|
+
const durationMs = Math.max(0.1, (typeof performance !== 'undefined' ? performance.now() : Date.now()) - t0);
|
|
1638
|
+
if (!Array.isArray(this.lastHttpTrace)) this.lastHttpTrace = [];
|
|
1639
|
+
const errMsg = String((err && err.message) || err);
|
|
1640
|
+
this.lastHttpTrace.push({
|
|
1641
|
+
id: 'trace_' + Date.now() + '_' + Math.random().toString(36).slice(2, 6),
|
|
1642
|
+
timestamp: new Date().toLocaleTimeString(),
|
|
1643
|
+
method,
|
|
1644
|
+
url: reqPath,
|
|
1645
|
+
fullUrl,
|
|
1646
|
+
port: parsedPort,
|
|
1647
|
+
fromPort,
|
|
1648
|
+
chaosEffect: (err && err.chaosEffect) || (err && err.code) || 'ERROR',
|
|
1649
|
+
status: 0,
|
|
1650
|
+
statusText: (err && (err.chaosEffect || err.code)) || 'ERROR',
|
|
1651
|
+
durationMs,
|
|
1652
|
+
size: 0,
|
|
1653
|
+
requestHeaders: (init && init.headers) || {},
|
|
1654
|
+
requestBody: (init && init.body) || '',
|
|
1655
|
+
responseHeaders: {},
|
|
1656
|
+
responseBody: errMsg,
|
|
1657
|
+
formattedBody: errMsg
|
|
1658
|
+
});
|
|
1659
|
+
const netPill = this.container ? this.container.querySelector('#cl-network-pill') : null;
|
|
1660
|
+
if (netPill) netPill.textContent = `${this.lastHttpTrace.length} reqs`;
|
|
1631
1661
|
throw err;
|
|
1632
1662
|
}
|
|
1633
1663
|
};
|
|
@@ -3725,10 +3755,10 @@ declare module 'bun:sqlite' {
|
|
|
3725
3755
|
|
|
3726
3756
|
if (isFirstToken) {
|
|
3727
3757
|
const commands = [
|
|
3728
|
-
'
|
|
3729
|
-
'
|
|
3730
|
-
'
|
|
3731
|
-
'uniq', 'unset', 'wc', 'which', '
|
|
3758
|
+
'ab', 'bun', 'cat', 'cd', 'chaos', 'clear', 'cp', 'curl', 'echo', 'env',
|
|
3759
|
+
'export', 'find', 'grep', 'head', 'help', 'hey', 'history', 'jobs', 'kill',
|
|
3760
|
+
'ls', 'mkdir', 'mv', 'node', 'npm', 'npx', 'ps', 'pwd', 'redis-cli', 'rm',
|
|
3761
|
+
'sed', 'sort', 'sqlite3', 'tail', 'touch', 'uniq', 'unset', 'wc', 'which', 'wrk'
|
|
3732
3762
|
];
|
|
3733
3763
|
return commands.filter(c => c.startsWith(token));
|
|
3734
3764
|
} else {
|
|
@@ -3789,25 +3819,53 @@ declare module 'bun:sqlite' {
|
|
|
3789
3819
|
<th>Host / URL</th>
|
|
3790
3820
|
<th>Protocol</th>
|
|
3791
3821
|
<th>Process / Service</th>
|
|
3792
|
-
<th>Status</th>
|
|
3793
|
-
<th style="text-align:right;">Actions</th>
|
|
3822
|
+
<th>Status & Chaos</th>
|
|
3823
|
+
<th style="text-align:right;">Chaos Injection & Actions</th>
|
|
3794
3824
|
</tr>
|
|
3795
3825
|
</thead>
|
|
3796
3826
|
<tbody>
|
|
3797
|
-
${servers.map(s =>
|
|
3827
|
+
${servers.map(s => {
|
|
3828
|
+
const rule = (this.portTable && typeof this.portTable.getChaosRule === 'function')
|
|
3829
|
+
? this.portTable.getChaosRule(s.port)
|
|
3830
|
+
: null;
|
|
3831
|
+
const isCrashed = Boolean(rule && rule.crashed);
|
|
3832
|
+
const hasLat = Boolean(rule && rule.latencyMs > 0);
|
|
3833
|
+
const hasErr = Boolean(rule && rule.errorRate > 0);
|
|
3834
|
+
const hasDrop = Boolean(rule && rule.dropRate > 0);
|
|
3835
|
+
const hasAnyChaos = isCrashed || hasLat || hasErr || hasDrop || Boolean(rule && rule.partitionFromPorts && rule.partitionFromPorts.length);
|
|
3836
|
+
const chaosPills = [];
|
|
3837
|
+
if (isCrashed) chaosPills.push(`<span class="codelab-chaos-badge codelab-chaos-badge--danger">CRASHED</span>`);
|
|
3838
|
+
if (hasLat) chaosPills.push(`<span class="codelab-chaos-badge codelab-chaos-badge--warn">+${rule.latencyMs}ms</span>`);
|
|
3839
|
+
if (hasErr) chaosPills.push(`<span class="codelab-chaos-badge codelab-chaos-badge--danger">${Math.round(rule.errorRate * 100)}% HTTP ${rule.errorStatus || 503}</span>`);
|
|
3840
|
+
if (hasDrop) chaosPills.push(`<span class="codelab-chaos-badge codelab-chaos-badge--danger">${Math.round(rule.dropRate * 100)}% DROP</span>`);
|
|
3841
|
+
return `
|
|
3798
3842
|
<tr>
|
|
3799
3843
|
<td><span class="codelab-port-tag">${s.port}</span></td>
|
|
3800
3844
|
<td><a href="http://127.0.0.1:${s.port}/" target="_blank" class="codelab-port-link">http://127.0.0.1:${s.port}/</a></td>
|
|
3801
3845
|
<td><span class="codelab-badge">${escapeHtml(s.protocol || 'HTTP/1.1')}</span></td>
|
|
3802
3846
|
<td><code>${escapeHtml(s.service || (s.pid ? `PID ${s.pid}` : 'node'))}</code></td>
|
|
3803
|
-
<td
|
|
3847
|
+
<td>
|
|
3848
|
+
<div style="display:flex;align-items:center;gap:6px;flex-wrap:wrap;">
|
|
3849
|
+
<span class="codelab-port-status ${isCrashed ? 'codelab-port-status--crashed' : 'codelab-port-status--listening'}">
|
|
3850
|
+
<span class="codelab-port-status-dot"></span>${isCrashed ? 'CRASHED' : 'LISTENING'}
|
|
3851
|
+
</span>
|
|
3852
|
+
${chaosPills.join('')}
|
|
3853
|
+
</div>
|
|
3854
|
+
</td>
|
|
3804
3855
|
<td style="text-align:right;white-space:nowrap;">
|
|
3856
|
+
<span class="codelab-chaos-btn-group" title="Inject network faults on port :${s.port}">
|
|
3857
|
+
<button type="button" class="codelab-btn codelab-btn--sm ${hasLat ? 'codelab-btn--chaos-active' : ''}" data-cl-action="chaos-latency" data-port="${s.port}" title="Toggle +200ms network latency on :${s.port}">+200ms</button>
|
|
3858
|
+
<button type="button" class="codelab-btn codelab-btn--sm ${hasErr ? 'codelab-btn--chaos-active' : ''}" data-cl-action="chaos-error" data-port="${s.port}" title="Toggle 25% HTTP 503 error rate on :${s.port}">25% 503</button>
|
|
3859
|
+
<button type="button" class="codelab-btn codelab-btn--sm ${isCrashed ? 'codelab-btn--danger' : ''}" data-cl-action="chaos-crash" data-port="${s.port}" title="Simulate node crash (ECONNREFUSED) on :${s.port}">${isCrashed ? 'Recover' : 'Crash'}</button>
|
|
3860
|
+
${hasAnyChaos ? `<button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="chaos-heal" data-port="${s.port}" title="Heal all chaos rules on :${s.port}">Heal</button>` : ''}
|
|
3861
|
+
</span>
|
|
3805
3862
|
<button type="button" class="codelab-btn codelab-btn--sm codelab-btn--primary" data-cl-action="open-web-preview" data-port="${s.port}" data-cl-port="${s.port}">Preview</button>
|
|
3806
3863
|
<button type="button" class="codelab-btn codelab-btn--sm" data-cl-action="open-port-client" data-port="${s.port}" data-cl-port="${s.port}">Open in Client</button>
|
|
3807
3864
|
<button type="button" class="codelab-btn codelab-btn--sm codelab-btn--danger" data-cl-action="stop-port" data-port="${s.port}" data-cl-port="${s.port}">Stop</button>
|
|
3808
3865
|
</td>
|
|
3809
3866
|
</tr>
|
|
3810
|
-
|
|
3867
|
+
`;
|
|
3868
|
+
}).join('')}
|
|
3811
3869
|
</tbody>
|
|
3812
3870
|
</table>
|
|
3813
3871
|
</div>
|
|
@@ -3860,7 +3918,7 @@ declare module 'bun:sqlite' {
|
|
|
3860
3918
|
<div class="codelab-ports-panel">
|
|
3861
3919
|
<div class="codelab-panel-section">
|
|
3862
3920
|
<div class="codelab-section-title">
|
|
3863
|
-
<span>${CL_ICONS.radio || ''} Active Port Listeners</span>
|
|
3921
|
+
<span>${CL_ICONS.radio || ''} Active Port Listeners & Chaos Controls</span>
|
|
3864
3922
|
<span class="codelab-badge">${servers.length} listening</span>
|
|
3865
3923
|
</div>
|
|
3866
3924
|
${serversHtml}
|
|
@@ -3945,6 +4003,85 @@ declare module 'bun:sqlite' {
|
|
|
3945
4003
|
const traces = Array.isArray(this.lastHttpTrace) ? this.lastHttpTrace : [];
|
|
3946
4004
|
const filter = this.networkFilter;
|
|
3947
4005
|
|
|
4006
|
+
// Compute SLO & Latency Percentiles across all captured traces
|
|
4007
|
+
const totalReqs = traces.length;
|
|
4008
|
+
let count2xx = 0;
|
|
4009
|
+
let count429 = 0;
|
|
4010
|
+
let count5xxOrErr = 0;
|
|
4011
|
+
const sortedDurations = traces.map(t => Number(t.durationMs || 0)).sort((a, b) => a - b);
|
|
4012
|
+
for (const t of traces) {
|
|
4013
|
+
const st = Number(t.status || 0);
|
|
4014
|
+
if (st >= 200 && st < 300) count2xx++;
|
|
4015
|
+
else if (st === 429) count429++;
|
|
4016
|
+
else if (st >= 500 || st === 0) count5xxOrErr++;
|
|
4017
|
+
}
|
|
4018
|
+
const pctLat = (p) => {
|
|
4019
|
+
if (!sortedDurations.length) return '0.0';
|
|
4020
|
+
const idx = Math.min(sortedDurations.length - 1, Math.floor((p / 100) * sortedDurations.length));
|
|
4021
|
+
return sortedDurations[idx].toFixed(1);
|
|
4022
|
+
};
|
|
4023
|
+
const okPct = totalReqs > 0 ? ((count2xx / totalReqs) * 100).toFixed(1) : '100.0';
|
|
4024
|
+
const p50Ms = pctLat(50);
|
|
4025
|
+
const p95Ms = pctLat(95);
|
|
4026
|
+
const p99Ms = pctLat(99);
|
|
4027
|
+
|
|
4028
|
+
// Build Live Service Topology & Chaos Map
|
|
4029
|
+
const servers = (this.portTable && typeof this.portTable.listServers === 'function')
|
|
4030
|
+
? this.portTable.listServers()
|
|
4031
|
+
: [];
|
|
4032
|
+
const edgeMap = new Map();
|
|
4033
|
+
for (const t of traces) {
|
|
4034
|
+
const src = t.fromPort ? `:${t.fromPort}` : 'Client';
|
|
4035
|
+
const dst = `:${t.port || 3000}`;
|
|
4036
|
+
const key = `${src}→${dst}`;
|
|
4037
|
+
const cur = edgeMap.get(key) || { src, dst, targetPort: Number(t.port || 3000), count: 0, errCount: 0, totalMs: 0 };
|
|
4038
|
+
cur.count++;
|
|
4039
|
+
if (Number(t.status || 0) >= 500 || Number(t.status || 0) === 0) cur.errCount++;
|
|
4040
|
+
cur.totalMs += Number(t.durationMs || 0);
|
|
4041
|
+
edgeMap.set(key, cur);
|
|
4042
|
+
}
|
|
4043
|
+
|
|
4044
|
+
let topologyHtml = '';
|
|
4045
|
+
if (servers.length > 0 || edgeMap.size > 0) {
|
|
4046
|
+
const edgePills = Array.from(edgeMap.values()).map(e => {
|
|
4047
|
+
const avg = (e.totalMs / Math.max(1, e.count)).toFixed(1);
|
|
4048
|
+
const hasErrors = e.errCount > 0;
|
|
4049
|
+
return `
|
|
4050
|
+
<span class="codelab-topo-edge ${hasErrors ? 'codelab-topo-edge--err' : ''}">
|
|
4051
|
+
<strong>${escapeHtml(e.src)}</strong>
|
|
4052
|
+
<span class="codelab-topo-arrow">──(${e.count} req · ${avg}ms${hasErrors ? ` · ${e.errCount} err` : ''})──▶</span>
|
|
4053
|
+
<strong>${escapeHtml(e.dst)}</strong>
|
|
4054
|
+
</span>
|
|
4055
|
+
`;
|
|
4056
|
+
}).join('');
|
|
4057
|
+
|
|
4058
|
+
const nodePills = servers.map(s => {
|
|
4059
|
+
const rule = (this.portTable && typeof this.portTable.getChaosRule === 'function')
|
|
4060
|
+
? this.portTable.getChaosRule(s.port)
|
|
4061
|
+
: null;
|
|
4062
|
+
const isCrashed = Boolean(rule && rule.crashed);
|
|
4063
|
+
const hasLat = Boolean(rule && rule.latencyMs > 0);
|
|
4064
|
+
const hasErr = Boolean(rule && rule.errorRate > 0);
|
|
4065
|
+
return `
|
|
4066
|
+
<span class="codelab-topo-node ${isCrashed ? 'is-crashed' : (hasLat || hasErr ? 'is-degraded' : 'is-healthy')}">
|
|
4067
|
+
<span class="codelab-port-status-dot"></span>
|
|
4068
|
+
<code>:${s.port}</code>
|
|
4069
|
+
<span>${escapeHtml(s.service || 'node')}</span>
|
|
4070
|
+
${isCrashed ? '<span class="codelab-chaos-badge codelab-chaos-badge--danger">CRASHED</span>' : ''}
|
|
4071
|
+
${hasLat ? `<span class="codelab-chaos-badge codelab-chaos-badge--warn">+${rule.latencyMs}ms</span>` : ''}
|
|
4072
|
+
${hasErr ? `<span class="codelab-chaos-badge codelab-chaos-badge--danger">${Math.round(rule.errorRate * 100)}% ${rule.errorStatus || 503}</span>` : ''}
|
|
4073
|
+
</span>
|
|
4074
|
+
`;
|
|
4075
|
+
}).join('');
|
|
4076
|
+
|
|
4077
|
+
topologyHtml = `
|
|
4078
|
+
<div class="codelab-topo-bar">
|
|
4079
|
+
<div class="codelab-topo-nodes">${nodePills || '<span style="font-size:11px;color:var(--cl-fg-muted);">No listening servers</span>'}</div>
|
|
4080
|
+
${edgePills ? `<div class="codelab-topo-edges">${edgePills}</div>` : ''}
|
|
4081
|
+
</div>
|
|
4082
|
+
`;
|
|
4083
|
+
}
|
|
4084
|
+
|
|
3948
4085
|
const filtered = traces.filter(t => {
|
|
3949
4086
|
if (filter.method && filter.method !== 'ALL' && (t.method || 'GET').toUpperCase() !== filter.method) return false;
|
|
3950
4087
|
if (filter.status && filter.status !== 'ALL') {
|
|
@@ -3952,7 +4089,7 @@ declare module 'bun:sqlite' {
|
|
|
3952
4089
|
if (filter.status === '2xx' && (s < 200 || s >= 300)) return false;
|
|
3953
4090
|
if (filter.status === '3xx' && (s < 300 || s >= 400)) return false;
|
|
3954
4091
|
if (filter.status === '4xx' && (s < 400 || s >= 500)) return false;
|
|
3955
|
-
if (filter.status === '5xx' && (s < 500
|
|
4092
|
+
if (filter.status === '5xx' && (s < 500 && s !== 0)) return false;
|
|
3956
4093
|
}
|
|
3957
4094
|
if (filter.search) {
|
|
3958
4095
|
const query = filter.search.toLowerCase();
|
|
@@ -3971,23 +4108,26 @@ declare module 'bun:sqlite' {
|
|
|
3971
4108
|
rowsHtml = `
|
|
3972
4109
|
<tr>
|
|
3973
4110
|
<td colspan="7" style="text-align:center;padding:32px;color:var(--cl-fg-muted);">
|
|
3974
|
-
${traces.length === 0 ? 'No network requests recorded yet. Run a demo,
|
|
4111
|
+
${traces.length === 0 ? 'No network requests recorded yet. Run a demo, click "⚡ Load Test", or run `hey -n 50 http://localhost:3000` in the terminal.' : 'No network requests match the active filters.'}
|
|
3975
4112
|
</td>
|
|
3976
4113
|
</tr>
|
|
3977
4114
|
`;
|
|
3978
4115
|
} else {
|
|
3979
4116
|
const maxDuration = Math.max(1, ...filtered.map(t => t.durationMs || 1));
|
|
3980
4117
|
rowsHtml = filtered.map(t => {
|
|
3981
|
-
const status = Number(t.status ||
|
|
3982
|
-
const
|
|
4118
|
+
const status = Number(t.status || 0);
|
|
4119
|
+
const statusLabel = status === 0 ? (t.statusText || 'ERR') : String(status);
|
|
4120
|
+
const statusClass = status === 0 ? 'status-5xx' : (status < 300 ? 'status-2xx' : (status < 400 ? 'status-3xx' : (status < 500 ? 'status-4xx' : 'status-5xx')));
|
|
3983
4121
|
const widthPct = Math.min(100, Math.max(8, Math.round(((t.durationMs || 1) / maxDuration) * 100)));
|
|
3984
4122
|
const isSelected = selectedTrace && String(selectedTrace.id) === String(t.id);
|
|
4123
|
+
const hopLabel = t.fromPort ? `:${t.fromPort}→:${t.port || 3000}` : `:${t.port || 3000}`;
|
|
4124
|
+
const chaosChip = t.chaosEffect ? `<span class="codelab-chaos-badge codelab-chaos-badge--warn" style="margin-left:4px;">${escapeHtml(String(t.chaosEffect))}</span>` : '';
|
|
3985
4125
|
return `
|
|
3986
4126
|
<tr class="codelab-net-row ${isSelected ? 'selected' : ''}" data-cl-action="select-net-trace" data-trace-id="${escapeHtml(t.id || '')}" data-cl-trace-id="${escapeHtml(t.id || '')}">
|
|
3987
|
-
<td><span class="codelab-status-badge ${statusClass}">${
|
|
4127
|
+
<td><span class="codelab-status-badge ${statusClass}">${escapeHtml(statusLabel)}</span>${chaosChip}</td>
|
|
3988
4128
|
<td><span class="codelab-method-badge codelab-method-${(t.method || 'GET').toLowerCase()}">${escapeHtml(t.method || 'GET')}</span></td>
|
|
3989
4129
|
<td class="codelab-net-path" title="${escapeHtml(t.url || '/')}">${escapeHtml(t.url || '/')}</td>
|
|
3990
|
-
<td><code>${
|
|
4130
|
+
<td><code>${escapeHtml(hopLabel)}</code></td>
|
|
3991
4131
|
<td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${(t.durationMs || 0).toFixed(1)} ms</td>
|
|
3992
4132
|
<td style="white-space:nowrap;font-family:var(--cl-font-mono);font-size:11.5px;">${t.size != null ? t.size : 0} B</td>
|
|
3993
4133
|
<td class="codelab-waterfall-cell">
|
|
@@ -4021,6 +4161,8 @@ declare module 'bun:sqlite' {
|
|
|
4021
4161
|
<div class="codelab-net-detail__section">
|
|
4022
4162
|
<div class="codelab-detail-label">General</div>
|
|
4023
4163
|
<div class="codelab-detail-kv"><strong>URL:</strong> 127.0.0.1:${selectedTrace.port}${escapeHtml(selectedTrace.url || '/')}</div>
|
|
4164
|
+
${selectedTrace.fromPort ? `<div class="codelab-detail-kv"><strong>Caller Port:</strong> :${selectedTrace.fromPort}</div>` : ''}
|
|
4165
|
+
${selectedTrace.chaosEffect ? `<div class="codelab-detail-kv"><strong>Chaos Fault:</strong> ${escapeHtml(String(selectedTrace.chaosEffect))}</div>` : ''}
|
|
4024
4166
|
<div class="codelab-detail-kv"><strong>Status:</strong> ${selectedTrace.status} ${escapeHtml(selectedTrace.statusText || '')}</div>
|
|
4025
4167
|
<div class="codelab-detail-kv"><strong>Duration:</strong> ${(selectedTrace.durationMs || 0).toFixed(2)} ms</div>
|
|
4026
4168
|
<div class="codelab-detail-kv"><strong>Size:</strong> ${selectedTrace.size || 0} bytes</div>
|
|
@@ -4050,8 +4192,42 @@ declare module 'bun:sqlite' {
|
|
|
4050
4192
|
|
|
4051
4193
|
bodyEl.innerHTML = `
|
|
4052
4194
|
<div class="codelab-network-panel ${selectedTrace ? 'has-detail' : ''}">
|
|
4195
|
+
<div class="codelab-slo-bar" role="region" aria-label="SLO and Latency Telemetry">
|
|
4196
|
+
<div class="codelab-slo-metric">
|
|
4197
|
+
<span class="codelab-slo-label">Requests</span>
|
|
4198
|
+
<span class="codelab-slo-val">${totalReqs}</span>
|
|
4199
|
+
</div>
|
|
4200
|
+
<div class="codelab-slo-metric">
|
|
4201
|
+
<span class="codelab-slo-label">2xx SLO</span>
|
|
4202
|
+
<span class="codelab-slo-val ${Number(okPct) < 95 && totalReqs > 0 ? 'is-warn' : 'is-ok'}">${okPct}%</span>
|
|
4203
|
+
</div>
|
|
4204
|
+
<div class="codelab-slo-metric">
|
|
4205
|
+
<span class="codelab-slo-label">429 Throttled</span>
|
|
4206
|
+
<span class="codelab-slo-val ${count429 > 0 ? 'is-warn' : ''}">${count429}</span>
|
|
4207
|
+
</div>
|
|
4208
|
+
<div class="codelab-slo-metric">
|
|
4209
|
+
<span class="codelab-slo-label">5xx / Faults</span>
|
|
4210
|
+
<span class="codelab-slo-val ${count5xxOrErr > 0 ? 'is-err' : ''}">${count5xxOrErr}</span>
|
|
4211
|
+
</div>
|
|
4212
|
+
<div class="codelab-slo-metric">
|
|
4213
|
+
<span class="codelab-slo-label">p50</span>
|
|
4214
|
+
<span class="codelab-slo-val">${p50Ms} ms</span>
|
|
4215
|
+
</div>
|
|
4216
|
+
<div class="codelab-slo-metric">
|
|
4217
|
+
<span class="codelab-slo-label">p95</span>
|
|
4218
|
+
<span class="codelab-slo-val">${p95Ms} ms</span>
|
|
4219
|
+
</div>
|
|
4220
|
+
<div class="codelab-slo-metric">
|
|
4221
|
+
<span class="codelab-slo-label">p99</span>
|
|
4222
|
+
<span class="codelab-slo-val">${p99Ms} ms</span>
|
|
4223
|
+
</div>
|
|
4224
|
+
<div style="margin-left:auto;display:flex;align-items:center;gap:6px;">
|
|
4225
|
+
<button type="button" class="codelab-btn codelab-btn--sm codelab-btn--primary" data-cl-action="run-quick-loadtest" title="Run 50 concurrent requests (hey -n 50 -c 10) against active server">⚡ Load Test (50 reqs)</button>
|
|
4226
|
+
</div>
|
|
4227
|
+
</div>
|
|
4228
|
+
${topologyHtml}
|
|
4053
4229
|
<div class="codelab-net-toolbar">
|
|
4054
|
-
<input type="text" class="codelab-input" id="cl-net-search" placeholder="Filter URL or method..." value="${escapeHtml(filter.search)}" aria-label="Filter network traces">
|
|
4230
|
+
<input type="text" class="codelab-input" id="cl-net-search" placeholder="Filter URL, port, or method..." value="${escapeHtml(filter.search)}" aria-label="Filter network traces">
|
|
4055
4231
|
<select class="codelab-select" id="cl-net-method" aria-label="Filter by method">
|
|
4056
4232
|
<option value="ALL" ${filter.method === 'ALL' ? 'selected' : ''}>All Methods</option>
|
|
4057
4233
|
<option value="GET" ${filter.method === 'GET' ? 'selected' : ''}>GET</option>
|
|
@@ -4065,7 +4241,7 @@ declare module 'bun:sqlite' {
|
|
|
4065
4241
|
<option value="2xx" ${filter.status === '2xx' ? 'selected' : ''}>2xx Success</option>
|
|
4066
4242
|
<option value="3xx" ${filter.status === '3xx' ? 'selected' : ''}>3xx Redirect</option>
|
|
4067
4243
|
<option value="4xx" ${filter.status === '4xx' ? 'selected' : ''}>4xx Client Error</option>
|
|
4068
|
-
<option value="5xx" ${filter.status === '5xx' ? 'selected' : ''}>5xx
|
|
4244
|
+
<option value="5xx" ${filter.status === '5xx' ? 'selected' : ''}>5xx / Network Fault</option>
|
|
4069
4245
|
</select>
|
|
4070
4246
|
<button type="button" class="codelab-btn" data-cl-action="clear-net-traces">Clear</button>
|
|
4071
4247
|
<span style="margin-left:auto;font-size:11.5px;color:var(--cl-fg-muted);">${filtered.length} of ${traces.length} requests</span>
|
|
@@ -4075,10 +4251,10 @@ declare module 'bun:sqlite' {
|
|
|
4075
4251
|
<table class="codelab-net-table">
|
|
4076
4252
|
<thead>
|
|
4077
4253
|
<tr>
|
|
4078
|
-
<th style="width:
|
|
4254
|
+
<th style="width:85px;">Status</th>
|
|
4079
4255
|
<th style="width:65px;">Method</th>
|
|
4080
4256
|
<th>Path</th>
|
|
4081
|
-
<th style="width:
|
|
4257
|
+
<th style="width:95px;">Route</th>
|
|
4082
4258
|
<th style="width:75px;">Time</th>
|
|
4083
4259
|
<th style="width:70px;">Size</th>
|
|
4084
4260
|
<th style="width:140px;">Waterfall</th>
|
|
@@ -4276,6 +4452,9 @@ declare module 'bun:sqlite' {
|
|
|
4276
4452
|
if (this.drawerTab === 'ports') this._renderDrawerBody();
|
|
4277
4453
|
this._dismissPortToast(port);
|
|
4278
4454
|
}));
|
|
4455
|
+
this._portListenerUnsubs.push(this.portTable.on('chaos', () => {
|
|
4456
|
+
if (this.drawerTab === 'ports' || this.drawerTab === 'network') this._renderDrawerBody();
|
|
4457
|
+
}));
|
|
4279
4458
|
} catch (err) {
|
|
4280
4459
|
this.logger.warn('Failed to attach portTable event listeners.', err);
|
|
4281
4460
|
}
|
|
@@ -6218,6 +6397,43 @@ declare module 'bun:sqlite' {
|
|
|
6218
6397
|
this.networkFilter.selectedTraceId = null;
|
|
6219
6398
|
}
|
|
6220
6399
|
this._renderDrawerBody();
|
|
6400
|
+
} else if (action === 'chaos-latency' || action === 'chaos-error' || action === 'chaos-crash' || action === 'chaos-heal') {
|
|
6401
|
+
const port = Number(actionBtn.dataset.port || actionBtn.dataset.clPort);
|
|
6402
|
+
if (port && this.portTable && typeof this.portTable.setChaosRule === 'function') {
|
|
6403
|
+
const cur = (typeof this.portTable.getChaosRule === 'function' ? this.portTable.getChaosRule(port) : null) || {};
|
|
6404
|
+
if (action === 'chaos-latency') {
|
|
6405
|
+
const nextLat = cur.latencyMs > 0 ? 0 : 200;
|
|
6406
|
+
this.portTable.setChaosRule(port, { latencyMs: nextLat, jitterMs: nextLat ? 40 : 0 });
|
|
6407
|
+
this._showToast(nextLat ? `Injected +200ms latency (±40ms jitter) on :${port}` : `Removed latency injection on :${port}`, 'info');
|
|
6408
|
+
} else if (action === 'chaos-error') {
|
|
6409
|
+
const nextErr = cur.errorRate > 0 ? 0 : 0.25;
|
|
6410
|
+
this.portTable.setChaosRule(port, { errorRate: nextErr, errorStatus: 503 });
|
|
6411
|
+
this._showToast(nextErr ? `Injected 25% HTTP 503 error rate on :${port}` : `Removed HTTP 503 fault injection on :${port}`, nextErr ? 'error' : 'info');
|
|
6412
|
+
} else if (action === 'chaos-crash') {
|
|
6413
|
+
const nextCrash = !cur.crashed;
|
|
6414
|
+
this.portTable.setChaosRule(port, { crashed: nextCrash });
|
|
6415
|
+
this._showToast(nextCrash ? `Port :${port} marked CRASHED (ECONNREFUSED)` : `Port :${port} recovered`, nextCrash ? 'error' : 'info');
|
|
6416
|
+
} else if (action === 'chaos-heal') {
|
|
6417
|
+
this.portTable.clearChaosRules(port);
|
|
6418
|
+
this._showToast(`Port :${port} healed (all fault rules cleared)`, 'info');
|
|
6419
|
+
}
|
|
6420
|
+
this._renderDrawerBody();
|
|
6421
|
+
}
|
|
6422
|
+
} else if (action === 'run-quick-loadtest') {
|
|
6423
|
+
const targetPort = this._firstListeningPort() || 3000;
|
|
6424
|
+
const targetUrl = `http://127.0.0.1:${targetPort}/`;
|
|
6425
|
+
if (this.shell && typeof this.shell.execute === 'function') {
|
|
6426
|
+
this._showToast(`Running load test: hey -n 50 -c 10 ${targetUrl}`, 'info');
|
|
6427
|
+
this.shell.execute(`hey -n 50 -c 10 ${targetUrl}`, {}).then((res) => {
|
|
6428
|
+
if (res && res.stdout) {
|
|
6429
|
+
this.terminalLogs.push({ type: 'system', text: `\n$ hey -n 50 -c 10 ${targetUrl}` });
|
|
6430
|
+
this.terminalLogs.push({ type: 'stdout', text: res.stdout.replace(/\n$/, '') });
|
|
6431
|
+
}
|
|
6432
|
+
this._renderDrawerBody();
|
|
6433
|
+
}).catch((err) => {
|
|
6434
|
+
this.logger.debug('Quick load test failed.', err);
|
|
6435
|
+
});
|
|
6436
|
+
}
|
|
6221
6437
|
}
|
|
6222
6438
|
return;
|
|
6223
6439
|
}
|