[ML] Better error reporting when parsing JSON in file dataviz (#29123) (#29160)

* [ML] Better error reporting when parsing JSON in file dataviz

* first step depends on json parsing
This commit is contained in:
James Gowdy 2019-01-24 10:44:49 +00:00 committed by GitHub
parent 41f5fbe721
commit 8f06f7bcce
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 26 deletions

View file

@ -41,6 +41,13 @@ function title(statuses) {
defaultMessage="Error reading file"
/>
);
case statuses.parseJSONStatus:
return (
<FormattedMessage
id="xpack.ml.fileDatavisualizer.importErrors.parsingJSONErrorMessage"
defaultMessage="Error parsing JSON"
/>
);
case statuses.indexCreatedStatus:
return (
<FormattedMessage

View file

@ -24,6 +24,7 @@ export const ImportProgress = injectI18n(function ({ statuses, intl }) {
const {
reading,
readStatus,
parseJSONStatus,
indexCreatedStatus,
ingestPipelineCreatedStatus,
indexPatternCreatedStatus,
@ -37,7 +38,11 @@ export const ImportProgress = injectI18n(function ({ statuses, intl }) {
let completedStep = 0;
if (reading === true && readStatus === IMPORT_STATUS.INCOMPLETE) {
if (
reading === true &&
readStatus === IMPORT_STATUS.INCOMPLETE &&
parseJSONStatus === IMPORT_STATUS.INCOMPLETE
) {
completedStep = 0;
}
if (
@ -183,8 +188,8 @@ export const ImportProgress = injectI18n(function ({ statuses, intl }) {
{
title: processFileTitle,
isSelected: true,
isComplete: (readStatus === IMPORT_STATUS.COMPLETE),
status: readStatus,
isComplete: (readStatus === IMPORT_STATUS.COMPLETE && parseJSONStatus === IMPORT_STATUS.COMPLETE),
status: (parseJSONStatus === IMPORT_STATUS.FAILED) ? parseJSONStatus : readStatus, // if JSON parsing failed, fail the first step
onClick: () => {},
},
{

View file

@ -40,6 +40,7 @@ const DEFAULT_STATE = {
reading: false,
readProgress: 0,
readStatus: IMPORT_STATUS.INCOMPLETE,
parseJSONStatus: IMPORT_STATUS.INCOMPLETE,
indexCreatedStatus: IMPORT_STATUS.INCOMPLETE,
indexPatternCreatedStatus: IMPORT_STATUS.INCOMPLETE,
ingestPipelineCreatedStatus: IMPORT_STATUS.INCOMPLETE,
@ -142,34 +143,62 @@ export class ImportView extends Component {
}, () => {
this.props.hideBottomBar();
setTimeout(async () => {
let success = false;
let success = true;
const createPipeline = (pipelineString !== '');
let indexCreationSettings = {};
let settings = {};
let mappings = {};
let pipeline = {};
try {
const settings = JSON.parse(indexSettingsString);
const mappings = JSON.parse(mappingsString);
indexCreationSettings = {
settings,
mappings,
};
if (createPipeline) {
indexCreationSettings.pipeline = JSON.parse(pipelineString);
}
// if an @timestamp field has been added to the
// mappings, use this field as the time field.
// This relies on the field being populated by
// the ingest pipeline on ingest
if (mappings[DEFAULT_TIME_FIELD] !== undefined) {
timeFieldName = DEFAULT_TIME_FIELD;
this.setState({ timeFieldName });
}
success = true;
settings = JSON.parse(indexSettingsString);
} catch (error) {
success = false;
errors.push(error);
const parseError = i18n.translate('xpack.ml.fileDatavisualizer.importView.parseSettingsError', {
defaultMessage: 'Error parsing settings:'
});
errors.push(`${parseError} ${error.message}`);
}
try {
mappings = JSON.parse(mappingsString);
} catch (error) {
success = false;
const parseError = i18n.translate('xpack.ml.fileDatavisualizer.importView.parseMappingsError', {
defaultMessage: 'Error parsing mappings:'
});
errors.push(`${parseError} ${error.message}`);
}
const indexCreationSettings = {
settings,
mappings,
};
try {
if (createPipeline) {
pipeline = JSON.parse(pipelineString);
indexCreationSettings.pipeline = pipeline;
}
} catch (error) {
success = false;
const parseError = i18n.translate('xpack.ml.fileDatavisualizer.importView.parsePipelineError', {
defaultMessage: 'Error parsing ingest pipeline:'
});
errors.push(`${parseError} ${error.message}`);
}
this.setState({
parseJSONStatus: success ? IMPORT_STATUS.COMPLETE : IMPORT_STATUS.FAILED,
});
// if an @timestamp field has been added to the
// mappings, use this field as the time field.
// This relies on the field being populated by
// the ingest pipeline on ingest
if (mappings[DEFAULT_TIME_FIELD] !== undefined) {
timeFieldName = DEFAULT_TIME_FIELD;
this.setState({ timeFieldName });
}
if (success) {
@ -345,6 +374,7 @@ export class ImportView extends Component {
reading,
initialized,
readStatus,
parseJSONStatus,
indexCreatedStatus,
ingestPipelineCreatedStatus,
indexPatternCreatedStatus,
@ -368,6 +398,7 @@ export class ImportView extends Component {
const statuses = {
reading,
readStatus,
parseJSONStatus,
indexCreatedStatus,
ingestPipelineCreatedStatus,
indexPatternCreatedStatus,