Skip to content
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
merged 32 commits into from
Jul 18, 2018

Conversation

cjcenizal
Copy link
Contributor

@cjcenizal cjcenizal commented Jul 5, 2018

Addresses initial steps in #20004:

  • Create a registry for adding a handler that can create a search based on index pattern type.
  • Refactor Courier to have a clear integration point for this registry.

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:

image

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.

@cjcenizal cjcenizal added the WIP Work in progress label Jul 5, 2018
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@cjcenizal cjcenizal force-pushed the search-strategy-registry branch from 2ca6559 to 973c580 Compare July 5, 2018 21:30
…ing search behavior, and integrate it with CallClient.
@cjcenizal cjcenizal added :Discovery v7.0.0 v6.4.0 and removed WIP Work in progress labels Jul 5, 2018
@cjcenizal cjcenizal requested review from jen-huang and bmcconaghy July 5, 2018 22:21
@cjcenizal cjcenizal force-pushed the search-strategy-registry branch from 973c580 to 2bd4962 Compare July 5, 2018 22:22
@cjcenizal cjcenizal mentioned this pull request Jul 5, 2018
52 tasks
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@cjcenizal cjcenizal changed the title Add SearchStrategyRegistry with a default strategy to support existing search behavior, and integrate it with CallClient. Add SearchStrategyRegistry and defaultSearchStrategy to support existing search behavior, and integrate it with CallClient. Jul 6, 2018
@cjcenizal cjcenizal requested a review from spalger July 6, 2018 18:02
@elasticmachine
Copy link
Contributor

💔 Build Failed

esPromise = es.msearch({ body: serializedFetchParams });
const clientResponse = await esPromise;
await respond(clientResponse.responses);
esPromise = Promise.all(esPromises);
Copy link
Contributor

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

Copy link
Contributor

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.

Copy link
Contributor Author

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;
Copy link
Contributor

@jen-huang jen-huang Jul 6, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getting an error for a rollup index pattern in Discover, as it doesn't match any registered search strategies:

screen shot 2018-07-06 at 3 56 25 pm

should handle cases where there is no matching search strategy. maybe we set strategy id to default?

@cjcenizal
Copy link
Contributor Author

cjcenizal commented Jul 6, 2018

@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 feature/rollups branch, and that's where I'm also going to add the rollup specific strategy (WIP here: #20505). This branch is just supposed to create some abstractions we can use without changing any functionality. So I just solved the problem for myself by deleting the rollup index pattern, which is a more realistic scenario.

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 'uiExports/search' or b) we've created an index pattern which has a type defined that our UI doesn't currently support. Both of those seem like error cases to me, so I think we should probably handle them by throwing an informative error. WDYT?

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Copy link
Contributor

@bmcconaghy bmcconaghy left a 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);
Copy link
Contributor

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.

Copy link
Contributor Author

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."
Copy link
Contributor

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."

Copy link
Contributor Author

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) => {
Copy link
Contributor

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?

Copy link
Contributor Author

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either works for me

Copy link
Contributor

@spalger spalger left a 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 => {
Copy link
Contributor

@jen-huang jen-huang Jul 16, 2018

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 = (
Copy link
Contributor

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;
}

Copy link
Contributor

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 {
Copy link
Contributor

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 @@
/*
Copy link
Contributor

@jen-huang jen-huang Jul 16, 2018

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
Copy link
Contributor

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

@cjcenizal
Copy link
Contributor Author

@spalger @jen-huang I've updated the error message and removed references in the code to rollups (except for comments). I've also changed callClient to expect a strategy's searching promise to resolve with a responses array.

image

@spalger
Copy link
Contributor

spalger commented Jul 16, 2018

Still LGTM

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 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 });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@gchaps
Copy link
Contributor

gchaps commented Jul 17, 2018

@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

@gchaps
Copy link
Contributor

gchaps commented Jul 17, 2018

@cjcenizal @alexfrancoeur

re: the wording of Please use X-Pack to search this index pattern or Please install an Elastic licensed version of Kibana to use rollups.

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

Copy link
Contributor

@jen-huang jen-huang left a 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.

@cjcenizal
Copy link
Contributor Author

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.

Copy link
Contributor

@jen-huang jen-huang left a 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!

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@cjcenizal cjcenizal merged commit a36b87a into elastic:master Jul 18, 2018
@cjcenizal cjcenizal deleted the search-strategy-registry branch July 18, 2018 01:49
cjcenizal added a commit to cjcenizal/kibana that referenced this pull request Jul 18, 2018
…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.
cjcenizal added a commit that referenced this pull request Jul 18, 2018
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants