-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search]Add EQL search strategy (#78645)
* Add EQL search strategy Since EQL is an x-pack feature, this strategy will live in the x-pack plugin data_enhanced. * Refactor our test setup to minimize shared state * Ensures that the same variable is not used for both test setup and test assertions * Ensures that mocks are reinstantiated on every test * Use explicit top-level exports * Move async search options to a helper function * Move our workaround to a helper function This was repeated in five places, time to consolidate. * Commit documentation changes We export a few new helper functions. * Mark our internal methods as such Updates documentation accordingly. Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
5f53d4f
commit 951034c
Showing
17 changed files
with
429 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/plugins/data/server/search/es_search/shim_abort_signal.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { elasticsearchServiceMock } from '../../../../../core/server/mocks'; | ||
import { shimAbortSignal } from '.'; | ||
|
||
describe('shimAbortSignal', () => { | ||
it('aborts the promise if the signal is aborted', () => { | ||
const promise = elasticsearchServiceMock.createSuccessTransportRequestPromise({ | ||
success: true, | ||
}); | ||
const controller = new AbortController(); | ||
shimAbortSignal(promise, controller.signal); | ||
controller.abort(); | ||
|
||
expect(promise.abort).toHaveBeenCalled(); | ||
}); | ||
|
||
it('returns the original promise', async () => { | ||
const promise = elasticsearchServiceMock.createSuccessTransportRequestPromise({ | ||
success: true, | ||
}); | ||
const controller = new AbortController(); | ||
const response = await shimAbortSignal(promise, controller.signal); | ||
|
||
expect(response).toEqual(expect.objectContaining({ body: { success: true } })); | ||
}); | ||
|
||
it('allows the promise to be aborted manually', () => { | ||
const promise = elasticsearchServiceMock.createSuccessTransportRequestPromise({ | ||
success: true, | ||
}); | ||
const controller = new AbortController(); | ||
const enhancedPromise = shimAbortSignal(promise, controller.signal); | ||
|
||
enhancedPromise.abort(); | ||
expect(promise.abort).toHaveBeenCalled(); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
src/plugins/data/server/search/es_search/shim_abort_signal.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { TransportRequestPromise } from '@elastic/elasticsearch/lib/Transport'; | ||
|
||
/** | ||
* | ||
* @internal | ||
* NOTE: Temporary workaround until https://github.com/elastic/elasticsearch-js/issues/1297 | ||
* is resolved | ||
* | ||
* @param promise a TransportRequestPromise | ||
* @param signal optional AbortSignal | ||
* | ||
* @returns a TransportRequestPromise that will be aborted if the signal is aborted | ||
*/ | ||
export const shimAbortSignal = <T extends TransportRequestPromise<unknown>>( | ||
promise: T, | ||
signal: AbortSignal | undefined | ||
): T => { | ||
if (signal) { | ||
signal.addEventListener('abort', () => promise.abort()); | ||
} | ||
return promise; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.