Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ body.ops-observability:has(#view-collection:not(.hidden)) .page-head :is(.worksp
function once(script:string,before:string,after:string){if(script.split(before).length!==2)throw new Error('collection_shell_baseline_mismatch');return script.replace(before,after);}
export function integrateCollectionScriptA(script:string):string{
let result=once(script,"const viewNames = ['overview'","const viewNames = ['collection','data','overview'");
result=once(result,'const viewModuleChildren = {platform:',"const viewModuleChildren = {collection:['tasks','sources','modules','runs'],data:['assets','datasets','loops','tasks','overview'],platform:");
result=once(result,'const viewModuleChildren = {',"const viewModuleChildren = {collection:['tasks','sources','modules','runs'],data:['assets','datasets','loops','tasks','overview'],");
result=once(result,'const viewMeta = {overview:',"const viewMeta = {collection:['数据与可观测中心 / 采集','统一采集工作区','配置现有云端与终端采集,固定流程版本,跟踪每个模块的实际运行与结果。'],data:['数据与可观测中心 / 数据','数据资产与改善闭环','从采集结果追溯资产和固定数据集,以真实证据验证改善。'],overview:");
result=once(result,'const moduleNavKey = {',"const moduleNavKey = {'collection/tasks':'collection/tasks','collection/sources':'collection/tasks','collection/modules':'collection/tasks','collection/runs':'collection/tasks','data/assets':'data/assets','data/datasets':'data/assets','data/loops':'data/assets','data/tasks':'data/assets','data/overview':'data/assets',");
result=once(result,"else if(name!=='devices'&&state.domain==='edge')","else if(!['devices','collection','data'].includes(name)&&state.domain==='edge')");
result=once(result,'applyViewModules(name,source);',"applyViewModules(name,source);const collectionDomainSwitcher=$('domainSwitcher');if(collectionDomainSwitcher)collectionDomainSwitcher.hidden=['collection','data'].includes(name);if(typeof collectionWorkspace!=='undefined'&&name!=='collection')collectionWorkspace.hide();if(typeof dataCenterWorkspace!=='undefined'&&name!=='data')dataCenterWorkspace.hide();if(name==='collection'&&typeof collectionWorkspace!=='undefined')collectionWorkspace.show(resolved.child);if(name==='data'&&typeof dataCenterWorkspace!=='undefined')dataCenterWorkspace.show(resolved.child);");
return result;
}
export function integrateCollectionNavScript(script:string):string{return once(script,"const primaryRoutes=['overview','alerts/center','traces','signals','devices'];","const primaryRoutes=['overview','collection/tasks','data/assets','alerts/center','traces','signals','devices'];");}
export function integrateCollectionNavScript(script:string):string{return once(script,"const primaryRoutes=['overview',","const primaryRoutes=['overview','collection/tasks','data/assets',");}
export const COLLECTION_SHELL_IDENTITY_SCRIPT=String.raw`
function collectionShellContext(){return JSON.stringify([obsAuthState.me&&obsAuthState.me.user&&obsAuthState.me.user.id,Boolean(obsAuthState.me&&obsAuthState.me.admin),obsActiveTenant(),apiHeaders(false)])}
let collectionShellIdentity=null;
Expand Down
4 changes: 2 additions & 2 deletions server/monitoring/observability-page-focus-navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ function harness(mobile = true, authGate = false) {
return { body, document, tabs, navMain, primary, buttons, originalOrder, main, more, byId, resize, routeCalls, active: () => active, scheduled: () => scheduled };
}

const PRIMARY_VIEWS = ['overview', 'collection/tasks', 'data/assets', 'alerts/center', 'traces', 'signals', 'devices'];
const PRIMARY_VIEWS = ['overview', 'collection/tasks', 'data/assets', 'alerts/center', 'traces', 'gateway', 'signals', 'devices'];
const MOBILE_PRIMARY_VIEWS = ['overview', 'alerts/center', 'traces', 'signals', 'devices'];

function assertClosed(h: ReturnType<typeof harness>) {
Expand All @@ -195,7 +195,7 @@ function assertClosed(h: ReturnType<typeof harness>) {
assert.equal(h.more.getAttribute('aria-expanded'), 'false');
}

test('实际页面提供七个直接工作区,其余路由与看板高级操作按需展开', () => {
test('实际页面提供八个直接工作区,其余路由与看板高级操作按需展开', () => {
const h = harness(false);
// Application links have href; only workspace route buttons have data-view.
assert.deepEqual(h.navMain.querySelectorAll('.module-tab').filter(button => button.dataset.view).map(button => button.dataset.view), PRIMARY_VIEWS);
Expand Down
17 changes: 12 additions & 5 deletions server/monitoring/observability-page-focus.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ function harness() {
const state: { overview: typeof overview; actions: unknown[] | null; remediation: null; view: string; viewSource: string; viewChild: string; actionLoop?: ActionState } = { overview, actions: [], remediation: null, view: 'overview', viewSource: 'overview', viewChild: '' };
const viewMeta: Record<string, string[]> = {};
const navGroupByView: Record<string, string> = { overview: 'primary', signals: 'data', devices: 'infra' };
const moduleNavKey: Record<string, string> = { 'platform/model-pool': 'model-pool' };
const moduleNavDeclaration = OPS_OBSERVABILITY_SCRIPT_A.split('\n').find(line => line.includes('const moduleNavKey ='));
assert.ok(moduleNavDeclaration);
const moduleNavKey: Record<string, string> = vm.runInNewContext(moduleNavDeclaration + '\nmoduleNavKey');
const viewCalls: Array<{ requested: string; updateHash: boolean }> = [];
const context = vm.createContext({
document, make, add, $: byId, state, viewMeta, navGroupByView, moduleNavKey,
Expand Down Expand Up @@ -251,14 +253,19 @@ test('产品无快照时只需一次展开,有数据后保留相同外层披
assert.equal(h.byId('overviewProductHealthEmpty'), null);
});

test('新导航分组复用真实路由解析,旧别名与平台高亮继续可用', () => {
test('新导航分组复用真实路由解析,旧模型池入口高亮独立网关', () => {
const h = harness();
for (const view of ['overview', 'alerts/center', 'traces', 'signals', 'devices']) assert.equal(h.navGroupByView[view], undefined);
assert.equal(h.moduleNavKey['platform/model-pool'], 'platform');
for (const [request, group] of [['investigate', 'data'], ['signals/panels', 'data'], ['learning', 'data'], ['postgres', 'infra'], ['rules', 'advanced'], ['model-pool', 'advanced']] as const) {
for (const view of ['overview', 'alerts/center', 'traces', 'gateway', 'signals', 'devices']) assert.equal(h.navGroupByView[view], undefined);
assert.equal(h.moduleNavKey['gateway/model-pool'], 'gateway');
for (const [request, group] of [['investigate', 'data'], ['signals/panels', 'data'], ['learning', 'data'], ['postgres', 'infra'], ['rules', 'advanced']] as const) {
vm.runInContext('setView(' + JSON.stringify(request) + ',false)', h.context);
assert.equal(h.groups.find(node => node.open)?.dataset.navGroup, group);
}
for (const route of ['model-pool', 'platform/model-pool']) {
vm.runInContext('setView(' + JSON.stringify(route) + ',false)', h.context);
assert.equal(h.state.viewSource, 'gateway/model-pool');
assert.equal(h.groups.some(node => node.open), false);
}
vm.runInContext('setView("signals",false)', h.context);
assert.equal(h.groups.some(node => node.open), false);
assert.equal(h.viewCalls.every(call => call.updateHash === false), true);
Expand Down
1 change: 0 additions & 1 deletion server/monitoring/observability-page-focus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export const OPS_OBSERVABILITY_SCRIPT_FOCUS = `
'alerts/strategies':'advanced','alerts/metrics':'advanced','alerts/objects':'advanced',
'alerts/channels':'advanced','alerts/silence':'advanced'
});
moduleNavKey['platform/model-pool']='platform';
function syncFocusContext(){
const overview=state.view==='overview';
const incidentFact=$('globalIncidentFact');
Expand Down
94 changes: 94 additions & 0 deletions server/monitoring/observability-page-gateway.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
export const OPS_OBSERVABILITY_GATEWAY_STYLE = `
.gateway-workspace{display:grid;gap:16px}
.gateway-workspace .gateway-panel{min-width:0;padding:18px}
.gateway-panel h2{margin:0 0 12px;font-size:16px;color:var(--text)}
.gateway-checks{list-style:none;margin:0;padding:0}
.gateway-checks li{display:grid;grid-template-columns:minmax(0,1fr) auto;gap:8px 16px;align-items:start;padding:12px 0;border-top:1px solid var(--line)}
.gateway-checks p{margin:4px 0 0;color:var(--muted);overflow-wrap:anywhere}
.gateway-checks .gateway-status{display:flex;gap:7px;align-items:center;white-space:nowrap}
.gateway-checks time{color:var(--muted);font-size:12px}
.gateway-checks .gateway-evidence{grid-column:1/-1;justify-self:start}
.gateway-slo{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:16px}
.gateway-slo article{min-width:0;border-top:1px solid var(--line);padding-top:12px}
.gateway-slo h3{margin:0;color:var(--text);font-size:13px;font-weight:600}
.gateway-slo strong{display:block;margin:7px 0;font-size:22px;font-variant-numeric:tabular-nums}
.gateway-slo small{display:block;color:var(--muted);line-height:1.5}
.gateway-panel>.btn{margin-top:14px}
@media(min-width:1050px){
.gateway-workspace:has(.gateway-public){grid-template-columns:minmax(0,1fr) minmax(0,1fr);align-items:start}
.gateway-public{grid-column:2;grid-row:1/3}
.gateway-reliability{grid-column:1;grid-row:2}
}
@media(max-width:720px){.gateway-workspace .gateway-panel{padding:14px}.gateway-slo{grid-template-columns:1fr;gap:12px}}
`;

export const OPS_OBSERVABILITY_GATEWAY_HTML = `
<section id="view-gateway" class="view hidden" aria-label="网关">
<div class="module-switcher" role="tablist" aria-label="网关视图">
<button class="module-switch-tab" type="button" role="tab" data-module-tab="gateway/overview" aria-selected="true">概况</button>
<button class="module-switch-tab" type="button" role="tab" data-module-tab="gateway/model-pool" aria-selected="false">模型池</button>
</div>
<div class="view-module is-active" data-view-module="gateway/overview" role="tabpanel" aria-label="网关概况">
<div id="gatewayOverviewContent" class="gateway-workspace"></div>
</div>
<div class="view-module" data-view-module="gateway/model-pool" role="tabpanel" aria-label="模型池" hidden>
<div id="modelPoolContent"></div>
</div>
</section>`;

export const OPS_OBSERVABILITY_GATEWAY_SCRIPT = String.raw`
const gatewayCheckGroups=[
['模型网关', [['agent-model-target-degraded','主备模型目标']]],
['公网入口', [['public-health','入口健康'],['nginx-5xx-log','Nginx 5xx'],['external-dns','异地 DNS'],['external-tls','异地 TLS']]],
];
function gatewayPlatformAvailable(){return !opsTenantMode&&!opsMemberMode&&!adminTenantQuery()}
function gatewayScopeNotice(root){
OpsUI.state(root,{kind:'empty',title:'网关属于平台视图',hint:'切换到平台范围后查看。'});
}
function updateGatewayReadError(message){
state.gatewayReadError=message;
if(state.viewSource==='gateway/overview')renderGatewayOverview();
}
function renderGatewayOverview(){
const root=$('gatewayOverviewContent');if(!root)return;
root.replaceChildren();
if(!gatewayPlatformAvailable()){gatewayScopeNotice(root);return}
if(state.gatewayReadError){
OpsUI.state(root,{kind:'error',title:'网关状态读取失败',hint:'刷新数据后重新确认当前状态。',retry:()=>loadAll(true)});
return;
}
if(!state.overview){OpsUI.state(root,{kind:'loading',title:'正在读取网关状态…'});return}
const checks=new Map((state.overview.checks||[]).map(check=>[check.key,check]));
const knownStatuses={...statusNames,observing:'观察中',unknown:'待确认'};
gatewayCheckGroups.forEach(([title,rows])=>{
const panel=add(root,'section','panel gateway-panel'+(title==='公网入口'?' gateway-public':''));add(panel,'h2','',title);
const list=add(panel,'ul','gateway-checks');
rows.forEach(([key,label])=>{
const check=checks.get(key);
const status=check&&Object.hasOwn(knownStatuses,check.status)?check.status:'unknown';
const item=add(list,'li','');const body=add(item,'div','');add(body,'strong','',label);
add(body,'p','',check?.summary||'暂无检查回执');
if(check?.checkedAt){const time=add(body,'time','','最近检查 '+when(check.checkedAt));time.dateTime=check.checkedAt}
const indicator=add(item,'div','gateway-status');add(indicator,'span','state-dot '+status);add(indicator,'span','',knownStatuses[status]);
const def=['agent-model-target-degraded','nginx-5xx-log'].includes(key)&&state.config?.definitions?.find(rule=>rule.key===key);
if(check&&def&&state.config?.rules?.[key]){
const button=add(item,'button','btn gateway-evidence','查看'+label+'证据');button.type='button';
button.addEventListener('click',()=>openAlertDetail(def));
}
});
});
const panel=add(root,'section','panel gateway-panel gateway-reliability');add(panel,'h2','','可用性与延迟');
const metrics=add(panel,'div','gateway-slo');
const objectives=state.overview.serviceLevels?.objectives||[];
[['gateway-availability','网关可用性'],['gateway-latency','网关响应时间达标率'],['ai-ttft','Studio AI 首字延迟达标率']].forEach(([key,label])=>{
const objective=objectives.find(item=>item.key===key);
const card=add(metrics,'article','');add(card,'h3','',label);
if(!objective){add(card,'strong','','暂无读数');return}
const rate=objective.compliancePercent;
const measured=objective.dataAvailable&&Number.isFinite(rate);
add(card,'strong',measured&&rate<objective.targetPercent?'bad':'',measured?new Intl.NumberFormat('zh-CN',{maximumFractionDigits:4}).format(rate)+'%':'样本不足');
add(card,'small','','目标 '+objective.targetPercent+'% · '+objective.windowDays+' 天 · '+Number(objective.sampleCount).toLocaleString('zh-CN')+' 个样本');
});
const more=add(panel,'button','btn','查看服务可靠性');more.type='button';more.addEventListener('click',()=>setView('service-levels'));
}
`;
7 changes: 4 additions & 3 deletions server/monitoring/observability-page-interaction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ function setup(): Harness {
"renderOperatorMetrics:typeof renderOperatorMetrics!=='undefined'?renderOperatorMetrics:null," +
"resolveViewRequest:typeof resolveViewRequest!=='undefined'?resolveViewRequest:null," +
"renderSettings:typeof renderSettings!=='undefined'?renderSettings:null," +
"loadModelPool:typeof loadModelPool!=='undefined'?loadModelPool:null," +
"renderModelPool:typeof renderModelPool!=='undefined'?renderModelPool:null," +
"renderBoardPanels:typeof renderBoardPanels!=='undefined'?renderBoardPanels:null," +
"renderObjects:typeof renderObjects!=='undefined'?renderObjects:null," +
Expand Down Expand Up @@ -446,7 +447,7 @@ test('两级路由:旧 hash 别名规范化为 视图/子模块,未知视图
const resolve = h.obs.resolveViewRequest as (r: string) => Record<string, string>;
assert.equal(typeof resolve, 'function', '应能取到 resolveViewRequest');
const canon = (r: string) => JSON.stringify(resolve(r));
assert.equal(canon('model-pool'), JSON.stringify({ name: 'platform', child: 'model-pool', source: 'platform/model-pool' }));
assert.equal(canon('model-pool'), JSON.stringify({ name: 'gateway', child: 'model-pool', source: 'gateway/model-pool' }));
assert.equal(canon('settings/probing'), JSON.stringify({ name: 'platform', child: 'probing', source: 'platform/probing' }));
assert.equal(canon('platform'), JSON.stringify({ name: 'platform', child: 'general', source: 'platform/general' }));
assert.equal(canon('alerts'), JSON.stringify({ name: 'alerts', child: 'center', source: 'alerts/center' }), '裸 #alerts 默认落在告警中心(响应队列优先)');
Expand Down Expand Up @@ -807,8 +808,8 @@ test('模型池:拓扑与指标条按真实夹具渲染,保存权重走 PUT
const h = setup();
const obs = h.obs;
assert.equal(typeof obs.renderModelPool, 'function', '应能取到 renderModelPool');
(obs.setObsState as (p: Record<string, unknown>) => unknown)({ modelPool: MODEL_POOL_FIXTURE });
(obs.renderModelPool as () => void)();
h.setJsonResponse(MODEL_POOL_FIXTURE);
await (obs.loadModelPool as () => Promise<void>)();
const root = h.byIdNode('modelPoolContent');
assert.ok(root, 'modelPoolContent 应已渲染');

Expand Down
6 changes: 3 additions & 3 deletions server/monitoring/observability-page-navigation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ function setup(options: { tenantToken?: string; session?: string; tenant?: strin
return { shell, body, hooks, calls, renders, storage, dispatchDocument, byId: document.getElementById, reloads: () => reloads };
}

test('真实壳保留七个日常入口和三个分类菜单,每个强绑定 ID 唯一存在', () => {
test('真实壳保留八个日常入口和三个分类菜单,每个强绑定 ID 唯一存在', () => {
const shell = parseShell(); const primary = shell.querySelector('.nav-main')!;
assert.deepEqual(primary.querySelectorAll('.module-tab[data-view]').map(node => node.dataset.view), ['overview', 'collection/tasks', 'data/assets', 'alerts/center', 'traces', 'signals', 'devices']);
assert.deepEqual(primary.querySelectorAll('.module-tab[data-view]').map(node => node.dataset.view), ['overview', 'collection/tasks', 'data/assets', 'alerts/center', 'traces', 'gateway', 'signals', 'devices']);
const groups = shell.querySelectorAll('.nav-group');
assert.deepEqual(groups.map(node => node.dataset.navGroup), ['data', 'infra', 'advanced']);
for (const group of groups) { assert.equal(group.tagName, 'DETAILS'); assert.equal(group.id, 'nav-group-' + group.dataset.navGroup); }
Expand All @@ -152,7 +152,7 @@ test('主导航与更多入口按实际目标高亮,旧深链仍定位正确
['overview', 'overview', 'overview'], ['alerts', 'alerts/center', 'alerts/center'],
['signals/logs', 'signals', 'signals/logs'], ['agent-traces', 'traces', 'traces/runs'],
['session-traces', 'traces', 'traces/session'], ['signals/panels', 'signals/panels', 'signals/panels'],
['model-pool', 'platform', 'platform/model-pool'], ['platform/probing', 'platform', 'platform/probing'],
['model-pool', 'gateway', 'gateway/model-pool'], ['platform/model-pool', 'gateway', 'gateway/model-pool'], ['gateway', 'gateway', 'gateway/overview'], ['platform/probing', 'platform', 'platform/probing'],
['rules', 'alerts/rules', 'alerts/rules'], ['objects', 'alerts/rules', 'alerts/objects'],
['devices/logs', 'devices', 'devices/logs'], ['tenants/create', 'tenants', 'tenants/create'],
];
Expand Down
4 changes: 2 additions & 2 deletions server/monitoring/observability-page-restraint.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function setup(options: { tenantToken?: string; member?: boolean } = {}) {
test('实际页面默认只铺开三个查询入口、一个平台配置入口和一个告警入口', () => {
const h = setup();
assert.deepEqual(h.directRoutes('signals'), ['signals/metrics', 'signals/logs', 'signals/promql']);
assert.deepEqual(h.directRoutes('platform'), ['platform/model-pool']);
assert.deepEqual(h.directRoutes('platform'), ['platform/general']);
assert.deepEqual(h.directRoutes('alerts'), ['alerts/center']);
for (const name of ['signals', 'platform', 'alerts']) {
const menus = h.list(name).querySelectorAll('details'); assert.equal(menus.length, 1);
Expand Down Expand Up @@ -242,7 +242,7 @@ test('更多菜单内部可操作,Escape 关闭后焦点回到摘要,外部

test('同一路由轮询保留展开的更多菜单和菜单内焦点,真正换页才关闭', () => {
const h = setup();
for (const [route, name] of [['signals/metrics', 'signals'], ['platform/model-pool', 'platform'], ['alerts/rules', 'alerts']] as const) {
for (const [route, name] of [['signals/metrics', 'signals'], ['platform/general', 'platform'], ['alerts/rules', 'alerts']] as const) {
h.hooks.setView(route, false);
const menu = h.menu(name); const summary = menu.querySelector('summary')!;
const tabs = h.list(name).querySelectorAll('[data-module-tab]');
Expand Down
Loading
Loading