Skip to content

Commit

Permalink
[ML] DF Analytics - ensure destination index pattern created (#62450) (
Browse files Browse the repository at this point in the history
…#62518)

* ensure destinationIndex name is defined

* set array for destIndex as invalid

* update type

* reset destIndex already exists error when updating advanced editor
  • Loading branch information
alvarezmelissa87 authored Apr 3, 2020
1 parent e1b2f32 commit 5e0d368
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/ml/common/util/es_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ function isValidIndexNameLength(indexName: string) {
// https://github.com/elastic/elasticsearch/blob/master/docs/reference/indices/create-index.asciidoc
export function isValidIndexName(indexName: string) {
return (
typeof indexName === 'string' &&
// Lowercase only
indexName === indexName.toLowerCase() &&
// Cannot include \, /, *, ?, ", <, >, |, space character, comma, #, :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,17 @@ export const validateAdvancedEditor = (state: State): State => {
),
message: '',
});
} else if (destinationIndexPatternTitleExists && !createIndexPattern) {
state.advancedEditorMessages.push({
error: i18n.translate(
'xpack.ml.dataframe.analytics.create.advancedEditorMessage.destinationIndexNameExistsWarn',
{
defaultMessage:
'An index with this destination index name already exists. Be aware that running this analytics job will modify this destination index.',
}
),
message: '',
});
} else if (!destinationIndexNameValid) {
state.advancedEditorMessages.push({
error: i18n.translate(
Expand Down Expand Up @@ -276,6 +287,8 @@ export const validateAdvancedEditor = (state: State): State => {
});
}

state.form.destinationIndexPatternTitleExists = destinationIndexPatternTitleExists;

state.isValid =
maxDistinctValuesError === undefined &&
excludesValid &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
const { refresh } = useRefreshAnalyticsList();

const { form, jobConfig, isAdvancedEditorEnabled } = state;
const { createIndexPattern, destinationIndex, jobId } = form;
const { createIndexPattern, jobId } = form;
let { destinationIndex } = form;

const addRequestMessage = (requestMessage: FormMessage) =>
dispatch({ type: ACTION.ADD_REQUEST_MESSAGE, requestMessage });
Expand Down Expand Up @@ -90,9 +91,13 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
resetRequestMessages();
setIsModalButtonDisabled(true);

const analyticsJobConfig = isAdvancedEditorEnabled
const analyticsJobConfig = (isAdvancedEditorEnabled
? jobConfig
: getJobConfigFromFormState(form);
: getJobConfigFromFormState(form)) as DataFrameAnalyticsConfig;

if (isAdvancedEditorEnabled) {
destinationIndex = analyticsJobConfig.dest.index;
}

try {
await ml.dataFrameAnalytics.createDataFrameAnalytics(jobId, analyticsJobConfig);
Expand Down

0 comments on commit 5e0d368

Please sign in to comment.