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
@@ -27,18 +27,19 @@ import {
|
||||
severityBadge,
|
||||
} from './agentAlertHelper';
|
||||
import { AgentRuleDialog } from './AgentRuleDialog';
|
||||
import type { JsonData } from '@/types/common';
|
||||
|
||||
export function AgentAlerts() {
|
||||
const confirm = useConfirm();
|
||||
const [activeTab, setActiveTab] = useState('events');
|
||||
const [alerts, setAlerts] = useState<any[]>([]);
|
||||
const [rules, setRules] = useState<any[]>([]);
|
||||
const [alerts, setAlerts] = useState<JsonData[]>([]);
|
||||
const [rules, setRules] = useState<JsonData[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [resolvedView, setResolvedView] = useState(false);
|
||||
|
||||
// 规则编辑弹窗
|
||||
const [ruleOpen, setRuleOpen] = useState(false);
|
||||
const [editingRule, setEditingRule] = useState<any>(null);
|
||||
const [editingRule, setEditingRule] = useState<JsonData>(null);
|
||||
|
||||
const loadData = useCallback(async () => {
|
||||
setLoading(true);
|
||||
@@ -80,7 +81,7 @@ export function AgentAlerts() {
|
||||
setRuleOpen(true);
|
||||
};
|
||||
|
||||
const openEditRule = ( rule: any) => {
|
||||
const openEditRule = (rule: JsonData) => {
|
||||
setEditingRule(rule);
|
||||
setRuleOpen(true);
|
||||
};
|
||||
@@ -97,7 +98,7 @@ export function AgentAlerts() {
|
||||
}
|
||||
};
|
||||
|
||||
const handleToggleRule = async ( rule: any) => {
|
||||
const handleToggleRule = async (rule: JsonData) => {
|
||||
try {
|
||||
await agentApi.updateRule(rule.id, { ...rule, enabled: !rule.enabled });
|
||||
loadData();
|
||||
|
||||
@@ -23,11 +23,12 @@ import {
|
||||
} from '@/components/ui/select';
|
||||
import { Loader2 } from 'lucide-react';
|
||||
import { METRIC_OPTIONS, OPERATOR_OPTIONS, SEVERITY_OPTIONS } from './agentAlertHelper';
|
||||
import type { JsonData } from '@/types/common';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onOpenChange: (v: boolean) => void;
|
||||
editingRule: any;
|
||||
editingRule?: JsonData;
|
||||
onSuccess: () => void;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,17 +29,18 @@ import {
|
||||
Tooltip,
|
||||
ResponsiveContainer,
|
||||
} from 'recharts';
|
||||
import type { JsonData } from '@/types/common';
|
||||
|
||||
export function HostDetailDialog({
|
||||
host,
|
||||
onClose,
|
||||
onCommand,
|
||||
}: {
|
||||
host: any;
|
||||
host?: JsonData;
|
||||
onClose: () => void;
|
||||
onCommand: (hostname: string) => void;
|
||||
}) {
|
||||
const [history, setHistory] = useState<any[]>([]);
|
||||
const [history, setHistory] = useState<JsonData[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [hours, setHours] = useState(1);
|
||||
|
||||
@@ -60,7 +61,7 @@ export function HostDetailDialog({
|
||||
if (!host) return null;
|
||||
|
||||
const online = isOnline(host.last_report || host.last_reported_at || host.updated_at);
|
||||
const ports: Record<string, any>[] = Array.isArray(host.ports) ? host.ports : [];
|
||||
const ports: JsonData[] = Array.isArray(host.ports) ? host.ports : [];
|
||||
|
||||
const chartData = history.map((h) => ({
|
||||
time: new Date(h.timestamp || h.time || h.created_at || Date.now()).toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' }),
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Agent 告警常量与辅助函数(从 AgentAlerts.tsx 提取) // Logan.Li
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { AlertTriangle, Cpu, MemoryStick, HardDrive, WifiOff, Network } from 'lucide-react';
|
||||
import type { JsonData } from '@/types/common';
|
||||
|
||||
// 监控指标选项(含图标,告警事件/规则/编辑弹窗共用) // Logan.Li
|
||||
export const METRIC_OPTIONS = [
|
||||
@@ -33,7 +34,7 @@ export function getMetricLabel(metric: string) {
|
||||
}
|
||||
|
||||
// 兼容多种列表响应格式(数组 / {list} / {items} / {data}) // Logan.Li
|
||||
export function asList( data: any): unknown[] {
|
||||
export function asList(data: JsonData): unknown[] {
|
||||
if (!data) return [];
|
||||
if (Array.isArray(data)) return data;
|
||||
if (Array.isArray(data.list)) return data.list;
|
||||
|
||||
Reference in new issue
Block a user