Skip to content

Commit

Permalink
[ML] Fixes to error handling for analytics jobs and file data viz
Browse files Browse the repository at this point in the history
  • Loading branch information
peteharverson committed Mar 16, 2020
1 parent 746e236 commit 7d4eb54
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 28 deletions.
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]) };
}
}),
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 {
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 =
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

0 comments on commit 7d4eb54

Please sign in to comment.