Skip to content

[Security Solution] [Detection Engine] Logs shard failures for eql event queries on rule details page and in event log#207396

Merged
dhurley14 merged 22 commits intoelastic:mainfrom
dhurley14:eql-partial-results
Jan 30, 2025
Merged

[Security Solution] [Detection Engine] Logs shard failures for eql event queries on rule details page and in event log#207396
dhurley14 merged 22 commits intoelastic:mainfrom
dhurley14:eql-partial-results

Conversation

@dhurley14
Copy link
Contributor

@dhurley14 dhurley14 commented Jan 21, 2025

Summary

Related: elastic/elasticsearch#116388

Adds support for shard failures for EQL event queries in the detection engine.

How to test:

  1. start auditbeat and packetbeat
  2. Add the following "broken" runtime field to ONLY ONE of those index mappings
PUT auditbeat-8.13.2/_mapping
{
  "runtime": {
    "broken": {
      "type": "long",
      "script": {
        "lang": "painless",
        "source": "emit(doc['non_existing'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ENGLISH))"
      }
    }
  }
}
  1. Create an EQL rule with the following query: any where agent.type == "auditbeat" or broken == 1
  2. Create and enable the rule.
  3. Warning message should appear on the rule details page
warning_shard_result_auditbeat
  1. Similarly, you can create an eql sequence query and see the error appear for shard failures, as we don't support partial results for sequence queries.
error_sequence_shard_failure

Checklist

Check the PR satisfies following conditions.

Reviewers should verify this PR satisfies this list as well.

  • Documentation was added for features that require explanation or tutorials
  • Unit or functional tests were updated or added to match the most common scenarios
  • The PR description includes the appropriate Release Notes section, and the correct release_note:* label is applied per the guidelines

@dhurley14 dhurley14 changed the title [Security Solution] [Detection Engine] log shard failures on eql event queries as partial failures [Security Solution] [Detection Engine] Logs shard failures for eql event queries on rule details page and in event log Jan 21, 2025
@dhurley14 dhurley14 marked this pull request as ready for review January 22, 2025 17:07
@dhurley14 dhurley14 requested a review from a team as a code owner January 22, 2025 17:07
@dhurley14 dhurley14 requested a review from rylnd January 22, 2025 17:07
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detection-engine (Team:Detection Engine)

@dhurley14 dhurley14 added the backport:version Backport to applied version labels label Jan 22, 2025
},
// the allow_partial$ query parameters supersede xpack settings on cluster
// @ts-expect-error unknown property allow_partial_search_results
// TODO: remove this ts-expect when 8.18 elasticsearch client is released.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a PR/Issue we can reference, 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.

Good question.. Maybe this? elastic/elasticsearch-specification#3342

Copy link
Contributor Author

Choose a reason for hiding this comment

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

v8.16.0 package.json:

"@elastic/elasticsearch": "^8.16.0",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@yctercero @rylnd I just opened this ticket to track the missing type support. Wondering when the 8.18 client will be added to the codebase 🤔

#208760 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

@dhurley14 dhurley14 requested a review from rylnd January 24, 2025 16:42
@yctercero yctercero added ci:cloud-deploy Create or update a Cloud deployment ci:cloud-redeploy Always create a new Cloud deployment labels Jan 27, 2025

const { events, sequences } = response.hits;

if (shardFailures) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Chatted on Zoom, but to summarize - shardFailures is returned for both sequence and non-sequence queries, so we can't rely on this alone to determine what error message to display.

Testing it out, it looks great for non-sequence queries, but the same error displays for sequence queries. Still super helpful to show the shard failures for both types of queries, but for sequence queries we'll want to tweak the language just a bit to make it clear that no search was done, even on available shards.

@dhurley14 dhurley14 linked an issue Jan 27, 2025 that may be closed by this pull request
3 tasks
Copy link
Contributor

@rylnd rylnd left a comment

Choose a reason for hiding this comment

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

I was able to reproduce both the non-sequence warning:

Screenshot 2025-01-29 at 2 19 34 PM

As well as the error for sequence queries:

Screenshot 2025-01-29 at 2 31 00 PM

NB that you need the data necessary to find a sequence hit in order to reproduce the error.

} from '@kbn/alerting-plugin/server';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { Filter } from '@kbn/es-query';

Copy link
Contributor

Choose a reason for hiding this comment

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

I appreciate the addition of meaningful whitespace 👍

@dhurley14 dhurley14 requested a review from a team as a code owner January 30, 2025 02:15
@dhurley14 dhurley14 enabled auto-merge (squash) January 30, 2025 13:34
@approksiu
Copy link

@dhurley14 what is the error message for EQL sequence failure with unavailable shards?

@dhurley14 dhurley14 disabled auto-merge January 30, 2025 17:40
@dhurley14
Copy link
Contributor Author

dhurley14 commented Jan 30, 2025

@approksiu the error message for shard failures with sequence queries is: The EQL query failed to run successfully on the following shards: {shardFailures}

I can update it to something else if that's not clear.

Edit: Missed the suggested text in the slack message. I will update now. Sorry!

@dhurley14 dhurley14 enabled auto-merge (squash) January 30, 2025 18:20
@dhurley14
Copy link
Contributor Author

@approksiu Updated it to match suggested text in slack: The EQL query failed to run successfully due to unavailable shards: {shardFailures}

@elasticmachine
Copy link
Contributor

⏳ Build in-progress, with failures

Failed CI Steps

History

@dhurley14 dhurley14 merged commit 4419390 into elastic:main Jan 30, 2025
9 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

https://github.com/elastic/kibana/actions/runs/13060174669

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 30, 2025
…ent queries on rule details page and in event log (elastic#207396)

## Summary

Related: elastic/elasticsearch#116388

Adds support for shard failures for EQL event queries in the detection
engine.

(cherry picked from commit 4419390)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.x

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Jan 30, 2025
…eql event queries on rule details page and in event log (#207396) (#209019)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution] [Detection Engine] Logs shard failures for eql
event queries on rule details page and in event log
(#207396)](#207396)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Devin W.
Hurley","email":"devin.hurley@elastic.co"},"sourceCommit":{"committedDate":"2025-01-30T19:55:53Z","message":"[Security
Solution] [Detection Engine] Logs shard failures for eql event queries
on rule details page and in event log (#207396)\n\n##
Summary\r\n\r\nRelated:
https://github.com/elastic/elasticsearch/pull/116388/\r\n\r\nAdds
support for shard failures for EQL event queries in the
detection\r\nengine.","sha":"441939028248c3ddc8d17d2f5647baad5aff3f7b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","release_note:fix","v9.0.0","ci:cloud-deploy","ci:cloud-redeploy","Team:Detection
Engine","backport:version","v8.18.0"],"title":"[Security Solution]
[Detection Engine] Logs shard failures for eql event queries on rule
details page and in event
log","number":207396,"url":"https://github.com/elastic/kibana/pull/207396","mergeCommit":{"message":"[Security
Solution] [Detection Engine] Logs shard failures for eql event queries
on rule details page and in event log (#207396)\n\n##
Summary\r\n\r\nRelated:
https://github.com/elastic/elasticsearch/pull/116388/\r\n\r\nAdds
support for shard failures for EQL event queries in the
detection\r\nengine.","sha":"441939028248c3ddc8d17d2f5647baad5aff3f7b"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207396","number":207396,"mergeCommit":{"message":"[Security
Solution] [Detection Engine] Logs shard failures for eql event queries
on rule details page and in event log (#207396)\n\n##
Summary\r\n\r\nRelated:
https://github.com/elastic/elasticsearch/pull/116388/\r\n\r\nAdds
support for shard failures for EQL event queries in the
detection\r\nengine.","sha":"441939028248c3ddc8d17d2f5647baad5aff3f7b"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Devin W. Hurley <devin.hurley@elastic.co>
@marshallmain
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
9.0

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

marshallmain pushed a commit to marshallmain/kibana that referenced this pull request Mar 7, 2025
…ent queries on rule details page and in event log (elastic#207396)

## Summary

Related: elastic/elasticsearch#116388

Adds support for shard failures for EQL event queries in the detection
engine.

(cherry picked from commit 4419390)
marshallmain added a commit that referenced this pull request Mar 7, 2025
…eql event queries on rule details page and in event log (#207396) (#213616)

# Backport

This will backport the following commits from `main` to `9.0`:
- [[Security Solution] [Detection Engine] Logs shard failures for eql
event queries on rule details page and in event log
(#207396)](#207396)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Devin W.
Hurley","email":"devin.hurley@elastic.co"},"sourceCommit":{"committedDate":"2025-01-30T19:55:53Z","message":"[Security
Solution] [Detection Engine] Logs shard failures for eql event queries
on rule details page and in event log (#207396)\n\n##
Summary\r\n\r\nRelated:
https://github.com/elastic/elasticsearch/pull/116388/\r\n\r\nAdds
support for shard failures for EQL event queries in the
detection\r\nengine.","sha":"441939028248c3ddc8d17d2f5647baad5aff3f7b","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["review","release_note:fix","v9.0.0","ci:cloud-deploy","ci:cloud-redeploy","Team:Detection
Engine","backport:version","v8.18.0"],"title":"[Security Solution]
[Detection Engine] Logs shard failures for eql event queries on rule
details page and in event
log","number":207396,"url":"https://github.com/elastic/kibana/pull/207396","mergeCommit":{"message":"[Security
Solution] [Detection Engine] Logs shard failures for eql event queries
on rule details page and in event log (#207396)\n\n##
Summary\r\n\r\nRelated:
https://github.com/elastic/elasticsearch/pull/116388/\r\n\r\nAdds
support for shard failures for EQL event queries in the
detection\r\nengine.","sha":"441939028248c3ddc8d17d2f5647baad5aff3f7b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207396","number":207396,"mergeCommit":{"message":"[Security
Solution] [Detection Engine] Logs shard failures for eql event queries
on rule details page and in event log (#207396)\n\n##
Summary\r\n\r\nRelated:
https://github.com/elastic/elasticsearch/pull/116388/\r\n\r\nAdds
support for shard failures for EQL event queries in the
detection\r\nengine.","sha":"441939028248c3ddc8d17d2f5647baad5aff3f7b"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/209019","number":209019,"state":"MERGED","mergeCommit":{"sha":"be9fcb6b3b35bb677a50362ca131ad5f972581ae","message":"[8.x]
[Security Solution] [Detection Engine] Logs shard failures for eql event
queries on rule details page and in event log (#207396) (#209019)\n\n#
Backport\n\nThis will backport the following commits from `main` to
`8.x`:\n- [[Security Solution] [Detection Engine] Logs shard failures
for eql\nevent queries on rule details page and in event
log\n(#207396)](https://github.com/elastic/kibana/pull/207396)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sqren/backport)\n\n\n\nCo-authored-by:
Devin W. Hurley <devin.hurley@elastic.co>"}}]}] BACKPORT-->

Co-authored-by: Devin W. Hurley <devin.hurley@elastic.co>
@dhurley14 dhurley14 self-assigned this Mar 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels ci:cloud-deploy Create or update a Cloud deployment ci:cloud-redeploy Always create a new Cloud deployment release_note:fix review Team:Detection Engine Security Solution Detection Engine Area v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Detection Engine] Expose EQL partial results

7 participants