From 3667ab1a9780b8596b3d3d3fa58b0455ce7c0cde Mon Sep 17 00:00:00 2001 From: dengqichen Date: Mon, 29 Dec 2025 09:36:26 +0800 Subject: [PATCH] 1.44 --- .../Dashboard/components/LogWindowManager.tsx | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/frontend/src/pages/Dashboard/components/LogWindowManager.tsx b/frontend/src/pages/Dashboard/components/LogWindowManager.tsx index 29f7e335..79d71559 100644 --- a/frontend/src/pages/Dashboard/components/LogWindowManager.tsx +++ b/frontend/src/pages/Dashboard/components/LogWindowManager.tsx @@ -84,6 +84,7 @@ const LogViewerContent: React.FC<{ const onCloseReadyRef = useRef(onCloseReady); const onStatusChangeRef = useRef(onStatusChange); const updateWindowTitleRef = useRef(updateWindowTitle); + const prevPodNameRef = useRef(''); // 保持最新的回调引用和状态 useEffect(() => { @@ -190,6 +191,62 @@ const LogViewerContent: React.FC<{ handleStartRef.current = handleStart; }, [handleStart]); + // 监听Pod切换,自动重启日志流 + useEffect(() => { + // 跳过初始化(prevPodNameRef为空) + if (!prevPodNameRef.current) { + prevPodNameRef.current = podName; + return; + } + + // 跳过相同的Pod名称 + if (prevPodNameRef.current === podName) { + return; + } + + // 只在正在streaming或paused时才重启 + if (status !== LogStreamStatus.STREAMING && status !== LogStreamStatus.PAUSED) { + prevPodNameRef.current = podName; + return; + } + + console.log('[LogWindowManager] Pod changed from', prevPodNameRef.current, 'to', podName, '- restarting stream'); + + // 更新引用 + prevPodNameRef.current = podName; + + // 重启流程:STOP → 清空 → START + if (controlApiRef.current) { + // 1. 发送STOP消息 + const stopMessage = { + type: 'CONTROL', + data: { request: { action: 'STOP' } }, + }; + controlApiRef.current.send(JSON.stringify(stopMessage)); + + // 2. 清空日志 + logApiRef.current?.clear(); + + // 3. 延迟后发送START消息(包含新的Pod名称) + setTimeout(() => { + if (controlApiRef.current) { + const startMessage = { + type: 'START', + data: { + request: { + lines, + ...(app.runtimeType === 'K8S' && podName ? { name: podName } : {}), + }, + }, + }; + console.log('[LogWindowManager] Sending START with new pod:', startMessage); + controlApiRef.current.send(JSON.stringify(startMessage)); + setStatus(LogStreamStatus.STREAMING); + } + }, 200); + } + }, [podName, status, lines, app.runtimeType]); + // 创建WebSocket数据源 const dataSource = useMemo(() => { console.log('[LogWindowManager] Creating new dataSource for app:', app.teamApplicationId, app.runtimeType);