-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ML] DF Analytics - auto-populate model_memory_limit #50714
Merged
alvarezmelissa87
merged 8 commits into
elastic:master
from
alvarezmelissa87:ml-regression-config-mmlimit
Nov 18, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b25cab8
create modelMemoryLimit estimation endpoint. add value to form
alvarezmelissa87 f5e80e8
add validation for model memory limit field
alvarezmelissa87 c8877e9
update jest tests
alvarezmelissa87 f13927f
update validateModelMemoryLimitUnitsUtils to be more generic
alvarezmelissa87 211762d
add placeholder and validation with helpText to modelMemoryLimit field
alvarezmelissa87 74133c7
update endpoint name to estimateDataFrameAnalyticsMemoryUsage for cla…
alvarezmelissa87 0c4f7d8
tweak modelMemoryLimitEmpty check in reducer
alvarezmelissa87 94598c4
add tests for modelMemoryLimit validation
alvarezmelissa87 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,15 +21,21 @@ import { FormattedMessage } from '@kbn/i18n/react'; | |
|
||
import { metadata } from 'ui/metadata'; | ||
import { IndexPattern, INDEX_PATTERN_ILLEGAL_CHARACTERS } from 'ui/index_patterns'; | ||
import { ml } from '../../../../../services/ml_api_service'; | ||
import { Field, EVENT_RATE_FIELD_ID } from '../../../../../../common/types/fields'; | ||
|
||
import { newJobCapsService } from '../../../../../services/new_job_capabilities_service'; | ||
import { useKibanaContext } from '../../../../../contexts/kibana'; | ||
import { CreateAnalyticsFormProps } from '../../hooks/use_create_analytics_form'; | ||
import { JOB_TYPES } from '../../hooks/use_create_analytics_form/state'; | ||
import { | ||
JOB_TYPES, | ||
DEFAULT_MODEL_MEMORY_LIMIT, | ||
getJobConfigFromFormState, | ||
} from '../../hooks/use_create_analytics_form/state'; | ||
import { JOB_ID_MAX_LENGTH } from '../../../../../../common/constants/validation'; | ||
import { Messages } from './messages'; | ||
import { JobType } from './job_type'; | ||
import { mmlUnitInvalidErrorMessage } from '../../hooks/use_create_analytics_form/reducer'; | ||
|
||
// based on code used by `ui/index_patterns` internally | ||
// remove the space character from the list of illegal characters | ||
|
@@ -73,6 +79,8 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta | |
jobIdInvalidMaxLength, | ||
jobType, | ||
loadingDepFieldOptions, | ||
modelMemoryLimit, | ||
modelMemoryLimitUnitValid, | ||
sourceIndex, | ||
sourceIndexNameEmpty, | ||
sourceIndexNameValid, | ||
|
@@ -103,6 +111,25 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta | |
} | ||
}; | ||
|
||
const loadModelMemoryLimitEstimate = async () => { | ||
try { | ||
const jobConfig = getJobConfigFromFormState(form); | ||
delete jobConfig.dest; | ||
delete jobConfig.model_memory_limit; | ||
const resp = await ml.dataFrameAnalytics.estimateDataFrameAnalyticsMemoryUsage(jobConfig); | ||
setFormState({ | ||
modelMemoryLimit: resp.expected_memory_without_disk, | ||
}); | ||
} catch (e) { | ||
setFormState({ | ||
modelMemoryLimit: | ||
jobType !== undefined | ||
? DEFAULT_MODEL_MEMORY_LIMIT[jobType] | ||
: DEFAULT_MODEL_MEMORY_LIMIT.outlier_detection, | ||
}); | ||
} | ||
}; | ||
|
||
const loadDependentFieldOptions = async () => { | ||
setFormState({ | ||
loadingDepFieldOptions: true, | ||
|
@@ -175,6 +202,21 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta | |
} | ||
}, [sourceIndex, jobType, sourceIndexNameEmpty]); | ||
|
||
useEffect(() => { | ||
const hasBasicRequiredFields = | ||
jobType !== undefined && sourceIndex !== '' && sourceIndexNameValid === true; | ||
|
||
const hasRequiredAnalysisFields = | ||
(jobType === JOB_TYPES.REGRESSION && | ||
dependentVariable !== '' && | ||
trainingPercent !== undefined) || | ||
jobType === JOB_TYPES.OUTLIER_DETECTION; | ||
|
||
if (hasBasicRequiredFields && hasRequiredAnalysisFields) { | ||
loadModelMemoryLimitEstimate(); | ||
} | ||
}, [jobType, sourceIndex, dependentVariable, trainingPercent]); | ||
|
||
return ( | ||
<EuiForm className="mlDataFrameAnalyticsCreateForm"> | ||
<Messages messages={requestMessages} /> | ||
|
@@ -277,7 +319,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta | |
placeholder={i18n.translate( | ||
'xpack.ml.dataframe.analytics.create.sourceIndexPlaceholder', | ||
{ | ||
defaultMessage: 'Choose a source index pattern or saved search.', | ||
defaultMessage: 'Choose a source index pattern.', | ||
} | ||
)} | ||
singleSelection={{ asPlainText: true }} | ||
|
@@ -437,6 +479,24 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta | |
</EuiFormRow> | ||
</Fragment> | ||
)} | ||
<EuiFormRow | ||
label={i18n.translate('xpack.ml.dataframe.analytics.create.modelMemoryLimitLabel', { | ||
defaultMessage: 'Model memory limit', | ||
})} | ||
helpText={!modelMemoryLimitUnitValid && mmlUnitInvalidErrorMessage} | ||
> | ||
<EuiFieldText | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Placeholder added: f8c50cfe758da1782208983286bf40e4fc06af1f |
||
placeholder={ | ||
jobType !== undefined | ||
? DEFAULT_MODEL_MEMORY_LIMIT[jobType] | ||
: DEFAULT_MODEL_MEMORY_LIMIT.outlier_detection | ||
} | ||
disabled={isJobCreated} | ||
value={modelMemoryLimit || ''} | ||
onChange={e => setFormState({ modelMemoryLimit: e.target.value })} | ||
isInvalid={modelMemoryLimit === ''} | ||
peteharverson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</EuiFormRow> | ||
<EuiFormRow | ||
isInvalid={createIndexPattern && destinationIndexPatternTitleExists} | ||
error={ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it can be
const { dest, ...jobConfig} = getJobConfigFromFormState(form);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a look! 😄
I think that's a good option if mutability is a concern, but in this case
jobConfig
isn't relied on for anything else. I think in this case I prefer clarity of semantics and functionality by explicitly usingdelete
.Unless I'm missing some other benefit that this has over using
delete
🤔cc @darnautov