Skip to content

Commit

Permalink
ensure excludes cloned correctly and update clone action jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarezmelissa87 committed Jun 9, 2020
1 parent 9892e43 commit 48f6804
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export const MemoizedAnalysisFieldsTable: FC<{
if (excludes.length > 0) {
setCurrentSelection(excludes);
}
}, []);
}, [tableItems]);

// Only set form state on unmount to prevent re-renders due to props changing if exludes was updated on each selection
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,12 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
modelMemoryLimit,
previousJobType,
requiredFieldsError,
sourceIndex,
trainingPercent,
} = form;

const toastNotifications = getToastNotifications();

const setJobConfigQuery = ({ query, queryString }: { query: any; queryString: string }) => {
setFormState({ jobConfigQuery: query, jobConfigQueryString: queryString });
};
Expand All @@ -90,7 +93,7 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
const indexPreviewProps = {
...indexData,
dataTestSubj: 'mlAnalyticsCreationDataGrid',
toastNotifications: getToastNotifications(),
toastNotifications,
};

const isJobTypeWithDepVar =
Expand Down Expand Up @@ -209,7 +212,8 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
});
}
} catch (e) {
let errorMessage;
let maxDistinctValuesErrorMessage;

if (
jobType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION &&
e.body &&
Expand All @@ -218,7 +222,23 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
(e.body.message.includes('must have at most') ||
e.body.message.includes('must have at least'))
) {
errorMessage = e.body.message;
maxDistinctValuesErrorMessage = e.body.message;
}

if (
e.body &&
e.body.message !== undefined &&
e.body.message.includes('status_exception') &&
e.body.message.includes('Unable to estimate memory usage as no documents')
) {
toastNotifications.addWarning(
i18n.translate('xpack.ml.dataframe.analytics.create.allDocsMissingFieldsErrorMessage', {
defaultMessage: `Unable to estimate memory usage. There are mapped fields for source index [{index}] that do not exist in any indexed documents. You will have to switch to the JSON editor for explicit field selection and include only fields that exist in indexed documents.`,
values: {
index: sourceIndex,
},
})
);
}
const fallbackModelMemoryLimit =
jobType !== undefined
Expand All @@ -227,7 +247,7 @@ export const ConfigurationStepForm: FC<CreateAnalyticsStepProps> = ({
setEstimatedModelMemoryLimit(fallbackModelMemoryLimit);
setFormState({
fieldOptionsFetchFail: true,
maxDistinctValuesError: errorMessage,
maxDistinctValuesError: maxDistinctValuesErrorMessage,
loadingFieldOptions: false,
...(shouldUpdateModelMemoryLimit ? { modelMemoryLimit: fallbackModelMemoryLimit } : {}),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ export const CreateAnalyticsAdvancedEditor: FC<CreateAnalyticsFormProps> = (prop
onChange={onChange}
setOptions={{
fontSize: '12px',
maxLines: 20,
}}
theme="textmate"
aria-label={i18n.translate(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,19 @@ export const Page: FC<Props> = ({ jobId }) => {
<EuiFlexItem grow={false}>
<EuiTitle size="m">
<h1>
<FormattedMessage
id="xpack.ml.dataframe.analytics.creationPageTitle"
defaultMessage="Create analytics job"
/>
{jobId === undefined && (
<FormattedMessage
id="xpack.ml.dataframe.analytics.creationPageTitle"
defaultMessage="Create analytics job"
/>
)}
{jobId !== undefined && (
<FormattedMessage
id="xpack.ml.dataframe.analytics.clone.creationPageTitle"
defaultMessage="Clone analytics job from {jobId}"
values={{ jobId }}
/>
)}
</h1>
</EuiTitle>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ describe('Analytics job clone action', () => {
expect(isAdvancedConfig(advancedClassificationJob)).toBe(true);
});

test('should detect advanced outlier_detection job', () => {
const advancedOutlierDetectionJob = {
test('should detect advanced regression job', () => {
const advancedRegressionJob = {
description: "Outlier detection job with 'glass' dataset",
source: {
index: ['glass_withoutdupl_norm'],
Expand All @@ -155,10 +155,8 @@ describe('Analytics job clone action', () => {
results_field: 'ml',
},
analysis: {
outlier_detection: {
compute_feature_influence: false,
outlier_fraction: 0.05,
standardization_enabled: true,
regression: {
loss_function: 'msle',
},
},
analyzed_fields: {
Expand All @@ -168,7 +166,7 @@ describe('Analytics job clone action', () => {
model_memory_limit: '1mb',
allow_lazy_start: false,
};
expect(isAdvancedConfig(advancedOutlierDetectionJob)).toBe(true);
expect(isAdvancedConfig(advancedRegressionJob)).toBe(true);
});

test('should detect a custom query', () => {
Expand Down Expand Up @@ -207,32 +205,6 @@ describe('Analytics job clone action', () => {
expect(isAdvancedConfig(advancedRegressionJob)).toBe(true);
});

test('should detect custom analysis settings', () => {
const config = {
description: "Classification clone with 'bank-marketing' dataset",
source: {
index: 'bank-marketing',
},
dest: {
index: 'bank_classification4',
},
analyzed_fields: {
excludes: [],
},
analysis: {
classification: {
dependent_variable: 'y',
training_percent: 71,
max_trees: 1500,
num_top_feature_importance_values: 4,
},
},
model_memory_limit: '400mb',
};

expect(isAdvancedConfig(config)).toBe(true);
});

test('should detect as advanced if the prop is unknown', () => {
const config = {
description: "Classification clone with 'bank-marketing' dataset",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const getAnalyticsJobMeta = (config: CloneDataFrameAnalyticsConfig): AnalyticsJo
standardization_enabled: {
defaultValue: true,
optional: true,
formKey: 'standardizationEnabled',
},
compute_feature_influence: {
defaultValue: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ export const useCreateAnalyticsForm = (): CreateAnalyticsFormProps => {
};

const setJobClone = async (cloneJob: DeepReadonly<DataFrameAnalyticsConfig>) => {
// resetForm();
resetForm();
const config = extractCloningConfig(cloneJob);
if (isAdvancedConfig(config)) {
setJobConfig(config);
Expand Down

0 comments on commit 48f6804

Please sign in to comment.