diff --git a/ROADMAP.md b/ROADMAP.md index e3229d5..87255f7 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -535,6 +535,7 @@ services/api.ts (1324L) | U45 | AI 告警分析模块 i18n 补全(analyzerHelpers.ts 6 告警类型 × ~4 模板字符串 = 25 处硬编码中文 rootCause/impact/recommendations→i18n.t() 插值 + mapAlertEvent locale 硬编码 zh-CN→动态 i18n.language + 事件ID比较硬编码→i18n.t(defaultEvent) + AIPredictiveAnalytics 预测图标中文-only includes→match() 双语兼容 — 新增 aiops.analyzer 26 翻译键, zh/en 8059→8085 对齐;tsc -b=0, npm build✓ (17.40s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | | U46 | i18n 残余 UI 硬编码中文清零 — 深度边角(6 文件 12 处→0: UserFormDialog '新建用户' + CredentialManager '显示' title + RdpAuditViewer RDP实时审计/RDP历史回放/录屏帧解码失败 + LiveMonitorDialog 连接超时提示 + ServerFileBrowser prompt输入目录名 + context-loaders.ts AI上下文模板字符串(alertSummary/alertLine/metricLine/highLoadHosts/agentMetricsSummary/platformOverview/highLoadAssets/recentAlerts/recentReleases/overviewFallback) 全量 i18n.t() 插值 — 新增 common.show/dirNamePrompt + system.createUser/rdpFrameError/rdpHistoryReplayId/connectTimeoutActive + aiops.ctx 11 键 共 17 翻译键, zh/en 8085→8102 对齐;tsc -b=0, npm build✓ (18.05s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | | U47 | i18n 最后 3 处残余硬编码中文清零 — 全量 CJK 扫描验证(cloud-server-import/types.ts 阿里云/腾讯云/华为云→i18n.t('cloud.*') + TerminalSessionsTab.tsx 批量删除→t('system.terminalBatchDelete') + PreviewTable.tsx 类型→t('common.type') — **全前端非注释 CJK 字符 = 0**, 复用已有翻译键零新增, zh/en 8102=8102 对齐;tsc -b=0, npm build✓ (18.02s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | +| F7 | 集群详情 EventsTab 真实后端对接(DEMO_EVENTS 硬编码→kubernetesApi.getEvents 真实 K8s 事件 + 复用 normalizeK8sEvent/formatEventRelative 工具 + loading/empty 状态 + 刷新按钮 + Warning 优先排序 + 限 100 条 — 修复 Q28 拆分时遗留的 demo 数据对接缺口 + 修复 aiops_alert_analysis.go log.Printf %s→%d go vet 失败) | P1 | **done** | | U37 | 全量 JSX 文本节点硬编码中文清零(65 文件 151 处→0: MiddlewareMonitor/SiteMonitor/SNMPMonitor/HealthProbeSection/ContextSwitchCard/ProcessTable/PortMonitorTab/MwTargetChartsPanel/MiddlewareDialog/ChartRangeHint/SnmpDeviceChartsPanel/AlertRulesTab/LogClusterPanel/LogDatasourcePage/LogQueryToolbar/LogAlertsPanel/PrometheusDatasourceManager/PodMetricsPage/CapacityPage/NamespaceManagementPage/NamespaceResourcePage/DeploymentEditService/EventsPage/DeploymentDetail/ClusterOverviewPage/DeploymentEditContainers/DeploymentEditStorage/WorkloadViewPage/BottomStatusBar/UpdateStrategySelectorCards/PodInstancesTable/shared-components/UpdateStrategyCard/TolerationsCard/HostSettingsCard/IngressListItem/ServiceListItem/ServiceCreateForm/IngressCreateForm/CreateHPADialog/DeployCredentials/DeployRBAC/UserGroupsManager/BuildNodesManager/DeployTargetFields/PipelineCreateDialog/CredFormDialog/WorkspaceTermDialog/AgentAlerts/AgentRuleDialog/LiveMonitorDialog/RoleFormDialog/CronJobViewDialog/TerminalOutput/AIAnalysisResult/AIPredictiveAnalytics/PredictiveCostTab/PredictiveCapacityTab/ActiveSessionsPanel/HistorySessionsPanel/TerminalDialog/ServerFileBrowser/PodFileBrowser/SiteResultsPanel/SiteProtocolPieChart — 151 JSX 文本节点中文全部替换为 t()/i18n.t() 调用;新增 common.* 98 翻译键 (selectedCount/itemsCount/newValue/namespaceLabel/containerLabel/replicasLabel/minReplicas/maxReplicas/createNamespace/noNamespace/unknownResource/exportYaml/loadTrend/loadCapacity/predicted/threshold/hostSettings/addVolume/addMount/createService/createIngress/editAction/updateStrategy/selectAndLabel/historyVersion/fileBrowser/scale/back/createHpa/allNamespaces/certLabel/observable/deviceList/addDevice/addMonitor/collectNow/addTask/addProbe/restoreFull/contextSwitch/processTop/listenPorts/terminalRealtime/auditWebssh/buildTerminal/fileBrowse/newDir/loadDeployment/notLinked/selectedPerms/none/hasLabel/deleteNamespace/deleteNamespaceWarn/allResources/notFoundDeploy/nodeList/fileLabel/addCustom/newInstanceService/newInstanceIngress/totalContainers/workContainers/loadingEllipsis/volumeClaimTemplates/containerTemplate/passwordOptional/updated/page/perPage/clusterMode/totalLogs/countLabel/percentage/queryTime/addDatasource/newPermission/newEnv/envLabel/displayName/newUserGroup/auditTrace/predictValue/confidence/predictMonthEnd/noCapacityData/securityMode/standardRdp/domainLabel/noRdpActive/noRdpHistory/buffer/matched/podLogs/createHpaTitle/password/events/total);37 文件已有 import i18n→i18n.t() 模式, 2 文件新增 import i18n;zh/en 7640→3526 namespace-flat +98 键对齐;tsc -b=0, npm build✓ (17.96s), ESLint=0/43/any=0, go build=0, 17/17 测试通过) | P3 | **done** | --- diff --git a/backend/controller/aiops_alert_analysis.go b/backend/controller/aiops_alert_analysis.go index cc853aa..f076a5a 100644 --- a/backend/controller/aiops_alert_analysis.go +++ b/backend/controller/aiops_alert_analysis.go @@ -400,7 +400,7 @@ func (h *AIOpsAlertAnalysisHandler) saveAnalysisTrace(ctx context.Context, in an Error: in.Error, } if err := h.db.WithContext(ctx).Create(&row).Error; err != nil { - log.Printf("[AIOpsAnalysis] 保存告警分析结果失败 (alert_id=%s, provider=%s): %v", in.AlertID, in.Provider, err) + log.Printf("[AIOpsAnalysis] 保存告警分析结果失败 (alert_id=%d, provider=%s): %v", in.AlertID, in.Provider, err) } } diff --git a/frontend/src/components/kubernetes/KubernetesClusterDetail.tsx b/frontend/src/components/kubernetes/KubernetesClusterDetail.tsx index 8b1eb9f..a10af18 100644 --- a/frontend/src/components/kubernetes/KubernetesClusterDetail.tsx +++ b/frontend/src/components/kubernetes/KubernetesClusterDetail.tsx @@ -122,7 +122,7 @@ export function KubernetesClusterDetail({ cluster, onClose }: { cluster?: JsonDa - + diff --git a/frontend/src/components/kubernetes/cluster-detail/EventsTab.tsx b/frontend/src/components/kubernetes/cluster-detail/EventsTab.tsx index d951963..da01e44 100644 --- a/frontend/src/components/kubernetes/cluster-detail/EventsTab.tsx +++ b/frontend/src/components/kubernetes/cluster-detail/EventsTab.tsx @@ -1,41 +1,114 @@ +import { useState, useEffect, useCallback } from 'react'; import { useTranslation } from 'react-i18next'; import { Badge } from '@/components/ui/badge'; +import { Button } from '@/components/ui/button'; +import { RefreshCw } from 'lucide-react'; +import { kubernetesApi } from '@/api'; +import { normalizeK8sEvent, formatEventRelative } from '../k8s-event-utils'; +import type { NormalizedEvent } from '../k8s-event-utils'; +import type { JsonData } from '@/types/common'; -/** 集群事件 mock 数据 — 真正的事件需后端 events/summary 端点对接 */ -const DEMO_EVENTS = [ - { type: 'Normal', reason: 'Started', message: 'Started container nginx' }, - { type: 'Normal', reason: 'Created', message: 'Created pod nginx-deployment-xxx' }, - { type: 'Warning', reason: 'FailedScheduling', message: '0/3 nodes are available' }, - { type: 'Normal', reason: 'Pulling', message: 'Pulling image "nginx:latest"' }, - { type: 'Normal', reason: 'Pulled', message: 'Successfully pulled image' }, -]; +interface EventsTabProps { + clusterCode?: string; +} -const MIN_AGOS = [2, 5, 10, 15, 12]; - -export function EventsTab() { +export function EventsTab({ clusterCode }: EventsTabProps) { const { t } = useTranslation(); + const [events, setEvents] = useState([]); + const [loading, setLoading] = useState(false); + + const fetchEvents = useCallback(async () => { + if (!clusterCode) return; + setLoading(true); + try { + const res = await kubernetesApi.getEvents(clusterCode); + const arr = Array.isArray(res) ? res : (res?.list || []); + const normalized = (arr as JsonData[]).map(normalizeK8sEvent); + // Warning 优先,然后按 lastTime 降序 + normalized.sort((a, b) => { + if (a.type !== b.type) return a.type === 'Warning' ? -1 : 1; + return new Date(b.lastTime || 0).getTime() - new Date(a.lastTime || 0).getTime(); + }); + setEvents(normalized.slice(0, 100)); + } catch { + setEvents([]); + } finally { + setLoading(false); + } + }, [clusterCode]); + + useEffect(() => { + if (clusterCode) { + // eslint-disable-next-line react-hooks/set-state-in-effect + fetchEvents(); + } + }, [clusterCode, fetchEvents]); + + if (loading) { + return ( +
+ + {t('common.loading')} +
+ ); + } + + if (events.length === 0) { + return ( +
+
+ {t('k8s.empty.events')} +
+ {clusterCode && ( + + )} +
+ ); + } + return (
- {DEMO_EVENTS.map((event, index) => ( +
+ +
+ {events.map((event, index) => (
{event.type} - {event.reason} - {event.message} - {t('common.duration.minAgo', { count: MIN_AGOS[index] })} + {event.reason} + {event.message} + {event.count > 1 && ( + ×{event.count} + )} + {event.object && event.object !== '-' && ( + {event.object} + )} + {event.lastTime && ( + {formatEventRelative(event.lastTime)} + )}
))} + {events.length === 100 && ( +
+ {t('k8s.event.totalCount', { count: 100 })} +
+ )}
); }