Skip to content
This repository was archived by the owner on Jun 6, 2024. It is now read-only.

Commit f04d999

Browse files
authored
Fix bug: Get wrong log for retried task & frontend crash (#5177) (#5190)
When calling getTaskAttempts API. The task attempt list returned and sorted by DESC order of attemptId. Previous code treat the list as ASC order and return wrong log content for retried task. Fix this issue, as well as frontend bug.
1 parent 15990fc commit f04d999

File tree

4 files changed

+50
-56
lines changed

4 files changed

+50
-56
lines changed

src/rest-server/src/controllers/v2/job.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ const getLogs = asyncHandler(async (req, res) => {
302302
res.json(data);
303303
} catch (error) {
304304
logger.error(`Got error when retrieving log list, error: ${error}`);
305-
throw error.code === 'NoTaskLogErr'
305+
throw error.code === 'NoTaskLogError'
306306
? error
307307
: createError(
308308
'Internal Server Error',

src/rest-server/src/models/v2/job/log.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ const getLogListFromLogManager = async (
5858
'NoTaskLogError',
5959
`Log of task is not found.`,
6060
);
61-
const taskStatus = taskDetail.data.attempts[Number(taskAttemptId)];
62-
if (!taskStatus) {
63-
logger.error(`Failed to find task to retrive log`);
61+
const taskStatus = taskDetail.data.attempts.find(
62+
(attempt) => attempt.attemptId === Number(taskAttemptId),
63+
);
64+
if (!taskStatus || !taskStatus.containerIp) {
65+
logger.error(`Failed to find task to retrive log or task not started`);
6466
throw NoTaskLogErr;
6567
}
6668

src/webportal/src/app/job/job-view/fabric/job-detail/components/task-role-container-list.jsx

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -134,30 +134,25 @@ PortTooltipContent.propTypes = {
134134
ports: PropTypes.object,
135135
};
136136

137-
const LogDialogContent = ({ urlLists }) => {
138-
const lists = [];
139-
for (const p of urlLists) {
140-
lists.push(p);
141-
}
142-
if (lists.length === 0) {
137+
const LogDialogContent = ({ urls }) => {
138+
if (isEmpty(urls)) {
143139
return <Stack>No log file generated or log files be rotated</Stack>;
144140
}
145-
const urlpairs = lists.map((lists, index) => (
146-
<Stack key={`log-list-${index}`}>
147-
<Link
148-
href={lists.uri}
149-
target='_blank'
150-
styles={{ root: [FontClassNames.mediumPlus] }}
151-
>
152-
<Icon iconName='TextDocument'></Icon> {lists.name}
153-
</Link>
154-
</Stack>
155-
));
156-
return urlpairs;
141+
const urlPairs = [];
142+
for (const [key, url] of Object.entries(urls)) {
143+
urlPairs.push(
144+
<Stack key={`log-list-${key}`}>
145+
<Link href={url} styles={{ root: [FontClassNames.mediumPlus] }}>
146+
<Icon iconName='TextDocument'></Icon> {key}
147+
</Link>
148+
</Stack>,
149+
);
150+
}
151+
return urlPairs;
157152
};
158153

159154
LogDialogContent.propTypes = {
160-
urlLists: PropTypes.array,
155+
urlLists: PropTypes.object,
161156
};
162157

163158
export default class TaskRoleContainerList extends React.Component {
@@ -410,10 +405,15 @@ export default class TaskRoleContainerList extends React.Component {
410405
.then(({ fullLogUrls, _ }) => {
411406
this.setState({
412407
hideAllLogsDialog: !hideAllLogsDialog,
413-
fullLogUrls: fullLogUrls,
408+
fullLogUrls: this.convertObjectFormat(fullLogUrls),
414409
});
415410
})
416-
.catch(() => this.setState({ hideAllLogsDialog: !hideAllLogsDialog }));
411+
.catch(() =>
412+
this.setState({
413+
hideAllLogsDialog: !hideAllLogsDialog,
414+
fullLogUrls: {},
415+
}),
416+
);
417417
}
418418

419419
getTaskPropertyFromColumnKey(item, key) {
@@ -531,13 +531,7 @@ export default class TaskRoleContainerList extends React.Component {
531531
>
532532
<Stack gap='m'>
533533
<Text variant='xLarge'>All Logs:</Text>
534-
<LogDialogContent
535-
urlLists={
536-
!isNil(fullLogUrls) && !isNil(fullLogUrls.locations)
537-
? fullLogUrls.locations
538-
: []
539-
}
540-
/>
534+
<LogDialogContent urls={fullLogUrls} />
541535
</Stack>
542536
<DialogFooter>
543537
<PrimaryButton

src/webportal/src/app/job/job-view/fabric/task-attempt/task-attempt-list.jsx

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -93,30 +93,25 @@ PortTooltipContent.propTypes = {
9393
ports: PropTypes.object,
9494
};
9595

96-
const LogDialogContent = ({ urlLists }) => {
97-
const lists = [];
98-
for (const p of urlLists) {
99-
lists.push(p);
100-
}
101-
if (lists.length === 0) {
96+
const LogDialogContent = ({ urls }) => {
97+
if (isEmpty(urls)) {
10298
return <Stack>No log file generated or log files be rotated</Stack>;
10399
}
104-
const urlpairs = lists.map((lists, index) => (
105-
<Stack key={`log-list-${index}`}>
106-
<Link
107-
href={lists.uri}
108-
target='_blank'
109-
styles={{ root: [FontClassNames.mediumPlus] }}
110-
>
111-
<Icon iconName='TextDocument'></Icon> {lists.name}
112-
</Link>
113-
</Stack>
114-
));
115-
return urlpairs;
100+
const urlPairs = [];
101+
for (const [key, url] of Object.entries(urls)) {
102+
urlPairs.push(
103+
<Stack key={`log-list-${key}`}>
104+
<Link href={url} styles={{ root: [FontClassNames.mediumPlus] }}>
105+
<Icon iconName='TextDocument'></Icon> {key}
106+
</Link>
107+
</Stack>,
108+
);
109+
}
110+
return urlPairs;
116111
};
117112

118113
LogDialogContent.propTypes = {
119-
urlLists: PropTypes.array,
114+
urlLists: PropTypes.object,
120115
};
121116

122117
export default class TaskAttemptList extends React.Component {
@@ -223,10 +218,15 @@ export default class TaskAttemptList extends React.Component {
223218
.then(({ fullLogUrls, _ }) => {
224219
this.setState({
225220
hideAllLogsDialog: !hideAllLogsDialog,
226-
fullLogUrls: fullLogUrls,
221+
fullLogUrls: this.convertObjectFormat(fullLogUrls),
227222
});
228223
})
229-
.catch(() => this.setState({ hideAllLogsDialog: !hideAllLogsDialog }));
224+
.catch(() =>
225+
this.setState({
226+
hideAllLogsDialog: !hideAllLogsDialog,
227+
fullLogUrls: {},
228+
}),
229+
);
230230
}
231231

232232
showContainerTailLog(logListUrl, logType) {
@@ -432,9 +432,7 @@ export default class TaskAttemptList extends React.Component {
432432
>
433433
<Stack gap='m'>
434434
<Text variant='xLarge'>All Logs:</Text>
435-
<LogDialogContent
436-
urlLists={!isNil(fullLogUrls) ? fullLogUrls.locations : []}
437-
/>
435+
<LogDialogContent urls={fullLogUrls} />
438436
</Stack>
439437
<DialogFooter>
440438
<PrimaryButton

0 commit comments

Comments
 (0)