Skip to content

Commit

Permalink
fix: requested pr changes
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas <[email protected]>
  • Loading branch information
LukasLJL committed Mar 25, 2024
1 parent d988747 commit 143b199
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
27 changes: 7 additions & 20 deletions ui/src/app/shared/services/workflows-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,39 +244,26 @@ 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<LogEntry> {
// 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';
})
.sort((a, b) => {
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);
})
);
},
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Error>();
const [loaded, setLoaded] = useState(false);
Expand All @@ -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[] = [];
Expand Down Expand Up @@ -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 = [
Expand Down Expand Up @@ -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
}}
/>{' '}
/{' '}
Expand Down

0 comments on commit 143b199

Please sign in to comment.