Skip to content

Commit

Permalink
[ML] DF Analytics: use new _explain endpoint to estimate model memory…
Browse files Browse the repository at this point in the history
… limit (elastic#51644)

* update analytics job creation to use _explain api endpoint for modelMemoryLimit estimate

* debounce modelMemoryLimit estimation fetch
  • Loading branch information
alvarezmelissa87 committed Dec 3, 2019
1 parent b5b24da commit 25005b6
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
EuiRange,
EuiSwitch,
} from '@elastic/eui';
import { debounce } from 'lodash';

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
Expand Down Expand Up @@ -111,14 +112,14 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
}
};

const loadModelMemoryLimitEstimate = async () => {
const debouncedMmlEstimateLoad = debounce(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,
modelMemoryLimit: resp.memory_estimation?.expected_memory_without_disk,
});
} catch (e) {
setFormState({
Expand All @@ -128,7 +129,7 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
: DEFAULT_MODEL_MEMORY_LIMIT.outlier_detection,
});
}
};
}, 500);

const loadDependentFieldOptions = async () => {
setFormState({
Expand Down Expand Up @@ -213,8 +214,12 @@ export const CreateAnalyticsForm: FC<CreateAnalyticsFormProps> = ({ actions, sta
jobType === JOB_TYPES.OUTLIER_DETECTION;

if (hasBasicRequiredFields && hasRequiredAnalysisFields) {
loadModelMemoryLimitEstimate();
debouncedMmlEstimateLoad();
}

return () => {
debouncedMmlEstimateLoad.cancel();
};
}, [jobType, sourceIndex, dependentVariable, trainingPercent]);

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export const dataFrameAnalytics = {
},
estimateDataFrameAnalyticsMemoryUsage(jobConfig) {
return http({
url: `${basePath}/data_frame/analytics/_estimate_memory_usage`,
url: `${basePath}/data_frame/analytics/_explain`,
method: 'POST',
data: jobConfig
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/legacy/plugins/ml/server/client/elasticsearch_ml.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const elasticsearchJsPlugin = (Client, config, components) => { // eslint
ml.estimateDataFrameAnalyticsMemoryUsage = ca({
urls: [
{
fmt: '/_ml/data_frame/analytics/_estimate_memory_usage',
fmt: '/_ml/data_frame/analytics/_explain',
}
],
needBody: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function dataFrameAnalyticsRoutes({ commonRouteConfig, elasticsearchPlugi

route({
method: 'POST',
path: '/api/ml/data_frame/analytics/_estimate_memory_usage',
path: '/api/ml/data_frame/analytics/_explain',
handler(request) {
const callWithRequest = callWithRequestFactory(elasticsearchPlugin, request);
return callWithRequest('ml.estimateDataFrameAnalyticsMemoryUsage', { body: request.payload })
Expand Down

0 comments on commit 25005b6

Please sign in to comment.