feat(monitor): keep operator telemetry live and retire local replicas

Keep operator monitoring in bounded live snapshots and provide scoped replica retirement. Update the board dashboard and retirement regressions.
This commit is contained in:
DCCONSTRUCTIONS
2026-10-29 09:10:01 +03:00
parent 7878937691
commit bec20d63e2
9 changed files with 940 additions and 429 deletions
@@ -1,24 +1,57 @@
import assert from 'node:assert/strict';
import {before,after,test} from 'node:test';
import {createServer} from 'vite';
let server,series,segments,frames,localPreview,MEDIA_PROTOCOL;
import {createServer} from './support/vite-server.mjs';
import {createElement} from 'react';
import {renderToStaticMarkup as render} from 'react-dom/server';
let server,age,segments,frames,localPreview,MEDIA_PROTOCOL,Readout;
before(async()=>{
server=await createServer({appType:'custom',logLevel:'silent',server:{middlewareMode:true}});
({monitorSeries:series}=await server.ssrLoadModule('/src/core/fleet/boardMonitor.ts'));
({ageBoardMonitor:age}=await server.ssrLoadModule('/src/core/fleet/boardMonitor.ts'));
({BoardMonitorReadout:Readout}=await server.ssrLoadModule('/src/workspaces/fleet/BoardMonitorView.tsx'));
({lineSegments:segments}=await server.ssrLoadModule('/src/components/system/TelemetrySeries.tsx'));
({MEDIA_PROTOCOL}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/previewFrames.ts'));
({localPreviewFrames:frames,localPreview}=await server.ssrLoadModule('@xgrids-k1/frontend/sensors/localPreview.ts'));
});
after(async()=>{await server?.close();});
test('archive gaps break the plot instead of manufacturing zero or connecting missing time',()=>{
const values=series({start:0,end:20,bucket_seconds:5,series:[{at:0,max:80},{at:5,max:90},{at:20,max:10}]},'max');
assert.deepEqual(values,[80,90,null,null,10]);
test('plot gaps remain gaps for other telemetry consumers',()=>{
const values=[80,90,null,null,10];
const result=segments(values,100);
assert.equal(result.length,2);
assert.match(result[0],/^0.00,8.80 25.00,5.40$/);
assert.deepEqual(segments([null,NaN,null]),[]);
assert.notEqual(segments([-10,0,10])[0].split(' ')[0].split(',')[1],segments([-10,0,10])[0].split(' ')[1].split(',')[1]);
});
const live=()=>({available:true,fresh:true,mode:'live',history_available:false,ttl_seconds:30,source_id:'source',
latest:{seq:1,at:1000,boot_id:'boot',values:{'cpu.usage':72.3}},
definitions:{'cpu.usage':{label:'Загрузка',group:'CPU',resource:'CPU',unit:'%',reason:null}},received_at:1000,
sample_age_seconds:0,received_age_seconds:0,expires_in_seconds:30,events:[]});
test('network loss cannot leave a fresh badge or stale values indefinitely',()=>{
const value=live();
assert.equal(age(value,9).fresh,true);assert.equal(age(value,10).fresh,false);
assert.equal(age(value,29).available,true);
const expired=age(value,30);
assert.equal(expired.available,false);assert.equal(expired.latest,null);
assert.deepEqual(expired.definitions,{});assert.deepEqual(expired.events,[]);
assert.equal(age(value,3600).latest,null);assert.equal(age(value,Infinity).latest,null);
assert.equal(age(null,0),null);
});
test('server remaining lifetime is never restarted by a successful poll',()=>{
const value={...live(),fresh:false,sample_age_seconds:27,expires_in_seconds:3};
assert.equal(age(value,2).fresh,false);assert.equal(age(value,3).available,false);
});
test('monitor readout renders live values and has no historical navigation',()=>{
const html=render(createElement(Readout,{name:'Synthetic board',value:live(),error:'',loading:false}));
assert.match(html,/Текущие показатели/);assert.match(html,/72,3/);assert.match(html,/Данные поступают/);
assert.doesNotMatch(html,/История нагрузки|7 дней|Конец периода|Зафиксировать время|Копия в Mission Core/);
const unavailable=render(createElement(Readout,{name:'Synthetic board',value:age(live(),30),error:'',loading:false}));
assert.match(unavailable,/Нет текущих измерений/);assert.doesNotMatch(unavailable,/72,3|Данные поступают/);
});
test('initial error terminates loading and stale readout never claims fresh data',()=>{
const html=render(createElement(Readout,{name:'Synthetic board',value:null,error:'unavailable',loading:false}));
assert.match(html,/Мониторинг БК недоступен/);assert.doesNotMatch(html,/role="status"[^>]*aria-busy="true"/);
const stale=render(createElement(Readout,{name:'Synthetic board',value:age(live(),11),error:'',loading:false}));
assert.match(stale,/Нет свежих данных/);assert.doesNotMatch(stale,/Данные поступают/);
});
test('HTTP media framing survives every byte boundary and refuses oversized frames',()=>{
const output=[],receive=frames((kind,bytes)=>output.push([kind,[...bytes]]));
const encoded=Uint8Array.of(2,0,0,0,3,4,5,6,3,0,0,0,2,7,8);