diff --git a/ui/src/app/shared/services/workflows-service.ts b/ui/src/app/shared/services/workflows-service.ts index 4cea745962f7..8970e16cbb90 100644 --- a/ui/src/app/shared/services/workflows-service.ts +++ b/ui/src/app/shared/services/workflows-service.ts @@ -244,16 +244,15 @@ export const WorkflowsService = { return from(requests.get(this.getArtifactLogsPath(workflow, nodeId, container, archived))); }), mergeMap(r => r.text.split('\n')), - //check for empty content - filter(x => !!x), + filter(x => !!x), //check for empty content map(content => ({content, podName: workflow.status.nodes[nodeId].displayName}) as LogEntry), filter(x => !!x.content.match(grep)) ); }, getContainerLogsFromArtifacts(workflow: Workflow, container: string, grep: string, archived: boolean): Observable { - // Iterate workflow and get all node ids and check if node is a pod. Then sort nodes by startedAt - const nodeIds: string[] = Object.keys(workflow.status.nodes) + // Iterate over all nodes and check if node is a pod. Then sort nodes by startedAt. + const podNodeIds: string[] = Object.keys(workflow.status.nodes) .filter(nodeId => { return workflow.status.nodes[nodeId].type === 'Pod'; }) @@ -261,22 +260,10 @@ export const WorkflowsService = { return new Date(workflow.status.nodes[a].startedAt).getTime() - new Date(workflow.status.nodes[b].startedAt).getTime(); }); - // Iterate over all nodes and get the logs - return from(nodeIds).pipe( + // Iterate over pod node ids and get their logs + return from(podNodeIds).pipe( concatMap(nodeId => { - return of(hasArtifactLogs(workflow, nodeId, container)).pipe( - switchMap(isArtifactLogs => { - if (!isArtifactLogs) { - throw new Error('no artifact logs are available'); - } - return from(requests.get(this.getArtifactLogsPath(workflow, nodeId, container, archived))); - }), - mergeMap(r => r.text.split('\n')), - //check for empty content - filter(x => !!x), - map(content => ({content, podName: workflow.status.nodes[nodeId].displayName}) as LogEntry), - filter(x => !!x.content.match(grep)) - ); + return this.getContainerLogs(workflow, container, nodeId, container, grep, archived); }) ); }, @@ -288,7 +275,7 @@ export const WorkflowsService = { // If our workflow is archived, don't even bother inspecting the cluster for logs since it's likely // that the Workflow and associated pods have been deleted - // If we have a node ID, then we can assume that we are looking for logs for a specific node, if not we wan´t the logs from all nodes + // If we don't have a node id, then we want the logs from all nodes if (archived && !nodeId) { return getLogsFromArtifacts(); } diff --git a/ui/src/app/workflows/components/workflow-logs-viewer/workflow-logs-viewer.tsx b/ui/src/app/workflows/components/workflow-logs-viewer/workflow-logs-viewer.tsx index 0f72293b7ff8..5c782d09ede3 100644 --- a/ui/src/app/workflows/components/workflow-logs-viewer/workflow-logs-viewer.tsx +++ b/ui/src/app/workflows/components/workflow-logs-viewer/workflow-logs-viewer.tsx @@ -83,6 +83,7 @@ export function WorkflowLogsViewer({workflow, nodeId, initialPodName, container, const {popup} = useContext(Context); const [podName, setPodName] = useState(initialPodName || ''); const [selectedContainer, setContainer] = useState(container); + const [selectedNodeId, setNodeId] = useState(nodeId); const [grep, setGrep] = useState(''); const [error, setError] = useState(); const [loaded, setLoaded] = useState(false); @@ -102,17 +103,7 @@ export function WorkflowLogsViewer({workflow, nodeId, initialPodName, container, setError(null); setLoaded(false); - if (archived) { - // replace nodeId with a nodeId which is associated with the podName, so we can also switch bewteen archived logs if a differnet node was selected. - nodeId = podNamesToNodeIDs.get(podName); - - // if a podName is provided but no valid nodeId is found, clear the podName. So the selector is automatically set to 'All' - if (podName && !nodeId) { - setPodName(''); - } - } - - const source = services.workflows.getContainerLogs(workflow, podName, nodeId, selectedContainer, grep, archived).pipe( + const source = services.workflows.getContainerLogs(workflow, podName, selectedNodeId, selectedContainer, grep, archived).pipe( // extract message from LogEntry map(e => { const values: string[] = []; @@ -186,7 +177,12 @@ export function WorkflowLogsViewer({workflow, nodeId, initialPodName, container, }) ); - const node = workflow.status.nodes[nodeId]; + // if no node id is set (for example, when no node is selected), then use the node id of of the pod. + if (archived && !selectedNodeId && podNamesToNodeIDs.get(podName)) { + setNodeId(podNamesToNodeIDs.get(podName)); + } + + const node = workflow.status.nodes[selectedNodeId]; const templates = execSpec(workflow).templates.filter(t => !node || t.name === node.templateName); const containers = [ @@ -233,6 +229,7 @@ export function WorkflowLogsViewer({workflow, nodeId, initialPodName, container, value={(podNames.find(x => x.value === podName) || {label: ''}).label} onSelect={(_, item) => { setPodName(item.value); + setNodeId(podNamesToNodeIDs.get(item.value)); // set the correct node id to be able to fetch archived logs }} />{' '} /{' '}