Initial import of weiyuan frontend
This commit is contained in:
@@ -0,0 +1,557 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import {
|
||||
Banner,
|
||||
Button,
|
||||
Input,
|
||||
InputNumber,
|
||||
Modal,
|
||||
Popconfirm,
|
||||
Select,
|
||||
Switch,
|
||||
Table,
|
||||
Tag,
|
||||
Toast,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { BellRing, Plus } from 'lucide-react';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import {
|
||||
ALERT_DIM_TYPES,
|
||||
ALERT_METRICS,
|
||||
fmtInt,
|
||||
fmtTs,
|
||||
qualityErrorText,
|
||||
} from './qualityConstants';
|
||||
|
||||
const EMPTY_RULE = {
|
||||
name: '',
|
||||
enabled: true,
|
||||
dim_type: 1,
|
||||
dim_key: '',
|
||||
metric: 'success_rate',
|
||||
comparator: 'lt',
|
||||
threshold: 95,
|
||||
window_minutes: 15,
|
||||
min_samples: 20,
|
||||
silence_minutes: 60,
|
||||
};
|
||||
|
||||
const metricUnit = (metric) =>
|
||||
ALERT_METRICS.find((m) => m.value === metric)?.unit || '';
|
||||
|
||||
const QualityAlerts = ({ quality, t }) => {
|
||||
const { get, send, options } = quality;
|
||||
const [rules, setRules] = useState([]);
|
||||
const [events, setEvents] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [editing, setEditing] = useState(null);
|
||||
const [saving, setSaving] = useState(false);
|
||||
const [testResult, setTestResult] = useState(null);
|
||||
const [testing, setTesting] = useState(false);
|
||||
const isMobile = useIsMobile();
|
||||
|
||||
const load = useCallback(() => {
|
||||
setLoading(true);
|
||||
setError('');
|
||||
Promise.all([get('/alerts/rules'), get('/alerts/events')])
|
||||
.then(([r, e]) => {
|
||||
setRules(r || []);
|
||||
setEvents(e || []);
|
||||
})
|
||||
.catch((e) => setError(e.code || 'query_failed'))
|
||||
.finally(() => setLoading(false));
|
||||
}, [get]);
|
||||
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, [load]);
|
||||
|
||||
const patch = (p) => setEditing((prev) => ({ ...prev, ...p }));
|
||||
|
||||
const payloadOf = (rule) => ({
|
||||
...rule,
|
||||
dim_type: Number(rule.dim_type),
|
||||
threshold: Number(rule.threshold || 0),
|
||||
window_minutes: Number(rule.window_minutes || 0),
|
||||
min_samples: Number(rule.min_samples || 0),
|
||||
silence_minutes: Number(rule.silence_minutes || 0),
|
||||
});
|
||||
|
||||
// 阈值清空时不能静默按 0 保存("成功率低于 0%" 永远不会触发)
|
||||
const thresholdMissing = (rule) =>
|
||||
rule.threshold === null ||
|
||||
rule.threshold === undefined ||
|
||||
rule.threshold === '';
|
||||
|
||||
const save = async () => {
|
||||
if (thresholdMissing(editing)) {
|
||||
Toast.error(t('请填写阈值'));
|
||||
return;
|
||||
}
|
||||
setSaving(true);
|
||||
try {
|
||||
if (editing.id) {
|
||||
await send('put', `/alerts/rules/${editing.id}`, payloadOf(editing));
|
||||
} else {
|
||||
await send('post', '/alerts/rules', payloadOf(editing));
|
||||
}
|
||||
Toast.success(t('已保存'));
|
||||
setEditing(null);
|
||||
setTestResult(null);
|
||||
load();
|
||||
} catch (e) {
|
||||
Toast.error(saveErrorText(e));
|
||||
} finally {
|
||||
setSaving(false);
|
||||
}
|
||||
};
|
||||
|
||||
const saveErrorText = (e) =>
|
||||
e.code === 'forbidden' || /权限|permission/i.test(e.message || '')
|
||||
? t('仅超级管理员或已被授权「运营设置」的管理员可修改告警规则')
|
||||
: qualityErrorText(t, e.code);
|
||||
|
||||
const test = async () => {
|
||||
if (thresholdMissing(editing)) {
|
||||
Toast.error(t('请填写阈值'));
|
||||
return;
|
||||
}
|
||||
setTesting(true);
|
||||
try {
|
||||
const res = await send('post', '/alerts/rules/test', payloadOf(editing));
|
||||
setTestResult(res);
|
||||
} catch (e) {
|
||||
setTestResult(null);
|
||||
Toast.error(qualityErrorText(t, e.code));
|
||||
} finally {
|
||||
setTesting(false);
|
||||
}
|
||||
};
|
||||
|
||||
const toggle = async (rule, enabled) => {
|
||||
try {
|
||||
await send('put', `/alerts/rules/${rule.id}`, { ...rule, enabled });
|
||||
load();
|
||||
} catch (e) {
|
||||
Toast.error(saveErrorText(e));
|
||||
}
|
||||
};
|
||||
|
||||
const remove = async (rule) => {
|
||||
try {
|
||||
await send('delete', `/alerts/rules/${rule.id}`);
|
||||
Toast.success(t('已删除'));
|
||||
load();
|
||||
} catch (e) {
|
||||
Toast.error(saveErrorText(e));
|
||||
}
|
||||
};
|
||||
|
||||
const describe = (rule) => {
|
||||
const metric = ALERT_METRICS.find((m) => m.value === rule.metric);
|
||||
const unit = metricUnit(rule.metric);
|
||||
return `${t(metric?.label || rule.metric)} ${rule.comparator === 'lt' ? '<' : '>'} ${rule.threshold}${unit === '%' ? '%' : unit ? ' ' + unit : ''}`;
|
||||
};
|
||||
|
||||
const scopeText = (rule) => {
|
||||
const dim = ALERT_DIM_TYPES.find((d) => d.value === rule.dim_type);
|
||||
if (rule.dim_type === 1) return t(dim?.label || '全平台');
|
||||
if (rule.dim_type === 3) {
|
||||
const ch = (options.channels || []).find(
|
||||
(c) => String(c.id) === rule.dim_key,
|
||||
);
|
||||
return `${t(dim.label)}: ${ch ? ch.name : '#' + rule.dim_key}`;
|
||||
}
|
||||
return `${t(dim?.label || '')}: ${rule.dim_key}`;
|
||||
};
|
||||
|
||||
const ruleColumns = [
|
||||
{
|
||||
title: t('启用'),
|
||||
dataIndex: 'enabled',
|
||||
width: 70,
|
||||
render: (v, rule) => (
|
||||
<Switch
|
||||
size='small'
|
||||
checked={v}
|
||||
onChange={(checked) => toggle(rule, checked)}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{ title: t('规则名称'), dataIndex: 'name', width: 180 },
|
||||
{
|
||||
title: t('监控范围'),
|
||||
dataIndex: 'dim_type',
|
||||
width: 180,
|
||||
render: (_v, r) => scopeText(r),
|
||||
},
|
||||
{
|
||||
title: t('触发条件'),
|
||||
dataIndex: 'metric',
|
||||
width: 200,
|
||||
render: (_v, r) => describe(r),
|
||||
},
|
||||
{
|
||||
title: t('窗口 / 最小样本 / 静默'),
|
||||
dataIndex: 'window_minutes',
|
||||
width: 260,
|
||||
render: (_v, r) =>
|
||||
t('{{w}} 分钟 / {{s}} 次 / {{q}} 分钟', {
|
||||
w: r.window_minutes,
|
||||
s: r.min_samples,
|
||||
q: r.silence_minutes,
|
||||
}),
|
||||
},
|
||||
{
|
||||
title: '',
|
||||
dataIndex: 'op',
|
||||
width: 140,
|
||||
render: (_v, rule) => (
|
||||
<div className='flex gap-1'>
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
onClick={() => {
|
||||
setTestResult(null);
|
||||
setEditing({ ...rule });
|
||||
}}
|
||||
>
|
||||
{t('编辑')}
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title={t('确定删除该告警规则?')}
|
||||
onConfirm={() => remove(rule)}
|
||||
>
|
||||
<Button size='small' theme='borderless' type='danger'>
|
||||
{t('删除')}
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</div>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const eventColumns = [
|
||||
{
|
||||
title: t('触发时间'),
|
||||
dataIndex: 'created_at',
|
||||
width: 140,
|
||||
render: (v) => <span className='quality-num'>{fmtTs(v, true)}</span>,
|
||||
},
|
||||
{ title: t('规则'), dataIndex: 'rule_name', width: 180 },
|
||||
{
|
||||
title: t('观测值 / 阈值'),
|
||||
dataIndex: 'observed_value',
|
||||
width: 160,
|
||||
render: (v, r) => (
|
||||
<span className='quality-num'>
|
||||
{Number(v).toFixed(2)} / {r.threshold}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('样本数'),
|
||||
dataIndex: 'samples',
|
||||
width: 90,
|
||||
render: (v) => <span className='quality-num'>{fmtInt(v)}</span>,
|
||||
},
|
||||
{
|
||||
title: t('详情'),
|
||||
dataIndex: 'message',
|
||||
render: (v) => (
|
||||
<span className='block truncate max-w-[420px]' title={v}>
|
||||
{v}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
|
||||
const dimKeyInput = () => {
|
||||
if (!editing || editing.dim_type === 1) return null;
|
||||
if (editing.dim_type === 2) {
|
||||
return (
|
||||
<Select
|
||||
filter
|
||||
value={editing.dim_key || undefined}
|
||||
placeholder={t('选择模型')}
|
||||
optionList={(options.models || []).map((m) => ({
|
||||
value: m,
|
||||
label: m,
|
||||
}))}
|
||||
onChange={(v) => patch({ dim_key: v || '' })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
if (editing.dim_type === 3) {
|
||||
return (
|
||||
<Select
|
||||
filter
|
||||
value={editing.dim_key || undefined}
|
||||
placeholder={t('选择渠道')}
|
||||
optionList={(options.channels || []).map((c) => ({
|
||||
value: String(c.id),
|
||||
label: `${c.name} (#${c.id})`,
|
||||
}))}
|
||||
onChange={(v) => patch({ dim_key: v || '' })}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
);
|
||||
}
|
||||
return (
|
||||
<Input
|
||||
value={editing.dim_key}
|
||||
placeholder={t('企业 ID')}
|
||||
onChange={(v) => patch({ dim_key: v.replace(/\D/g, '') })}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<BellRing size={16} />
|
||||
{t('阈值告警')}
|
||||
<span className='quality-card-sub'>
|
||||
{t('每 5 分钟评估一次,命中后通知超级管理员')}
|
||||
</span>
|
||||
</span>
|
||||
<Button
|
||||
icon={<Plus size={14} />}
|
||||
theme='solid'
|
||||
onClick={() => {
|
||||
setTestResult(null);
|
||||
setEditing({ ...EMPTY_RULE });
|
||||
}}
|
||||
>
|
||||
{t('新建规则')}
|
||||
</Button>
|
||||
</div>
|
||||
<div className='quality-card-body flex flex-col gap-4'>
|
||||
{error ? (
|
||||
<div className='quality-empty flex flex-col items-center gap-3'>
|
||||
<span>{qualityErrorText(t, error)}</span>
|
||||
<Button size='small' onClick={load}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Table
|
||||
size='small'
|
||||
rowKey='id'
|
||||
loading={loading}
|
||||
columns={ruleColumns}
|
||||
dataSource={rules}
|
||||
pagination={false}
|
||||
scroll={{ x: 980 }}
|
||||
empty={
|
||||
<div className='quality-empty'>
|
||||
{t(
|
||||
'还没有告警规则,建议先为全平台成功率与兜底失败次数各建一条',
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<div>
|
||||
<div className='mb-2 text-sm font-semibold'>{t('最近告警')}</div>
|
||||
<Table
|
||||
size='small'
|
||||
rowKey='id'
|
||||
loading={loading}
|
||||
columns={eventColumns}
|
||||
dataSource={events}
|
||||
pagination={{ pageSize: 10 }}
|
||||
scroll={{ x: 900 }}
|
||||
empty={<div className='quality-empty'>{t('暂无告警记录')}</div>}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Modal
|
||||
visible={Boolean(editing)}
|
||||
title={editing?.id ? t('编辑告警规则') : t('新建告警规则')}
|
||||
onCancel={() => setEditing(null)}
|
||||
width={isMobile ? '100%' : 560}
|
||||
footer={
|
||||
<div className='flex justify-between flex-wrap gap-2'>
|
||||
<Button loading={testing} onClick={test}>
|
||||
{t('按当前数据试算')}
|
||||
</Button>
|
||||
<div className='flex gap-2'>
|
||||
<Button onClick={() => setEditing(null)}>{t('取消')}</Button>
|
||||
<Button theme='solid' loading={saving} onClick={save}>
|
||||
{t('保存')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
{editing && (
|
||||
<div className='flex flex-col gap-3'>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('规则名称')}
|
||||
<Input
|
||||
value={editing.name}
|
||||
maxLength={64}
|
||||
onChange={(v) => patch({ name: v })}
|
||||
/>
|
||||
</label>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-2 gap-3'>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('监控范围')}
|
||||
<Select
|
||||
value={editing.dim_type}
|
||||
optionList={ALERT_DIM_TYPES.map((d) => ({
|
||||
value: d.value,
|
||||
label: t(d.label),
|
||||
}))}
|
||||
onChange={(v) => patch({ dim_type: v, dim_key: '' })}
|
||||
/>
|
||||
</label>
|
||||
{editing.dim_type !== 1 && (
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('监控对象')}
|
||||
{dimKeyInput()}
|
||||
</label>
|
||||
)}
|
||||
</div>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-3 gap-3'>
|
||||
<label className='flex flex-col gap-1 text-sm sm:col-span-1'>
|
||||
{t('指标')}
|
||||
<Select
|
||||
value={editing.metric}
|
||||
optionList={ALERT_METRICS.map((m) => ({
|
||||
value: m.value,
|
||||
label: t(m.label),
|
||||
}))}
|
||||
onChange={(v) =>
|
||||
patch({
|
||||
metric: v,
|
||||
comparator: v === 'success_rate' ? 'lt' : 'gt',
|
||||
})
|
||||
}
|
||||
/>
|
||||
</label>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('比较')}
|
||||
<Select
|
||||
value={editing.comparator}
|
||||
optionList={[
|
||||
{ value: 'lt', label: t('低于') },
|
||||
{ value: 'gt', label: t('高于') },
|
||||
]}
|
||||
onChange={(v) => patch({ comparator: v })}
|
||||
/>
|
||||
</label>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('阈值')}
|
||||
<InputNumber
|
||||
min={0}
|
||||
value={editing.threshold}
|
||||
suffix={metricUnit(editing.metric)}
|
||||
onChange={(v) => patch({ threshold: v })}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className='grid grid-cols-1 sm:grid-cols-3 gap-3'>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('统计窗口(分钟)')}
|
||||
<InputNumber
|
||||
min={5}
|
||||
max={1440}
|
||||
step={5}
|
||||
value={editing.window_minutes}
|
||||
onChange={(v) => patch({ window_minutes: v })}
|
||||
/>
|
||||
</label>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('最小样本量')}
|
||||
<InputNumber
|
||||
min={1}
|
||||
value={editing.min_samples}
|
||||
onChange={(v) => patch({ min_samples: v })}
|
||||
/>
|
||||
</label>
|
||||
<label className='flex flex-col gap-1 text-sm'>
|
||||
{t('静默期(分钟)')}
|
||||
<InputNumber
|
||||
min={5}
|
||||
max={10080}
|
||||
value={editing.silence_minutes}
|
||||
onChange={(v) => patch({ silence_minutes: v })}
|
||||
/>
|
||||
</label>
|
||||
</div>
|
||||
<div className='flex items-center gap-2 text-sm'>
|
||||
<Switch
|
||||
checked={editing.enabled}
|
||||
onChange={(v) => patch({ enabled: v })}
|
||||
/>
|
||||
{t('启用')}
|
||||
</div>
|
||||
<div className='text-xs text-[var(--text-secondary)]'>
|
||||
{t(
|
||||
'样本量不足最小样本量时不告警,避免低峰期 1 次失败就误报;触发后静默期内不重复通知。',
|
||||
)}
|
||||
</div>
|
||||
{testResult && (
|
||||
<Banner
|
||||
type={testResult.triggered ? 'danger' : 'success'}
|
||||
closeIcon={null}
|
||||
description={
|
||||
<span className='quality-num'>
|
||||
{t(
|
||||
'窗口 {{start}} ~ {{end}}:观测值 {{value}},样本 {{samples}}',
|
||||
{
|
||||
start: fmtTs(testResult.start),
|
||||
end: fmtTs(testResult.end),
|
||||
value: Number(testResult.value).toFixed(2),
|
||||
samples: fmtInt(testResult.samples),
|
||||
},
|
||||
)}
|
||||
{' · '}
|
||||
{testResult.samples < Number(editing.min_samples || 0)
|
||||
? t('样本不足,不会触发')
|
||||
: testResult.triggered
|
||||
? t('会触发告警')
|
||||
: t('不会触发')}
|
||||
</span>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
{editing.id ? (
|
||||
<Tag size='small' color='grey' className='self-start'>
|
||||
ID {editing.id}
|
||||
</Tag>
|
||||
) : null}
|
||||
</div>
|
||||
)}
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QualityAlerts;
|
||||
@@ -0,0 +1,261 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Select, Table, TabPane, Tabs, Tooltip } from '@douyinfe/semi-ui';
|
||||
import { Layers } from 'lucide-react';
|
||||
import {
|
||||
ORDER_OPTIONS,
|
||||
ORG_DIMS,
|
||||
PLATFORM_DIMS,
|
||||
fmtInt,
|
||||
fmtMs,
|
||||
pct,
|
||||
qualityErrorText,
|
||||
} from './qualityConstants';
|
||||
import { QualityMetaNotice } from './QualityOverview';
|
||||
|
||||
export const RateBar = ({ value }) => (
|
||||
<div className='quality-rate'>
|
||||
<div className='quality-rate-track'>
|
||||
<div
|
||||
className='quality-rate-fill'
|
||||
style={{ width: `${Math.max(0, Math.min(1, value || 0)) * 100}%` }}
|
||||
/>
|
||||
</div>
|
||||
<span className='quality-num text-xs'>{pct(value)}</span>
|
||||
</div>
|
||||
);
|
||||
|
||||
/** 维度分布:每行可点击,把该维度值加入筛选(下钻) */
|
||||
const QualityBreakdown = ({ quality, t }) => {
|
||||
const { scope, get, params, setFilters } = quality;
|
||||
const dims = scope === 'org' ? ORG_DIMS : PLATFORM_DIMS;
|
||||
const [dim, setDim] = useState('model');
|
||||
const [orderBy, setOrderBy] = useState('total');
|
||||
const [data, setData] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const seq = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const current = ++seq.current;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
get('/breakdown', { ...params, dim, order_by: orderBy, limit: 50 })
|
||||
.then((d) => current === seq.current && setData(d))
|
||||
.catch((e) => {
|
||||
if (current !== seq.current) return;
|
||||
setData(null);
|
||||
setError(e.code || 'query_failed');
|
||||
})
|
||||
.finally(() => current === seq.current && setLoading(false));
|
||||
}, [get, params, dim, orderBy]);
|
||||
|
||||
const dimSpec = dims.find((d) => d.value === dim);
|
||||
const labelOf = (row) => {
|
||||
if ((dim === 'dept' || dim === 'project') && row.key === '0') {
|
||||
return dim === 'dept' ? t('未分配部门') : t('未绑定项目');
|
||||
}
|
||||
if (dim === 'model' && row.key === '__unknown__') return t('未知模型');
|
||||
if (dim === 'error') {
|
||||
// 错误码维度按 (错误码, 状态码) 分组,同一错误码不同状态码必须区分显示
|
||||
const code =
|
||||
row.key === 'service_error'
|
||||
? t('服务侧错误')
|
||||
: row.key || t('(无错误码)');
|
||||
return row.key2 ? `${code} · HTTP ${row.key2}` : code;
|
||||
}
|
||||
if (row.key === '') return t('(空)');
|
||||
return row.label || row.key;
|
||||
};
|
||||
|
||||
const columns = useMemo(
|
||||
() => [
|
||||
{
|
||||
title: t(dimSpec?.label || '维度'),
|
||||
dataIndex: 'key',
|
||||
width: 220,
|
||||
render: (_v, row) => (
|
||||
<Tooltip content={row.key}>
|
||||
<span className='block truncate max-w-[220px] font-medium'>
|
||||
{labelOf(row)}
|
||||
</span>
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('请求数'),
|
||||
dataIndex: 'metrics.total',
|
||||
align: 'right',
|
||||
render: (_v, row) => (
|
||||
<span className='quality-num'>{fmtInt(row.metrics.total)}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('成功率'),
|
||||
dataIndex: 'metrics.success_rate',
|
||||
width: 170,
|
||||
render: (_v, row) => <RateBar value={row.metrics.success_rate} />,
|
||||
},
|
||||
{
|
||||
title: t('兜底成功'),
|
||||
align: 'right',
|
||||
dataIndex: 'metrics.fallback_saved',
|
||||
render: (_v, row) => (
|
||||
<span className='quality-num'>
|
||||
{fmtInt(row.metrics.fallback_saved)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('兜底失败'),
|
||||
align: 'right',
|
||||
dataIndex: 'metrics.fallback_failed',
|
||||
render: (_v, row) => (
|
||||
<span
|
||||
className={`quality-num ${row.metrics.fallback_failed > 0 ? 'text-[var(--semi-color-danger)] font-semibold' : ''}`}
|
||||
>
|
||||
{fmtInt(row.metrics.fallback_failed)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('失败(未兜底)'),
|
||||
align: 'right',
|
||||
dataIndex: 'metrics.failed_no_fallback',
|
||||
render: (_v, row) => (
|
||||
<span className='quality-num'>
|
||||
{fmtInt(row.metrics.failed_no_fallback)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: scope === 'org' ? t('服务侧故障率') : t('上游故障率'),
|
||||
align: 'right',
|
||||
dataIndex: 'metrics.upstream_fault_rate',
|
||||
render: (_v, row) => (
|
||||
<span className='quality-num'>
|
||||
{pct(row.metrics.upstream_fault_rate)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: 'P95',
|
||||
align: 'right',
|
||||
dataIndex: 'metrics.p95_ms',
|
||||
render: (_v, row) => (
|
||||
<span className='quality-num'>{fmtMs(row.metrics.p95_ms)}</span>
|
||||
),
|
||||
},
|
||||
],
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[dim, t, scope],
|
||||
);
|
||||
|
||||
// 行下钻:只对能表达成筛选条件的值生效
|
||||
const canDrill = (row) => {
|
||||
if (!dimSpec) return false;
|
||||
if (dim === 'error')
|
||||
return row.key !== 'service_error' && (row.key || row.key2);
|
||||
if (row.key === '' || row.key === '__unknown__') return false;
|
||||
// 渠道 / 企业 / 用户 / 令牌的 0 表示"无",筛选参数里 0 等于不过滤
|
||||
if (['channel', 'org', 'user', 'token'].includes(dim) && row.key === '0')
|
||||
return false;
|
||||
return true;
|
||||
};
|
||||
|
||||
const drill = (row) => {
|
||||
if (!canDrill(row)) return;
|
||||
if (dim === 'error') {
|
||||
setFilters({ error_code: row.key || '', status_code: row.key2 || '' });
|
||||
return;
|
||||
}
|
||||
setFilters({ [dimSpec.filterKey]: row.key });
|
||||
};
|
||||
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<Layers size={16} />
|
||||
{t('维度分布')}
|
||||
<span className='quality-card-sub'>{t('点击行下钻到该维度')}</span>
|
||||
</span>
|
||||
<Select
|
||||
value={orderBy}
|
||||
style={{ width: 190 }}
|
||||
optionList={ORDER_OPTIONS.map((o) => ({
|
||||
value: o.value,
|
||||
label: t(o.label),
|
||||
}))}
|
||||
onChange={setOrderBy}
|
||||
/>
|
||||
</div>
|
||||
<div className='quality-card-body quality-nested-tabs'>
|
||||
<Tabs type='button' size='small' activeKey={dim} onChange={setDim}>
|
||||
{dims.map((d) => (
|
||||
<TabPane key={d.value} itemKey={d.value} tab={t(d.label)} />
|
||||
))}
|
||||
</Tabs>
|
||||
{data?.meta && (
|
||||
<QualityMetaNotice meta={data.meta} scope={scope} t={t} />
|
||||
)}
|
||||
{error ? (
|
||||
<div className='quality-empty'>{qualityErrorText(t, error)}</div>
|
||||
) : (
|
||||
<div className='overflow-x-auto app-scrollbar mt-2'>
|
||||
<Table
|
||||
size='small'
|
||||
rowKey={(row) => `${row.key}|${row.key2 || ''}`}
|
||||
loading={loading}
|
||||
columns={columns}
|
||||
dataSource={data?.rows || []}
|
||||
pagination={false}
|
||||
scroll={{ x: 960 }}
|
||||
onRow={(row) =>
|
||||
canDrill(row)
|
||||
? {
|
||||
className: 'quality-row-clickable',
|
||||
tabIndex: 0,
|
||||
onClick: () => drill(row),
|
||||
onKeyDown: (e) => {
|
||||
if (e.key === 'Enter') drill(row);
|
||||
},
|
||||
}
|
||||
: {}
|
||||
}
|
||||
empty={<div className='quality-empty'>{t('暂无数据')}</div>}
|
||||
/>
|
||||
{data && data.total_rows > (data.rows || []).length && (
|
||||
<div className='mt-2 text-xs text-[var(--text-secondary)]'>
|
||||
{t('共 {{total}} 项,仅展示排序后的前 {{shown}} 项', {
|
||||
total: data.total_rows,
|
||||
shown: (data.rows || []).length,
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QualityBreakdown;
|
||||
@@ -0,0 +1,171 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useRef, useState } from 'react';
|
||||
import { Button, Radio } from '@douyinfe/semi-ui';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { initVChartSemiTheme } from '@visactor/vchart-semi-theme';
|
||||
import { ListTree } from 'lucide-react';
|
||||
import useQualityDashboard from '../../hooks/quality/useQualityDashboard';
|
||||
import QualityFilterBar from './QualityFilterBar';
|
||||
import {
|
||||
QualityErrorState,
|
||||
QualityFaultChart,
|
||||
QualityKpiCards,
|
||||
QualityMetaNotice,
|
||||
QualityTrendChart,
|
||||
} from './QualityOverview';
|
||||
import QualityBreakdown from './QualityBreakdown';
|
||||
import QualityHeatmap from './QualityHeatmap';
|
||||
import QualityDetail from './QualityDetail';
|
||||
import QualityAlerts from './QualityAlerts';
|
||||
import './quality.css';
|
||||
|
||||
/**
|
||||
* 调用质量看板(平台侧 / 企业侧共用)。
|
||||
* 平台侧额外有:渠道维度、热力图、请求链路、阈值告警;企业侧只见本企业数据,
|
||||
* 渠道身份与上游错误原文由后端剔除,前端不承担隔离职责。
|
||||
*
|
||||
* @param {'platform'|'org'} scope
|
||||
* @param {number} [orgId]
|
||||
* @param {boolean} [active] 所在页签未激活时不发请求
|
||||
*/
|
||||
const QualityDashboard = ({ scope = 'platform', orgId, active = true }) => {
|
||||
const { t } = useTranslation();
|
||||
const quality = useQualityDashboard(scope, active, orgId);
|
||||
const isOrg = scope === 'org';
|
||||
const [view, setView] = useState('board');
|
||||
const [detailOpen, setDetailOpen] = useState(false);
|
||||
const detailRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
initVChartSemiTheme({ isWatchingThemeSwitch: true });
|
||||
}, []);
|
||||
|
||||
const openDetail = () => {
|
||||
setDetailOpen(true);
|
||||
window.setTimeout(() => {
|
||||
detailRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||
}, 50);
|
||||
};
|
||||
|
||||
const drillOutcome = (outcome) => {
|
||||
quality.setFilters({ outcome });
|
||||
openDetail();
|
||||
};
|
||||
|
||||
// 放大到单个桶后粒度回到自动,否则手动选的"1 天"会让放大后的区间只剩一根柱子
|
||||
const zoomTo = (start, end) =>
|
||||
quality.setFilters({
|
||||
range: 'custom',
|
||||
start: String(start),
|
||||
end: String(end),
|
||||
granularity: 'auto',
|
||||
});
|
||||
|
||||
if (!active) return null;
|
||||
|
||||
return (
|
||||
<div className='quality-board'>
|
||||
{!isOrg && (
|
||||
<Radio.Group
|
||||
type='button'
|
||||
value={view}
|
||||
onChange={(e) => setView(e.target.value)}
|
||||
className='self-start'
|
||||
>
|
||||
<Radio value='board'>{t('质量看板')}</Radio>
|
||||
<Radio value='alerts'>{t('阈值告警')}</Radio>
|
||||
</Radio.Group>
|
||||
)}
|
||||
|
||||
{view === 'alerts' && !isOrg ? (
|
||||
<QualityAlerts quality={quality} t={t} />
|
||||
) : (
|
||||
<>
|
||||
<QualityFilterBar quality={quality} t={t} onOpenDetail={openDetail} />
|
||||
|
||||
{quality.error ? (
|
||||
<QualityErrorState
|
||||
error={quality.error}
|
||||
onRetry={quality.refresh}
|
||||
t={t}
|
||||
/>
|
||||
) : (
|
||||
<>
|
||||
<QualityMetaNotice
|
||||
meta={quality.summary?.meta}
|
||||
scope={scope}
|
||||
t={t}
|
||||
/>
|
||||
<QualityKpiCards
|
||||
summary={quality.summary}
|
||||
loading={quality.loading}
|
||||
onDrillOutcome={drillOutcome}
|
||||
t={t}
|
||||
/>
|
||||
<div className='quality-grid-2'>
|
||||
<QualityTrendChart
|
||||
trend={quality.trend}
|
||||
loading={quality.loading}
|
||||
onZoom={zoomTo}
|
||||
t={t}
|
||||
/>
|
||||
<QualityFaultChart
|
||||
summary={quality.summary}
|
||||
scope={scope}
|
||||
loading={quality.loading}
|
||||
onDrillFault={(fault) =>
|
||||
quality.setFilters({ fault_side: fault })
|
||||
}
|
||||
t={t}
|
||||
/>
|
||||
</div>
|
||||
<QualityBreakdown quality={quality} t={t} />
|
||||
{!isOrg && <QualityHeatmap quality={quality} t={t} />}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div ref={detailRef}>
|
||||
{detailOpen ? (
|
||||
<QualityDetail quality={quality} t={t} />
|
||||
) : (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<ListTree size={16} />
|
||||
{t('请求明细')}
|
||||
<span className='quality-card-sub'>
|
||||
{t('明细直接查询调用日志,按需加载')}
|
||||
</span>
|
||||
</span>
|
||||
<Button theme='light' onClick={openDetail}>
|
||||
{t('加载明细')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QualityDashboard;
|
||||
@@ -0,0 +1,497 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
SideSheet,
|
||||
Spin,
|
||||
Table,
|
||||
Tag,
|
||||
Tooltip,
|
||||
Typography,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { ChevronRight, ListTree, Route } from 'lucide-react';
|
||||
import { renderQuota } from '../../helpers/render';
|
||||
import { useIsMobile } from '../../hooks/common/useIsMobile';
|
||||
import {
|
||||
FAULTS,
|
||||
OUTCOMES,
|
||||
fmtInt,
|
||||
fmtMs,
|
||||
fmtTs,
|
||||
outcomeTagColor,
|
||||
qualityErrorText,
|
||||
} from './qualityConstants';
|
||||
|
||||
const OutcomeTag = ({ value, t }) => {
|
||||
const o = OUTCOMES.find((x) => x.value === value);
|
||||
if (!o) return <Tag size='small'>{t('中间跳')}</Tag>;
|
||||
return (
|
||||
<Tag size='small' color={outcomeTagColor[value]}>
|
||||
{t(o.label)}
|
||||
</Tag>
|
||||
);
|
||||
};
|
||||
|
||||
const faultLabel = (value, scope, t) => {
|
||||
const f = FAULTS.find((x) => x.value === value);
|
||||
if (!f) return '-';
|
||||
return t(scope === 'org' ? f.orgLabel : f.label);
|
||||
};
|
||||
|
||||
/** 兜底链路:逐跳展示渠道与该跳错误 */
|
||||
export const HopChain = ({ hops, outcome, t }) => {
|
||||
if (!hops || hops.length === 0) {
|
||||
return (
|
||||
<span className='text-xs text-[var(--text-secondary)]'>
|
||||
{t('无渠道尝试记录')}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
const success = outcome === 1 || outcome === 2 || outcome === 6;
|
||||
return (
|
||||
<div className='quality-hops'>
|
||||
{hops.map((hop, i) => {
|
||||
const last = i === hops.length - 1;
|
||||
const failed =
|
||||
Boolean(hop.error_code || hop.status_code) || (last && !success);
|
||||
return (
|
||||
<React.Fragment key={`${hop.seq}-${i}`}>
|
||||
{i > 0 && <ChevronRight size={14} className='quality-hop-arrow' />}
|
||||
<div
|
||||
className='quality-hop'
|
||||
data-failed={failed}
|
||||
data-ok={last && success && !failed}
|
||||
>
|
||||
<span className='font-medium truncate'>
|
||||
{t('第 {{n}} 跳', { n: i + 1 })} ·{' '}
|
||||
{hop.channel_name || `#${hop.channel_id}`}
|
||||
</span>
|
||||
{failed ? (
|
||||
<span className='quality-mono'>
|
||||
{hop.status_code ? `HTTP ${hop.status_code}` : ''}
|
||||
{hop.error_code ? ` ${hop.error_code}` : ''}
|
||||
{!hop.status_code && !hop.error_code ? t('失败') : ''}
|
||||
</span>
|
||||
) : (
|
||||
<span className='text-[var(--semi-color-success)]'>
|
||||
{t('成功')}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</React.Fragment>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/** 明细:按 id 游标翻页(不做 COUNT,大表友好) */
|
||||
const QualityDetail = ({ quality, t }) => {
|
||||
const { scope, get, params } = quality;
|
||||
const isOrg = scope === 'org';
|
||||
const isMobile = useIsMobile();
|
||||
const [items, setItems] = useState([]);
|
||||
const [nextCursor, setNextCursor] = useState('');
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [reloading, setReloading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const [moreError, setMoreError] = useState('');
|
||||
const [trace, setTrace] = useState(null);
|
||||
const [traceLoading, setTraceLoading] = useState(false);
|
||||
const seq = useRef(0);
|
||||
|
||||
const load = useCallback(
|
||||
(cursor) => {
|
||||
const current = ++seq.current;
|
||||
const firstPage = !cursor;
|
||||
setLoading(true);
|
||||
// 翻页失败只在"加载更多"处提示,不清掉已加载的列表;筛选变化(第一页)时遮罩旧数据
|
||||
setReloading(firstPage);
|
||||
setMoreError('');
|
||||
if (firstPage) setError('');
|
||||
get('/detail', { ...params, cursor: cursor || undefined, limit: 20 })
|
||||
.then((d) => {
|
||||
if (current !== seq.current) return;
|
||||
setItems((prev) =>
|
||||
firstPage ? d.items || [] : [...prev, ...(d.items || [])],
|
||||
);
|
||||
setNextCursor(d.next_cursor || '');
|
||||
})
|
||||
.catch((e) => {
|
||||
if (current !== seq.current) return;
|
||||
if (firstPage) {
|
||||
setItems([]);
|
||||
setNextCursor('');
|
||||
setError(e.code || 'query_failed');
|
||||
} else {
|
||||
setMoreError(e.code || 'query_failed');
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
if (current !== seq.current) return;
|
||||
setLoading(false);
|
||||
setReloading(false);
|
||||
});
|
||||
},
|
||||
[get, params],
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
load('');
|
||||
}, [load]);
|
||||
|
||||
const openTrace = (row) => {
|
||||
if (!row.request_id) return;
|
||||
setTrace({ row, items: [] });
|
||||
setTraceLoading(true);
|
||||
get('/trace', {
|
||||
request_id: row.request_id,
|
||||
user_id: row.user_id,
|
||||
created_at: row.created_at,
|
||||
})
|
||||
.then((d) => setTrace({ row, items: d.items || [] }))
|
||||
.catch((e) =>
|
||||
setTrace({ row, items: [], error: e.code || 'query_failed' }),
|
||||
)
|
||||
.finally(() => setTraceLoading(false));
|
||||
};
|
||||
|
||||
const columns = [
|
||||
{
|
||||
title: t('时间'),
|
||||
dataIndex: 'created_at',
|
||||
width: 130,
|
||||
render: (v) => <span className='quality-num'>{fmtTs(v, true)}</span>,
|
||||
},
|
||||
{
|
||||
title: t('结局'),
|
||||
dataIndex: 'outcome',
|
||||
width: 120,
|
||||
render: (v) => <OutcomeTag value={v} t={t} />,
|
||||
},
|
||||
{
|
||||
title: t('责任方'),
|
||||
dataIndex: 'fault_side',
|
||||
width: 110,
|
||||
render: (v) => faultLabel(v, scope, t),
|
||||
},
|
||||
{
|
||||
title: isOrg ? t('成员') : t('用户'),
|
||||
dataIndex: 'username',
|
||||
width: 130,
|
||||
render: (v, row) => (
|
||||
<span className='block truncate max-w-[130px]' title={v}>
|
||||
{v || `#${row.user_id}`}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
...(!isOrg
|
||||
? [
|
||||
{
|
||||
title: t('企业'),
|
||||
dataIndex: 'org_name',
|
||||
width: 130,
|
||||
render: (v, row) =>
|
||||
row.organization_id ? (
|
||||
<span className='block truncate max-w-[130px]' title={v}>
|
||||
{v || `#${row.organization_id}`}
|
||||
</span>
|
||||
) : (
|
||||
<span className='text-[var(--text-secondary)]'>
|
||||
{t('个人')}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: t('模型'),
|
||||
dataIndex: 'model_name',
|
||||
width: 170,
|
||||
render: (v) => (
|
||||
<span className='block truncate max-w-[170px]' title={v}>
|
||||
{v || '-'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
...(!isOrg
|
||||
? [
|
||||
{
|
||||
title: t('最终渠道'),
|
||||
dataIndex: 'channel_name',
|
||||
width: 140,
|
||||
render: (v, row) => (
|
||||
<span className='block truncate max-w-[140px]' title={v}>
|
||||
{row.channel_id ? v || `#${row.channel_id}` : '-'}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
]
|
||||
: []),
|
||||
{
|
||||
title: t('状态码 / 错误码'),
|
||||
dataIndex: 'error_code',
|
||||
width: 190,
|
||||
render: (v, row) =>
|
||||
row.status_code || v ? (
|
||||
<span className='quality-mono'>
|
||||
{row.status_code || ''}{' '}
|
||||
{v === 'service_error' ? t('服务侧错误') : v || ''}
|
||||
</span>
|
||||
) : (
|
||||
'-'
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('尝试次数'),
|
||||
dataIndex: 'attempt_count',
|
||||
width: 120,
|
||||
align: 'right',
|
||||
render: (v) => <span className='quality-num'>{v || '-'}</span>,
|
||||
},
|
||||
{
|
||||
title: t('耗时'),
|
||||
dataIndex: 'use_time',
|
||||
width: 90,
|
||||
align: 'right',
|
||||
render: (v) => (
|
||||
<span className='quality-num'>{v ? fmtMs(v * 1000) : '-'}</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: t('费用'),
|
||||
dataIndex: 'quota',
|
||||
width: 100,
|
||||
align: 'right',
|
||||
render: (v) => (
|
||||
<span className='quality-num'>{v ? renderQuota(v) : '-'}</span>
|
||||
),
|
||||
},
|
||||
...(!isOrg
|
||||
? [
|
||||
{
|
||||
title: '',
|
||||
dataIndex: 'op',
|
||||
width: 90,
|
||||
fixed: isMobile ? undefined : 'right',
|
||||
render: (_v, row) =>
|
||||
row.request_id ? (
|
||||
<Button
|
||||
size='small'
|
||||
theme='borderless'
|
||||
icon={<Route size={14} />}
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
openTrace(row);
|
||||
}}
|
||||
>
|
||||
{t('链路')}
|
||||
</Button>
|
||||
) : null,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
];
|
||||
|
||||
const expandRowRender = (row) => (
|
||||
<div className='flex flex-col gap-2 py-1'>
|
||||
{!isOrg && (
|
||||
<div>
|
||||
<div className='mb-1 text-xs text-[var(--text-secondary)]'>
|
||||
{t('兜底链路')}
|
||||
</div>
|
||||
<HopChain hops={row.hops} outcome={row.outcome} t={t} />
|
||||
</div>
|
||||
)}
|
||||
{!isOrg && row.content && (
|
||||
<div>
|
||||
<div className='mb-1 text-xs text-[var(--text-secondary)]'>
|
||||
{t('错误信息')}
|
||||
</div>
|
||||
<Typography.Paragraph
|
||||
className='quality-mono'
|
||||
ellipsis={{ rows: 3, expandable: true, collapsible: true }}
|
||||
>
|
||||
{row.content}
|
||||
</Typography.Paragraph>
|
||||
</div>
|
||||
)}
|
||||
<div className='flex flex-wrap gap-x-6 gap-y-1 text-xs text-[var(--text-secondary)]'>
|
||||
{row.request_id && (
|
||||
<span>
|
||||
{t('请求 ID')}:{' '}
|
||||
<span className='quality-mono'>{row.request_id}</span>
|
||||
</span>
|
||||
)}
|
||||
{row.token_name && (
|
||||
<span>
|
||||
{t('令牌')}: {row.token_name}
|
||||
</span>
|
||||
)}
|
||||
{!isOrg && row.group && (
|
||||
<span>
|
||||
{t('分组')}: {row.group}
|
||||
</span>
|
||||
)}
|
||||
{!isOrg && row.upstream_model_name && (
|
||||
<span>
|
||||
{t('上游模型')}: {row.upstream_model_name}
|
||||
</span>
|
||||
)}
|
||||
{!isOrg && row.fallback_depth > 0 && (
|
||||
<span>
|
||||
{t('兜底深度')}: {row.fallback_depth}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<ListTree size={16} />
|
||||
{t('请求明细')}
|
||||
<span className='quality-card-sub'>
|
||||
{t('默认只列失败与兜底请求;在筛选栏选择「结局」可查看其他请求')}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className='quality-card-body'>
|
||||
{error ? (
|
||||
<div className='quality-empty flex flex-col items-center gap-3'>
|
||||
<span>{qualityErrorText(t, error)}</span>
|
||||
<Button size='small' onClick={() => load('')}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<>
|
||||
<Table
|
||||
size='small'
|
||||
rowKey='id'
|
||||
loading={reloading}
|
||||
columns={columns}
|
||||
dataSource={items}
|
||||
pagination={false}
|
||||
expandedRowRender={expandRowRender}
|
||||
rowExpandable={() => true}
|
||||
scroll={{ x: isOrg ? 1100 : 1500 }}
|
||||
empty={
|
||||
<div className='quality-empty'>{t('没有符合条件的请求')}</div>
|
||||
}
|
||||
/>
|
||||
{nextCursor && (
|
||||
<div className='mt-3 flex flex-col items-center gap-2'>
|
||||
{moreError && (
|
||||
<span className='text-xs text-[var(--semi-color-danger)]'>
|
||||
{qualityErrorText(t, moreError)}
|
||||
</span>
|
||||
)}
|
||||
<Button
|
||||
loading={loading && !reloading}
|
||||
onClick={() => load(nextCursor)}
|
||||
>
|
||||
{moreError ? t('重试') : t('加载更多')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<SideSheet
|
||||
visible={Boolean(trace)}
|
||||
width={isMobile ? '100%' : 720}
|
||||
title={t('请求链路')}
|
||||
onCancel={() => setTrace(null)}
|
||||
>
|
||||
<Spin spinning={traceLoading}>
|
||||
{trace?.error ? (
|
||||
<div className='quality-empty'>
|
||||
{qualityErrorText(t, trace.error)}
|
||||
</div>
|
||||
) : (
|
||||
<div className='flex flex-col gap-3'>
|
||||
<div className='text-xs text-[var(--text-secondary)]'>
|
||||
{t('请求 ID')}:{' '}
|
||||
<span className='quality-mono'>{trace?.row?.request_id}</span>
|
||||
</div>
|
||||
{(trace?.items || []).map((row) => (
|
||||
<div key={row.id} className='quality-card'>
|
||||
<div className='quality-card-body flex flex-col gap-2'>
|
||||
<div className='flex flex-wrap items-center gap-2'>
|
||||
<span className='quality-num text-xs'>
|
||||
{fmtTs(row.created_at, true)}
|
||||
</span>
|
||||
<Tag
|
||||
size='small'
|
||||
color={row.type === 5 ? 'red' : 'green'}
|
||||
>
|
||||
{row.type === 5 ? t('错误日志') : t('消费日志')}
|
||||
</Tag>
|
||||
<OutcomeTag value={row.outcome} t={t} />
|
||||
<span className='text-xs'>
|
||||
{row.channel_name ||
|
||||
(row.channel_id ? `#${row.channel_id}` : '')}
|
||||
</span>
|
||||
{(row.status_code || row.error_code) && (
|
||||
<span className='quality-mono'>
|
||||
{row.status_code || ''} {row.error_code || ''}
|
||||
</span>
|
||||
)}
|
||||
{row.quota > 0 && (
|
||||
<span className='text-xs quality-num'>
|
||||
{renderQuota(row.quota)}
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
<HopChain hops={row.hops} outcome={row.outcome} t={t} />
|
||||
{row.content && (
|
||||
<Tooltip content={row.content}>
|
||||
<div className='quality-mono line-clamp-2'>
|
||||
{row.content}
|
||||
</div>
|
||||
</Tooltip>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{!traceLoading &&
|
||||
(trace?.items || []).length === 0 &&
|
||||
!trace?.error && (
|
||||
<div className='quality-empty'>{t('未找到该请求的日志')}</div>
|
||||
)}
|
||||
{(trace?.items || []).length > 0 && (
|
||||
<div className='text-xs text-[var(--text-secondary)]'>
|
||||
{t('共 {{n}} 条日志', { n: fmtInt(trace.items.length) })}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</SideSheet>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QualityDetail;
|
||||
@@ -0,0 +1,534 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useRef,
|
||||
useState,
|
||||
} from 'react';
|
||||
import {
|
||||
Button,
|
||||
Checkbox,
|
||||
DatePicker,
|
||||
InputNumber,
|
||||
Radio,
|
||||
Select,
|
||||
Tag,
|
||||
} from '@douyinfe/semi-ui';
|
||||
import { Filter, RefreshCw, RotateCcw, SlidersHorizontal } from 'lucide-react';
|
||||
import {
|
||||
FAULTS,
|
||||
OUTCOMES,
|
||||
SOURCES,
|
||||
TIME_RANGES,
|
||||
fmtTs,
|
||||
} from './qualityConstants';
|
||||
|
||||
const splitList = (v) => (v ? String(v).split(',').filter(Boolean) : []);
|
||||
|
||||
/**
|
||||
* 远程搜索下拉(企业 / 用户 / 令牌)。选中项的名称缓存在本地,
|
||||
* 即使结果列表被新的搜索替换,已选值仍能显示名称而非裸 ID。
|
||||
*/
|
||||
const RemoteSelect = ({
|
||||
quality,
|
||||
type,
|
||||
value,
|
||||
onChange,
|
||||
placeholder,
|
||||
extra,
|
||||
emptyText,
|
||||
}) => {
|
||||
const [list, setList] = useState([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const labels = useRef({});
|
||||
const timer = useRef(null);
|
||||
const seq = useRef(0);
|
||||
const extraKey = JSON.stringify(extra || {});
|
||||
|
||||
const search = useCallback(
|
||||
(keyword) => {
|
||||
window.clearTimeout(timer.current);
|
||||
timer.current = window.setTimeout(() => {
|
||||
// 序号保护:慢返回的旧关键词结果不得覆盖新关键词结果
|
||||
const current = ++seq.current;
|
||||
setLoading(true);
|
||||
quality
|
||||
.get('/options/search', { type, keyword, ...(extra || {}) })
|
||||
.then((items) => {
|
||||
if (current !== seq.current) return;
|
||||
(items || []).forEach((it) => {
|
||||
labels.current[String(it.id)] = it.name;
|
||||
});
|
||||
setList(items || []);
|
||||
})
|
||||
.catch(() => current === seq.current && setList([]))
|
||||
.finally(() => current === seq.current && setLoading(false));
|
||||
}, 250);
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[quality.get, type, extraKey],
|
||||
);
|
||||
|
||||
// 联动条件(如令牌随用户)变化后清空候选,下次展开时按新条件重新搜索
|
||||
useEffect(() => {
|
||||
seq.current += 1;
|
||||
setList([]);
|
||||
}, [extraKey]);
|
||||
|
||||
useEffect(() => () => window.clearTimeout(timer.current), []);
|
||||
|
||||
const optionList = useMemo(() => {
|
||||
const opts = list.map((it) => ({
|
||||
value: String(it.id),
|
||||
label: `${it.name || '-'} (#${it.id})`,
|
||||
}));
|
||||
if (value && !opts.some((o) => o.value === String(value))) {
|
||||
const name = labels.current[String(value)];
|
||||
opts.unshift({
|
||||
value: String(value),
|
||||
label: name ? `${name} (#${value})` : `#${value}`,
|
||||
});
|
||||
}
|
||||
return opts;
|
||||
}, [list, value]);
|
||||
|
||||
return (
|
||||
<Select
|
||||
filter
|
||||
remote
|
||||
showClear
|
||||
loading={loading}
|
||||
value={value || undefined}
|
||||
placeholder={placeholder}
|
||||
optionList={optionList}
|
||||
onSearch={search}
|
||||
onFocus={() => list.length === 0 && search('')}
|
||||
onChange={(v) => onChange(v ? String(v) : '')}
|
||||
emptyContent={loading ? null : emptyText}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const QualityFilterBar = ({ quality, t, onOpenDetail }) => {
|
||||
const {
|
||||
filters,
|
||||
setFilters,
|
||||
resetFilters,
|
||||
options,
|
||||
scope,
|
||||
refresh,
|
||||
loading,
|
||||
} = quality;
|
||||
const isOrg = scope === 'org';
|
||||
const [moreOpen, setMoreOpen] = useState(false);
|
||||
|
||||
const idOptions = (items) =>
|
||||
(items || []).map((it) => ({
|
||||
value: String(it.id),
|
||||
label: `${it.name || '-'} (#${it.id})`,
|
||||
}));
|
||||
const strOptions = (items) =>
|
||||
(items || []).map((v) => ({ value: v, label: v }));
|
||||
|
||||
const multiValue = (key) => splitList(filters[key]).map(Number);
|
||||
const setMulti = (key) => (vals) =>
|
||||
setFilters({ [key]: (vals || []).join(',') });
|
||||
|
||||
const outcomeOptions = OUTCOMES.map((o) => ({
|
||||
value: o.value,
|
||||
label: t(o.label),
|
||||
}));
|
||||
const faultOptions = (
|
||||
isOrg ? FAULTS.filter((f) => f.value !== 2) : FAULTS
|
||||
).map((f) => ({ value: f.value, label: t(isOrg ? f.orgLabel : f.label) }));
|
||||
|
||||
// 当前生效的条件 chip(可逐个移除)
|
||||
const chips = useMemo(() => {
|
||||
const out = [];
|
||||
const nameOf = (list, id) =>
|
||||
(list || []).find((it) => String(it.id) === String(id))?.name;
|
||||
const push = (key, label) => out.push({ key, label });
|
||||
if (filters.model) push('model', `${t('模型')}: ${filters.model}`);
|
||||
if (filters.channel_id)
|
||||
push(
|
||||
'channel_id',
|
||||
`${t('渠道')}: ${nameOf(options.channels, filters.channel_id) || '#' + filters.channel_id}`,
|
||||
);
|
||||
if (filters.group) push('group', `${t('分组')}: ${filters.group}`);
|
||||
if (filters.org_id) push('org_id', `${t('企业')}: #${filters.org_id}`);
|
||||
if (filters.dept_id)
|
||||
push(
|
||||
'dept_id',
|
||||
`${t('部门')}: ${nameOf(options.depts, filters.dept_id) || (filters.dept_id === '0' ? t('未分配部门') : '#' + filters.dept_id)}`,
|
||||
);
|
||||
if (filters.project_id)
|
||||
push(
|
||||
'project_id',
|
||||
`${t('项目')}: ${nameOf(options.projects, filters.project_id) || (filters.project_id === '0' ? t('未绑定项目') : '#' + filters.project_id)}`,
|
||||
);
|
||||
if (filters.user_id)
|
||||
push(
|
||||
'user_id',
|
||||
`${isOrg ? t('成员') : t('用户')}: ${nameOf(options.members, filters.user_id) || '#' + filters.user_id}`,
|
||||
);
|
||||
if (filters.token_id)
|
||||
push(
|
||||
'token_id',
|
||||
`${t('令牌')}: ${nameOf(options.tokens, filters.token_id) || '#' + filters.token_id}`,
|
||||
);
|
||||
if (filters.path) push('path', `${t('接口')}: ${filters.path}`);
|
||||
if (filters.error_code)
|
||||
push('error_code', `${t('错误码')}: ${filters.error_code}`);
|
||||
if (filters.status_code)
|
||||
push('status_code', `${t('状态码')}: ${filters.status_code}`);
|
||||
if (filters.outcome)
|
||||
push(
|
||||
'outcome',
|
||||
`${t('结局')}: ${multiValue('outcome')
|
||||
.map((v) =>
|
||||
t(OUTCOMES.find((o) => o.value === v)?.label || String(v)),
|
||||
)
|
||||
.join(' / ')}`,
|
||||
);
|
||||
if (filters.fault_side)
|
||||
push(
|
||||
'fault_side',
|
||||
`${t('责任方')}: ${multiValue('fault_side')
|
||||
.map((v) => {
|
||||
const f = FAULTS.find((x) => x.value === v);
|
||||
return f ? t(isOrg ? f.orgLabel : f.label) : String(v);
|
||||
})
|
||||
.join(' / ')}`,
|
||||
);
|
||||
if (filters.source)
|
||||
push(
|
||||
'source',
|
||||
`${t('调用来源')}: ${multiValue('source')
|
||||
.map((v) => t(SOURCES.find((s) => s.value === v)?.label || String(v)))
|
||||
.join(' / ')}`,
|
||||
);
|
||||
return out;
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [filters, options, t, isOrg]);
|
||||
|
||||
const customRange =
|
||||
filters.range === 'custom' && filters.start && filters.end
|
||||
? [
|
||||
new Date(Number(filters.start) * 1000),
|
||||
new Date(Number(filters.end) * 1000),
|
||||
]
|
||||
: undefined;
|
||||
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-body flex flex-col gap-3'>
|
||||
<div className='quality-filter-row'>
|
||||
<Radio.Group
|
||||
type='button'
|
||||
value={filters.range}
|
||||
onChange={(e) =>
|
||||
setFilters({ range: e.target.value, start: '', end: '' })
|
||||
}
|
||||
>
|
||||
{TIME_RANGES.map((r) => (
|
||||
<Radio key={r.value} value={r.value}>
|
||||
{t(r.label)}
|
||||
</Radio>
|
||||
))}
|
||||
<Radio value='custom'>{t('自定义')}</Radio>
|
||||
</Radio.Group>
|
||||
{filters.range === 'custom' && (
|
||||
<DatePicker
|
||||
type='dateTimeRange'
|
||||
value={customRange}
|
||||
style={{ maxWidth: 380, width: '100%' }}
|
||||
placeholder={[t('开始时间'), t('结束时间')]}
|
||||
onChange={(range) => {
|
||||
if (!range || !range[0] || !range[1]) return;
|
||||
setFilters({
|
||||
start: String(
|
||||
Math.floor(new Date(range[0]).getTime() / 1000),
|
||||
),
|
||||
end: String(Math.floor(new Date(range[1]).getTime() / 1000)),
|
||||
});
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
<Select
|
||||
value={filters.granularity}
|
||||
style={{ width: 130 }}
|
||||
onChange={(v) => setFilters({ granularity: v })}
|
||||
optionList={[
|
||||
{ value: 'auto', label: t('自动粒度') },
|
||||
{ value: '5m', label: t('5 分钟') },
|
||||
{ value: '1h', label: t('1 小时') },
|
||||
{ value: '1d', label: t('1 天') },
|
||||
]}
|
||||
/>
|
||||
<div className='flex flex-wrap items-center gap-2 ml-auto'>
|
||||
<Button
|
||||
icon={<SlidersHorizontal size={14} />}
|
||||
theme={moreOpen ? 'solid' : 'light'}
|
||||
onClick={() => setMoreOpen((v) => !v)}
|
||||
>
|
||||
{t('更多筛选')}
|
||||
</Button>
|
||||
<Button icon={<RotateCcw size={14} />} onClick={resetFilters}>
|
||||
{t('重置')}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<RefreshCw size={14} />}
|
||||
loading={loading}
|
||||
onClick={refresh}
|
||||
>
|
||||
{t('刷新')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className='quality-filter-grid'>
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.model || undefined}
|
||||
placeholder={t('全部模型')}
|
||||
optionList={strOptions(options.models)}
|
||||
onChange={(v) => setFilters({ model: v || '' })}
|
||||
/>
|
||||
{!isOrg && (
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.channel_id || undefined}
|
||||
placeholder={t('全部渠道')}
|
||||
optionList={idOptions(options.channels)}
|
||||
onChange={(v) => setFilters({ channel_id: v || '' })}
|
||||
/>
|
||||
)}
|
||||
{!isOrg && (
|
||||
<RemoteSelect
|
||||
emptyText={t('无匹配结果')}
|
||||
quality={quality}
|
||||
type='org'
|
||||
value={filters.org_id}
|
||||
placeholder={t('全部企业(输入名称或 ID 搜索)')}
|
||||
onChange={(v) => setFilters({ org_id: v })}
|
||||
/>
|
||||
)}
|
||||
{!isOrg && (
|
||||
<RemoteSelect
|
||||
emptyText={t('无匹配结果')}
|
||||
quality={quality}
|
||||
type='user'
|
||||
value={filters.user_id}
|
||||
placeholder={t('全部用户(输入用户名或 ID 搜索)')}
|
||||
onChange={(v) => setFilters({ user_id: v, token_id: '' })}
|
||||
/>
|
||||
)}
|
||||
{isOrg && (
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.dept_id || undefined}
|
||||
placeholder={t('全部部门')}
|
||||
optionList={idOptions(options.depts)}
|
||||
onChange={(v) => setFilters({ dept_id: v || '' })}
|
||||
/>
|
||||
)}
|
||||
{isOrg && (
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.project_id || undefined}
|
||||
placeholder={t('全部项目')}
|
||||
optionList={idOptions(options.projects)}
|
||||
onChange={(v) => setFilters({ project_id: v || '' })}
|
||||
/>
|
||||
)}
|
||||
{isOrg && (
|
||||
<RemoteSelect
|
||||
emptyText={t('无匹配结果')}
|
||||
quality={quality}
|
||||
type='member'
|
||||
value={filters.user_id}
|
||||
placeholder={t('全部成员(输入姓名搜索)')}
|
||||
onChange={(v) => setFilters({ user_id: v })}
|
||||
/>
|
||||
)}
|
||||
<Select
|
||||
multiple
|
||||
maxTagCount={1}
|
||||
showClear
|
||||
value={multiValue('outcome')}
|
||||
placeholder={t('全部结局')}
|
||||
optionList={outcomeOptions}
|
||||
onChange={setMulti('outcome')}
|
||||
/>
|
||||
<Select
|
||||
multiple
|
||||
maxTagCount={1}
|
||||
showClear
|
||||
value={multiValue('fault_side')}
|
||||
placeholder={t('全部责任方')}
|
||||
optionList={faultOptions}
|
||||
onChange={setMulti('fault_side')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{moreOpen && (
|
||||
<div className='quality-filter-grid'>
|
||||
{!isOrg && (
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.group || undefined}
|
||||
placeholder={t('全部分组')}
|
||||
optionList={strOptions(options.groups)}
|
||||
onChange={(v) => setFilters({ group: v || '' })}
|
||||
/>
|
||||
)}
|
||||
{!isOrg && (
|
||||
<RemoteSelect
|
||||
emptyText={t('无匹配结果')}
|
||||
quality={quality}
|
||||
type='token'
|
||||
value={filters.token_id}
|
||||
extra={
|
||||
filters.user_id ? { user_id: filters.user_id } : undefined
|
||||
}
|
||||
placeholder={t('全部令牌(输入名称搜索)')}
|
||||
onChange={(v) => setFilters({ token_id: v })}
|
||||
/>
|
||||
)}
|
||||
{isOrg && (
|
||||
<RemoteSelect
|
||||
emptyText={t('无匹配结果')}
|
||||
quality={quality}
|
||||
type='token'
|
||||
value={filters.token_id}
|
||||
placeholder={t('全部令牌(输入名称搜索)')}
|
||||
onChange={(v) => setFilters({ token_id: v })}
|
||||
/>
|
||||
)}
|
||||
{!isOrg && (
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.path || undefined}
|
||||
placeholder={t('全部接口')}
|
||||
optionList={strOptions(options.paths)}
|
||||
onChange={(v) => setFilters({ path: v || '' })}
|
||||
/>
|
||||
)}
|
||||
<Select
|
||||
filter
|
||||
showClear
|
||||
value={filters.error_code || undefined}
|
||||
placeholder={t('全部错误码')}
|
||||
optionList={strOptions(options.error_codes)}
|
||||
onChange={(v) => setFilters({ error_code: v || '' })}
|
||||
emptyContent={t('近 30 天暂无错误码')}
|
||||
/>
|
||||
<InputNumber
|
||||
min={100}
|
||||
max={599}
|
||||
hideButtons
|
||||
value={
|
||||
filters.status_code ? Number(filters.status_code) : undefined
|
||||
}
|
||||
placeholder={t('HTTP 状态码')}
|
||||
onChange={(v) =>
|
||||
setFilters({ status_code: v ? String(Math.trunc(v)) : '' })
|
||||
}
|
||||
/>
|
||||
{!isOrg && (
|
||||
<Select
|
||||
multiple
|
||||
maxTagCount={1}
|
||||
showClear
|
||||
value={multiValue('source')}
|
||||
placeholder={t('调用来源:API + 异步任务')}
|
||||
optionList={SOURCES.map((s) => ({
|
||||
value: s.value,
|
||||
label: t(s.label),
|
||||
}))}
|
||||
onChange={setMulti('source')}
|
||||
/>
|
||||
)}
|
||||
<div className='flex flex-wrap items-center gap-3'>
|
||||
<Checkbox
|
||||
checked={filters.include_abort === 'true'}
|
||||
onChange={(e) =>
|
||||
setFilters({ include_abort: e.target.checked ? 'true' : '' })
|
||||
}
|
||||
>
|
||||
{t('分母含客户端中断')}
|
||||
</Checkbox>
|
||||
<Checkbox
|
||||
checked={filters.include_blocked === 'true'}
|
||||
onChange={(e) =>
|
||||
setFilters({
|
||||
include_blocked: e.target.checked ? 'true' : '',
|
||||
})
|
||||
}
|
||||
>
|
||||
{t('分母含内容拦截')}
|
||||
</Checkbox>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(chips.length > 0 || filters.range === 'custom') && (
|
||||
<div className='quality-chips'>
|
||||
<Filter size={14} className='text-[var(--text-secondary)]' />
|
||||
{filters.range === 'custom' && filters.start && (
|
||||
<Tag
|
||||
color='blue'
|
||||
closable
|
||||
onClose={() => setFilters({ range: '24h', start: '', end: '' })}
|
||||
>
|
||||
{fmtTs(Number(filters.start))} ~ {fmtTs(Number(filters.end))}
|
||||
</Tag>
|
||||
)}
|
||||
{chips.map((chip) => (
|
||||
<Tag
|
||||
key={chip.key}
|
||||
color='light-blue'
|
||||
closable
|
||||
onClose={() => setFilters({ [chip.key]: '' })}
|
||||
>
|
||||
<span className='truncate'>{chip.label}</span>
|
||||
</Tag>
|
||||
))}
|
||||
{onOpenDetail && (
|
||||
<Button size='small' theme='borderless' onClick={onOpenDetail}>
|
||||
{t('查看这些条件下的明细')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QualityFilterBar;
|
||||
@@ -0,0 +1,186 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { Spin, Tooltip } from '@douyinfe/semi-ui';
|
||||
import { Grid3x3 } from 'lucide-react';
|
||||
import { fmtInt, fmtTs, pct, qualityErrorText } from './qualityConstants';
|
||||
import { QualityMetaNotice } from './QualityOverview';
|
||||
|
||||
/**
|
||||
* 渠道 × 时间 上游故障率热力图(仅平台侧)。
|
||||
* 色阶由 --semi-color-danger 按故障率混入,跟随主题;点击格子下钻到该渠道该时段。
|
||||
*/
|
||||
const QualityHeatmap = ({ quality, t }) => {
|
||||
const { get, params, setFilters } = quality;
|
||||
const [data, setData] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [error, setError] = useState('');
|
||||
const seq = useRef(0);
|
||||
|
||||
useEffect(() => {
|
||||
const current = ++seq.current;
|
||||
setLoading(true);
|
||||
setError('');
|
||||
get('/heatmap', { ...params, top: 20 })
|
||||
.then((d) => current === seq.current && setData(d))
|
||||
.catch((e) => {
|
||||
if (current !== seq.current) return;
|
||||
setData(null);
|
||||
setError(e.code || 'query_failed');
|
||||
})
|
||||
.finally(() => current === seq.current && setLoading(false));
|
||||
}, [get, params]);
|
||||
|
||||
const gran = data?.meta?.granularity || 3600;
|
||||
const timeline = useMemo(() => {
|
||||
const set = new Set();
|
||||
(data?.rows || []).forEach((row) =>
|
||||
(row.cells || []).forEach((c) => set.add(c.ts)),
|
||||
);
|
||||
return Array.from(set).sort((a, b) => a - b);
|
||||
}, [data]);
|
||||
|
||||
const rows = data?.rows || [];
|
||||
const names = data?.channel_names || {};
|
||||
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<Grid3x3 size={16} />
|
||||
{t('渠道故障热力图')}
|
||||
<span className='quality-card-sub'>
|
||||
{t('流量前 20 的渠道 · 颜色越深上游故障率越高 · 点击格子下钻')}
|
||||
</span>
|
||||
</span>
|
||||
<div className='quality-heatmap-legend'>
|
||||
<span>0%</span>
|
||||
{[0, 25, 50, 75, 100].map((lvl) => (
|
||||
<span
|
||||
key={lvl}
|
||||
className='swatch quality-heatmap-cell'
|
||||
style={{ '--cell-level': `${lvl}%`, cursor: 'default' }}
|
||||
/>
|
||||
))}
|
||||
<span>≥50%</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className='quality-card-body'>
|
||||
{data?.meta && (
|
||||
<QualityMetaNotice meta={data.meta} scope='platform' t={t} />
|
||||
)}
|
||||
<Spin spinning={loading}>
|
||||
{error ? (
|
||||
<div className='quality-empty'>{qualityErrorText(t, error)}</div>
|
||||
) : rows.length === 0 ? (
|
||||
<div className='quality-empty'>{t('暂无渠道调用数据')}</div>
|
||||
) : (
|
||||
<div className='quality-heatmap app-scrollbar mt-2'>
|
||||
<table className='quality-heatmap-table'>
|
||||
<tbody>
|
||||
{rows.map((row) => {
|
||||
const byTs = {};
|
||||
(row.cells || []).forEach((c) => {
|
||||
byTs[c.ts] = c;
|
||||
});
|
||||
const name = names[row.channel_id] || `#${row.channel_id}`;
|
||||
return (
|
||||
<tr key={row.channel_id}>
|
||||
<th title={name}>
|
||||
<button
|
||||
type='button'
|
||||
className='truncate max-w-[170px] text-left'
|
||||
onClick={() =>
|
||||
setFilters({ channel_id: row.channel_id })
|
||||
}
|
||||
>
|
||||
{name}
|
||||
</button>
|
||||
</th>
|
||||
{timeline.map((ts) => {
|
||||
const cell = byTs[ts];
|
||||
if (!cell || !cell.total) {
|
||||
return (
|
||||
<td key={ts}>
|
||||
<span
|
||||
className='quality-heatmap-cell block'
|
||||
data-empty='true'
|
||||
/>
|
||||
</td>
|
||||
);
|
||||
}
|
||||
// 50% 及以上即满色,低故障率也保持可见的层次
|
||||
const level =
|
||||
Math.min(1, cell.upstream_fault_rate / 0.5) * 100;
|
||||
return (
|
||||
<td key={ts}>
|
||||
<Tooltip
|
||||
content={
|
||||
<div className='text-xs'>
|
||||
<div>{name}</div>
|
||||
<div>{fmtTs(ts)}</div>
|
||||
<div>
|
||||
{t('请求数')} {fmtInt(cell.total)} ·{' '}
|
||||
{t('上游故障')}{' '}
|
||||
{fmtInt(cell.upstream_fault)} (
|
||||
{pct(cell.upstream_fault_rate)})
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<button
|
||||
type='button'
|
||||
aria-label={`${name} ${fmtTs(ts)}`}
|
||||
className='quality-heatmap-cell block'
|
||||
style={{ '--cell-level': `${level}%` }}
|
||||
onClick={() =>
|
||||
setFilters({
|
||||
channel_id: row.channel_id,
|
||||
range: 'custom',
|
||||
start: String(ts),
|
||||
end: String(ts + gran),
|
||||
granularity: 'auto',
|
||||
})
|
||||
}
|
||||
/>
|
||||
</Tooltip>
|
||||
</td>
|
||||
);
|
||||
})}
|
||||
</tr>
|
||||
);
|
||||
})}
|
||||
</tbody>
|
||||
</table>
|
||||
{timeline.length > 0 && (
|
||||
<div className='mt-2 flex justify-between text-xs text-[var(--text-secondary)] quality-num'>
|
||||
<span>{fmtTs(timeline[0])}</span>
|
||||
<span>{fmtTs(timeline[timeline.length - 1])}</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
</Spin>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default QualityHeatmap;
|
||||
@@ -0,0 +1,514 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
import React, { useMemo } from 'react';
|
||||
import { Button, Skeleton, Tooltip } from '@douyinfe/semi-ui';
|
||||
import { useActualTheme } from '../../context/Theme';
|
||||
import { VChart } from '@visactor/react-vchart';
|
||||
import { Activity, AlertTriangle, Info, PieChart } from 'lucide-react';
|
||||
import {
|
||||
DEGRADE_TEXT,
|
||||
FAULTS,
|
||||
OUTCOMES,
|
||||
fmtInt,
|
||||
fmtMs,
|
||||
fmtTs,
|
||||
outcomeColors,
|
||||
pct,
|
||||
qualityErrorText,
|
||||
readCssVar,
|
||||
toneColor,
|
||||
} from './qualityConstants';
|
||||
|
||||
const Delta = ({ current, previous, higherIsBetter = true, asRate, t }) => {
|
||||
if (previous === undefined || previous === null) return null;
|
||||
const diff = current - previous;
|
||||
if (!Number.isFinite(diff) || Math.abs(diff) < (asRate ? 0.0005 : 0.5)) {
|
||||
return <span>{t('与上一周期持平')}</span>;
|
||||
}
|
||||
const good = higherIsBetter ? diff > 0 : diff < 0;
|
||||
const text = asRate
|
||||
? `${diff > 0 ? '+' : ''}${(diff * 100).toFixed(1)}pp`
|
||||
: `${diff > 0 ? '+' : ''}${fmtInt(Math.round(diff))}`;
|
||||
return (
|
||||
<span className={good ? 'quality-delta-up' : 'quality-delta-down'}>
|
||||
{t('环比')} {text}
|
||||
</span>
|
||||
);
|
||||
};
|
||||
|
||||
/** 数据来源 / 降级 / 完整度提示条 */
|
||||
export const QualityMetaNotice = ({ meta, scope, t }) => {
|
||||
if (!meta) return null;
|
||||
const notes = [];
|
||||
// 未知原因码不直显(避免英文内部标识出现在界面上)
|
||||
const reasons = String(meta.degraded_reason || '')
|
||||
.split(',')
|
||||
.filter((r) => DEGRADE_TEXT[r])
|
||||
.map((r) => t(DEGRADE_TEXT[r]));
|
||||
if (reasons.length > 0 || meta.data_source === 'logs') {
|
||||
notes.push({
|
||||
tone: 'info',
|
||||
text:
|
||||
reasons.join(';') ||
|
||||
t('当前条件下直接统计调用日志,时间范围最长 7 天'),
|
||||
});
|
||||
}
|
||||
if (meta.narrowed) {
|
||||
notes.push({
|
||||
tone: 'info',
|
||||
text: t(
|
||||
'已按结局 / 责任方收窄:耗时分位与用量为收窄前的整体值,仅供参考',
|
||||
),
|
||||
});
|
||||
}
|
||||
const c = meta.completeness || {};
|
||||
if (scope !== 'org' && c.enabled === false) {
|
||||
notes.push({
|
||||
tone: 'warn',
|
||||
text: t(
|
||||
'质量采集已关闭(MONITOR_QUALITY_ENABLED=false),新调用不会进入看板',
|
||||
),
|
||||
});
|
||||
}
|
||||
if (scope !== 'org' && (c.dropped_events > 0 || c.dropped_rows > 0)) {
|
||||
notes.push({
|
||||
tone: 'warn',
|
||||
text: t(
|
||||
'本节点自启动以来丢弃了 {{events}} 条事件 / {{rows}} 行聚合,统计可能偏低',
|
||||
{
|
||||
events: fmtInt(c.dropped_events),
|
||||
rows: fmtInt(c.dropped_rows),
|
||||
},
|
||||
),
|
||||
});
|
||||
}
|
||||
if (meta.detail_available === false) {
|
||||
notes.push({
|
||||
tone: 'warn',
|
||||
text: t('日志表尚未完成质量字段升级,明细与按用户 / 令牌分析暂不可用'),
|
||||
});
|
||||
}
|
||||
if (notes.length === 0) return null;
|
||||
return (
|
||||
<div className='flex flex-col gap-2'>
|
||||
{notes.map((n, i) => (
|
||||
<div key={i} className='quality-notice' data-tone={n.tone}>
|
||||
{n.tone === 'warn' ? (
|
||||
<AlertTriangle size={14} className='mt-0.5 flex-shrink-0' />
|
||||
) : (
|
||||
<Info size={14} className='mt-0.5 flex-shrink-0' />
|
||||
)}
|
||||
<span>{n.text}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const QualityErrorState = ({ error, onRetry, t }) => (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-empty flex flex-col items-center gap-3'>
|
||||
<AlertTriangle size={22} className='text-[var(--semi-color-danger)]' />
|
||||
<div>{qualityErrorText(t, error)}</div>
|
||||
{onRetry && (
|
||||
<Button size='small' onClick={onRetry}>
|
||||
{t('重试')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
/** KPI 卡:点击结局类卡片直接下钻到对应明细 */
|
||||
export const QualityKpiCards = ({ summary, loading, onDrillOutcome, t }) => {
|
||||
if (loading && !summary) {
|
||||
return (
|
||||
<div className='quality-kpis'>
|
||||
{Array.from({ length: 6 }).map((_, i) => (
|
||||
<div key={i} className='quality-kpi'>
|
||||
<Skeleton.Paragraph rows={2} />
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
const cur = summary?.current || {};
|
||||
// 直查日志时后端不计算上一周期,不能拿全 0 当环比基数
|
||||
const prev = summary?.meta?.no_previous ? undefined : summary?.previous;
|
||||
const cards = [
|
||||
{
|
||||
key: 'total',
|
||||
label: t('请求总数'),
|
||||
value: fmtInt(cur.total),
|
||||
color: toneColor('primary'),
|
||||
foot: (
|
||||
<>
|
||||
<Delta current={cur.total} previous={prev?.total} t={t} />
|
||||
{cur.total_raw !== cur.total && (
|
||||
<Tooltip content={t('含客户端中断与内容拦截的原始请求数')}>
|
||||
<span>
|
||||
{t('原始')} {fmtInt(cur.total_raw)}
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'success_rate',
|
||||
label: t('成功率'),
|
||||
value: pct(cur.success_rate, 2),
|
||||
color: toneColor('success'),
|
||||
foot: (
|
||||
<>
|
||||
<Delta
|
||||
current={cur.success_rate}
|
||||
previous={prev?.success_rate}
|
||||
asRate
|
||||
t={t}
|
||||
/>
|
||||
<span>
|
||||
{t('直接成功率')} {pct(cur.direct_rate)}
|
||||
</span>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'fallback_saved',
|
||||
label: t('兜底成功'),
|
||||
value: fmtInt(cur.fallback_saved),
|
||||
color: toneColor('primary'),
|
||||
outcome: '2',
|
||||
foot: (
|
||||
<>
|
||||
<span>
|
||||
{t('触发兜底')} {fmtInt(cur.fallback_triggered)}
|
||||
</span>
|
||||
<span>
|
||||
{t('挽救率')} {pct(cur.fallback_save_rate)}
|
||||
</span>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'fallback_failed',
|
||||
label: t('兜底失败'),
|
||||
value: fmtInt(cur.fallback_failed),
|
||||
color: toneColor('danger'),
|
||||
outcome: '3',
|
||||
foot: (
|
||||
<Delta
|
||||
current={cur.fallback_failed}
|
||||
previous={prev?.fallback_failed}
|
||||
higherIsBetter={false}
|
||||
t={t}
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'failed_no_fallback',
|
||||
label: t('失败(未兜底)'),
|
||||
value: fmtInt(cur.failed_no_fallback),
|
||||
color: toneColor('warning'),
|
||||
outcome: '4',
|
||||
foot: (
|
||||
<span>
|
||||
{t('上游故障率')} {pct(cur.upstream_fault_rate)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'p95',
|
||||
label: t('P95 耗时'),
|
||||
value: fmtMs(cur.p95_ms),
|
||||
color: toneColor('tertiary'),
|
||||
foot: (
|
||||
<>
|
||||
<span>P50 {fmtMs(cur.p50_ms)}</span>
|
||||
<span>
|
||||
{t('平均')} {fmtMs(cur.avg_ms)}
|
||||
</span>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: 'abort',
|
||||
label: t('客户端中断 / 内容拦截'),
|
||||
value: `${fmtInt(cur.client_abort)} / ${fmtInt(cur.blocked)}`,
|
||||
color: toneColor('purple'),
|
||||
outcome: '5,6',
|
||||
foot: (
|
||||
<span>
|
||||
{t('拦截率')} {pct(cur.block_rate)}
|
||||
</span>
|
||||
),
|
||||
},
|
||||
];
|
||||
return (
|
||||
<div className='quality-kpis'>
|
||||
{cards.map((card) => {
|
||||
const clickable = Boolean(card.outcome && onDrillOutcome);
|
||||
return (
|
||||
<div
|
||||
key={card.key}
|
||||
className='quality-kpi'
|
||||
style={{ '--kpi-color': card.color }}
|
||||
data-clickable={clickable}
|
||||
role={clickable ? 'button' : undefined}
|
||||
tabIndex={clickable ? 0 : undefined}
|
||||
onClick={clickable ? () => onDrillOutcome(card.outcome) : undefined}
|
||||
onKeyDown={
|
||||
clickable
|
||||
? (e) => {
|
||||
if (e.key === 'Enter' || e.key === ' ') {
|
||||
e.preventDefault();
|
||||
onDrillOutcome(card.outcome);
|
||||
}
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<span className='quality-kpi-label'>{card.label}</span>
|
||||
<span className='quality-kpi-value'>{card.value}</span>
|
||||
<span className='quality-kpi-foot'>{card.foot}</span>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/** 趋势:结局堆叠柱 + 成功率折线;点击柱子把时间范围放大到该桶 */
|
||||
export const QualityTrendChart = ({ trend, loading, onZoom, t }) => {
|
||||
const actualTheme = useActualTheme();
|
||||
const points = useMemo(() => trend?.points || [], [trend]);
|
||||
const gran = trend?.meta?.granularity || 3600;
|
||||
const spec = useMemo(() => {
|
||||
if (points.length === 0) return null;
|
||||
const colors = outcomeColors();
|
||||
const bars = [];
|
||||
points.forEach((p) => {
|
||||
OUTCOMES.forEach((o) => {
|
||||
bars.push({
|
||||
ts: p.ts,
|
||||
time: fmtTs(p.ts),
|
||||
outcome: t(o.label),
|
||||
value: p[o.key] || 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
const rateLabel = t('成功率');
|
||||
const line = points.map((p) => ({
|
||||
ts: p.ts,
|
||||
time: fmtTs(p.ts),
|
||||
series: rateLabel,
|
||||
rate: p.total > 0 ? Number((p.success_rate * 100).toFixed(2)) : null,
|
||||
}));
|
||||
return {
|
||||
type: 'common',
|
||||
data: [
|
||||
{ id: 'bars', values: bars },
|
||||
{ id: 'line', values: line },
|
||||
],
|
||||
// 第 7 个颜色给成功率折线,图例色块与线色一致
|
||||
color: [...colors, readCssVar('--semi-color-success', '#3bb346')],
|
||||
series: [
|
||||
{
|
||||
type: 'bar',
|
||||
id: 'outcomeBar',
|
||||
dataIndex: 0,
|
||||
xField: 'time',
|
||||
yField: 'value',
|
||||
seriesField: 'outcome',
|
||||
stack: true,
|
||||
},
|
||||
{
|
||||
type: 'line',
|
||||
id: 'rateLine',
|
||||
dataIndex: 1,
|
||||
xField: 'time',
|
||||
yField: 'rate',
|
||||
seriesField: 'series',
|
||||
line: {
|
||||
style: {
|
||||
stroke: readCssVar('--semi-color-success', '#3bb346'),
|
||||
lineWidth: 2,
|
||||
},
|
||||
},
|
||||
point: {
|
||||
style: {
|
||||
fill: readCssVar('--semi-color-success', '#3bb346'),
|
||||
size: 4,
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
axes: [
|
||||
{ orient: 'left', seriesId: ['outcomeBar'], title: { visible: false } },
|
||||
{
|
||||
orient: 'right',
|
||||
seriesId: ['rateLine'],
|
||||
min: 0,
|
||||
max: 100,
|
||||
grid: { visible: false },
|
||||
label: { formatMethod: (v) => `${v}%` },
|
||||
},
|
||||
{ orient: 'bottom', type: 'band' },
|
||||
],
|
||||
legends: { visible: true, orient: 'top', position: 'start' },
|
||||
tooltip: {
|
||||
dimension: {
|
||||
content: [
|
||||
{
|
||||
seriesId: 'outcomeBar',
|
||||
key: (d) => d?.outcome,
|
||||
value: (d) => fmtInt(d?.value),
|
||||
},
|
||||
{
|
||||
seriesId: 'rateLine',
|
||||
key: t('成功率'),
|
||||
value: (d) => (d?.rate === null ? '-' : `${d?.rate}%`),
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
};
|
||||
// actualTheme:切换亮 / 暗色时重新读取主题色
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [points, t, actualTheme]);
|
||||
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<Activity size={16} />
|
||||
{t('调用结局趋势')}
|
||||
<span className='quality-card-sub'>
|
||||
{t('粒度')}{' '}
|
||||
{gran >= 86400
|
||||
? t('1 天')
|
||||
: gran >= 3600
|
||||
? t('1 小时')
|
||||
: t('5 分钟')}
|
||||
{' · '}
|
||||
{t('点击柱子放大到该时段')}
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className='quality-card-body' style={{ height: 340 }}>
|
||||
{loading && !spec ? (
|
||||
<Skeleton.Image style={{ width: '100%', height: '100%' }} />
|
||||
) : spec ? (
|
||||
<VChart
|
||||
spec={spec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
onClick={(e) => {
|
||||
const ts = e?.datum?.ts;
|
||||
if (ts && onZoom) onZoom(ts, ts + gran);
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className='quality-empty'>{t('所选时间范围内暂无调用')}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
/** 责任方分布:点击扇区按责任方筛选 */
|
||||
export const QualityFaultChart = ({
|
||||
summary,
|
||||
scope,
|
||||
loading,
|
||||
onDrillFault,
|
||||
t,
|
||||
}) => {
|
||||
const actualTheme = useActualTheme();
|
||||
const fault = summary?.current?.fault || {};
|
||||
const isOrg = scope === 'org';
|
||||
// 颜色按责任方固定,不随"哪些类别为 0 被过滤掉"而错位
|
||||
const faultColor = {
|
||||
upstream: ['--semi-color-danger', '#f93920'],
|
||||
platform: ['--semi-color-warning', '#fc8800'],
|
||||
client: ['--semi-color-primary', '#0064fa'],
|
||||
quota: ['--semi-color-secondary', '#8b5cf6'],
|
||||
abort: ['--semi-color-tertiary', '#6b7075'],
|
||||
};
|
||||
const data = FAULTS.filter((f) => !(isOrg && f.value === 2))
|
||||
.map((f) => ({
|
||||
value: f.value,
|
||||
key: f.key,
|
||||
name: t(isOrg ? f.orgLabel : f.label),
|
||||
count: fault[f.key] || 0,
|
||||
}))
|
||||
.filter((d) => d.count > 0);
|
||||
const spec = useMemo(
|
||||
() =>
|
||||
data.length === 0
|
||||
? null
|
||||
: {
|
||||
type: 'pie',
|
||||
data: [{ id: 'fault', values: data }],
|
||||
valueField: 'count',
|
||||
categoryField: 'name',
|
||||
outerRadius: 0.8,
|
||||
innerRadius: 0.55,
|
||||
color: data.map((d) => readCssVar(...faultColor[d.key])),
|
||||
legends: { visible: true, orient: 'bottom' },
|
||||
label: { visible: true, formatMethod: (_t, d) => fmtInt(d?.count) },
|
||||
tooltip: {
|
||||
mark: {
|
||||
content: [
|
||||
{ key: (d) => d?.name, value: (d) => fmtInt(d?.count) },
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
[JSON.stringify(data), actualTheme],
|
||||
);
|
||||
return (
|
||||
<div className='quality-card'>
|
||||
<div className='quality-card-head'>
|
||||
<span className='quality-card-title'>
|
||||
<PieChart size={16} />
|
||||
{t('失败责任方')}
|
||||
<span className='quality-card-sub'>{t('点击扇区筛选')}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className='quality-card-body' style={{ height: 340 }}>
|
||||
{loading && !summary ? (
|
||||
<Skeleton.Image style={{ width: '100%', height: '100%' }} />
|
||||
) : spec ? (
|
||||
<VChart
|
||||
spec={spec}
|
||||
option={{ mode: 'desktop-browser' }}
|
||||
onClick={(e) => {
|
||||
const v = e?.datum?.value;
|
||||
if (v && onDrillFault) onDrillFault(String(v));
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<div className='quality-empty'>{t('所选范围内没有失败请求')}</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,374 @@
|
||||
/* 调用质量看板:配色全部从主题 token 派生(亮 / 暗色与品牌色切换自动跟随) */
|
||||
.quality-board {
|
||||
--q-ink: var(--text-primary);
|
||||
--q-muted: var(--text-secondary);
|
||||
--q-line: var(--border-subtle);
|
||||
--q-card: var(--surface-card);
|
||||
--q-accent: var(--semi-color-primary);
|
||||
--q-success: var(--semi-color-success);
|
||||
--q-danger: var(--semi-color-danger);
|
||||
--q-warning: var(--semi-color-warning);
|
||||
--q-tint: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-primary) 6%,
|
||||
var(--surface-card)
|
||||
);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 16px;
|
||||
color: var(--q-ink);
|
||||
}
|
||||
|
||||
.quality-board button:focus-visible,
|
||||
.quality-board [role='button']:focus-visible {
|
||||
outline: 2px solid
|
||||
color-mix(in srgb, var(--semi-color-primary) 55%, transparent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.quality-card {
|
||||
border: 1px solid var(--q-line);
|
||||
border-radius: 12px;
|
||||
background: var(--q-card);
|
||||
box-shadow: var(--elevation-xs, none);
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.quality-card-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px 12px;
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid var(--q-line);
|
||||
}
|
||||
|
||||
.quality-card-title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--q-ink);
|
||||
}
|
||||
|
||||
.quality-card-title svg {
|
||||
color: var(--q-accent);
|
||||
}
|
||||
|
||||
.quality-card-sub {
|
||||
font-size: 12px;
|
||||
font-weight: 400;
|
||||
color: var(--q-muted);
|
||||
}
|
||||
|
||||
.quality-card-body {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
/* 筛选栏 */
|
||||
.quality-filter-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.quality-filter-grid .semi-select,
|
||||
.quality-filter-grid .semi-input-number,
|
||||
.quality-filter-grid .semi-input-wrapper {
|
||||
width: 100% !important;
|
||||
}
|
||||
|
||||
.quality-filter-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 8px 12px;
|
||||
}
|
||||
|
||||
.quality-chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.quality-chips .semi-tag {
|
||||
max-width: 280px;
|
||||
}
|
||||
|
||||
/* KPI */
|
||||
.quality-kpis {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.quality-kpi {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
padding: 14px 16px;
|
||||
border: 1px solid var(--q-line);
|
||||
border-radius: 12px;
|
||||
background: var(--q-card);
|
||||
text-align: left;
|
||||
transition:
|
||||
transform 160ms ease,
|
||||
box-shadow 160ms ease,
|
||||
border-color 160ms ease;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.quality-kpi::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
inset: 0 auto 0 0;
|
||||
width: 3px;
|
||||
background: var(--kpi-color, var(--q-accent));
|
||||
}
|
||||
|
||||
.quality-kpi[data-clickable='true'] {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.quality-kpi[data-clickable='true']:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: color-mix(
|
||||
in srgb,
|
||||
var(--kpi-color, var(--q-accent)) 40%,
|
||||
transparent
|
||||
);
|
||||
box-shadow: 0 6px 16px
|
||||
color-mix(in srgb, var(--kpi-color, var(--q-accent)) 12%, transparent);
|
||||
}
|
||||
|
||||
.quality-kpi-label {
|
||||
font-size: 12px;
|
||||
color: var(--q-muted);
|
||||
}
|
||||
|
||||
.quality-kpi-value {
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
letter-spacing: -0.01em;
|
||||
font-variant-numeric: tabular-nums;
|
||||
color: var(--q-ink);
|
||||
line-height: 1.25;
|
||||
}
|
||||
|
||||
.quality-kpi-foot {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px 8px;
|
||||
font-size: 12px;
|
||||
color: var(--q-muted);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.quality-delta-up {
|
||||
color: var(--q-success);
|
||||
}
|
||||
|
||||
.quality-delta-down {
|
||||
color: var(--q-danger);
|
||||
}
|
||||
|
||||
.quality-num {
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
/* 通知条 */
|
||||
.quality-notice {
|
||||
display: flex;
|
||||
align-items: flex-start;
|
||||
gap: 8px;
|
||||
padding: 8px 12px;
|
||||
border-radius: 10px;
|
||||
font-size: 12px;
|
||||
color: var(--q-ink);
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-warning) 10%,
|
||||
var(--surface-card)
|
||||
);
|
||||
border: 1px solid
|
||||
color-mix(in srgb, var(--semi-color-warning) 30%, transparent);
|
||||
}
|
||||
|
||||
.quality-notice[data-tone='info'] {
|
||||
background: var(--q-tint);
|
||||
border-color: color-mix(in srgb, var(--semi-color-primary) 22%, transparent);
|
||||
}
|
||||
|
||||
.quality-grid-2 {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
@media (max-width: 1024px) {
|
||||
.quality-grid-2 {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
}
|
||||
|
||||
/* 成功率条 */
|
||||
.quality-rate {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
min-width: 120px;
|
||||
}
|
||||
|
||||
.quality-rate-track {
|
||||
flex: 1;
|
||||
height: 6px;
|
||||
border-radius: 999px;
|
||||
background: color-mix(in srgb, var(--semi-color-danger) 18%, transparent);
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.quality-rate-fill {
|
||||
height: 100%;
|
||||
border-radius: 999px;
|
||||
background: var(--q-success);
|
||||
}
|
||||
|
||||
.quality-row-clickable {
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* 热力图 */
|
||||
.quality-heatmap {
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
.quality-heatmap-table {
|
||||
border-collapse: separate;
|
||||
border-spacing: 2px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.quality-heatmap-table th {
|
||||
position: sticky;
|
||||
left: 0;
|
||||
z-index: 1;
|
||||
background: var(--q-card);
|
||||
text-align: left;
|
||||
font-weight: 500;
|
||||
color: var(--q-ink);
|
||||
padding: 0 8px 0 0;
|
||||
max-width: 180px;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.quality-heatmap-cell {
|
||||
width: 22px;
|
||||
min-width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
padding: 0;
|
||||
cursor: pointer;
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-danger) var(--cell-level, 0%),
|
||||
color-mix(in srgb, var(--semi-color-success) 14%, var(--surface-card))
|
||||
);
|
||||
}
|
||||
|
||||
.quality-heatmap-cell[data-empty='true'] {
|
||||
cursor: default;
|
||||
background: color-mix(in srgb, var(--text-secondary) 8%, transparent);
|
||||
}
|
||||
|
||||
.quality-heatmap-legend {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
font-size: 12px;
|
||||
color: var(--q-muted);
|
||||
}
|
||||
|
||||
.quality-heatmap-legend span.swatch {
|
||||
display: inline-block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
/* 兜底链路 */
|
||||
.quality-hops {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.quality-hop {
|
||||
display: inline-flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
padding: 6px 10px;
|
||||
border-radius: 8px;
|
||||
border: 1px solid var(--q-line);
|
||||
background: var(--q-tint);
|
||||
font-size: 12px;
|
||||
max-width: 260px;
|
||||
}
|
||||
|
||||
.quality-hop[data-failed='true'] {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-danger) 8%,
|
||||
var(--surface-card)
|
||||
);
|
||||
border-color: color-mix(in srgb, var(--semi-color-danger) 28%, transparent);
|
||||
}
|
||||
|
||||
.quality-hop[data-ok='true'] {
|
||||
background: color-mix(
|
||||
in srgb,
|
||||
var(--semi-color-success) 8%,
|
||||
var(--surface-card)
|
||||
);
|
||||
border-color: color-mix(in srgb, var(--semi-color-success) 28%, transparent);
|
||||
}
|
||||
|
||||
.quality-hop-arrow {
|
||||
color: var(--q-muted);
|
||||
}
|
||||
|
||||
.quality-mono {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
|
||||
font-size: 12px;
|
||||
word-break: break-all;
|
||||
}
|
||||
|
||||
.quality-empty {
|
||||
padding: 32px 16px;
|
||||
text-align: center;
|
||||
font-size: 13px;
|
||||
color: var(--q-muted);
|
||||
}
|
||||
|
||||
.quality-nested-tabs .semi-tabs-bar {
|
||||
margin-bottom: 8px;
|
||||
overflow-x: auto;
|
||||
}
|
||||
|
||||
/* 维度页签是卡片内的二级切换:窄屏下横向滚动,不撑破页面 */
|
||||
.quality-nested-tabs .semi-tabs-bar .semi-tabs-tab {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.quality-row-clickable:focus-visible {
|
||||
outline: 2px solid
|
||||
color-mix(in srgb, var(--semi-color-primary) 55%, transparent);
|
||||
outline-offset: -2px;
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
Copyright (C) 2025 QuantumNous
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as
|
||||
published by the Free Software Foundation, either version 3 of the
|
||||
License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
For commercial licensing, please contact support@quantumnous.com
|
||||
*/
|
||||
|
||||
// 调用质量看板的枚举与文案。枚举值与后端 service/monitor/outcome.go 保持一致。
|
||||
|
||||
export const OUTCOMES = [
|
||||
{ value: 1, key: 'c1', label: '直接成功', tone: 'success' },
|
||||
{ value: 2, key: 'c2', label: '兜底成功', tone: 'primary' },
|
||||
{ value: 3, key: 'c3', label: '兜底失败', tone: 'danger' },
|
||||
{ value: 4, key: 'c4', label: '失败(未兜底)', tone: 'warning' },
|
||||
{ value: 5, key: 'c5', label: '客户端中断', tone: 'tertiary' },
|
||||
{ value: 6, key: 'c6', label: '内容安全拦截', tone: 'purple' },
|
||||
];
|
||||
|
||||
export const FAULTS = [
|
||||
{ value: 1, key: 'upstream', label: '上游故障', orgLabel: '服务侧故障' },
|
||||
{ value: 2, key: 'platform', label: '平台故障', orgLabel: '服务侧故障' },
|
||||
{ value: 3, key: 'client', label: '请求参数问题', orgLabel: '请求参数问题' },
|
||||
{ value: 4, key: 'quota', label: '额度 / 限流', orgLabel: '额度 / 限流' },
|
||||
{ value: 5, key: 'abort', label: '客户端中断', orgLabel: '客户端中断' },
|
||||
];
|
||||
|
||||
export const SOURCES = [
|
||||
{ value: 1, label: 'API 调用' },
|
||||
{ value: 2, label: '异步任务' },
|
||||
{ value: 3, label: '任务提交' },
|
||||
{ value: 4, label: '体验中心' },
|
||||
{ value: 5, label: '内部调用' },
|
||||
{ value: 6, label: '未鉴权请求' },
|
||||
];
|
||||
|
||||
export const TIME_RANGES = [
|
||||
{ value: '1h', label: '近 1 小时', seconds: 3600 },
|
||||
{ value: '6h', label: '近 6 小时', seconds: 6 * 3600 },
|
||||
{ value: '24h', label: '近 24 小时', seconds: 24 * 3600 },
|
||||
{ value: '7d', label: '近 7 天', seconds: 7 * 86400 },
|
||||
{ value: '30d', label: '近 30 天', seconds: 30 * 86400 },
|
||||
];
|
||||
|
||||
export const PLATFORM_DIMS = [
|
||||
{ value: 'model', label: '模型', filterKey: 'model' },
|
||||
{ value: 'channel', label: '渠道', filterKey: 'channel_id' },
|
||||
{ value: 'org', label: '企业', filterKey: 'org_id' },
|
||||
{ value: 'group', label: '分组', filterKey: 'group' },
|
||||
{ value: 'error', label: '错误码', filterKey: 'error_code' },
|
||||
{ value: 'path', label: '接口', filterKey: 'path' },
|
||||
{ value: 'user', label: '用户', filterKey: 'user_id' },
|
||||
{ value: 'token', label: '令牌', filterKey: 'token_id' },
|
||||
];
|
||||
|
||||
export const ORG_DIMS = [
|
||||
{ value: 'model', label: '模型', filterKey: 'model' },
|
||||
{ value: 'dept', label: '部门', filterKey: 'dept_id' },
|
||||
{ value: 'project', label: '项目', filterKey: 'project_id' },
|
||||
{ value: 'user', label: '成员', filterKey: 'user_id' },
|
||||
{ value: 'token', label: '令牌', filterKey: 'token_id' },
|
||||
{ value: 'error', label: '错误码', filterKey: 'error_code' },
|
||||
];
|
||||
|
||||
export const ORDER_OPTIONS = [
|
||||
{ value: 'total', label: '按调用量' },
|
||||
{ value: 'success_rate', label: '按成功率(低→高)' },
|
||||
{ value: 'fallback_failed', label: '按兜底失败数' },
|
||||
{ value: 'failed', label: '按失败数' },
|
||||
{ value: 'upstream_fault_rate', label: '按上游故障率' },
|
||||
{ value: 'p95', label: '按 P95 耗时' },
|
||||
];
|
||||
|
||||
export const ALERT_METRICS = [
|
||||
{ value: 'success_rate', label: '成功率(%)', unit: '%' },
|
||||
{ value: 'fallback_failed', label: '兜底失败次数', unit: '' },
|
||||
{ value: 'upstream_fault_pct', label: '上游故障率(%)', unit: '%' },
|
||||
{ value: 'p95_ms', label: 'P95 耗时(毫秒)', unit: 'ms' },
|
||||
];
|
||||
|
||||
export const ALERT_DIM_TYPES = [
|
||||
{ value: 1, label: '全平台' },
|
||||
{ value: 2, label: '模型' },
|
||||
{ value: 3, label: '渠道' },
|
||||
{ value: 5, label: '企业' },
|
||||
];
|
||||
|
||||
// 后端错误码 → 中文文案 key(前端经 t() 翻译)
|
||||
export const QUALITY_ERROR_TEXT = {
|
||||
window_invalid: '时间范围无效,请重新选择',
|
||||
window_too_wide:
|
||||
'按用户 / 令牌或交叉条件筛选时,时间范围最长 7 天,请缩小范围',
|
||||
detail_window_too_wide: '明细查询时间范围最长 31 天,请缩小范围',
|
||||
invalid_dimension: '不支持的分析维度',
|
||||
unsupported_dimension: '当前筛选条件下不支持该维度',
|
||||
query_failed: '查询失败,请稍后重试',
|
||||
invalid_source: '调用来源参数无效',
|
||||
invalid_outcome: '结局参数无效',
|
||||
invalid_fault_side: '责任方参数无效',
|
||||
invalid_model: '模型参数过长',
|
||||
invalid_group: '分组参数过长',
|
||||
invalid_path: '接口参数过长',
|
||||
invalid_error_code: '错误码参数过长',
|
||||
org_required: '缺少企业上下文,请重新进入企业中心',
|
||||
token_not_in_org: '该令牌不属于本企业',
|
||||
invalid_keyword: '搜索关键词过长',
|
||||
invalid_type: '搜索类型无效',
|
||||
request_trace_params_required: '缺少请求 ID,无法查看链路',
|
||||
invalid_body: '提交内容格式错误',
|
||||
invalid_name: '请填写规则名称(最长 64 字)',
|
||||
invalid_dim_type: '请选择监控范围',
|
||||
invalid_dim_key: '请填写监控对象',
|
||||
invalid_metric: '请选择监控指标',
|
||||
invalid_comparator: '请选择比较方式',
|
||||
invalid_threshold: '阈值不能为负数',
|
||||
invalid_window: '统计窗口需在 5~1440 分钟之间',
|
||||
invalid_min_samples: '最小样本量需大于 0',
|
||||
invalid_silence: '静默期需在 5 分钟 ~ 7 天之间',
|
||||
rule_not_found: '规则不存在或已被删除',
|
||||
forbidden: '无权查看调用质量,请联系企业所有者开通「调用质量」权限',
|
||||
feature_disabled: '企业未开通「调用质量」功能,请联系平台开通',
|
||||
logs_query_busy: '当前直查日志的查询较多,请稍后重试或缩小时间范围',
|
||||
query_timeout: '查询超时,请缩小时间范围或减少筛选条件后重试',
|
||||
};
|
||||
|
||||
export const DEGRADE_TEXT = {
|
||||
user_or_token_filter: '按用户 / 令牌筛选,已改为直接统计调用日志',
|
||||
user_or_token_dimension: '按用户 / 令牌维度分析,已改为直接统计调用日志',
|
||||
cross_dimension: '当前筛选组合超出预聚合范围,已改为直接统计调用日志',
|
||||
path_ignored: '直查日志时不支持按接口筛选,接口条件未生效',
|
||||
heatmap_requires_single_dimension:
|
||||
'热力图只支持按时间与渠道查看,当前筛选条件下不展示',
|
||||
};
|
||||
|
||||
// 错误展示:已知错误码翻译;未知码若是中文文案(如企业中间件返回的业务提示)原样展示;
|
||||
// 其余(英文内部错误、数据库报错)统一显示通用文案,不把内部信息直显给用户
|
||||
export const qualityErrorText = (t, message) => {
|
||||
const key = QUALITY_ERROR_TEXT[message];
|
||||
if (key) return t(key);
|
||||
if (message && /[一-鿿]/.test(message)) return message;
|
||||
return t('查询失败,请稍后重试');
|
||||
};
|
||||
|
||||
// 图表需要具体色值:从主题 token 读取,保证随亮 / 暗色与品牌色切换
|
||||
export const readCssVar = (name, fallback) => {
|
||||
if (typeof window === 'undefined') return fallback;
|
||||
const value = getComputedStyle(document.body).getPropertyValue(name).trim();
|
||||
return value || fallback;
|
||||
};
|
||||
|
||||
const toneVar = {
|
||||
success: ['--semi-color-success', '#3bb346'],
|
||||
primary: ['--semi-color-primary', '#0064fa'],
|
||||
danger: ['--semi-color-danger', '#f93920'],
|
||||
warning: ['--semi-color-warning', '#fc8800'],
|
||||
tertiary: ['--semi-color-tertiary', '#6b7075'],
|
||||
purple: ['--semi-color-secondary', '#8b5cf6'],
|
||||
};
|
||||
|
||||
export const outcomeColors = () =>
|
||||
OUTCOMES.map((o) => readCssVar(toneVar[o.tone][0], toneVar[o.tone][1]));
|
||||
|
||||
export const toneColor = (tone) =>
|
||||
readCssVar(toneVar[tone][0], toneVar[tone][1]);
|
||||
|
||||
export const outcomeTagColor = {
|
||||
1: 'green',
|
||||
2: 'blue',
|
||||
3: 'red',
|
||||
4: 'orange',
|
||||
5: 'grey',
|
||||
6: 'purple',
|
||||
};
|
||||
|
||||
export const pct = (v, digits = 1) =>
|
||||
v === null || v === undefined || Number.isNaN(v)
|
||||
? '-'
|
||||
: `${(v * 100).toFixed(digits)}%`;
|
||||
|
||||
export const fmtInt = (v) => Number(v || 0).toLocaleString();
|
||||
|
||||
export const fmtMs = (v) => {
|
||||
const n = Number(v || 0);
|
||||
if (n <= 0) return '-';
|
||||
if (n < 1000) return `${n} ms`;
|
||||
return `${(n / 1000).toFixed(n < 10000 ? 2 : 1)} s`;
|
||||
};
|
||||
|
||||
export const fmtTs = (ts, withSeconds = false) => {
|
||||
if (!ts) return '-';
|
||||
const d = new Date(ts * 1000);
|
||||
const pad = (n) => String(n).padStart(2, '0');
|
||||
const base = `${d.getMonth() + 1}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
|
||||
return withSeconds ? `${base}:${pad(d.getSeconds())}` : base;
|
||||
};
|
||||
Reference in New Issue
Block a user