From 873529a044e56b2600d279c50c155d47036d97df Mon Sep 17 00:00:00 2001 From: Melissa Alvarez Date: Tue, 3 Dec 2019 08:42:52 -0700 Subject: [PATCH] [ML] DF Analytics: use new _explain endpoint to estimate model memory limit (#51644) * update analytics job creation to use _explain api endpoint for modelMemoryLimit estimate * debounce modelMemoryLimit estimation fetch --- .../create_analytics_form/create_analytics_form.tsx | 13 +++++++++---- .../services/ml_api_service/data_frame_analytics.js | 2 +- .../plugins/ml/server/client/elasticsearch_ml.js | 2 +- .../ml/server/routes/data_frame_analytics.js | 2 +- 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx b/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx index 47af274424c44..9cbdc457e75ca 100644 --- a/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx +++ b/x-pack/legacy/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/create_analytics_form/create_analytics_form.tsx @@ -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'; @@ -111,14 +112,14 @@ export const CreateAnalyticsForm: FC = ({ 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({ @@ -128,7 +129,7 @@ export const CreateAnalyticsForm: FC = ({ actions, sta : DEFAULT_MODEL_MEMORY_LIMIT.outlier_detection, }); } - }; + }, 500); const loadDependentFieldOptions = async () => { setFormState({ @@ -213,8 +214,12 @@ export const CreateAnalyticsForm: FC = ({ actions, sta jobType === JOB_TYPES.OUTLIER_DETECTION; if (hasBasicRequiredFields && hasRequiredAnalysisFields) { - loadModelMemoryLimitEstimate(); + debouncedMmlEstimateLoad(); } + + return () => { + debouncedMmlEstimateLoad.cancel(); + }; }, [jobType, sourceIndex, dependentVariable, trainingPercent]); return ( diff --git a/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.js b/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.js index d29793366b9a2..a973950037347 100644 --- a/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.js +++ b/x-pack/legacy/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.js @@ -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 }); diff --git a/x-pack/legacy/plugins/ml/server/client/elasticsearch_ml.js b/x-pack/legacy/plugins/ml/server/client/elasticsearch_ml.js index 3df1d3e2c3bd0..2922bb9ebea01 100644 --- a/x-pack/legacy/plugins/ml/server/client/elasticsearch_ml.js +++ b/x-pack/legacy/plugins/ml/server/client/elasticsearch_ml.js @@ -173,7 +173,7 @@ export const elasticsearchJsPlugin = (Client, config, components) => { ml.estimateDataFrameAnalyticsMemoryUsage = ca({ urls: [ { - fmt: '/_ml/data_frame/analytics/_estimate_memory_usage', + fmt: '/_ml/data_frame/analytics/_explain', } ], needBody: true, diff --git a/x-pack/legacy/plugins/ml/server/routes/data_frame_analytics.js b/x-pack/legacy/plugins/ml/server/routes/data_frame_analytics.js index d467aeea31f99..5c4fc909cda05 100644 --- a/x-pack/legacy/plugins/ml/server/routes/data_frame_analytics.js +++ b/x-pack/legacy/plugins/ml/server/routes/data_frame_analytics.js @@ -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 })