Skip to content

Commit

Permalink
[Enterprise Search] Match simulate pipeline features with stack manag…
Browse files Browse the repository at this point in the history
…ement (#145275)

## Summary

Adds features to test pipeline with an existing document from the index.
Also updated the text to give consistent messages across the other parts
of the kibana


https://user-images.githubusercontent.com/1410658/201979420-005b6f3e-c44c-4e44-b40e-88c3c717bb99.mov

## Release note
Adds the ability to test Ingest pipelines with a document from the same
index.



### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
  • Loading branch information
efegurkan authored Nov 15, 2022
1 parent 73f1705 commit 12e6b2b
Show file tree
Hide file tree
Showing 10 changed files with 369 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum ErrorCode {
ANALYTICS_COLLECTION_NAME_INVALID = 'analytics_collection_name_invalid',
CONNECTOR_DOCUMENT_ALREADY_EXISTS = 'connector_document_already_exists',
CRAWLER_ALREADY_EXISTS = 'crawler_already_exists',
DOCUMENT_NOT_FOUND = 'document_not_found',
INDEX_ALREADY_EXISTS = 'index_already_exists',
INDEX_NOT_FOUND = 'index_not_found',
PIPELINE_ALREADY_EXISTS = 'pipeline_already_exists',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { GetResponse } from '@elastic/elasticsearch/lib/api/types';

import { createApiLogic } from '../../../shared/api_logic/create_api_logic';
import { HttpLogic } from '../../../shared/http';

export interface GetDocumentsArgs {
documentId: string;
indexName: string;
}

export type GetDocumentsResponse = GetResponse<unknown>;

export const getDocument = async ({ indexName, documentId }: GetDocumentsArgs) => {
const route = `/internal/enterprise_search/indices/${indexName}/document/${documentId}`;

return await HttpLogic.values.http.get<GetDocumentsResponse>(route);
};

export const GetDocumentsApiLogic = createApiLogic(['get_documents_logic'], getDocument);
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { mockHttpValues } from '../../../__mocks__/kea_logic';

import { nextTick } from '@kbn/test-jest-helpers';

import { getDocument } from './get_document_logic';

describe('getDocumentApiLogic', () => {
const { http } = mockHttpValues;
beforeEach(() => {
jest.clearAllMocks();
});

describe('getDocument', () => {
it('calls correct api', async () => {
const promise = Promise.resolve({
_id: 'test-id',
_index: 'indexName',
_source: {},
found: true,
});
http.get.mockReturnValue(promise);
const result = getDocument({ documentId: '123123', indexName: 'indexName' });
await nextTick();
expect(http.get).toHaveBeenCalledWith(
'/internal/enterprise_search/indices/indexName/document/123123'
);
await expect(result).resolves.toEqual({
_id: 'test-id',
_index: 'indexName',
_source: {},
found: true,
});
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { TrainedModelConfigResponse } from '@kbn/ml-plugin/common/types/trained_
import { ErrorResponse, HttpError, Status } from '../../../../../../../common/types/api';
import { TrainedModelState } from '../../../../../../../common/types/pipelines';

import { GetDocumentsApiLogic } from '../../../../api/documents/get_document_logic';
import { MappingsApiLogic } from '../../../../api/mappings/mappings_logic';
import { MLModelsApiLogic } from '../../../../api/ml_models/ml_models_logic';
import { AttachMlInferencePipelineApiLogic } from '../../../../api/pipelines/attach_ml_inference_pipeline';
Expand All @@ -35,22 +36,8 @@ const DEFAULT_VALUES: MLInferenceProcessorsValues = {
...EMPTY_PIPELINE_CONFIGURATION,
},
indexName: '',
simulateBody: `
[
{
"_index": "index",
"_id": "id",
"_source": {
"foo": "bar"
}
},
{
"_index": "index",
"_id": "id",
"_source": {
"foo": "baz"
}
}
simulateBody: `[
]`,
step: AddInferencePipelineSteps.Configuration,
},
Expand All @@ -61,7 +48,12 @@ const DEFAULT_VALUES: MLInferenceProcessorsValues = {
pipelineName: 'Field is required.',
sourceField: 'Field is required.',
},
getDocumentApiErrorMessage: undefined,
getDocumentApiStatus: Status.IDLE,
getDocumentData: undefined,
getDocumentsErr: '',
index: null,
isGetDocumentsLoading: false,
isLoading: true,
isPipelineDataValid: false,
mappingData: undefined,
Expand All @@ -71,6 +63,7 @@ const DEFAULT_VALUES: MLInferenceProcessorsValues = {
mlInferencePipelinesData: undefined,
mlModelsData: undefined,
mlModelsStatus: 0,
showGetDocumentErrors: false,
simulateExistingPipelineData: undefined,
simulateExistingPipelineStatus: 0,
simulatePipelineData: undefined,
Expand Down Expand Up @@ -103,6 +96,7 @@ describe('MlInferenceLogic', () => {
const { mount: mountFetchMlInferencePipelinesApiLogic } = new LogicMounter(
FetchMlInferencePipelinesApiLogic
);
const { mount: mountGetDocumentsApiLogic } = new LogicMounter(GetDocumentsApiLogic);

beforeEach(() => {
jest.clearAllMocks();
Expand All @@ -114,6 +108,7 @@ describe('MlInferenceLogic', () => {
mountSimulateMlInterfacePipelineApiLogic();
mountCreateMlInferencePipelineApiLogic();
mountAttachMlInferencePipelineApiLogic();
mountGetDocumentsApiLogic();
mount();
});

Expand Down Expand Up @@ -197,13 +192,35 @@ describe('MlInferenceLogic', () => {
expect(MLInferenceLogic.values.createErrors).not.toHaveLength(0);
MLInferenceLogic.actions.makeCreatePipelineRequest({
indexName: 'test',
pipelineName: 'unit-test',
modelId: 'test-model',
pipelineName: 'unit-test',
sourceField: 'body',
});
expect(MLInferenceLogic.values.createErrors).toHaveLength(0);
});
});
describe('getDocumentApiSuccess', () => {
it('sets simulateBody text to the returned document', () => {
GetDocumentsApiLogic.actions.apiSuccess({
_id: 'test-index-123',
_index: 'test-index',
found: true,
});
expect(MLInferenceLogic.values.addInferencePipelineModal.simulateBody).toEqual(
JSON.stringify(
[
{
_id: 'test-index-123',
_index: 'test-index',
found: true,
},
],
undefined,
2
)
);
});
});
});

describe('selectors', () => {
Expand Down Expand Up @@ -331,9 +348,9 @@ describe('MlInferenceLogic', () => {
{
destinationField: 'test-field',
disabled: false,
pipelineName: 'unit-test',
modelType: '',
modelId: 'test-model',
modelType: '',
pipelineName: 'unit-test',
sourceField: 'body',
},
]);
Expand Down Expand Up @@ -361,9 +378,9 @@ describe('MlInferenceLogic', () => {
destinationField: 'test-field',
disabled: true,
disabledReason: expect.any(String),
pipelineName: 'unit-test',
modelType: '',
modelId: 'test-model',
modelType: '',
pipelineName: 'unit-test',
sourceField: 'body_content',
},
]);
Expand Down Expand Up @@ -507,6 +524,46 @@ describe('MlInferenceLogic', () => {
expect(MLInferenceLogic.values.mlInferencePipeline).toEqual(existingPipeline);
});
});
describe('getDocumentsErr', () => {
it('returns empty string when no error is present', () => {
GetDocumentsApiLogic.actions.apiSuccess({
_id: 'test-123',
_index: 'test',
found: true,
});
expect(MLInferenceLogic.values.getDocumentsErr).toEqual('');
});
it('returns extracted error message from the http response', () => {
GetDocumentsApiLogic.actions.apiError({
body: {
error: 'document-not-found',
message: 'not-found',
statusCode: 404,
},
} as HttpError);
expect(MLInferenceLogic.values.getDocumentsErr).toEqual('not-found');
});
});
describe('showGetDocumentErrors', () => {
it('returns false when no error is present', () => {
GetDocumentsApiLogic.actions.apiSuccess({
_id: 'test-123',
_index: 'test',
found: true,
});
expect(MLInferenceLogic.values.showGetDocumentErrors).toEqual(false);
});
it('returns true when an error message is present', () => {
GetDocumentsApiLogic.actions.apiError({
body: {
error: 'document-not-found',
message: 'not-found',
statusCode: 404,
},
} as HttpError);
expect(MLInferenceLogic.values.showGetDocumentErrors).toEqual(true);
});
});
});

describe('listeners', () => {
Expand Down
Loading

0 comments on commit 12e6b2b

Please sign in to comment.