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:
attacker committed 2026-06-26 21:13:15 +08:00
1 parent 5ca0e6d83a
commit c68aef4444
150 files changed
+1038 -690

No files matched your search

@@ -15,13 +15,14 @@ import { DeploymentLogsTab } from './deployment-detail/DeploymentLogsTab';
import { DeploymentHpaTab } from './deployment-detail/DeploymentHpaTab';
import { DeploymentPodModals } from './deployment-detail/DeploymentPodModals';
import { YamlViewer } from './YamlViewer';
import type { JsonData } from '@/types/common';
export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBack }: DeploymentDetailProps) {
const { toast } = useToast();
const confirm = useConfirm();
const [deployment, setDeployment] = useState<any>(null);
const [pods, setPods] = useState<any[]>([]);
const [hpas, setHpas] = useState<any[]>([]);
const [deployment, setDeployment] = useState<JsonData>(null);
const [pods, setPods] = useState<JsonData[]>([]);
const [hpas, setHpas] = useState<JsonData[]>([]);
const [loading, setLoading] = useState(true);
const [actionLoading, setActionLoading] = useState('');
const [, setScaleValue] = useState(0);
@@ -45,19 +46,19 @@ export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBac
kubernetesApi.getNamespacePods(clusterCode, namespace).catch(() => []),
kubernetesApi.getHPAs(clusterCode, namespace).catch(() => ({ items: [] })),
]);
const toArray = (v: any) => (Array.isArray(v) ? v : (v?.list || v?.items || []));
const toArray = (v: JsonData) => (Array.isArray(v) ? v : (v?.list || v?.items || []));
const allDeps = toArray(depRes);
const allPods = toArray(podRes);
const allHpas = toArray(hpaRes);
const dep = allDeps.find((d: any) => d.name === deploymentName && d.namespace === namespace);
const dep = allDeps.find((d: JsonData) => d.name === deploymentName && d.namespace === namespace);
setDeployment(dep || null);
if (dep) {
setScaleValue(dep.replicas || 0);
setNewImage(dep.image || '');
}
setPods(allPods.filter((p: any) => p.namespace === namespace && p.name.startsWith(deploymentName)));
setHpas(allHpas.filter((h: any) => h.target_name === deploymentName && h.namespace === namespace));
setPods(allPods.filter((p: JsonData) => p.namespace === namespace && p.name.startsWith(deploymentName)));
setHpas(allHpas.filter((h: JsonData) => h.target_name === deploymentName && h.namespace === namespace));
} catch (e) {
console.error('加载详情失败:', e);
} finally {
@@ -103,7 +104,7 @@ export function DeploymentDetail({ clusterCode, namespace, deploymentName, onBac
} finally { setActionLoading(''); }
};
const handleHpaToggle = async (hpa: any) => {
const handleHpaToggle = async (hpa: JsonData) => {
const ok = await confirm({
title: '删除 HPA',
description: `确定删除 HPA "${hpa.name}"?`,