-
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
Add SearchStrategyRegistry and defaultSearchStrategy to support existing search behavior, and integrate it with CallClient. #20497
Conversation
💚 Build Succeeded |
2ca6559
to
973c580
Compare
…ing search behavior, and integrate it with CallClient.
973c580
to
2bd4962
Compare
💚 Build Succeeded |
…h uiExport to avoid race conditions with other plugins.
💔 Build Failed |
esPromise = es.msearch({ body: serializedFetchParams }); | ||
const clientResponse = await esPromise; | ||
await respond(clientResponse.responses); | ||
esPromise = Promise.all(esPromises); |
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 the esPromises
array because it needs access to the individual esPromise.abort()
methods
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.
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.
We'll need to update the esPromise logic to handle the esPromises array because it needs access to the individual esPromise.abort() methods
Can you see any problem with just removing the code that calls esPromise.abort()
? What's the point of aborting them?
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
@jen-huang I ran into this error myself and then smacked my forehead with my palm. Technically, this situation won't ever arise, because you'll only be able to create a rollup index pattern using the UI in our That said, I wonder if we really need to gracefully handle cases where there's no matching strategy? That would mean that either a) a plugin developer relies on courier for searching but failed to import |
💚 Build Succeeded |
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.
LGTM
// Assigning searchRequests to strategies means that the responses come back in a different | ||
// order than the original searchRequests. So we'll put them back in order so that we can | ||
// use the order to associate each response with the original request. | ||
const responsesInOriginalRequestOrder = new Array(searchRequestsAndStatuses.length); |
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.
Nothing "wrong" with this here, but I think it would be logical to use the searchRequests
array instead of the searchRequestsAndStatuses
array here, below, and in respondToSearchRequests()
, don't you think? Especially since respondToSearchRequests()
is reading the status from searchRequestsAndStatuses
by index anyway.
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.
At least for me, using searchRequestsAndStatuses
makes the code a bit easier to follow by reducing the number of variables I have to keep in mind. In terms of data structures being consumed, searchRequests
stops being important immediately, and searchRequestsAndStatuses
, requestsToFetch
, and searchStrategiesWithRequests
become the important ones. It would be a bit confusing to me if I were to read this code and see searchRequests
was reintroduced -- I'd wonder what the intention behind that was.
<EuiFlexGroup justifyContent="center"> | ||
<EuiFlexItem grow={false} className="discoverNoResults"> | ||
<EuiCallOut | ||
title="OSS Kibana doesn't support rollup index patterns. Please use X-Pack to search this index pattern." |
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.
Do you think users will understand "OSS Kibana"? I wonder if we should rephrase this to instead say something like: "Index Patterns based on rollup indices require the rollup plugin from X-Pack which is either not installed or disabled."
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.
I like this a lot. @gchaps thoughts?
// order than the original searchRequests. So we'll put them back in order so that we can | ||
// use the order to associate each response with the original request. | ||
const responsesInOriginalRequestOrder = new Array(searchRequestsAndStatuses.length); | ||
segregatedResponses.forEach((responses, strategyIndex) => { |
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.
Maybe replace responses
on this line with { responses }
to avoid some of the redundancy here?
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.
Maybe I should just change the interface to only return the responses
array. WDYT?
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.
Either works for me
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.
A couple nitpicks, but went through the code pretty thoroughly and pulled it down and searching/aborting/etc seem to work great.
return Boolean(getSearchStrategy(indexPattern)); | ||
}; | ||
|
||
const isRollupIndexPattern = indexPattern => { |
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.
I don't think we should have any rollup references in OSS code. when we embarked on this journey, we made the decision to avoid any cross stream code for x-pack features. maybe this can be abstracted out as part of as part of registered search strategies? see my next comments for ideas 😄
@@ -777,5 +777,16 @@ function discoverController( | |||
return loadedIndexPattern; | |||
} | |||
|
|||
// Block the UI from loading if the user has loaded a rollup index pattern but it isn't | |||
// supported. | |||
$scope.isUnsupportedRollup = ( |
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.
when rollup reference is abstracted away, maybe this can be something like:
import {
hasSearchStategyForIndexPattern,
isIndexPatternSupported,
renderUnsupportedIndexPatternMessage,
} from 'ui/courier';
if(
!hasSearchStategyForIndexPattern($route.current.locals.ip.loaded)
|| !isIndexPatternSupported($route.current.locals.ip.loaded)
) {
// psuedo code - implementation will need adjustment for rendering logic! :)
$scope.unsupportedMessage = renderUnsupportedIndexPatternMessage();
return;
}
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.
I redact my previous review after chatting with CJ and realizing that the unsupported rollup messages were are due to giving user hints when they're using OSS. X-Pack code isn't reachable in that scenario.
The comprise to support this type of error in OSS, while avoiding cross stream OSS/X-Pack code and rollup references, is to check whether the index pattern is the default type, instead of checking for rollup type.
@@ -25,8 +25,14 @@ import { | |||
DiscoverNoResults, | |||
} from './no_results'; | |||
|
|||
import { |
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.
references to rollup message can be removed with implementation of renderUnsupportedIndexPatternMessage
or similar
@@ -0,0 +1,43 @@ | |||
/* |
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.
then, this component can be moved somewhere inside x-pack/rollups directory as part of rollup PR
@@ -60,6 +60,10 @@ <h1 tabindex="0" id="kui_local_breadcrumb" class="kuiLocalBreadcrumb"> | |||
|
|||
<div class="discover-wrapper col-md-10"> | |||
<div class="discover-content"> | |||
<discover-unsupported-rollup |
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.
and this will use generic $scope.unsupportedMessage
or similar, instead of referencing rollups directly
@spalger @jen-huang I've updated the error message and removed references in the code to rollups (except for comments). I've also changed |
Still LGTM |
💔 Build Failed |
💚 Build Succeeded |
@@ -68,12 +68,12 @@ export const defaultSearchStrategy = { | |||
failedSearchRequests, | |||
} = await serializeAllFetchParams(allFetchParams, searchRequests, serializeFetchParams); | |||
|
|||
const searching = es.msearch({ body: serializedFetchParams }).then(({ responses }) => responses); | |||
const abort = searching.abort; | |||
const searching = es.msearch({ body: serializedFetchParams }); |
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.
👍
@cjcenizal A minor edit. Add a comma before which and I think we can remove "either" Index patterns based on rollup indices require the rollup plugin from X-pack, which is not installed or disabled |
re: the wording of How about: "OSS Kibana doesn't support rollup index patterns. You must use the default distribution of Kibana and a Basic license at a minimum." I picked "default distribution" due to the wording here: https://www.elastic.co/downloads/kibana |
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.
The new changes to abstract out the index pattern type are great! I tested locally and am able to get the unsupported message to show in Discover.
I think we need to apply the same logic (that checks default index pattern type and if it has a search strategy) to search calls made by visualizations. I still get the same Courier fetch: Cannot read property 'id' of undefined
when trying to create a visualization for a rollup pattern.
@jen-huang I agree but I'd like to make those changes in a separate PR to keep the size of this one down and to merge it in ASAP. |
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.
Since the error in visualizations for rollups won't affect anyone else due to rollup code not being in master, LGTM!
💔 Build Failed |
💚 Build Succeeded |
…ting search behavior, and integrate it with CallClient. (elastic#20497) * Add SearchStrategyRegistry and defaultSearchStrategy to support existing search behavior, and integrate it with CallClient. * Move fetch param logic from CallClient into defaultSearchStrategy. * Move defaultSearchStrategy configuration into kibana plugin via search uiExport to avoid race conditions with other plugins. * Add call-out react directive. * Show error in Discover if user tries to access a rollup index pattern without the right search strategy. Sentence-case copy in field chooser. * Add tests with multiple searchStrategies and fix errors in logic.
…ting search behavior, and integrate it with CallClient. (#20497) (#20912) * Add SearchStrategyRegistry and defaultSearchStrategy to support existing search behavior, and integrate it with CallClient. * Move fetch param logic from CallClient into defaultSearchStrategy. * Move defaultSearchStrategy configuration into kibana plugin via search uiExport to avoid race conditions with other plugins. * Add call-out react directive. * Show error in Discover if user tries to access a rollup index pattern without the right search strategy. Sentence-case copy in field chooser. * Add tests with multiple searchStrategies and fix errors in logic.
Addresses initial steps in #20004:
Handling errors
When you try to access a rollup index pattern in Discover without the correct search strategy (e.g. you've downgraded from X-Pack to OSS Kibana), you'll see an error:
This requires mentioning an X-Pack feature in OSS, but I talked about this with @AlonaNadler and we think it's acceptable since the user has already been using X-Pack to create the rollup originally.