From d0a6899d2ba5cf3119643f5c7fb9fd052f3bc4b7 Mon Sep 17 00:00:00 2001 From: Rodney Norris Date: Tue, 4 Oct 2022 16:32:53 -0500 Subject: [PATCH] [Enterprise Search] fix ml inference with api index Updates the the Pipelines logic to ensure you can configure ml inference pipelines with api-based indices. --- .../pipelines/ingest_pipelines_card.tsx | 2 +- .../search_index/pipelines/pipelines.tsx | 10 ++--- .../pipelines/pipelines_logic.test.ts | 44 ++++++++++++++++++- .../search_index/pipelines/pipelines_logic.ts | 18 ++++---- 4 files changed, 55 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/ingest_pipelines_card.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/ingest_pipelines_card.tsx index c7a3872ce6e3e..9202e6690408c 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/ingest_pipelines_card.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/ingest_pipelines_card.tsx @@ -85,7 +85,7 @@ export const IngestPipelinesCard: React.FC = () => { -

{pipelineState.name}

+

{pipelineName}

diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines.tsx index f695b7c541c5a..18190cef67ca3 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines.tsx @@ -33,12 +33,8 @@ import { PipelinesJSONConfigurations } from './pipelines_json_configurations'; import { PipelinesLogic } from './pipelines_logic'; export const SearchIndexPipelines: React.FC = () => { - const { - showAddMlInferencePipelineModal, - hasIndexIngestionPipeline, - index, - pipelineState: { name: pipelineName }, - } = useValues(PipelinesLogic); + const { showAddMlInferencePipelineModal, hasIndexIngestionPipeline, index, pipelineName } = + useValues(PipelinesLogic); const { closeAddMlInferencePipelineModal, openAddMlInferencePipelineModal } = useActions(PipelinesLogic); const apiIndex = isApiIndex(index); @@ -133,7 +129,7 @@ export const SearchIndexPipelines: React.FC = () => { 'xpack.enterpriseSearch.content.indices.pipelines.mlInferencePipelines.subtitleAPIindex', { defaultMessage: - "Inference pipelines will be run as processors from the Enterprise Search Ingest Pipeline. In order to use these pipeline on API-based indices you'll need to reference the {pipelineName} pipeline in your API requests.", + "Inference pipelines will be run as processors from the Enterprise Search Ingest Pipeline. In order to use these pipelines on API-based indices you'll need to reference the {pipelineName} pipeline in your API requests.", values: { pipelineName, }, diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.test.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.test.ts index b847b2fdc6b8c..ff3b779d61e29 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.test.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.test.ts @@ -4,11 +4,13 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - import { LogicMounter, mockFlashMessageHelpers } from '../../../../__mocks__/kea_logic'; -import { connectorIndex } from '../../../__mocks__/view_index.mock'; +import { apiIndex, connectorIndex } from '../../../__mocks__/view_index.mock'; + +import { IngestPipeline } from '@elastic/elasticsearch/lib/api/types'; import { UpdatePipelineApiLogic } from '../../../api/connector/update_pipeline_api_logic'; +import { FetchCustomPipelineApiLogic } from '../../../api/index/fetch_custom_pipeline_api_logic'; import { FetchIndexApiLogic } from '../../../api/index/fetch_index_api_logic'; import { PipelinesLogic } from './pipelines_logic'; @@ -40,6 +42,7 @@ describe('PipelinesLogic', () => { const { mount } = new LogicMounter(PipelinesLogic); const { mount: mountFetchIndexApiLogic } = new LogicMounter(FetchIndexApiLogic); const { mount: mountUpdatePipelineLogic } = new LogicMounter(UpdatePipelineApiLogic); + const { mount: mountFetchCustomPipelineApiLogic } = new LogicMounter(FetchCustomPipelineApiLogic); const { clearFlashMessages, flashAPIErrors, flashSuccessToast } = mockFlashMessageHelpers; const newPipeline = { @@ -51,6 +54,7 @@ describe('PipelinesLogic', () => { beforeEach(() => { jest.clearAllMocks(); mountFetchIndexApiLogic(); + mountFetchCustomPipelineApiLogic(); mountUpdatePipelineLogic(); mount(); }); @@ -195,5 +199,41 @@ describe('PipelinesLogic', () => { }); }); }); + describe('fetchCustomPipelineSuccess', () => { + it('should support api indices with custom ingest pipelines', () => { + PipelinesLogic.actions.fetchIndexApiSuccess({ + ...apiIndex, + }); + const indexName = apiIndex.name; + const indexPipelines: Record = { + [indexName]: { + processors: [], + version: 1, + }, + [`${indexName}@custom`]: { + processors: [], + version: 1, + }, + [`${indexName}@ml-inference`]: { + processors: [], + version: 1, + }, + }; + PipelinesLogic.actions.fetchCustomPipelineSuccess(indexPipelines); + + expect(PipelinesLogic.values).toEqual({ + ...DEFAULT_VALUES, + customPipelineData: indexPipelines, + index: { + ...apiIndex, + }, + indexName, + pipelineName: indexName, + canSetPipeline: false, + hasIndexIngestionPipeline: true, + canUseMlInferencePipeline: true, + }); + }); + }); }); }); diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.ts b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.ts index 952c5baf77553..dca18863cde02 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/search_index/pipelines/pipelines_logic.ts @@ -90,6 +90,10 @@ type PipelinesActions = Pick< FetchCustomPipelineApiLogicArgs, FetchCustomPipelineApiLogicResponse >['makeRequest']; + fetchCustomPipelineSuccess: Actions< + FetchCustomPipelineApiLogicArgs, + FetchCustomPipelineApiLogicResponse + >['apiSuccess']; fetchDefaultPipeline: Actions['makeRequest']; fetchDefaultPipelineSuccess: Actions['apiSuccess']; fetchIndexApiSuccess: Actions['apiSuccess']; @@ -143,7 +147,7 @@ export const PipelinesLogic = kea !isApiIndex(index), ], canUseMlInferencePipeline: [ - () => [ - selectors.canSetPipeline, - selectors.hasIndexIngestionPipeline, - selectors.pipelineState, - ], + () => [selectors.hasIndexIngestionPipeline, selectors.pipelineState, selectors.index], ( - canSetPipeline: boolean, hasIndexIngestionPipeline: boolean, - pipelineState: IngestPipelineParams - ) => canSetPipeline && hasIndexIngestionPipeline && pipelineState.run_ml_inference, + pipelineState: IngestPipelineParams, + index: ElasticsearchIndexWithIngestion + ) => hasIndexIngestionPipeline && (pipelineState.run_ml_inference || isApiIndex(index)), ], defaultPipelineValues: [ () => [selectors.defaultPipelineValuesData],