Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Fixes to error handling for analytics jobs and file data viz #60249

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ enum TASK_STATE_COLOR {

export const getTaskStateBadge = (
state: DataFrameAnalyticsStats['state'],
reason?: DataFrameAnalyticsStats['reason']
failureReason?: DataFrameAnalyticsStats['failure_reason']
) => {
const color = TASK_STATE_COLOR[state];

if (isDataFrameAnalyticsFailed(state) && reason !== undefined) {
if (isDataFrameAnalyticsFailed(state) && failureReason !== undefined) {
return (
<EuiToolTip content={reason}>
<EuiToolTip content={failureReason}>
<EuiBadge className="mlTaskStateBadge" color={color}>
{state}
</EuiBadge>
Expand Down Expand Up @@ -229,7 +229,7 @@ export const getColumns = (
sortable: (item: DataFrameAnalyticsListRow) => item.stats.state,
truncateText: true,
render(item: DataFrameAnalyticsListRow) {
return getTaskStateBadge(item.stats.state, item.stats.reason);
return getTaskStateBadge(item.stats.state, item.stats.failure_reason);
},
width: '100px',
'data-test-subj': 'mlAnalyticsTableColumnStatus',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export interface DataFrameAnalyticsStats {
transport_address: string;
};
progress: ProgressSection[];
reason?: string;
failure_reason?: string;
state: DATA_FRAME_TASK_STATE;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
loadEvalData,
Eval,
} from '../../../../common';
import { getTaskStateBadge } from './columns';
import { isCompletedAnalyticsJob } from './common';
import {
isRegressionAnalysis,
Expand Down Expand Up @@ -158,7 +159,11 @@ export const ExpandedRow: FC<Props> = ({ item }) => {
defaultMessage: 'State',
}),
items: Object.entries(stateValues).map(s => {
return { title: s[0].toString(), description: getItemDescription(s[1]) };
if (s[0].toString() === 'state') {
return { title: s[0].toString(), description: getTaskStateBadge(getItemDescription(s[1])) };
} else {
return { title: s[0].toString(), description: getItemDescription(s[1]) };
}
darnautov marked this conversation as resolved.
Show resolved Hide resolved
}),
position: 'left',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,36 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, FC } from 'react';
import React, { FC } from 'react';

import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { EuiCallOut, EuiCodeBlock, EuiSpacer } from '@elastic/eui';

import { FormMessage } from '../../hooks/use_create_analytics_form/state'; // State

interface Props {
messages: any; // TODO: fix --> something like State['requestMessages'];
messages: FormMessage[];
}

export const Messages: FC<Props> = ({ messages }) =>
messages.map((requestMessage: FormMessage, i: number) => (
<Fragment key={i}>
<EuiCallOut
title={requestMessage.message}
color={requestMessage.error !== undefined ? 'danger' : 'primary'}
iconType={requestMessage.error !== undefined ? 'alert' : 'checkInCircleFilled'}
size="s"
>
{requestMessage.error !== undefined ? <p>{requestMessage.error}</p> : null}
</EuiCallOut>
<EuiSpacer size="s" />
</Fragment>
));
export const Messages: FC<Props> = ({ messages }) => {
return (
<>
{messages.map((requestMessage, i) => (
<>
<EuiCallOut
title={requestMessage.message}
color={requestMessage.error !== undefined ? 'danger' : 'primary'}
iconType={requestMessage.error !== undefined ? 'alert' : 'checkInCircleFilled'}
size="s"
>
{requestMessage.error !== undefined && (
<EuiCodeBlock language="json" fontSize="s" paddingSize="s" isCopyable>
{requestMessage.error}
</EuiCodeBlock>
)}
</EuiCallOut>
<EuiSpacer size="s" />
</>
))}
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,25 @@ export interface CreateAnalyticsFormProps {
state: State;
}

interface ErrorResponse {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: do we have a generic interface for the error response?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added new ErrorResponse interface in d8926e2

body: {
statusCode: number;
error: string;
message: string;
};
name: string;
}

const isErrorResponse = (arg: any): arg is ErrorResponse => {
return arg?.body?.error !== undefined && arg?.body?.message !== undefined;
};

export function getErrorMessage(error: any) {
if (typeof error === 'object' && typeof error.message === 'string') {
return error.message;
if (isErrorResponse(error)) {
return `${error.body.error}: ${error.body.message}`;
} else {
return JSON.stringify(error, null, 2);
}

return JSON.stringify(error);
}

export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,22 @@ export class FileDataVisualizerView extends Component {
});
} catch (error) {
console.error(error);

let serverErrorMsg;
const isErrorResponse =
darnautov marked this conversation as resolved.
Show resolved Hide resolved
error?.body?.error !== undefined && error?.body?.message !== undefined;
if (isErrorResponse === true) {
serverErrorMsg = `${error.body.error}: ${error.body.message}`;
} else {
serverErrorMsg = JSON.stringify(error, null, 2);
}

this.setState({
results: undefined,
loaded: false,
loading: false,
fileCouldNotBeRead: true,
serverErrorMessage: error.message,
serverErrorMessage: serverErrorMsg,
});

// as long as the previous overrides are different to the current overrides,
Expand Down