fix(optimizer): правильно сопоставить направления DL и UL

This commit is contained in:
Denozordec committed 2026-10-07 13:44:36 +07:00
1 parent 7d331aff41
commit 4ba7f82ccf
6 files changed
+74 -17

No files matched your search

+20 -12
View File
@@ -52,8 +52,14 @@ export interface OptimizerObservedMetrics {
pingAt: string | null
}
export function readOptimizerObservedMetrics(probe?: RouteOptimizerSpeedProbe): OptimizerObservedMetrics {
return {probeId:probe?.id ?? null,pingMs:probe?.lastPingRttMs ?? null,lossPct:probe?.lastPingLossPct ?? null,dlMbps:probe?.lastTxAvgMbps ?? null,ulMbps:probe?.lastRxAvgMbps ?? null,pingAt:probe?.lastPingAt ?? null}
/** DL points toward Home, UL away from Home; TX/RX belong to the btest client. */
export function readOptimizerObservedMetrics(probe?: RouteOptimizerSpeedProbe, clientOnFarSide = false): OptimizerObservedMetrics {
return {
probeId:probe?.id ?? null,pingMs:probe?.lastPingRttMs ?? null,lossPct:probe?.lastPingLossPct ?? null,
dlMbps:(clientOnFarSide ? probe?.lastTxAvgMbps : probe?.lastRxAvgMbps) ?? null,
ulMbps:(clientOnFarSide ? probe?.lastRxAvgMbps : probe?.lastTxAvgMbps) ?? null,
pingAt:probe?.lastPingAt ?? null,
}
}
export interface WanJhLeg {
@@ -485,22 +491,23 @@ export function buildLiveOptimizerData(
const jhRow = byId.get(jh.id)
const jhOnline = jhRow?.status === "online"
const probe = assignedByWanId.get(wan.id)
const observed = readOptimizerObservedMetrics(probe)
const modelPing = legPing(homeLat, jhRow?.latency ?? null, homeOnline, !!jhOnline)
const ping = probe?.lastPingRttMs != null
? Math.max(1, Math.round(probe.lastPingRttMs))
: modelPing
const modelBw = legBandwidthMbps(ping, wan.maxDl, wan.maxUl)
const dl = probe?.lastTxAvgMbps != null
? Math.max(1, Math.min(wan.maxDl, Math.round(probe.lastTxAvgMbps)))
const dl = observed.dlMbps !== null
? Math.max(1, Math.min(wan.maxDl, Math.round(observed.dlMbps)))
: modelBw.dl
const ul = probe?.lastRxAvgMbps != null
? Math.max(1, Math.min(wan.maxUl, Math.round(probe.lastRxAvgMbps)))
const ul = observed.ulMbps !== null
? Math.max(1, Math.min(wan.maxUl, Math.round(observed.ulMbps)))
: modelBw.ul
const loss = probe?.lastPingLossPct != null
? Math.max(0, Math.min(100, Math.round(probe.lastPingLossPct)))
: (!homeOnline || !jhOnline ? 100 : 0)
wanJhLegs.push({
observed: readOptimizerObservedMetrics(probe),
observed,
wanId: wan.id,
jhId: jh.id,
pingMs: ping,
@@ -528,19 +535,20 @@ export function buildLiveOptimizerData(
const exRow = byId.get(ex.id)
const ok = jhRow?.status === "online" && exRow?.status === "online"
const probe = pickProbeForJhExit(jh.id, ex.id)
const observed = readOptimizerObservedMetrics(probe, probe?.srcServerId === ex.id)
const modelPing = legPing(jhRow?.latency ?? null, exRow?.latency ?? null, !!ok, !!ok)
const ping = probe?.lastPingRttMs != null
? Math.max(1, Math.round(probe.lastPingRttMs))
: modelPing
const modelBw = legBandwidthMbps(ping, 1000, 1000)
const dl = probe?.lastTxAvgMbps != null
? Math.max(1, Math.round(probe.lastTxAvgMbps))
const dl = observed.dlMbps !== null
? Math.max(1, Math.round(observed.dlMbps))
: modelBw.dl
const ul = probe?.lastRxAvgMbps != null
? Math.max(1, Math.round(probe.lastRxAvgMbps))
const ul = observed.ulMbps !== null
? Math.max(1, Math.round(observed.ulMbps))
: modelBw.ul
jhExMap.set(`${jh.id}::${ex.id}`, {
observed: readOptimizerObservedMetrics(probe),
observed,
jhId: jh.id,
exitId: ex.id,
pingMs: ping,