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

[Discover] Cancel long running requests in Discover alert #130077

Merged

Conversation

dimaanj
Copy link
Contributor

@dimaanj dimaanj commented Apr 13, 2022

Summary

Closes #128043

This PR adds ability to cancel search source request processing when it takes long within Discover alert rule. SearchSource object instance was wraped to pass abortSignal.

searchSource.fetch$({ ...options, abortSignal: abortController.signal });

To propogate such behaviour per each further created searchSource children, the following methods were also overwritten: searchSource.createChild(...), searchSource.createCopy(...), searchSource.create(...),

Checklist

Delete any items that are not applicable to this PR.

@dimaanj dimaanj added Feature:Discover Discover Application Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.3.0 labels Apr 13, 2022
@dimaanj dimaanj self-assigned this Apr 13, 2022
dimaanj added 2 commits April 20, 2022 16:57
…-long-running-requests-for-alert-rule

# Conflicts:
#	x-pack/plugins/alerting/server/lib/wrap_scoped_cluster_client.ts
#	x-pack/plugins/alerting/server/types.ts
#	x-pack/plugins/stack_alerts/server/alert_types/es_query/lib/fetch_search_source_query.ts
@dimaanj
Copy link
Contributor Author

dimaanj commented Apr 21, 2022

@elasticmachine merge upstream

@dimaanj dimaanj marked this pull request as ready for review April 25, 2022 07:04
@dimaanj dimaanj requested review from a team as code owners April 25, 2022 07:04
@dimaanj dimaanj requested a review from a team April 25, 2022 07:04
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-data-discovery (Team:DataDiscovery)

…-long-running-requests-for-alert-rule

# Conflicts:
#	x-pack/plugins/alerting/server/types.ts
#	x-pack/plugins/security_solution/server/lib/detection_engine/routes/rules/preview_rules_route.ts
@dimaanj dimaanj added the release_note:skip Skip the PR/issue when compiling release notes label Apr 25, 2022
@dimaanj
Copy link
Contributor Author

dimaanj commented Apr 25, 2022

@elasticmachine merge upstream

@dimaanj
Copy link
Contributor Author

dimaanj commented Apr 25, 2022

@elasticmachine merge upstream

@dimaanj dimaanj requested review from ymao1 and kertal April 26, 2022 14:00
Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

I did an initial pass, looking good! I had two questions before continuing my review 🙏

x-pack/plugins/alerting/common/rule_task_instance.ts Outdated Show resolved Hide resolved
x-pack/plugins/alerting/server/task_runner/task_runner.ts Outdated Show resolved Hide resolved
dimaanj added 2 commits April 28, 2022 10:52
…-long-running-requests-for-alert-rule

# Conflicts:
#	x-pack/plugins/alerting/common/rule_task_instance.ts
#	x-pack/plugins/alerting/server/lib/wrap_scoped_cluster_client.ts
#	x-pack/plugins/alerting/server/task_runner/task_runner.test.ts
#	x-pack/plugins/alerting/server/task_runner/task_runner.ts
#	x-pack/plugins/alerting/server/task_runner/task_runner_cancel.test.ts
@dimaanj
Copy link
Contributor Author

dimaanj commented Apr 30, 2022

@elasticmachine merge upstream

@kertal kertal requested a review from mikecote May 3, 2022 10:16
Copy link
Contributor

@mikecote mikecote left a comment

Choose a reason for hiding this comment

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

I finished my review, I was able to see it working locally 👌 I think type check will catch this but some tests were still referencing searchSourceUtils.

LGTM but I think we should sum up the metrics from search source and scoped cluster client before reporting them.

x-pack/plugins/alerting/server/task_runner/task_runner.ts Outdated Show resolved Hide resolved
dimaanj added 2 commits May 11, 2022 18:33
…-long-running-requests-for-alert-rule

# Conflicts:
#	x-pack/plugins/alerting/server/task_runner/task_runner.ts
@dimaanj
Copy link
Contributor Author

dimaanj commented May 14, 2022

@elasticmachine merge upstream

@dimaanj dimaanj force-pushed the improve-long-running-requests-for-alert-rule branch from 1ea6a98 to 7ab49d7 Compare May 15, 2022 08:00
@dimaanj
Copy link
Contributor Author

dimaanj commented May 15, 2022

@elasticmachine merge upstream

@dimaanj dimaanj requested a review from YulNaumenko May 15, 2022 12:38
Copy link
Contributor

@ymao1 ymao1 left a comment

Choose a reason for hiding this comment

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

LGTM!

@dimaanj
Copy link
Contributor Author

dimaanj commented May 17, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

References to deprecated APIs

id before after diff
alerting 5 21 +16
securitySolution 48 58 +10
total +26

History

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

cc @dmitriynj

Copy link
Member

@kertal kertal left a comment

Choose a reason for hiding this comment

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

Code LGTM 👍 , did not test, just review.
Only ask, there are plenty of changes under the hood that should be mentioned in the PR description ... like wrapping the searchSource client also get metrics

@dimaanj dimaanj requested a review from mgiota May 18, 2022 21:05
Copy link
Contributor

@YulNaumenko YulNaumenko left a comment

Choose a reason for hiding this comment

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

LGTM

@dimaanj dimaanj merged commit fdf2086 into elastic:main May 19, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 19, 2022
Copy link
Contributor

@mgiota mgiota left a comment

Choose a reason for hiding this comment

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

LGTM!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Discover Discover Application release_note:skip Skip the PR/issue when compiling release notes Team:DataDiscovery Discover, search (e.g. data plugin and KQL), data views, saved searches. For ES|QL, use Team:ES|QL. v8.3.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

[Discover] Long running search source fetches in a Elasticsearch query rule
10 participants