Skip to content

Commit

Permalink
[Enterprise Search] Custom pipelines update optimistically on creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sphilipse committed Oct 4, 2022
1 parent bcfa351 commit 4c72368
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}
Expand Down Expand Up @@ -111,7 +112,7 @@ export const IngestPipelinesCard: React.FC = () => {
<CurlRequest
document={{ body: 'body', title: 'Title' }}
indexName={indexName}
pipeline={pipelineState}
pipeline={{ ...pipelineState, name: pipelineName }}
/>
</EuiAccordion>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -105,11 +106,14 @@ type PipelinesActions = Pick<
interface PipelinesValues {
canSetPipeline: boolean;
canUseMlInferencePipeline: boolean;
customPipelineData: Record<string, IngestPipeline | undefined>;
defaultPipelineValues: IngestPipelineParams;
defaultPipelineValuesData: IngestPipelineParams | null;
hasIndexIngestionPipeline: boolean;
index: FetchIndexApiResponse;
indexName: string;
mlInferencePipelineProcessors: InferencePipeline[];
pipelineName: string;
pipelineState: IngestPipelineParams;
showAddMlInferencePipelineModal: boolean;
showModal: boolean;
Expand Down Expand Up @@ -155,6 +159,8 @@ export const PipelinesLogic = kea<MakeLogicType<PipelinesValues, PipelinesAction
],
],
values: [
FetchCustomPipelineApiLogic,
['data as customPipelineData'],
FetchDefaultPipelineApiLogic,
['data as defaultPipelineValuesData'],
FetchIndexApiLogic,
Expand Down Expand Up @@ -290,15 +296,6 @@ export const PipelinesLogic = kea<MakeLogicType<PipelinesValues, PipelinesAction
() => [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,
Expand All @@ -311,5 +308,23 @@ export const PipelinesLogic = kea<MakeLogicType<PipelinesValues, PipelinesAction
pipelineState: IngestPipelineParams
) => canSetPipeline && hasIndexIngestionPipeline && pipelineState.run_ml_inference,
],
defaultPipelineValues: [
() => [selectors.defaultPipelineValuesData],
(pipeline: IngestPipelineParams | null) => pipeline ?? DEFAULT_PIPELINE_VALUES,
],
hasIndexIngestionPipeline: [
() => [selectors.pipelineName, selectors.defaultPipelineValues],
(pipelineState: IngestPipelineParams, defaultPipelineValues: IngestPipelineParams) =>
pipelineState.name !== 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,
],
}),
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,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);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CreatedPipelines> => {
// 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',
Expand Down

0 comments on commit 4c72368

Please sign in to comment.