feat(alert): A2 告警引擎分布式安全 — Redis 分布式锁(SetNX)
- Cache 接口新增 SetNX 方法(go-redis 原子 / redka check-then-set 单副本安全) - AlertEngine 改造为支持分布式锁: tryAcquireLock/releaseLock/GetEngineStatus - 多副本部署时仅 Leader 执行告警检查, 60s TTL 防死锁, fail-open 容错 - 新增 GET /alerts/engine/status 监控端点(is_leader/instance_id/lock_holder) - 修复 GrafanaDashboard.tsx Panel.options 类型不匹配导致构建中断 - 同步未提交的前端类型安全迁移(140+ 文件) - ROADMAP/TDD_PLAN/PROJECT_EVALUATION 三文档同步更新 验证: go build 零错误, Docker 部署 healthy, 引擎状态端点正常, 锁竞争测试通过(非 Leader 跳过检查), 5/5 核心 API 回归通过
This commit is contained in:
1 parent
5ca0e6d83a
commit
c68aef4444
150 files changed
+1038
-690
No files matched your search
@@ -11,19 +11,20 @@ import {
|
||||
} from '@/components/ui/table';
|
||||
import { Cpu, HardDrive, RefreshCw, ChevronRight, Activity } from 'lucide-react';
|
||||
import { kubernetesApi } from '@/api';
|
||||
import type { JsonData } from '@/types/common';
|
||||
|
||||
export default function PodMetricsPage() {
|
||||
const { clusterCode } = useParams<{ clusterCode: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [metrics, setMetrics] = useState<any[]>([]);
|
||||
const [clusters, setClusters] = useState<any[]>([]);
|
||||
const [metrics, setMetrics] = useState<JsonData[]>([]);
|
||||
const [clusters, setClusters] = useState<JsonData[]>([]);
|
||||
const [namespaces, setNamespaces] = useState<string[]>([]);
|
||||
const [selectedNs, setSelectedNs] = useState('all');
|
||||
const [activeCluster, setActiveCluster] = useState(clusterCode || '');
|
||||
|
||||
useEffect(() => {
|
||||
kubernetesApi.getClusters().then(( res: any) => {
|
||||
kubernetesApi.getClusters().then((res: JsonData) => {
|
||||
const list = res?.list || [];
|
||||
setClusters(list);
|
||||
if (!activeCluster && list.length > 0) {
|
||||
@@ -36,7 +37,7 @@ export default function PodMetricsPage() {
|
||||
|
||||
useEffect(() => {
|
||||
if (!activeCluster) return;
|
||||
kubernetesApi.getNamespaces(activeCluster).then(( res: any) => {
|
||||
kubernetesApi.getNamespaces(activeCluster).then((res: JsonData) => {
|
||||
setNamespaces(Array.isArray(res) ? res : (res?.list || res?.data || []));
|
||||
}).catch(() => {});
|
||||
}, [activeCluster]);
|
||||
@@ -46,7 +47,7 @@ export default function PodMetricsPage() {
|
||||
setLoading(true);
|
||||
try {
|
||||
const ns = selectedNs === 'all' ? undefined : selectedNs;
|
||||
const res: Record<string, any> = await kubernetesApi.getPodMetrics(activeCluster, ns);
|
||||
const res: JsonData = await kubernetesApi.getPodMetrics(activeCluster, ns);
|
||||
setMetrics(Array.isArray(res) ? res : (res?.list || []));
|
||||
} catch { setMetrics([]); } finally { setLoading(false); }
|
||||
}, [activeCluster, selectedNs]);
|
||||
@@ -55,8 +56,8 @@ export default function PodMetricsPage() {
|
||||
|
||||
// Flatten for table
|
||||
const rows = useMemo(() =>
|
||||
metrics.flatMap(( pm: any) =>
|
||||
(pm.containers || []).map(( c: any) => ({
|
||||
metrics.flatMap((pm: JsonData) =>
|
||||
(pm.containers || []).map((c: JsonData) => ({
|
||||
pod: pm.name,
|
||||
namespace: pm.namespace,
|
||||
container: c.name,
|
||||
@@ -91,7 +92,7 @@ export default function PodMetricsPage() {
|
||||
<Select value={activeCluster} onValueChange={v => { setActiveCluster(v); navigate(`/kubernetes/${v}/metrics/pods`); }}>
|
||||
<SelectTrigger className="w-44 h-8 text-xs bg-slate-800 border-slate-700"><SelectValue /></SelectTrigger>
|
||||
<SelectContent className="bg-slate-800 border-slate-700">
|
||||
{clusters.map(( c: any) => <SelectItem key={c.id} value={c.code || String(c.id)} className="text-xs">{c.name || c.code}</SelectItem>)}
|
||||
{clusters.map((c: JsonData) => <SelectItem key={c.id} value={c.code || String(c.id)} className="text-xs">{c.name || c.code}</SelectItem>)}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Select value={selectedNs} onValueChange={setSelectedNs}>
|
||||
|
||||
Reference in new issue
Block a user