Skip to content

Commit

Permalink
[ML] DF Analytics creation and update: adds max_num_threads (elasti…
Browse files Browse the repository at this point in the history
…c#71318)

* add max_num_threads to edit flyout

* add maxNumThreads setting to job wizard

* add maxNumThreads to cloning
  • Loading branch information
alvarezmelissa87 committed Jul 13, 2020
1 parent e02bbe4 commit 6b691b4
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ export interface UpdateDataFrameAnalyticsConfig {
allow_lazy_start?: string;
description?: string;
model_memory_limit?: string;
max_num_threads?: number;
}

export interface DataFrameAnalyticsConfig {
Expand All @@ -358,6 +359,7 @@ export interface DataFrameAnalyticsConfig {
excludes: string[];
};
model_memory_limit: string;
max_num_threads?: number;
create_time: number;
version: string;
allow_lazy_start?: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const AdvancedStepDetails: FC<{ setCurrentStep: any; state: State }> = ({
jobType,
lambda,
method,
maxNumThreads,
maxTrees,
modelMemoryLimit,
nNeighbors,
Expand Down Expand Up @@ -214,6 +215,15 @@ export const AdvancedStepDetails: FC<{ setCurrentStep: any; state: State }> = ({
);
}

if (maxNumThreads !== undefined) {
advancedFirstCol.push({
title: i18n.translate('xpack.ml.dataframe.analytics.create.configDetails.maxNumThreads', {
defaultMessage: 'Maximum number of threads',
}),
description: `${maxNumThreads}`,
});
}

return (
<Fragment>
<EuiTitle size="xs">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
EuiAccordion,
EuiFieldNumber,
EuiFieldText,
EuiFlexGroup,
EuiFlexGrid,
EuiFlexItem,
EuiFormRow,
EuiSelect,
Expand Down Expand Up @@ -57,6 +57,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
gamma,
jobType,
lambda,
maxNumThreads,
maxTrees,
method,
modelMemoryLimit,
Expand All @@ -82,7 +83,8 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
const isStepInvalid =
mmlInvalid ||
Object.keys(advancedParamErrors).length > 0 ||
fetchingAdvancedParamErrors === true;
fetchingAdvancedParamErrors === true ||
maxNumThreads === 0;

useEffect(() => {
setFetchingAdvancedParamErrors(true);
Expand Down Expand Up @@ -112,6 +114,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
featureInfluenceThreshold,
gamma,
lambda,
maxNumThreads,
maxTrees,
method,
nNeighbors,
Expand All @@ -123,7 +126,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({

const outlierDetectionAdvancedConfig = (
<Fragment>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate(
'xpack.ml.dataframe.analytics.create.computeFeatureInfluenceLabel',
Expand Down Expand Up @@ -171,7 +174,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate(
'xpack.ml.dataframe.analytics.create.featureInfluenceThresholdLabel',
Expand Down Expand Up @@ -210,7 +213,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({

const regAndClassAdvancedConfig = (
<Fragment>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate(
'xpack.ml.dataframe.analytics.create.numTopFeatureImportanceValuesLabel',
Expand Down Expand Up @@ -261,7 +264,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.predictionFieldNameLabel', {
defaultMessage: 'Prediction field name',
Expand Down Expand Up @@ -294,11 +297,11 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
})}
</h3>
</EuiTitle>
<EuiFlexGroup wrap>
<EuiFlexGrid columns={3}>
{jobType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && outlierDetectionAdvancedConfig}
{isRegOrClassJob && regAndClassAdvancedConfig}
{jobType === ANALYSIS_CONFIG_TYPE.CLASSIFICATION && (
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.numTopClassesLabel', {
defaultMessage: 'Top classes',
Expand Down Expand Up @@ -332,7 +335,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
</EuiFormRow>
</EuiFlexItem>
)}
<EuiFlexItem style={{ width: '30%', minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.modelMemoryLimitLabel', {
defaultMessage: 'Model memory limit',
Expand Down Expand Up @@ -361,7 +364,43 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.maxNumThreadsLabel', {
defaultMessage: 'Maximum number of threads',
})}
helpText={i18n.translate('xpack.ml.dataframe.analytics.create.maxNumThreadsHelpText', {
defaultMessage:
'The maximum number of threads to be used by the analysis. The default value is 1',
})}
isInvalid={maxNumThreads === 0}
error={
maxNumThreads === 0 &&
i18n.translate('xpack.ml.dataframe.analytics.create.maxNumThreadsError', {
defaultMessage: 'The minimum value is 1.',
})
}
>
<EuiFieldNumber
aria-label={i18n.translate(
'xpack.ml.dataframe.analytics.create.maxNumThreadsInputAriaLabel',
{
defaultMessage: 'The maximum number of threads to be used by the analysis.',
}
)}
data-test-subj="mlAnalyticsCreateJobWizardMaxNumThreadsInput"
min={1}
onChange={(e) =>
setFormState({
maxNumThreads: e.target.value === '' ? undefined : +e.target.value,
})
}
step={1}
value={getNumberValue(maxNumThreads)}
/>
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGrid>
<EuiSpacer />
<EuiAccordion
id="hyper-parameters"
Expand All @@ -377,7 +416,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
initialIsOpen={false}
data-test-subj="mlAnalyticsCreateJobWizardHyperParametersSection"
>
<EuiFlexGroup wrap>
<EuiFlexGrid columns={3}>
{jobType === ANALYSIS_CONFIG_TYPE.OUTLIER_DETECTION && (
<OutlierHyperParameters
actions={actions}
Expand All @@ -392,7 +431,7 @@ export const AdvancedStepForm: FC<CreateAnalyticsStepProps> = ({
advancedParamErrors={advancedParamErrors}
/>
)}
</EuiFlexGroup>
</EuiFlexGrid>
</EuiAccordion>
<EuiSpacer />
<ContinueButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const HyperParameters: FC<Props> = ({ actions, state, advancedParamErrors

return (
<Fragment>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.lambdaLabel', {
defaultMessage: 'Lambda',
Expand All @@ -51,7 +51,7 @@ export const HyperParameters: FC<Props> = ({ actions, state, advancedParamErrors
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.maxTreesLabel', {
defaultMessage: 'Max trees',
Expand Down Expand Up @@ -81,7 +81,7 @@ export const HyperParameters: FC<Props> = ({ actions, state, advancedParamErrors
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.gammaLabel', {
defaultMessage: 'Gamma',
Expand All @@ -108,7 +108,7 @@ export const HyperParameters: FC<Props> = ({ actions, state, advancedParamErrors
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.etaLabel', {
defaultMessage: 'Eta',
Expand All @@ -134,7 +134,7 @@ export const HyperParameters: FC<Props> = ({ actions, state, advancedParamErrors
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.featureBagFractionLabel', {
defaultMessage: 'Feature bag fraction',
Expand Down Expand Up @@ -172,7 +172,7 @@ export const HyperParameters: FC<Props> = ({ actions, state, advancedParamErrors
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.randomizeSeedLabel', {
defaultMessage: 'Randomize seed',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const OutlierHyperParameters: FC<Props> = ({ actions, state, advancedPara

return (
<Fragment>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.methodLabel', {
defaultMessage: 'Method',
Expand All @@ -48,7 +48,7 @@ export const OutlierHyperParameters: FC<Props> = ({ actions, state, advancedPara
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.nNeighborsLabel', {
defaultMessage: 'N neighbors',
Expand Down Expand Up @@ -78,7 +78,7 @@ export const OutlierHyperParameters: FC<Props> = ({ actions, state, advancedPara
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.outlierFractionLabel', {
defaultMessage: 'Outlier fraction',
Expand Down Expand Up @@ -109,7 +109,7 @@ export const OutlierHyperParameters: FC<Props> = ({ actions, state, advancedPara
/>
</EuiFormRow>
</EuiFlexItem>
<EuiFlexItem style={{ minWidth: '30%' }}>
<EuiFlexItem>
<EuiFormRow
label={i18n.translate('xpack.ml.dataframe.analytics.create.standardizationEnabledLabel', {
defaultMessage: 'Standardization enabled',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ const getAnalyticsJobMeta = (config: CloneDataFrameAnalyticsConfig): AnalyticsJo
optional: true,
formKey: 'modelMemoryLimit',
},
max_num_threads: {
optional: true,
formKey: 'maxNumThreads',
},
});

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { i18n } from '@kbn/i18n';
import {
EuiButton,
EuiButtonEmpty,
EuiFieldNumber,
EuiFieldText,
EuiFlexGroup,
EuiFlexItem,
Expand Down Expand Up @@ -52,14 +53,15 @@ export const EditButtonFlyout: FC<Required<EditAction>> = ({ closeFlyout, item }
const [description, setDescription] = useState<string>(config.description || '');
const [modelMemoryLimit, setModelMemoryLimit] = useState<string>(config.model_memory_limit);
const [mmlValidationError, setMmlValidationError] = useState<string | undefined>();
const [maxNumThreads, setMaxNumThreads] = useState<number | undefined>(config.max_num_threads);

const {
services: { notifications },
} = useMlKibana();
const { refresh } = useRefreshAnalyticsList();

// Disable if mml is not valid
const updateButtonDisabled = mmlValidationError !== undefined;
const updateButtonDisabled = mmlValidationError !== undefined || maxNumThreads === 0;

useEffect(() => {
if (mmLValidator === undefined) {
Expand Down Expand Up @@ -93,7 +95,8 @@ export const EditButtonFlyout: FC<Required<EditAction>> = ({ closeFlyout, item }
allow_lazy_start: allowLazyStart,
description,
},
modelMemoryLimit && { model_memory_limit: modelMemoryLimit }
modelMemoryLimit && { model_memory_limit: modelMemoryLimit },
maxNumThreads && { max_num_threads: maxNumThreads }
);

try {
Expand Down Expand Up @@ -210,7 +213,7 @@ export const EditButtonFlyout: FC<Required<EditAction>> = ({ closeFlyout, item }
helpText={
state !== DATA_FRAME_TASK_STATE.STOPPED &&
i18n.translate('xpack.ml.dataframe.analyticsList.editFlyout.modelMemoryHelpText', {
defaultMessage: 'Model memory limit cannot be edited while the job is running.',
defaultMessage: 'Model memory limit cannot be edited until the job has stopped.',
})
}
label={i18n.translate(
Expand All @@ -236,6 +239,49 @@ export const EditButtonFlyout: FC<Required<EditAction>> = ({ closeFlyout, item }
)}
/>
</EuiFormRow>
<EuiFormRow
helpText={
state !== DATA_FRAME_TASK_STATE.STOPPED &&
i18n.translate(
'xpack.ml.dataframe.analyticsList.editFlyout.maxNumThreadsHelpText',
{
defaultMessage:
'Maximum number of threads cannot be edited until the job has stopped.',
}
)
}
label={i18n.translate(
'xpack.ml.dataframe.analyticsList.editFlyout.maxNumThreadsLabel',
{
defaultMessage: 'Maximum number of threads',
}
)}
isInvalid={maxNumThreads === 0}
error={
maxNumThreads === 0 &&
i18n.translate('xpack.ml.dataframe.analyticsList.editFlyout.maxNumThreadsError', {
defaultMessage: 'The minimum value is 1.',
})
}
>
<EuiFieldNumber
aria-label={i18n.translate(
'xpack.ml.dataframe.analyticsList.editFlyout.maxNumThreadsAriaLabel',
{
defaultMessage:
'Update the maximum number of threads to be used by the analysis.',
}
)}
data-test-subj="mlAnalyticsEditFlyoutMaxNumThreadsLimitInput"
onChange={(e) =>
setMaxNumThreads(e.target.value === '' ? undefined : +e.target.value)
}
step={1}
min={1}
readOnly={state !== DATA_FRAME_TASK_STATE.STOPPED}
value={maxNumThreads}
/>
</EuiFormRow>
</EuiForm>
</EuiFlyoutBody>
<EuiFlyoutFooter>
Expand Down
Loading

0 comments on commit 6b691b4

Please sign in to comment.