fix(traffic): сохранять историю отключённых интерфейсов

This commit is contained in:
Denozordec committed 2026-10-12 23:00:23 +07:00
1 parent c69d99ba80
commit a40b26c3c5
16 files changed
+1763 -14

No files matched your search

+1 -2
View File
@@ -168,7 +168,7 @@ export function buildTrafficFromSamples(
const sorted = [...arr].sort((a, b) => Date.parse(a.sampledAt) - Date.parse(b.sampledAt))
const last = sorted[sorted.length - 1]
if (!last) continue
if (!allowList && (!last.running || last.disabled)) continue
// Recorded counter deltas describe the period, independent of the latest link state.
includedSeries++
if (last.running && !last.disabled) sessions += 1
@@ -177,7 +177,6 @@ export function buildTrafficFromSamples(
const prev = sorted[i - 1]
const cur = sorted[i]
if (!prev || !cur) continue
if (!allowList && (!cur.running || cur.disabled)) continue
const t0 = parseIsoMs(prev.sampledAt)
const t1 = parseIsoMs(cur.sampledAt)
if(Number.isFinite(Date.parse(cur.sampledAt))&&t1>=rangeStartMs&&t1<=rangeEndMs)lastAttemptAt=Math.max(lastAttemptAt??t1,t1)
@@ -35,6 +35,13 @@ else {
const user=(await get("/traffic/users?range=1h")).users.find((u:{id:string})=>u.id===userId);assert.equal(user.rxTotal,100/1024);cases++
await pool.query("DELETE FROM traffic_samples WHERE server_id=$1",[serverId]);await put("ether1",-90_000,0);await put("ether1",-60_000,1024**2);await put("ether1",-30_000,512);await put("ether1",0,1024)
s=(await get(`/traffic/servers/${serverId}?range=1h`)).server;assert.equal(s.rxTotal,(1024**2+512)/1024**3);cases++
for(const flags of[4,7]){
await pool.query("DELETE FROM traffic_samples WHERE server_id=$1",[serverId]);
for(const[name,bytes]of[["ether1",2048],["ether2",0]] as const){await put(name,-60_000,0);await put(name,-30_000,bytes/2);await put(name,0,bytes)}
await pool.query("UPDATE traffic_samples SET flags=$1 WHERE server_id=$2 AND interface_name='ether1' AND sampled_at=$3",[flags,serverId,at]);
s=(await get(`/traffic/servers/${serverId}?range=1h`)).server;assert.equal(s.rxTotal,2048/1024**3);assert(s.observations.rxSeries.some(Boolean));assert(s.rxPeak>0);assert.equal(s.sessions,1);
const summary=(await get("/traffic/servers?range=1h")).servers.find((r:{id:string})=>r.id===String(serverId));assert.equal(summary.rxTotal,s.rxTotal);cases++
}
console.log(`traffic volume owned SQL: ${cases} cases; exact bytes/binary unit/server/user/binding/100-part aggregate/reset passed`)
}finally{await app.close();await pool.query("DELETE FROM app_users WHERE id=$1",[userId]);if(serverId!==undefined){await pool.query("DELETE FROM traffic_samples WHERE server_id=$1",[serverId]);await pool.query("DELETE FROM servers WHERE id=$1",[serverId])}await closePool()}
}