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

[Step 1] use Observables on server search API #79874

Merged
merged 6 commits into from
Oct 13, 2020

Conversation

alexwizp
Copy link
Contributor

@alexwizp alexwizp commented Oct 7, 2020

Summary

This PR is a first step of refactoring of server side Search API to use Observable instead of Promise.
What was done:

  • ISearchStrategy['search'] method was changed: context: RequestHandlerContext argument was moved to the end. I need it to unify this interface with client in future.
  • ISearchStrategy['search'] method now returns Observable instead of Promise
  • All search strategies were changed to return Observable. Temporary it was wrapped into from(new Promise()) but it will be refactored in step 2;

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@alexwizp alexwizp force-pushed the be_search_1 branch 2 times, most recently from 0d38bb3 to 7560f58 Compare October 8, 2020 09:49
@alexwizp alexwizp changed the title [WIP] use Observables on server search API [Step 1] use Observables on server search API Oct 8, 2020
@alexwizp
Copy link
Contributor Author

alexwizp commented Oct 8, 2020

@elasticmachine merge upstream

@alexwizp alexwizp requested review from lizozom and lukasolson October 8, 2020 13:04
@alexwizp alexwizp self-assigned this Oct 8, 2020
@alexwizp alexwizp added release_note:skip Skip the PR/issue when compiling release notes v7.11.0 v8.0.0 Feature:Search Querying infrastructure in Kibana Team:Visualizations Visualization editors, elastic-charts and infrastructure labels Oct 8, 2020
@alexwizp alexwizp marked this pull request as ready for review October 8, 2020 14:41
@alexwizp alexwizp requested a review from a team as a code owner October 8, 2020 14:41
@alexwizp alexwizp requested a review from a team October 8, 2020 14:41
@alexwizp alexwizp requested review from a team as code owners October 8, 2020 14:41
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-app (Team:KibanaApp)

@alexwizp
Copy link
Contributor Author

alexwizp commented Oct 9, 2020

@elasticmachine merge upstream

@alexwizp
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@lizozom lizozom left a comment

Choose a reason for hiding this comment

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

Looks good, added a couple comments

const uiSettingsClient = await context.core.uiSettings.client;
search: (request, options, context) =>
from(
new Promise<IEsSearchResponse>(async (resolve, reject) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already have a promise returned from shimAbortPromise.

I guess you're creating this promise just as a temporary step, but I wanted to make sure.

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 will do it in next step

search: <
SearchStrategyRequest extends IKibanaSearchRequest = IEsSearchRequest,
SearchStrategyResponse extends IKibanaSearchResponse = IEsSearchResponse
>(
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you have to get explicit here?
Doesn't the type come from SearchSourceDependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you are right, it comes from types, but please see the return statement of that method.
return this.search<SearchStrategyRequest, SearchStrategyResponse>(
we need somehow to get required generic types: SearchStrategyRequest, SearchStrategyResponse

src/plugins/data/server/search/search_service.ts Outdated Show resolved Hide resolved
options: ISearchOptions,
context: RequestHandlerContext
) => Observable<SearchStrategyResponse>;
cancel?: (context: RequestHandlerContext, id: string) => Promise<void>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we return an Observable here too?

return queryFactory.parse(request, esSearchRes);
return es
.search({ ...request, params: dsl }, options, context)
.pipe(mergeMap((esSearchRes) => queryFactory.parse(request, esSearchRes)));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you can use map instead of mergeMap here. Am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, so it can be change to a map when we get rid of Promises here?

Copy link
Contributor

@stratoula stratoula left a comment

Choose a reason for hiding this comment

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

KibanaApp code review mainly, I tested it locally, it seems ok to me.

@alexwizp
Copy link
Contributor Author

@elasticmachine merge upstream

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@XavierM XavierM left a comment

Choose a reason for hiding this comment

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

LGTM, everything is working as expected on our side.

@alexwizp alexwizp merged commit 1d1c3c7 into elastic:master Oct 13, 2020
alexwizp added a commit to alexwizp/kibana that referenced this pull request Oct 13, 2020
* use Observables on server search API

* fix PR comments

Co-authored-by: Kibana Machine <[email protected]>
jloleysens added a commit to jloleysens/kibana that referenced this pull request Oct 13, 2020
…otphase-to-formlib

* 'master' of github.com:elastic/kibana: (59 commits)
  [Security Solution][Resolver] Replace copy-to-clipboard with native navigator.clipboard (elastic#80193)
  [Security Solution] Reduce initial bundle size (elastic#78992)
  [Security Solution][Resolver] Fix Resize node box-shadow bug (elastic#80223)
  Move observability content (elastic#79978)
  skip flaky suite (elastic#79389)
  removing kibana_datatable` in favor of `datatable` (elastic#75184)
  [ML] Fixes for anomaly swim lane  (elastic#80299)
  [Lens] Smokescreen lens test unskip (elastic#80190)
  Improved AlertsClient tests structure by splitting a huge alerts_client.tests.ts file into a specific files defined by its responsibility. (elastic#80088)
  [APM] React key warning when opening popover with external resources (elastic#80328)
  [Step 1] use Observables on server search API (elastic#79874)
  Apply back pressure in Task Manager whenever Elasticsearch responds with a 429 (elastic#75666)
  [Lens] Leverage original http request error (elastic#79831)
  [Security Solution][Case] Improve ServiceConnectorCaseParams type (elastic#80109)
  [SECURITY_SOLUTION] Fix query on alert histogram (elastic#80219)
  [DOCS] Update ingest node pipelines doc (elastic#79187)
  [Ingest Manager] Split up OpenAPI spec file  (elastic#80107)
  [SECURITY_SOLUTION][ENDPOINT] Fix label on Trusted App create name field (elastic#80001)
  [Ingest Manager] Fix agent policy bump revision to create only one POLICY_CHANGE action (elastic#80081)
  Grid layout fixes (elastic#80305)
  ...

# Conflicts:
#	x-pack/plugins/index_lifecycle_management/public/application/sections/edit_policy/components/phases/shared/data_tier_allocation_field.tsx
#	x-pack/plugins/index_lifecycle_management/public/shared_imports.ts
alexwizp added a commit that referenced this pull request Oct 13, 2020
* use Observables on server search API

* fix PR comments

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Search Querying infrastructure in Kibana release_note:skip Skip the PR/issue when compiling release notes Team:Visualizations Visualization editors, elastic-charts and infrastructure v7.11.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants