fix(ui): отделить измерения цепочек от модели
This commit is contained in:
1 parent
9404bd5136
commit
255f272fab
7 files changed
+82
-13
No files matched your search
@@ -43,7 +43,21 @@ export interface ExitNode {
|
||||
ip: string
|
||||
}
|
||||
|
||||
export interface OptimizerObservedMetrics {
|
||||
probeId: string | null
|
||||
pingMs: number | null
|
||||
lossPct: number | null
|
||||
dlMbps: number | null
|
||||
ulMbps: number | null
|
||||
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}
|
||||
}
|
||||
|
||||
export interface WanJhLeg {
|
||||
observed?: OptimizerObservedMetrics
|
||||
wanId: string
|
||||
jhId: string
|
||||
pingMs: number
|
||||
@@ -54,6 +68,7 @@ export interface WanJhLeg {
|
||||
}
|
||||
|
||||
export interface JhExLeg {
|
||||
observed?: OptimizerObservedMetrics
|
||||
jhId: string
|
||||
exitId: string
|
||||
pingMs: number
|
||||
@@ -464,6 +479,7 @@ export function buildLiveOptimizerData(
|
||||
? Math.max(0, Math.min(100, Math.round(probe.lastPingLossPct)))
|
||||
: (!homeOnline || !jhOnline ? 100 : 0)
|
||||
wanJhLegs.push({
|
||||
observed: readOptimizerObservedMetrics(probe),
|
||||
wanId: wan.id,
|
||||
jhId: jh.id,
|
||||
pingMs: ping,
|
||||
@@ -494,6 +510,7 @@ export function buildLiveOptimizerData(
|
||||
? Math.max(1, Math.round(probe.lastRxAvgMbps))
|
||||
: modelBw.ul
|
||||
jhExMap.set(`${jh.id}::${ex.id}`, {
|
||||
observed: readOptimizerObservedMetrics(probe),
|
||||
jhId: jh.id,
|
||||
exitId: ex.id,
|
||||
pingMs: ping,
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import {test} from "node:test"
|
||||
import assert from "node:assert/strict"
|
||||
import {buildLiveOptimizerData,DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS,readOptimizerObservedMetrics,type OptimizerApiServer,type RouteOptimizerSpeedProbe,calcRouteScore} from "./route-optimizer-data"
|
||||
const rows:OptimizerApiServer[]=(["home-router","jump-host","exit-node"] as const).map((type,i)=>({id:i+1,name:"Router"+i,host:"192.0.2."+i,country:"RU",site:"TEST",model:"CHR",type,enabled:true,status:"online",latency:10,...(i===0?{wanUplinks:[{id:"w",name:"WAN",iface:"ether1",isp:"ISP",ip:"198.51.100.1",maxDl:100,maxUl:100}]}:{})}))
|
||||
const probe:RouteOptimizerSpeedProbe={id:"p",srcServerId:"1",dstServerId:"2",srcInterface:"ether1",dstInterface:"ether2",enabled:true,lastPingRttMs:0,lastPingLossPct:0,lastTxAvgMbps:150.25,lastRxAvgMbps:null,lastPingAt:"2020-01-01T00:00:00Z"}
|
||||
test("observed raw zero, decimal, null and old receipt stay separate from model clamp",()=>{
|
||||
const result=buildLiveOptimizerData(rows,[],DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS,[probe,{...probe,id:"e",srcServerId:"2",dstServerId:"3",lastTxAvgMbps:0}])
|
||||
const leg=result.homes[0].wanJhLegs[0],exit=result.homes[0].fullRoutes[0].je
|
||||
assert.equal(leg.pingMs,1);assert.equal(leg.dlMbps,100)
|
||||
assert.equal(leg.observed?.pingMs,0);assert.equal(leg.observed?.dlMbps,150.25);assert.equal(leg.observed?.ulMbps,null)
|
||||
assert.equal(leg.observed?.lossPct,0);assert.equal(leg.observed?.pingAt,"2020-01-01T00:00:00Z")
|
||||
assert.equal(leg.score,calcRouteScore(leg.pingMs,leg.dlMbps,leg.ulMbps,60))
|
||||
assert.equal(exit.pingMs,1);assert.equal(exit.observed?.pingMs,0);assert.equal(exit.observed?.dlMbps,0)
|
||||
})
|
||||
test("missing and disabled probe leave observed values unknown while model stays available",()=>{
|
||||
for(const probes of [[],[{...probe,enabled:false}]]){
|
||||
const result=buildLiveOptimizerData(rows,[],DEFAULT_ROUTE_AI_OPTIMIZER_SETTINGS,probes)
|
||||
const leg=result.homes[0].wanJhLegs[0]
|
||||
assert.deepEqual(leg.observed,readOptimizerObservedMetrics())
|
||||
assert.ok(leg.pingMs>0);assert.ok(leg.dlMbps>0)
|
||||
assert.equal(result.homes[0].fullRoutes[0].je.observed?.probeId,null)
|
||||
}
|
||||
})
|
||||
Reference in new issue
Block a user