Skip to content

Commit f3e041a

Browse files
qn895kibanamachine
andauthored
[ML] Fixes anomaly detection jobs list load if call to load job messages fails (#79792) (#80020)
Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent abb5c74 commit f3e041a

File tree

3 files changed

+37
-9
lines changed

3 files changed

+37
-9
lines changed

x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row_messages_pane.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { ml } from '../../../../../services/ml_api_service';
1212
import { useRefreshAnalyticsList } from '../../../../common';
1313
import { JobMessages } from '../../../../../components/job_messages';
1414
import { JobMessage } from '../../../../../../../common/types/audit_message';
15+
import { useToastNotificationService } from '../../../../../services/toast_notification_service';
1516

1617
interface Props {
1718
analyticsId: string;
@@ -21,6 +22,7 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
2122
const [messages, setMessages] = useState<JobMessage[]>([]);
2223
const [isLoading, setIsLoading] = useState(false);
2324
const [errorMessage, setErrorMessage] = useState('');
25+
const toastNotificationService = useToastNotificationService();
2426

2527
const getMessages = useCallback(async () => {
2628
try {
@@ -30,6 +32,16 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
3032
setMessages(messagesResp);
3133
} catch (error) {
3234
setIsLoading(false);
35+
toastNotificationService.displayErrorToast(
36+
error,
37+
i18n.translate(
38+
'xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorToastMessageTitle',
39+
{
40+
defaultMessage: 'Error loading job messages',
41+
}
42+
)
43+
);
44+
3345
setErrorMessage(
3446
i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', {
3547
defaultMessage: 'Messages could not be loaded',

x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/job_messages_pane.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
*/
66

77
import React, { FC, useCallback, useEffect, useState } from 'react';
8+
import { i18n } from '@kbn/i18n';
89
import { ml } from '../../../../services/ml_api_service';
910
import { JobMessages } from '../../../../components/job_messages';
1011
import { JobMessage } from '../../../../../../common/types/audit_message';
12+
import { extractErrorMessage } from '../../../../../../common/util/errors';
13+
import { useToastNotificationService } from '../../../../services/toast_notification_service';
1114
interface JobMessagesPaneProps {
1215
jobId: string;
1316
}
@@ -16,17 +19,23 @@ export const JobMessagesPane: FC<JobMessagesPaneProps> = ({ jobId }) => {
1619
const [messages, setMessages] = useState<JobMessage[]>([]);
1720
const [isLoading, setIsLoading] = useState(false);
1821
const [errorMessage, setErrorMessage] = useState('');
22+
const toastNotificationService = useToastNotificationService();
1923

2024
const fetchMessages = async () => {
2125
setIsLoading(true);
2226
try {
2327
setMessages(await ml.jobs.jobAuditMessages(jobId));
2428
setIsLoading(false);
25-
} catch (e) {
29+
} catch (error) {
2630
setIsLoading(false);
27-
setErrorMessage(e);
28-
// eslint-disable-next-line no-console
29-
console.error('Job messages could not be loaded', e);
31+
toastNotificationService.displayErrorToast(
32+
error,
33+
i18n.translate('xpack.ml.jobService.jobAuditMessagesErrorTitle', {
34+
defaultMessage: 'Error loading job messages',
35+
})
36+
);
37+
38+
setErrorMessage(extractErrorMessage(error));
3039
}
3140
};
3241

x-pack/plugins/ml/server/models/job_service/jobs.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,18 @@ export function jobsProvider(client: IScopedClusterClient) {
152152
async function jobsSummary(jobIds: string[] = []) {
153153
const fullJobsList: CombinedJobWithStats[] = await createFullJobsList();
154154
const fullJobsIds = fullJobsList.map((job) => job.job_id);
155-
const auditMessages: AuditMessage[] = await getAuditMessagesSummary(fullJobsIds);
156-
const auditMessagesByJob = auditMessages.reduce((acc, cur) => {
157-
acc[cur.job_id] = cur;
158-
return acc;
159-
}, {} as { [id: string]: AuditMessage });
155+
let auditMessagesByJob: { [id: string]: AuditMessage } = {};
156+
157+
// even if there are errors getting the audit messages, we still want to show the full list
158+
try {
159+
const auditMessages: AuditMessage[] = await getAuditMessagesSummary(fullJobsIds);
160+
auditMessagesByJob = auditMessages.reduce((acc, cur) => {
161+
acc[cur.job_id] = cur;
162+
return acc;
163+
}, auditMessagesByJob);
164+
} catch (e) {
165+
// fail silently
166+
}
160167

161168
const deletingStr = i18n.translate('xpack.ml.models.jobService.deletingJob', {
162169
defaultMessage: 'deleting',

0 commit comments

Comments
 (0)