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

Improve search typescript #69333

Merged
merged 45 commits into from
Jul 7, 2020

Conversation

lizozom
Copy link
Contributor

@lizozom lizozom commented Jun 16, 2020

Summary

This PR removes the concept of "Search Strategies" from the front end of Kibana.

Instead, it incorporates the search logic within the search_interceptors.
The OSS interceptor is responsible for synchronous querying, while the x-pack interceptor adds capabilities such as async queries, cancellation, running beyond timeout etc.

This PR also reduces the waitForCompletion timeout to 100ms (instead of 1s). This is especially important moving forward to async search, as this determins the earliest time we get the asyncID from ES.

Dev Docs

This PR deprecates the front end search strategy concept removes the following API methods from the data.search plugin:

  • registerSearchStrategy
  • getSearchStrategy

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@lizozom lizozom self-assigned this Jun 16, 2020
@lizozom lizozom changed the title Server side search strategy API Improve search typescript Jun 18, 2020
@lizozom
Copy link
Contributor Author

lizozom commented Jun 25, 2020

@elasticmachine merge upstream

...request.params,
};

params.trackTotalHits = true; // Get the exact count of hits

// If we have an ID, then just poll for that ID, otherwise send the entire request body
const { body = undefined, index = undefined, ...queryParams } = request.id ? {} : params;

const method = request.id ? 'GET' : 'POST';
const path = encodeURI(request.id ? `/_async_search/${request.id}` : `/${index}/_async_search`);

// Wait up to 1s for the response to return
Copy link
Contributor Author

Choose a reason for hiding this comment

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

delete comment

export function toPromise(signal: AbortSignal): Promise<never> {
return new Promise((resolve, reject) => {
if (signal.aborted) reject(new AbortError());
signal.addEventListener('abort', () => reject(new AbortError()));
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 every time we addEventListener we also have to have removeEventListener somewhere.
Otherwise we are spamming memory leaks.

Just double checked this is required, for example, fetch polyfill does this: https://github.com/github/fetch/blob/master/fetch.js#L534

I guess should be fixed in separate pr, since it isn't something new introduced with the refactor.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ahh, turns out I mentioned it here: #65051.
Added fetch example there in description

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a removeEventListener

Copy link
Contributor

@Dosant Dosant Jul 6, 2020

Choose a reason for hiding this comment

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

It won't always work. We also need to remove listener after corresponding request is successfully finished.
That is why they do it in finalise callback. https://github.com/github/fetch/blob/master/fetch.js#L534
Should be tacked properly in scope of #65051

@lizozom lizozom requested a review from Dosant July 5, 2020 10:41
@lizozom lizozom requested a review from a team as a code owner July 5, 2020 11:58
@lizozom
Copy link
Contributor Author

lizozom commented Jul 5, 2020

@elasticmachine merge upstream

@weltenwort
Copy link
Member

Could you explain how this changes the scope of the functionality that the data plugin offers? Does this remove the ability for plugins to register and use their own search strategies? Seeing how the examples were removed, will there be new documentation in their place to explain the usage?

@lizozom
Copy link
Contributor Author

lizozom commented Jul 6, 2020

@elasticmachine merge upstream

return new Promise((resolve, reject) => {
esSearcher
dataPlugin.search
Copy link
Member

Choose a reason for hiding this comment

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

Is there some documentation for how to interact with this API? How can I confirm that dataPlugin.search.search is the correct API function etc?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The docs are in the making.
Synced with @weltenwort to confirm the changes suit your needs.

Copy link
Member

Choose a reason for hiding this comment

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

OK, in the meantime without docs, can you confirm that the API is definitely dataPlugin.search.search vs dataPlugin.search? And what are the list of available keys and methods on dataPlugin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Data plugin contains several services

  • query (everything that has to do with the search bar - time range, query string, filters)
  • search (which contains the search function and the aggs helpers
  • index patterns
  • field formatting
  • autocompletion

The method relevant to you is indeed dataStart.search.search()

@lizozom lizozom requested a review from jasonrhodes July 7, 2020 08:22
@lizozom
Copy link
Contributor Author

lizozom commented Jul 7, 2020

@elasticmachine merge upstream

Copy link
Member

@jasonrhodes jasonrhodes left a comment

Choose a reason for hiding this comment

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

LGTM thanks for the explanations

Copy link
Contributor

@Dosant Dosant left a comment

Choose a reason for hiding this comment

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

I partially tested using flights dashboard (with x-pack)
Focused on 2 things:

  1. Cancelations are working as expected when clicking refresh fast. (this was flaky in that past)
  2. I set latency to 15s, and made sure I can cancel or run beyond timeout

With that didn't find any issues.
But this is just artificial client side tests and I didn't test with data to trigger proper async search flow.

…om/kibana into search/server-side-search-strategy
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

@kbn/optimizer bundle module count

id value diff baseline
data 202 -2 204
dataEnhanced 5 -1 6
total - -3 -

Saved Objects .kibana field count

id value diff baseline
action 5 +5 -
action_task_params 3 +3 -
alert 22 +22 -
apm-indices 8 +8 -
apm-telemetry 238 +238 -
application_usage_transactional 2 +2 -
canvas-element 8 +8 -
canvas-workpad 5 +5 -
canvas-workpad-template 8 +8 -
cases 32 +32 -
cases-comments 17 +17 -
cases-configure 14 +14 -
cases-user-actions 10 +10 -
config 2 +2 -
dashboard 17 +17 -
endpoint:user-artifact 10 +10 -
endpoint:user-artifact-manifest 3 +3 -
epm-packages 8 +8 -
exception-list 35 +35 -
exception-list-agnostic 35 +35 -
file-upload-telemetry 2 +2 -
fleet-agent-actions 6 +6 -
fleet-agent-events 11 +11 -
fleet-agents 23 +23 -
fleet-enrollment-api-keys 10 +10 -
graph-workspace 9 +9 -
index-pattern 10 +10 -
infrastructure-ui-source 21 +21 -
ingest_manager_settings 5 +5 -
ingest-agent-configs 11 +11 -
ingest-outputs 10 +10 -
ingest-package-configs 35 +35 -
inventory-view 40 +40 -
kql-telemetry 3 +3 -
lens 7 +7 -
lens-ui-telemetry 5 +5 -
map 7 +7 -
metrics-explorer-view 22 +22 -
ml-telemetry 3 +3 -
namespace 1 +1 -
namespaces 1 +1 -
query 6 +6 -
references 4 +4 -
sample-data-telemetry 3 +3 -
search 9 +9 -
siem-detection-engine-rule-actions 8 +8 -
siem-detection-engine-rule-status 12 +12 -
siem-ui-timeline 86 +86 -
siem-ui-timeline-note 8 +8 -
siem-ui-timeline-pinned-event 7 +7 -
space 9 +9 -
telemetry 9 +9 -
timelion-sheet 13 +13 -
tsvb-validation-telemetry 2 +2 -
type 1 +1 -
ui-metric 2 +2 -
updated_at 1 +1 -
upgrade-assistant-reindex-operation 15 +15 -
upgrade-assistant-telemetry 13 +13 -
uptime-dynamic-settings 4 +4 -
url 6 +6 -
visualization 9 +9 -
total - +951 -

History

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

@lizozom lizozom merged commit f290c68 into elastic:master Jul 7, 2020
lizozom added a commit to lizozom/kibana that referenced this pull request Jul 7, 2020
* [search] Refactor the way search strategies are registered/retrieved on the server

* Fix types and tests and update docs

* Fix failing test

* Fix build of example plugin

* Fix functional test

* Make server strategies sync

* Move strategy name into options

* docs

* Remove FE strategies

* TypeScript of hell
delete search explorer

* Fix search interceptor OSS tests

* typos

* test cleanup

* Delete search example
fix interceptor async tests to use fake timers

* docs

* fix

* return search wrapper

* Update search interceptor tests and abort utils

* ts

* jest test fix

* code review

* change how logs consume search API

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/data/public/public.api.md
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 8, 2020
* master: (36 commits)
  fixed api url in example plugin (elastic#70934)
  [data.search.aggs]: Remove remaining client dependencies (elastic#70251)
  [Security Solution][Endpoint] Fix base64 download bug and adopt new user artifact/manifest format (elastic#70998)
  [Security Solution][Exceptions] - Exception Modal Part I (elastic#70639)
  [SIEM][Detection Engine][Lists] Adds additional data types to value based lists
  [SIEM][Detection Engine][Lists] Removes feature flag for lists
  [APM] Show license callout in ML settings (elastic#70959)
  Migrate service settings test to jest (elastic#70992)
  [APM] Add cloud attributes to data telemetry (elastic#71008)
  Fix breadcrumb on panels for visibility / round corners (elastic#71010)
  Improve search typescript (elastic#69333)
  [savedObjects field count] run in baseline job (elastic#70999)
  [Security Solution] [Timeline] Timeline manager tweaks (elastic#69988)
  [Endpoint] Support redirect from Policy Details to Ingest when user initiates Edit Policy from Datasource Edit page (elastic#70874)
  [APM] Add API tests (elastic#70740)
  [Security Solution][Exceptions] - Tie server and client code together (elastic#70918)
  [Audit Logging] Add AuditTrail service (elastic#69278)
  [Usage Collection] Ensure no type duplicates (elastic#70946)
  [Security Solution] [Timeline] Bugfix for timeline row actions disappear sometimes (elastic#70958)
  [CI] Add pipeline task queue framework and merge workers into one (elastic#64011)
  ...
lizozom added a commit that referenced this pull request Jul 8, 2020
* Improve search typescript (#69333)

* [search] Refactor the way search strategies are registered/retrieved on the server

* Fix types and tests and update docs

* Fix failing test

* Fix build of example plugin

* Fix functional test

* Make server strategies sync

* Move strategy name into options

* docs

* Remove FE strategies

* TypeScript of hell
delete search explorer

* Fix search interceptor OSS tests

* typos

* test cleanup

* Delete search example
fix interceptor async tests to use fake timers

* docs

* fix

* return search wrapper

* Update search interceptor tests and abort utils

* ts

* jest test fix

* code review

* change how logs consume search API

Co-authored-by: Lukas Olson <olson.lukas@gmail.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
# Conflicts:
#	src/plugins/data/public/public.api.md

* docs

* Fix merge

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
@lizozom lizozom mentioned this pull request Jul 13, 2020
32 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:ExpressionLanguage Interpreter expression language (aka canvas pipeline) Feature:Search Querying infrastructure in Kibana release_note:plugin_api_changes Contains a Plugin API changes section for the breaking plugin API changes section. v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants