test(metrics): add v25.2.0 end-to-end assertions for per-IP, history, and HTTP request metrics

This commit is contained in:
2026-02-14 12:24:48 +00:00
parent c44216df28
commit 6bbd2b3ee1

View File

@@ -168,6 +168,22 @@ tap.test('TCP forward - real-time byte tracking', async (tools) => {
const byRoute = m.throughput.byRoute(); const byRoute = m.throughput.byRoute();
console.log('TCP forward — throughput byRoute:', Array.from(byRoute.entries())); console.log('TCP forward — throughput byRoute:', Array.from(byRoute.entries()));
// ── v25.2.0: Per-IP tracking (TCP connections) ──
const byIP = m.connections.byIP();
console.log('TCP forward — connections byIP:', Array.from(byIP.entries()));
expect(byIP.size).toBeGreaterThan(0);
const topIPs = m.connections.topIPs(10);
console.log('TCP forward — topIPs:', topIPs);
expect(topIPs.length).toBeGreaterThan(0);
expect(topIPs[0].ip).toBeTruthy();
// ── v25.2.0: Throughput history ──
const history = m.throughput.history(10);
console.log('TCP forward — throughput history length:', history.length);
expect(history.length).toBeGreaterThan(0);
expect(history[0].timestamp).toBeGreaterThan(0);
await proxy.stop(); await proxy.stop();
await tools.delayFor(200); await tools.delayFor(200);
}); });
@@ -233,6 +249,22 @@ tap.test('HTTP forward - byte totals tracking', async (tools) => {
expect(bytesIn).toBeGreaterThan(0); expect(bytesIn).toBeGreaterThan(0);
expect(bytesOut).toBeGreaterThan(0); expect(bytesOut).toBeGreaterThan(0);
// ── v25.2.0: Per-IP tracking (HTTP connections) ──
const byIP = m.connections.byIP();
console.log('HTTP forward — connections byIP:', Array.from(byIP.entries()));
expect(byIP.size).toBeGreaterThan(0);
const topIPs = m.connections.topIPs(10);
console.log('HTTP forward — topIPs:', topIPs);
expect(topIPs.length).toBeGreaterThan(0);
expect(topIPs[0].ip).toBeTruthy();
// ── v25.2.0: HTTP request counting ──
const totalReqs = m.requests.total();
const rps = m.requests.perSecond();
console.log(`HTTP forward — requests total: ${totalReqs}, perSecond: ${rps}`);
expect(totalReqs).toBeGreaterThan(0);
await proxy.stop(); await proxy.stop();
await tools.delayFor(200); await tools.delayFor(200);
}); });
@@ -607,6 +639,37 @@ tap.test('Throughput sampling - values appear during active HTTP traffic', async
console.log(`Sampling test — recent throughput: in=${tpRecent.in}, out=${tpRecent.out}`); console.log(`Sampling test — recent throughput: in=${tpRecent.in}, out=${tpRecent.out}`);
expect(tpRecent.in + tpRecent.out).toBeGreaterThan(0); expect(tpRecent.in + tpRecent.out).toBeGreaterThan(0);
// ── v25.2.0: Per-IP tracking ──
const byIP = m.connections.byIP();
console.log('Sampling test — connections byIP:', Array.from(byIP.entries()));
expect(byIP.size).toBeGreaterThan(0);
const topIPs = m.connections.topIPs(10);
console.log('Sampling test — topIPs:', topIPs);
expect(topIPs.length).toBeGreaterThan(0);
expect(topIPs[0].ip).toBeTruthy();
expect(topIPs[0].count).toBeGreaterThanOrEqual(0);
// ── v25.2.0: Throughput history ──
const history = m.throughput.history(10);
console.log(`Sampling test — throughput history: ${history.length} points`);
if (history.length > 0) {
console.log(' first:', history[0], 'last:', history[history.length - 1]);
}
expect(history.length).toBeGreaterThan(0);
expect(history[0].timestamp).toBeGreaterThan(0);
// ── v25.2.0: Per-IP throughput ──
const tpByIP = m.throughput.byIP();
console.log('Sampling test — throughput byIP:', Array.from(tpByIP.entries()));
// ── v25.2.0: HTTP request counting ──
const totalReqs = m.requests.total();
const rps = m.requests.perSecond();
const rpm = m.requests.perMinute();
console.log(`Sampling test — HTTP requests: total=${totalReqs}, perSecond=${rps}, perMinute=${rpm}`);
expect(totalReqs).toBeGreaterThan(0);
// Stop sending // Stop sending
sending = false; sending = false;
await sendLoop; await sendLoop;