mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[ML] Fixes anomaly detection jobs list load if call to load job messages fails (#79792)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
1cefc8eed0
commit
f04c295d4d
3 changed files with 37 additions and 9 deletions
|
@ -12,6 +12,7 @@ import { ml } from '../../../../../services/ml_api_service';
|
|||
import { useRefreshAnalyticsList } from '../../../../common';
|
||||
import { JobMessages } from '../../../../../components/job_messages';
|
||||
import { JobMessage } from '../../../../../../../common/types/audit_message';
|
||||
import { useToastNotificationService } from '../../../../../services/toast_notification_service';
|
||||
|
||||
interface Props {
|
||||
analyticsId: string;
|
||||
|
@ -21,6 +22,7 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
|
|||
const [messages, setMessages] = useState<JobMessage[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState('');
|
||||
const toastNotificationService = useToastNotificationService();
|
||||
|
||||
const getMessages = useCallback(async () => {
|
||||
try {
|
||||
|
@ -30,6 +32,16 @@ export const ExpandedRowMessagesPane: FC<Props> = ({ analyticsId }) => {
|
|||
setMessages(messagesResp);
|
||||
} catch (error) {
|
||||
setIsLoading(false);
|
||||
toastNotificationService.displayErrorToast(
|
||||
error,
|
||||
i18n.translate(
|
||||
'xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorToastMessageTitle',
|
||||
{
|
||||
defaultMessage: 'Error loading job messages',
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
setErrorMessage(
|
||||
i18n.translate('xpack.ml.dfAnalyticsList.analyticsDetails.messagesPane.errorMessage', {
|
||||
defaultMessage: 'Messages could not be loaded',
|
||||
|
|
|
@ -5,9 +5,12 @@
|
|||
*/
|
||||
|
||||
import React, { FC, useCallback, useEffect, useState } from 'react';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
import { ml } from '../../../../services/ml_api_service';
|
||||
import { JobMessages } from '../../../../components/job_messages';
|
||||
import { JobMessage } from '../../../../../../common/types/audit_message';
|
||||
import { extractErrorMessage } from '../../../../../../common/util/errors';
|
||||
import { useToastNotificationService } from '../../../../services/toast_notification_service';
|
||||
interface JobMessagesPaneProps {
|
||||
jobId: string;
|
||||
}
|
||||
|
@ -16,17 +19,23 @@ export const JobMessagesPane: FC<JobMessagesPaneProps> = ({ jobId }) => {
|
|||
const [messages, setMessages] = useState<JobMessage[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [errorMessage, setErrorMessage] = useState('');
|
||||
const toastNotificationService = useToastNotificationService();
|
||||
|
||||
const fetchMessages = async () => {
|
||||
setIsLoading(true);
|
||||
try {
|
||||
setMessages(await ml.jobs.jobAuditMessages(jobId));
|
||||
setIsLoading(false);
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
setIsLoading(false);
|
||||
setErrorMessage(e);
|
||||
// eslint-disable-next-line no-console
|
||||
console.error('Job messages could not be loaded', e);
|
||||
toastNotificationService.displayErrorToast(
|
||||
error,
|
||||
i18n.translate('xpack.ml.jobService.jobAuditMessagesErrorTitle', {
|
||||
defaultMessage: 'Error loading job messages',
|
||||
})
|
||||
);
|
||||
|
||||
setErrorMessage(extractErrorMessage(error));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -152,11 +152,18 @@ export function jobsProvider(client: IScopedClusterClient) {
|
|||
async function jobsSummary(jobIds: string[] = []) {
|
||||
const fullJobsList: CombinedJobWithStats[] = await createFullJobsList();
|
||||
const fullJobsIds = fullJobsList.map((job) => job.job_id);
|
||||
const auditMessages: AuditMessage[] = await getAuditMessagesSummary(fullJobsIds);
|
||||
const auditMessagesByJob = auditMessages.reduce((acc, cur) => {
|
||||
acc[cur.job_id] = cur;
|
||||
return acc;
|
||||
}, {} as { [id: string]: AuditMessage });
|
||||
let auditMessagesByJob: { [id: string]: AuditMessage } = {};
|
||||
|
||||
// even if there are errors getting the audit messages, we still want to show the full list
|
||||
try {
|
||||
const auditMessages: AuditMessage[] = await getAuditMessagesSummary(fullJobsIds);
|
||||
auditMessagesByJob = auditMessages.reduce((acc, cur) => {
|
||||
acc[cur.job_id] = cur;
|
||||
return acc;
|
||||
}, auditMessagesByJob);
|
||||
} catch (e) {
|
||||
// fail silently
|
||||
}
|
||||
|
||||
const deletingStr = i18n.translate('xpack.ml.models.jobService.deletingJob', {
|
||||
defaultMessage: 'deleting',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue