-
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
[Security Solution] Dedupe alerts by querying _id before creation #119045
Conversation
…into alert-deduplication
Pinging @elastic/security-solution (Team: SecuritySolution) |
@elasticmachine merge upstream |
💚 Build Succeeded
Metrics [docs]Public APIs missing comments
History
To update your PR or re-run it, just comment with: |
…astic#119045) * Dedupe alerts by querying _id before creation * Update alert chunk size * Use aggregations to find existing alert _ids * Remove tightly coupled tests * Add api integration test for alert deduplication * Remove unused import * Cleaner util implementation * Skip flaky test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
💚 Backport successful
This backport PR will be merged automatically after passing CI. |
…19045) (#119122) * Dedupe alerts by querying _id before creation * Update alert chunk size * Use aggregations to find existing alert _ids * Remove tightly coupled tests * Add api integration test for alert deduplication * Remove unused import * Cleaner util implementation * Skip flaky test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Marshall Main <55718608+marshallmain@users.noreply.github.com>
…astic#119045) * Dedupe alerts by querying _id before creation * Update alert chunk size * Use aggregations to find existing alert _ids * Remove tightly coupled tests * Add api integration test for alert deduplication * Remove unused import * Cleaner util implementation * Skip flaky test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
…19045) * Dedupe alerts by querying _id before creation * Update alert chunk size * Use aggregations to find existing alert _ids * Remove tightly coupled tests * Add api integration test for alert deduplication * Remove unused import * Cleaner util implementation * Skip flaky test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Summary
New PR because the last one (#118261) was failing to report the status from CI at all, even after closing/reopening and triggering CI re-runs. Not sure what was going wrong.
This PR adds logic to query for candidate alerts by
_id
before attempting to create them. This fixes 2 bugs.First bug: when a rule runs with a significant "additional lookback", it can find the same alert on multiple consecutive executions. The alerts generated on the later executions were overwriting the existing alert from the previous execution, updating the
@timestamp
field but leaving all other fields the same. With this change, the later executions see that the alert already exists and don't modify it.Second bug: for a long time, it has been possible for an alert with the same
_id
to exist in multiple concrete indices. As a result, if a rule finds the same alert on multiple runs but the alerts index rolls over between rule runs, then the alert will be duplicated in both the old and new index. Since this new logic queries the alerts index alias for the_id
, when an index rollover happens we will still detect that an alert has already been written and won't write a duplicate.Organization
This PR also moves more of the document creation logic into the Persistence Rule type. The
bulkCreateFactory
was responsible for parsing the bulk response before, but the persistence rule type was defining the request and response formats. The reorganization groups logic inalertWithPersistence
so that alerts to index are passed into the function and the alerts that were actually indexed are returned from the function.