From 45cd5bf7959f2aa7877ee916cd232b22a241f7f5 Mon Sep 17 00:00:00 2001
From: Sander Philipse <94373878+sphilipse@users.noreply.github.com>
Date: Tue, 4 Oct 2022 21:10:16 +0200
Subject: [PATCH] [Enterprise Search] Custom pipelines update optimistically on
creation (#142639)
* [Enterprise Search] Custom pipelines update optimistically on creation
* Fix tests
---
.../pipelines/ingest_pipelines_card.tsx | 7 ++--
.../pipelines/pipelines_logic.test.ts | 16 ++++++---
.../search_index/pipelines/pipelines_logic.ts | 33 ++++++++++++++-----
.../create_pipeline_definitions.test.ts | 6 ++--
.../pipelines/create_pipeline_definitions.ts | 10 +++---
5 files changed, 48 insertions(+), 24 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 7bf1ef06e1e75..c7a3872ce6e3e 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
@@ -37,7 +37,8 @@ import { PipelinesLogic } from './pipelines_logic';
export const IngestPipelinesCard: React.FC = () => {
const { indexName } = useValues(IndexViewLogic);
- const { canSetPipeline, index, pipelineState, showModal } = useValues(PipelinesLogic);
+ const { canSetPipeline, index, pipelineName, pipelineState, showModal } =
+ useValues(PipelinesLogic);
const { closeModal, openModal, setPipelineState, savePipeline } = useActions(PipelinesLogic);
const { makeRequest: fetchCustomPipeline } = useActions(FetchCustomPipelineApiLogic);
const { makeRequest: createCustomPipeline } = useActions(CreateCustomPipelineApiLogic);
@@ -61,7 +62,7 @@ export const IngestPipelinesCard: React.FC = () => {
indexName={indexName}
isGated={isGated}
isLoading={false}
- pipeline={pipelineState}
+ pipeline={{ ...pipelineState, name: pipelineName }}
savePipeline={savePipeline}
setPipeline={setPipelineState}
showModal={showModal}
@@ -111,7 +112,7 @@ export const IngestPipelinesCard: React.FC = () => {
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 7dc3a221cc57a..b847b2fdc6b8c 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
@@ -23,14 +23,17 @@ const DEFAULT_PIPELINE_VALUES = {
const DEFAULT_VALUES = {
canSetPipeline: true,
canUseMlInferencePipeline: false,
+ customPipelineData: undefined,
defaultPipelineValues: DEFAULT_PIPELINE_VALUES,
defaultPipelineValuesData: undefined,
+ hasIndexIngestionPipeline: false,
index: undefined,
+ indexName: '',
mlInferencePipelineProcessors: undefined,
+ pipelineName: DEFAULT_PIPELINE_VALUES.name,
pipelineState: DEFAULT_PIPELINE_VALUES,
- showModal: false,
showAddMlInferencePipelineModal: false,
- hasIndexIngestionPipeline: false,
+ showModal: false,
};
describe('PipelinesLogic', () => {
@@ -69,6 +72,7 @@ describe('PipelinesLogic', () => {
...connectorIndex,
connector: { ...connectorIndex.connector },
},
+ indexName: 'connector',
});
expect(flashSuccessToast).toHaveBeenCalled();
expect(PipelinesLogic.actions.fetchIndexApiSuccess).toHaveBeenCalledWith({
@@ -86,8 +90,9 @@ describe('PipelinesLogic', () => {
});
expect(PipelinesLogic.values).toEqual({
...DEFAULT_VALUES,
- pipelineState: { ...DEFAULT_PIPELINE_VALUES, name: 'new_pipeline_name' },
hasIndexIngestionPipeline: true,
+ pipelineName: 'new_pipeline_name',
+ pipelineState: { ...DEFAULT_PIPELINE_VALUES, name: 'new_pipeline_name' },
});
});
describe('makeRequest', () => {
@@ -152,12 +157,14 @@ describe('PipelinesLogic', () => {
expect(PipelinesLogic.values).toEqual({
...DEFAULT_VALUES,
canUseMlInferencePipeline: true,
+ hasIndexIngestionPipeline: true,
index: {
...connectorIndex,
connector: { ...connectorIndex.connector, pipeline: newPipeline },
},
+ indexName: 'connector',
+ pipelineName: 'new_pipeline_name',
pipelineState: newPipeline,
- hasIndexIngestionPipeline: true,
});
});
it('should not set configState if modal is open', () => {
@@ -172,6 +179,7 @@ describe('PipelinesLogic', () => {
...connectorIndex,
connector: { ...connectorIndex.connector, pipeline: newPipeline },
},
+ indexName: 'connector',
showModal: 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 bfcf297309d69..952c5baf77553 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
@@ -7,6 +7,7 @@
import { kea, MakeLogicType } from 'kea';
+import { IngestPipeline } from '@elastic/elasticsearch/lib/api/types';
import { i18n } from '@kbn/i18n';
import { DEFAULT_PIPELINE_VALUES } from '../../../../../../common/constants';
@@ -105,11 +106,14 @@ type PipelinesActions = Pick<
interface PipelinesValues {
canSetPipeline: boolean;
canUseMlInferencePipeline: boolean;
+ customPipelineData: Record;
defaultPipelineValues: IngestPipelineParams;
defaultPipelineValuesData: IngestPipelineParams | null;
hasIndexIngestionPipeline: boolean;
index: FetchIndexApiResponse;
+ indexName: string;
mlInferencePipelineProcessors: InferencePipeline[];
+ pipelineName: string;
pipelineState: IngestPipelineParams;
showAddMlInferencePipelineModal: boolean;
showModal: boolean;
@@ -155,6 +159,8 @@ export const PipelinesLogic = kea [selectors.index],
(index: ElasticsearchIndexWithIngestion) => !isApiIndex(index),
],
- defaultPipelineValues: [
- () => [selectors.defaultPipelineValuesData],
- (pipeline: IngestPipelineParams | null) => pipeline ?? DEFAULT_PIPELINE_VALUES,
- ],
- hasIndexIngestionPipeline: [
- () => [selectors.pipelineState, selectors.defaultPipelineValues],
- (pipelineState: IngestPipelineParams, defaultPipelineValues: IngestPipelineParams) =>
- pipelineState.name !== defaultPipelineValues.name,
- ],
canUseMlInferencePipeline: [
() => [
selectors.canSetPipeline,
@@ -317,5 +314,23 @@ export const PipelinesLogic = kea canSetPipeline && hasIndexIngestionPipeline && pipelineState.run_ml_inference,
],
+ defaultPipelineValues: [
+ () => [selectors.defaultPipelineValuesData],
+ (pipeline: IngestPipelineParams | null) => pipeline ?? DEFAULT_PIPELINE_VALUES,
+ ],
+ hasIndexIngestionPipeline: [
+ () => [selectors.pipelineName, selectors.defaultPipelineValues],
+ (pipelineName: string, defaultPipelineValues: IngestPipelineParams) =>
+ pipelineName !== defaultPipelineValues.name,
+ ],
+ indexName: [
+ () => [selectors.index],
+ (index?: ElasticsearchIndexWithIngestion) => index?.name ?? '',
+ ],
+ pipelineName: [
+ () => [selectors.pipelineState, selectors.customPipelineData, selectors.indexName],
+ (pipelineState, customPipelineData, indexName) =>
+ customPipelineData && customPipelineData[indexName] ? indexName : pipelineState.name,
+ ],
}),
});
diff --git a/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.test.ts b/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.test.ts
index 183e27a765c2f..3d54396a7d742 100644
--- a/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.test.ts
+++ b/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.test.ts
@@ -30,11 +30,11 @@ describe('createIndexPipelineDefinitions util function', () => {
jest.clearAllMocks();
});
- it('should create the pipelines', () => {
+ it('should create the pipelines', async () => {
mockClient.ingest.putPipeline.mockImplementation(() => Promise.resolve({ acknowledged: true }));
- expect(
+ await expect(
createIndexPipelineDefinitions(indexName, mockClient as unknown as ElasticsearchClient)
- ).toEqual(expectedResult);
+ ).resolves.toEqual(expectedResult);
expect(mockClient.ingest.putPipeline).toHaveBeenCalledTimes(3);
});
});
diff --git a/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.ts b/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.ts
index f32590fb516c5..4eba6dc5b0c8c 100644
--- a/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.ts
+++ b/x-pack/plugins/enterprise_search/server/lib/pipelines/create_pipeline_definitions.ts
@@ -27,24 +27,24 @@ export interface CreatedPipelines {
* @param indexName the index for which the pipelines should be created.
* @param esClient the Elasticsearch Client with which to create the pipelines.
*/
-export const createIndexPipelineDefinitions = (
+export const createIndexPipelineDefinitions = async (
indexName: string,
esClient: ElasticsearchClient
-): CreatedPipelines => {
+): Promise => {
// TODO: add back descriptions (see: https://github.com/elastic/elasticsearch-specification/issues/1827)
- esClient.ingest.putPipeline({
+ await esClient.ingest.putPipeline({
description: `Enterprise Search Machine Learning Inference pipeline for the '${indexName}' index`,
id: getInferencePipelineNameFromIndexName(indexName),
processors: [],
version: 1,
});
- esClient.ingest.putPipeline({
+ await esClient.ingest.putPipeline({
description: `Enterprise Search customizable ingest pipeline for the '${indexName}' index`,
id: `${indexName}@custom`,
processors: [],
version: 1,
});
- esClient.ingest.putPipeline({
+ await esClient.ingest.putPipeline({
_meta: {
managed: true,
managed_by: 'Enterprise Search',