From 3002108c401cfdf382b099a724bec9b305457c76 Mon Sep 17 00:00:00 2001 From: Dima Arnautov Date: Tue, 6 Oct 2020 19:31:59 +0200 Subject: [PATCH] [ML] rename inference to trained_models (#79676) --- .../types/{inference.ts => trained_models.ts} | 4 +- .../common/use_results_view_config.ts | 6 +- .../models_management/delete_models_modal.tsx | 8 +-- .../models_management/expanded_row.tsx | 26 ++++----- .../models_management/models_list.tsx | 58 +++++++++---------- .../{inference.ts => trained_models.ts} | 32 +++++----- .../data_frame_analytics/models_provider.ts | 2 +- x-pack/plugins/ml/server/plugin.ts | 4 +- .../{inference.ts => trained_models.ts} | 20 +++---- 9 files changed, 80 insertions(+), 80 deletions(-) rename x-pack/plugins/ml/common/types/{inference.ts => trained_models.ts} (95%) rename x-pack/plugins/ml/public/application/services/ml_api_service/{inference.ts => trained_models.ts} (73%) rename x-pack/plugins/ml/server/routes/{inference.ts => trained_models.ts} (85%) diff --git a/x-pack/plugins/ml/common/types/inference.ts b/x-pack/plugins/ml/common/types/trained_models.ts similarity index 95% rename from x-pack/plugins/ml/common/types/inference.ts rename to x-pack/plugins/ml/common/types/trained_models.ts index ce2cfb1f78fd..35425e74759d 100644 --- a/x-pack/plugins/ml/common/types/inference.ts +++ b/x-pack/plugins/ml/common/types/trained_models.ts @@ -44,7 +44,7 @@ export interface TrainedModelStat { }; } -export interface ModelConfigResponse { +export interface TrainedModelConfigResponse { created_by: string; create_time: string; default_field_map: Record; @@ -79,5 +79,5 @@ export interface ModelPipelines { * Get inference response from the ES endpoint */ export interface InferenceConfigResponse { - trained_model_configs: ModelConfigResponse[]; + trained_model_configs: TrainedModelConfigResponse[]; } diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts index 50be009d288f..7d2ca86a3808 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/common/use_results_view_config.ts @@ -19,7 +19,7 @@ import { DataFrameAnalyticsConfig } from '../common'; import { isGetDataFrameAnalyticsStatsResponseOk } from '../pages/analytics_management/services/analytics_service/get_analytics'; import { DATA_FRAME_TASK_STATE } from '../pages/analytics_management/components/analytics_list/common'; -import { useInferenceApiService } from '../../services/ml_api_service/inference'; +import { useTrainedModelsApiService } from '../../services/ml_api_service/trained_models'; import { TotalFeatureImportance } from '../../../../common/types/feature_importance'; import { getToastNotificationService } from '../../services/toast_notification_service'; import { @@ -29,7 +29,7 @@ import { export const useResultsViewConfig = (jobId: string) => { const mlContext = useMlContext(); - const inferenceApiService = useInferenceApiService(); + const trainedModelsApiService = useTrainedModelsApiService(); const [indexPattern, setIndexPattern] = useState(undefined); const [isInitialized, setIsInitialized] = useState(false); @@ -74,7 +74,7 @@ export const useResultsViewConfig = (jobId: string) => { isRegressionAnalysis(jobConfigUpdate.analysis) ) { try { - const inferenceModels = await inferenceApiService.getInferenceModel(`${jobId}*`, { + const inferenceModels = await trainedModelsApiService.getTrainedModels(`${jobId}*`, { include: 'total_feature_importance', }); const inferenceModel = inferenceModels.find( diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/delete_models_modal.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/delete_models_modal.tsx index 3c2ba13a1db2..571bda871d7e 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/delete_models_modal.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/delete_models_modal.tsx @@ -35,7 +35,7 @@ export const DeleteModelsModal: FC = ({ models, onClose = ({ models, onClose size="s" > = ({ models, onClose diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx index 803a2523a55e..f18f293ff953 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx @@ -120,7 +120,7 @@ export const ExpandedRow: FC = ({ item }) => { id: 'details', name: ( ), @@ -133,7 +133,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -156,7 +156,7 @@ export const ExpandedRow: FC = ({ item }) => { id: 'config', name: ( ), @@ -169,7 +169,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -190,7 +190,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -214,7 +214,7 @@ export const ExpandedRow: FC = ({ item }) => { id: 'stats', name: ( ), @@ -228,7 +228,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -248,7 +248,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -266,7 +266,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -300,7 +300,7 @@ export const ExpandedRow: FC = ({ item }) => {
@@ -354,7 +354,7 @@ export const ExpandedRow: FC = ({ item }) => { name: ( <> {' '} {stats.pipeline_count} @@ -390,7 +390,7 @@ export const ExpandedRow: FC = ({ item }) => { }} > @@ -402,7 +402,7 @@ export const ExpandedRow: FC = ({ item }) => {
diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx index d5a7ca6e96c0..6dd55f1881d7 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx @@ -24,16 +24,16 @@ import { EuiBasicTableColumn } from '@elastic/eui/src/components/basic_table/bas import { EuiTableSelectionType } from '@elastic/eui/src/components/basic_table/table_types'; import { Action } from '@elastic/eui/src/components/basic_table/action_types'; import { StatsBar, ModelsBarStats } from '../../../../../components/stats_bar'; -import { useInferenceApiService } from '../../../../../services/ml_api_service/inference'; +import { useTrainedModelsApiService } from '../../../../../services/ml_api_service/trained_models'; import { ModelsTableToConfigMapping } from './index'; import { DeleteModelsModal } from './delete_models_modal'; import { useMlKibana, useMlUrlGenerator, useNotifications } from '../../../../../contexts/kibana'; import { ExpandedRow } from './expanded_row'; import { - ModelConfigResponse, + TrainedModelConfigResponse, ModelPipelines, TrainedModelStat, -} from '../../../../../../../common/types/inference'; +} from '../../../../../../../common/types/trained_models'; import { getAnalysisType, REFRESH_ANALYTICS_LIST_STATE, @@ -48,7 +48,7 @@ import { timeFormatter } from '../../../../../../../common/util/date_utils'; type Stats = Omit; -export type ModelItem = ModelConfigResponse & { +export type ModelItem = TrainedModelConfigResponse & { type?: string; stats?: Stats; pipelines?: ModelPipelines['pipelines'] | null; @@ -66,7 +66,7 @@ export const ModelsList: FC = () => { const canDeleteDataFrameAnalytics = capabilities.ml.canDeleteDataFrameAnalytics as boolean; - const inferenceApiService = useInferenceApiService(); + const trainedModelsApiService = useTrainedModelsApiService(); const { toasts } = useNotifications(); const [searchQueryText, setSearchQueryText] = useState(''); @@ -110,7 +110,7 @@ export const ModelsList: FC = () => { */ const fetchData = useCallback(async () => { try { - const response = await inferenceApiService.getInferenceModel(undefined, { + const response = await trainedModelsApiService.getTrainedModels(undefined, { with_pipelines: true, size: 1000, }); @@ -146,7 +146,7 @@ export const ModelsList: FC = () => { } } catch (error) { toasts.addError(new Error(error.body?.message), { - title: i18n.translate('xpack.ml.inference.modelsList.fetchFailedErrorMessage', { + title: i18n.translate('xpack.ml.trainedModels.modelsList.fetchFailedErrorMessage', { defaultMessage: 'Models fetch failed', }), }); @@ -166,8 +166,8 @@ export const ModelsList: FC = () => { total: { show: true, value: items.length, - label: i18n.translate('xpack.ml.inference.modelsList.totalAmountLabel', { - defaultMessage: 'Total inference trained models', + label: i18n.translate('xpack.ml.trainedModels.modelsList.totalAmountLabel', { + defaultMessage: 'Total trained models', }), }, }; @@ -182,7 +182,7 @@ export const ModelsList: FC = () => { try { const { trained_model_stats: modelsStatsResponse, - } = await inferenceApiService.getInferenceModelStats(modelIdsToFetch); + } = await trainedModelsApiService.getTrainedModelStats(modelIdsToFetch); for (const { model_id: id, ...stats } of modelsStatsResponse) { const model = models.find((m) => m.model_id === id); @@ -191,7 +191,7 @@ export const ModelsList: FC = () => { return true; } catch (error) { toasts.addError(new Error(error.body.message), { - title: i18n.translate('xpack.ml.inference.modelsList.fetchModelStatsErrorMessage', { + title: i18n.translate('xpack.ml.trainedModels.modelsList.fetchModelStatsErrorMessage', { defaultMessage: 'Fetch model stats failed', }), }); @@ -221,7 +221,7 @@ export const ModelsList: FC = () => { setModelsToDelete(models as ModelItemFull[]); } else { toasts.addDanger( - i18n.translate('xpack.ml.inference.modelsList.unableToDeleteModelsErrorMessage', { + i18n.translate('xpack.ml.trainedModels.modelsList.unableToDeleteModelsErrorMessage', { defaultMessage: 'Unable to delete models', }) ); @@ -236,7 +236,7 @@ export const ModelsList: FC = () => { try { await Promise.all( - modelsToDeleteIds.map((modelId) => inferenceApiService.deleteInferenceModel(modelId)) + modelsToDeleteIds.map((modelId) => trainedModelsApiService.deleteTrainedModel(modelId)) ); setItems( items.filter( @@ -244,7 +244,7 @@ export const ModelsList: FC = () => { ) ); toasts.addSuccess( - i18n.translate('xpack.ml.inference.modelsList.successfullyDeletedMessage', { + i18n.translate('xpack.ml.trainedModels.modelsList.successfullyDeletedMessage', { defaultMessage: '{modelsCount, plural, one {Model {modelsToDeleteIds}} other {# models}} {modelsCount, plural, one {has} other {have}} been successfully deleted', values: { @@ -255,7 +255,7 @@ export const ModelsList: FC = () => { ); } catch (error) { toasts.addError(new Error(error?.body?.message), { - title: i18n.translate('xpack.ml.inference.modelsList.fetchDeletionErrorMessage', { + title: i18n.translate('xpack.ml.trainedModels.modelsList.fetchDeletionErrorMessage', { defaultMessage: '{modelsCount, plural, one {Model} other {Models}} deletion failed', values: { modelsCount: modelsToDeleteIds.length, @@ -270,10 +270,10 @@ export const ModelsList: FC = () => { */ const actions: Array> = [ { - name: i18n.translate('xpack.ml.inference.modelsList.viewTrainingDataActionLabel', { + name: i18n.translate('xpack.ml.trainedModels.modelsList.viewTrainingDataActionLabel', { defaultMessage: 'View training data', }), - description: i18n.translate('xpack.ml.inference.modelsList.viewTrainingDataActionLabel', { + description: i18n.translate('xpack.ml.trainedModels.modelsList.viewTrainingDataActionLabel', { defaultMessage: 'View training data', }), icon: 'visTable', @@ -298,10 +298,10 @@ export const ModelsList: FC = () => { isPrimary: true, }, { - name: i18n.translate('xpack.ml.inference.modelsList.deleteModelActionLabel', { + name: i18n.translate('xpack.ml.trainedModels.modelsList.deleteModelActionLabel', { defaultMessage: 'Delete model', }), - description: i18n.translate('xpack.ml.inference.modelsList.deleteModelActionLabel', { + description: i18n.translate('xpack.ml.trainedModels.modelsList.deleteModelActionLabel', { defaultMessage: 'Delete model', }), icon: 'trash', @@ -341,10 +341,10 @@ export const ModelsList: FC = () => { onClick={toggleDetails.bind(null, item)} aria-label={ itemIdToExpandedRowMap[item.model_id] - ? i18n.translate('xpack.ml.inference.modelsList.collapseRow', { + ? i18n.translate('xpack.ml.trainedModels.modelsList.collapseRow', { defaultMessage: 'Collapse', }) - : i18n.translate('xpack.ml.inference.modelsList.expandRow', { + : i18n.translate('xpack.ml.trainedModels.modelsList.expandRow', { defaultMessage: 'Expand', }) } @@ -354,7 +354,7 @@ export const ModelsList: FC = () => { }, { field: ModelsTableToConfigMapping.id, - name: i18n.translate('xpack.ml.inference.modelsList.modelIdHeader', { + name: i18n.translate('xpack.ml.trainedModels.modelsList.modelIdHeader', { defaultMessage: 'ID', }), sortable: true, @@ -362,7 +362,7 @@ export const ModelsList: FC = () => { }, { field: ModelsTableToConfigMapping.type, - name: i18n.translate('xpack.ml.inference.modelsList.typeHeader', { + name: i18n.translate('xpack.ml.trainedModels.modelsList.typeHeader', { defaultMessage: 'Type', }), sortable: true, @@ -371,7 +371,7 @@ export const ModelsList: FC = () => { }, { field: ModelsTableToConfigMapping.createdAt, - name: i18n.translate('xpack.ml.inference.modelsList.createdAtHeader', { + name: i18n.translate('xpack.ml.trainedModels.modelsList.createdAtHeader', { defaultMessage: 'Created at', }), dataType: 'date', @@ -379,7 +379,7 @@ export const ModelsList: FC = () => { sortable: true, }, { - name: i18n.translate('xpack.ml.inference.modelsList.actionsHeader', { + name: i18n.translate('xpack.ml.trainedModels.modelsList.actionsHeader', { defaultMessage: 'Actions', }), actions, @@ -413,7 +413,7 @@ export const ModelsList: FC = () => {
@@ -423,7 +423,7 @@ export const ModelsList: FC = () => { @@ -438,10 +438,10 @@ export const ModelsList: FC = () => { ? { selectableMessage: (selectable, item) => { return selectable - ? i18n.translate('xpack.ml.inference.modelsList.selectableMessage', { + ? i18n.translate('xpack.ml.trainedModels.modelsList.selectableMessage', { defaultMessage: 'Select a model', }) - : i18n.translate('xpack.ml.inference.modelsList.disableSelectableMessage', { + : i18n.translate('xpack.ml.trainedModels.modelsList.disableSelectableMessage', { defaultMessage: 'Model has associated pipelines', }); }, diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/inference.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/trained_models.ts similarity index 73% rename from x-pack/plugins/ml/public/application/services/ml_api_service/inference.ts rename to x-pack/plugins/ml/public/application/services/ml_api_service/trained_models.ts index ce211612fba6..ed5d7e37cd1c 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/inference.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/trained_models.ts @@ -10,10 +10,10 @@ import { HttpService } from '../http_service'; import { basePath } from './index'; import { useMlKibana } from '../../contexts/kibana'; import { - ModelConfigResponse, + TrainedModelConfigResponse, ModelPipelines, TrainedModelStat, -} from '../../../../common/types/inference'; +} from '../../../../common/types/trained_models'; export interface InferenceQueryParams { decompress_definition?: boolean; @@ -47,7 +47,7 @@ export interface InferenceStatsResponse { * Service with APIs calls to perform inference operations. * @param httpService */ -export function inferenceApiProvider(httpService: HttpService) { +export function trainedModelsApiProvider(httpService: HttpService) { const apiBasePath = basePath(); return { @@ -58,14 +58,14 @@ export function inferenceApiProvider(httpService: HttpService) { * Fetches all In case nothing is provided. * @param params - Optional query params */ - getInferenceModel(modelId?: string | string[], params?: InferenceQueryParams) { + getTrainedModels(modelId?: string | string[], params?: InferenceQueryParams) { let model = modelId ?? ''; if (Array.isArray(modelId)) { model = modelId.join(','); } - return httpService.http({ - path: `${apiBasePath}/inference${model && `/${model}`}`, + return httpService.http({ + path: `${apiBasePath}/trained_models${model && `/${model}`}`, method: 'GET', ...(params ? { query: params as HttpFetchQuery } : {}), }); @@ -78,14 +78,14 @@ export function inferenceApiProvider(httpService: HttpService) { * Fetches all In case nothing is provided. * @param params - Optional query params */ - getInferenceModelStats(modelId?: string | string[], params?: InferenceStatsQueryParams) { + getTrainedModelStats(modelId?: string | string[], params?: InferenceStatsQueryParams) { let model = modelId ?? '_all'; if (Array.isArray(modelId)) { model = modelId.join(','); } return httpService.http({ - path: `${apiBasePath}/inference/${model}/_stats`, + path: `${apiBasePath}/trained_models/${model}/_stats`, method: 'GET', }); }, @@ -95,14 +95,14 @@ export function inferenceApiProvider(httpService: HttpService) { * * @param modelId - Model ID, collection of Model IDs. */ - getInferenceModelPipelines(modelId: string | string[]) { + getTrainedModelPipelines(modelId: string | string[]) { let model = modelId; if (Array.isArray(modelId)) { model = modelId.join(','); } return httpService.http({ - path: `${apiBasePath}/inference/${model}/pipelines`, + path: `${apiBasePath}/trained_models/${model}/pipelines`, method: 'GET', }); }, @@ -112,25 +112,25 @@ export function inferenceApiProvider(httpService: HttpService) { * * @param modelId - Model ID */ - deleteInferenceModel(modelId: string) { + deleteTrainedModel(modelId: string) { return httpService.http({ - path: `${apiBasePath}/inference/${modelId}`, + path: `${apiBasePath}/trained_models/${modelId}`, method: 'DELETE', }); }, }; } -type InferenceApiService = ReturnType; +type TrainedModelsApiService = ReturnType; /** - * Hooks for accessing {@link InferenceApiService} in React components. + * Hooks for accessing {@link TrainedModelsApiService} in React components. */ -export function useInferenceApiService(): InferenceApiService { +export function useTrainedModelsApiService(): TrainedModelsApiService { const { services: { mlServices: { httpService }, }, } = useMlKibana(); - return useMemo(() => inferenceApiProvider(httpService), [httpService]); + return useMemo(() => trainedModelsApiProvider(httpService), [httpService]); } diff --git a/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts b/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts index b2a4ccdab43d..e10c460bbfbb 100644 --- a/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts +++ b/x-pack/plugins/ml/server/models/data_frame_analytics/models_provider.ts @@ -5,7 +5,7 @@ */ import { IScopedClusterClient } from 'kibana/server'; -import { PipelineDefinition } from '../../../common/types/inference'; +import { PipelineDefinition } from '../../../common/types/trained_models'; export function modelsProvider(client: IScopedClusterClient) { return { diff --git a/x-pack/plugins/ml/server/plugin.ts b/x-pack/plugins/ml/server/plugin.ts index 7224eacf84e9..d0c837b7a1ca 100644 --- a/x-pack/plugins/ml/server/plugin.ts +++ b/x-pack/plugins/ml/server/plugin.ts @@ -47,7 +47,7 @@ import { createSharedServices, SharedServices } from './shared_services'; import { getPluginPrivileges } from '../common/types/capabilities'; import { setupCapabilitiesSwitcher } from './lib/capabilities'; import { registerKibanaSettings } from './lib/register_settings'; -import { inferenceRoutes } from './routes/inference'; +import { trainedModelsRoutes } from './routes/trained_models'; export type MlPluginSetup = SharedServices; export type MlPluginStart = void; @@ -153,7 +153,7 @@ export class MlServerPlugin implements Plugin