fix(traffic): rename avg_request_bytes to avg_latency_ms (no bytes column in request_log)

The field was storing AVG(latency_ms) from the query but named as if it
held payload size. Rename across Rust struct, TypeScript type, RouteTable
column header/cell, and TrafficView bar chart. Remove now-unused formatBytes
helpers from both components.
This commit is contained in:
whit3rabbit
2026-04-05 15:20:22 -05:00
parent d40f2aa70d
commit 8d3facdb99
5 changed files with 18 additions and 28 deletions
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -162,7 +162,7 @@ export interface RouteMetrics {
path: string
requests_per_min: number
error_rate: number
avg_request_bytes: number
avg_latency_ms: number
p95_latency_ms: number
total_requests: number
}
@@ -9,7 +9,7 @@ export default function RouteTable({ routes }: { routes: RouteMetrics[] }) {
<th>Route</th>
<th>Req/min</th>
<th>Error rate</th>
<th>Avg payload</th>
<th>Avg latency</th>
<th>P95 latency</th>
<th>Total</th>
</tr>
@@ -22,7 +22,7 @@ export default function RouteTable({ routes }: { routes: RouteMetrics[] }) {
<td className="mono" style={{ color: r.error_rate > 0.05 ? 'var(--err)' : r.error_rate > 0.01 ? 'var(--warn)' : undefined }}>
{(r.error_rate * 100).toFixed(1)}%
</td>
<td className="mono">{formatBytes(r.avg_request_bytes)}</td>
<td className="mono">{r.avg_latency_ms.toFixed(0)}ms</td>
<td className="mono">{r.p95_latency_ms}ms</td>
<td className="mono">{r.total_requests.toLocaleString()}</td>
</tr>
@@ -32,8 +32,3 @@ export default function RouteTable({ routes }: { routes: RouteMetrics[] }) {
)
}
function formatBytes(n: number) {
if (n < 1024) return `${n}B`
if (n < 1024 * 1024) return `${(n / 1024).toFixed(1)}KB`
return `${(n / (1024 * 1024)).toFixed(1)}MB`
}
@@ -9,11 +9,6 @@ const AMBER_COLORS = ['#e8a030', '#d4922b', '#c07820', '#a86015', '#8c500a']
// Teal palette for payload bar chart
const TEAL_COLORS = ['#6eb5c0', '#5aa0ab', '#468b96', '#327681', '#1e616c']
function formatBytes(bytes: number): string {
if (bytes < 1024) return `${bytes} B`
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`
}
export default function TrafficView() {
const [windowHours, setWindowHours] = useState(6)
@@ -57,8 +52,8 @@ export default function TrafficView() {
<div className="chart-card">
<div className="chart-header">
<div>
<div className="chart-title">Avg payload per route</div>
<div className="chart-subtitle">Bytes</div>
<div className="chart-title">Avg latency per route</div>
<div className="chart-subtitle">ms</div>
</div>
</div>
{routes.length === 0 ? (
@@ -66,13 +61,13 @@ export default function TrafficView() {
) : (
<div style={{ display: 'flex', flexDirection: 'column', gap: 8, paddingTop: 8 }}>
{routes.slice(0, 5).map((r, i) => {
const maxBytes = Math.max(...routes.slice(0, 5).map((x) => x.avg_request_bytes), 1)
const pct = (r.avg_request_bytes / maxBytes) * 100
const maxLatency = Math.max(...routes.slice(0, 5).map((x) => x.avg_latency_ms), 1)
const pct = (r.avg_latency_ms / maxLatency) * 100
return (
<div key={r.path}>
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11, marginBottom: 2 }}>
<span className="mono dim" style={{ overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', maxWidth: '70%' }}>{r.path}</span>
<span className="mono">{formatBytes(r.avg_request_bytes)}</span>
<span className="mono">{r.avg_latency_ms.toFixed(0)}ms</span>
</div>
<div style={{ height: 6, background: 'var(--border)', borderRadius: 0 }}>
<div style={{ height: '100%', width: `${pct}%`, background: TEAL_COLORS[i % TEAL_COLORS.length], borderRadius: 0 }} />
+2 -2
View File
@@ -23,7 +23,7 @@ pub struct RouteMetrics {
path: String,
requests_per_min: f64,
error_rate: f64,
avg_request_bytes: f64,
avg_latency_ms: f64,
p95_latency_ms: i64,
total_requests: i64,
}
@@ -94,7 +94,7 @@ fn query_traffic(conn: &rusqlite::Connection, window_hours: u32) -> Option<Traff
} else {
0.0
},
avg_request_bytes: avg_latency,
avg_latency_ms: avg_latency,
p95_latency_ms: 0,
total_requests: total,
})