-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add SearchStrategyRegistry and defaultSearchStrategy to support existing search behavior, and integrate it with CallClient. #20497
Merged
cjcenizal
merged 32 commits into
elastic:master
from
cjcenizal:search-strategy-registry
Jul 18, 2018
Merged
Changes from 5 commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
2bd4962
Add SearchStrategyRegistry and defaultSearchStrategy to support exist…
cjcenizal 1c1b99a
Fix typo.
cjcenizal a0386ea
Move fetch param logic from CallClient into defaultSearchStrategy.
cjcenizal ebd3544
Move defaultSearchStrategy configuration into kibana plugin via searc…
cjcenizal 27ba85c
Fix typo in comment.
cjcenizal 8a7e05f
Fix bug where Dashboard Only Mode was broken.
cjcenizal 0a8442b
Don't throw ABORTED.
cjcenizal 9777a60
Add comments and refactor for clarity.
cjcenizal 31925d5
Refactor strategy interface to be more flexible with the arguments it…
cjcenizal b74224c
Add call-out react directive.
cjcenizal 9d02ff2
Show error in Discover if user tries to access a rollup index pattern…
cjcenizal d48f65b
Improve logic for resolving an early response if all searchRequests h…
cjcenizal bcce546
Merge branch 'master' of github.com:elastic/kibana into search-strate…
cjcenizal 5c7666c
Fix bugs in callClient using the tests as a guide.
cjcenizal 6b97760
Fix bug caused by typo in defaultSearchStrategy.
cjcenizal 3964b3a
Improve appearance of Discover when an unsupported rollup index patte…
cjcenizal 596a8c9
Remove unnecessary if.
cjcenizal dcddc1c
Return separate searching and abort properties from strategy.search().
cjcenizal 00a8fe5
Simplify isViable to only expect an indexPattern.
cjcenizal ae033f2
Remove duplicate call to respondToSearchRequests().
cjcenizal 5bd4b01
Send responses in original order to respondToSearchRequests.
cjcenizal d867a3f
Fix Jest tests.
cjcenizal 714990c
Add tests with multiple searchStrategies and fix errors in logic.
cjcenizal 683a2f3
Merge branch 'master' of github.com:elastic/kibana into search-strate…
cjcenizal 5ad6a55
Rename describe block.
cjcenizal 464b568
Rename describe block.
cjcenizal 6d4fc57
Merge branch 'master' of github.com:elastic/kibana into search-strate…
cjcenizal 4aba1fa
Check for default type index pattern instead of rollup type.
cjcenizal 4c51a51
CallClient now expects search to resolve with responses array.
cjcenizal 1c4e668
Fix tests.
cjcenizal ff73efb
Tweak copy.
cjcenizal e6379d8
Merge branch 'master' of github.com:elastic/kibana into search-strate…
cjcenizal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
71 changes: 71 additions & 0 deletions
71
src/ui/public/courier/search_strategy/default_search_strategy.js
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,71 @@ | ||
/* | ||
* 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 { addSearchStrategy } from './search_strategy_registry'; | ||
|
||
function getAllFetchParams(searchRequests, Promise) { | ||
return Promise.map(searchRequests, (searchRequest) => { | ||
return Promise.try(searchRequest.getFetchParams, void 0, searchRequest) | ||
.then((fetchParams) => { | ||
return (searchRequest.fetchParams = fetchParams); | ||
}) | ||
.then(value => ({ resolved: value })) | ||
.catch(error => ({ rejected: error })); | ||
}); | ||
} | ||
|
||
function serializeAllFetchParams(fetchParams, searchRequests, serializeFetchParams) { | ||
const requestsWithFetchParams = []; | ||
|
||
// Gather the fetch param responses from all the successful requests. | ||
fetchParams.forEach((result, index) => { | ||
if (result.resolved) { | ||
requestsWithFetchParams.push(result.resolved); | ||
} else { | ||
const request = searchRequests[index]; | ||
request.handleFailure(result.rejected); | ||
searchRequests[index] = undefined; | ||
} | ||
}); | ||
|
||
return serializeFetchParams(requestsWithFetchParams); | ||
} | ||
|
||
export const defaultSearchStrategy = { | ||
id: 'default', | ||
|
||
search: async ({ searchRequests, es, Promise, serializeFetchParams }) => { | ||
// Flatten the searchSource within each searchRequest to get the fetch params, | ||
// e.g. body, filters, index pattern, query. | ||
const allFetchParams = await getAllFetchParams(searchRequests, Promise); | ||
|
||
// Serialize the fetch params into a format suitable for the body of an ES query. | ||
const serializedFetchParams = await serializeAllFetchParams(allFetchParams, searchRequests, serializeFetchParams); | ||
|
||
return es.msearch({ body: serializedFetchParams }); | ||
}, | ||
|
||
isValidForSearchRequest: searchRequest => { | ||
// Basic index patterns don't have `type` defined. | ||
const indexPattern = searchRequest.source.getField('index'); | ||
return indexPattern.type == null; | ||
}, | ||
}; | ||
|
||
addSearchStrategy(defaultSearchStrategy); |
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,23 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export { | ||
assignSearchRequestsToSearchStrategies, | ||
addSearchStrategy, | ||
} from './search_strategy_registry'; |
69 changes: 69 additions & 0 deletions
69
src/ui/public/courier/search_strategy/search_strategy_registry.js
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,69 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
const searchStrategies = []; | ||
|
||
const addSearchStrategy = searchStrategy => { | ||
searchStrategies.push(searchStrategy); | ||
}; | ||
|
||
/** | ||
* Build a structure like this: | ||
* | ||
* [{ | ||
* searchStrategy: <rollupSearchStrategy>, | ||
* searchRequests: []<SearchRequest>, | ||
* }, { | ||
* searchStrategy: <defaultSearchStrategy>, | ||
* searchRequests: []<SearchRequest>, | ||
* }] | ||
* | ||
* We use an array of objects to preserve the order of the search requests, which we use to | ||
* deterministically associate each response with the originating request. | ||
*/ | ||
const assignSearchRequestsToSearchStrategies = searchRequests => { | ||
const searchStrategiesWithRequests = []; | ||
const searchStrategyById = {}; | ||
|
||
searchRequests.forEach(searchRequest => { | ||
const matchingSearchStrategy = searchStrategies.find(searchStrategy => searchStrategy.isValidForSearchRequest(searchRequest)); | ||
const { id } = matchingSearchStrategy; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
let searchStrategyWithRequest = searchStrategyById[id]; | ||
|
||
// Create the data structure if we don't already have it. | ||
if (!searchStrategyWithRequest) { | ||
searchStrategyWithRequest = { | ||
searchStrategy: matchingSearchStrategy, | ||
searchRequests: [], | ||
}; | ||
|
||
searchStrategyById[id] = searchStrategyWithRequest; | ||
searchStrategiesWithRequests.push(searchStrategyWithRequest); | ||
} | ||
|
||
searchStrategyWithRequest.searchRequests.push(searchRequest); | ||
}); | ||
|
||
return searchStrategiesWithRequests; | ||
}; | ||
|
||
export { | ||
assignSearchRequestsToSearchStrategies, | ||
addSearchStrategy, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'll need to update the
esPromise
logic to handle theesPromises
array because it needs access to the individualesPromise.abort()
methodsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, would you mind trying to write a test that validates that promises from the esClient are aborted correctly when a single request in a batch is aborted? I imagine it's going to be tricky but would probably be a good idea to have given the scope of this refactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you see any problem with just removing the code that calls
esPromise.abort()
? What's the point of aborting them?