Skip to content

[Security Solution][Detection Engine] adds preview logged requests for new terms, threshold, query, ML rule types#203320

Merged
vitaliidm merged 46 commits intoelastic:mainfrom
vitaliidm:de_8_18/adds-logged-requests
Jan 28, 2025
Merged

[Security Solution][Detection Engine] adds preview logged requests for new terms, threshold, query, ML rule types#203320
vitaliidm merged 46 commits intoelastic:mainfrom
vitaliidm:de_8_18/adds-logged-requests

Conversation

@vitaliidm
Copy link
Contributor

@vitaliidm vitaliidm commented Dec 6, 2024

Summary

  • partially addresses [Epic][Security Solution][Detection Engine] add request logging on preview for the rest of rule types #202545 (except of IM rule type)
  • extends logged requests preview for:
    • New terms
    • Query
    • ML
    • Threshold
  • For Threshold, Query, New terms rule type introduced Page view, where each loop of rule execution is presented as a separate page
  • Only first 2 search queries requests of each type are logged for performance reasons(rule can have very a large and multiple requests). That's why property request was made not mandatory in rule_preview.schema.yaml

DEMO

Screen.Recording.2025-01-22.at.18.33.10.mov

@vitaliidm vitaliidm self-assigned this Dec 6, 2024
@vitaliidm vitaliidm added v9.0.0 Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. release_note:feature Makes this part of the condensed release notes Team:Detection Engine Security Solution Detection Engine Area backport:version Backport to applied version labels v8.18.0 labels Dec 6, 2024
# Conflicts:
#	x-pack/solutions/security/plugins/security_solution/server/lib/detection_engine/rule_types/utils/logged_requests/log_search_request.test.ts
#	x-pack/solutions/security/plugins/security_solution/server/lib/detection_engine/rule_types/utils/logged_requests/log_search_request.ts
@vitaliidm vitaliidm requested review from a team as code owners January 23, 2025 12:14
@vitaliidm vitaliidm requested review from dplumlee and rylnd January 23, 2025 12:14
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@elasticmachine
Copy link
Contributor

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

@banderror banderror requested review from jkelas and removed request for dplumlee January 27, 2025 16:17
Copy link
Contributor

@marshallmain marshallmain left a comment

Choose a reason for hiding this comment

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

The overall approach looks good, but we need to find a way to stringify search requests that don't use the body key.


const url = `/${index}/_search${urlParams ? `?${urlParams}` : ''}`;

if (body) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The body key is going away in 9.0 (#204858) so we should try to avoid relying on it.

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've seen that PR, my idea was to get this one merged first before FF.
Then help to resolve conflicts in #204858, since there are multiple places changed in both PRs

Copy link
Contributor

Choose a reason for hiding this comment

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

Won't we have to completely change the way we stringify the query after #204858 ? It seems like resolving the conflicts in that PR will essentially require re-implementing this PR, no?

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 think it's only this function that needs to be changed.
Utilities that do ES query call have been refactored to not use body parameter.
So, I would need handle this

const url = `/${index}/_search${urlParams ? `?${urlParams}` : ''}`;

if (body) {
return `POST ${url}\n${JSON.stringify({ ...body }, null, 2)}`;
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 significant difference in response size when we return stringified JSON with whitespace included vs returning a normal JSON object in the response? Including the whitespace seems like it would make the response larger but save CPU on the client since it wouldn't have to parse that large JSON query.

Copy link
Contributor Author

@vitaliidm vitaliidm Jan 28, 2025

Choose a reason for hiding this comment

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

@marshallmain No, there is no significant difference.
I did quick tests:

  • for small queries like query, ML rule it's the same size
  • for large queries (new_terms), current implementation's response is 10% larger

Another advantages of current implementation, we don't need to pass large JSON object in response with multiple nested fields which is difficult to type.

isLoggedRequestsEnabled: boolean | undefined,
sortIds: estypes.SortResults | undefined,
page: number
): LoggedRequestsEnabled | undefined => {
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 we should change the name of the type LoggedRequestsEnabled since it sounds like a boolean but it's a config object

Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed in dfeb094

@elasticmachine
Copy link
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #3 / Policy Advanced Settings section should expand and collapse section when button is clicked

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 6600 6602 +2

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 21.3MB 21.3MB +2.0KB
Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 574 576 +2

Total ESLint disabled count

id before after diff
securitySolution 657 659 +2

History

cc @vitaliidm

Copy link
Contributor

@jkelas jkelas left a comment

Choose a reason for hiding this comment

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

I reviewed the changes owned by rule management team and I approve.
I also confirm the functionality works correct, the author walked me through it.

@vitaliidm vitaliidm merged commit 0f996c3 into elastic:main Jan 28, 2025
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.x

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

kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Jan 28, 2025
…r new terms, threshold, query, ML rule types (elastic#203320)

## Summary

- partially addresses elastic#202545
(except of IM rule type)
- extends logged requests preview for:
  - [x] New terms
  - [x] Query
  - [x] ML
  - [x] Threshold
- For Threshold, Query, New terms rule type introduced Page view, where
each loop of rule execution is presented as a separate page
- Only first 2 search queries requests of each type are logged for
performance reasons(rule can have very a large and multiple requests).
That's why property **request** was made not mandatory in
`rule_preview.schema.yaml`

### DEMO

https://github.com/user-attachments/assets/abfbd3ff-d06c-4892-b805-0f05084042ed

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 0f996c3)
@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 28, 2025
…sts for new terms, threshold, query, ML rule types (#203320) (#208581)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Security Solution][Detection Engine] adds preview logged requests
for new terms, threshold, query, ML rule types
(#203320)](#203320)

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

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

<!--BACKPORT [{"author":{"name":"Vitalii
Dmyterko","email":"92328789+vitaliidm@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-01-28T16:50:00Z","message":"[Security
Solution][Detection Engine] adds preview logged requests for new terms,
threshold, query, ML rule types (#203320)\n\n## Summary\r\n\r\n-
partially addresses
https://github.com/elastic/kibana/issues/202545\r\n(except of IM rule
type)\r\n- extends logged requests preview for:\r\n - [x] New terms\r\n
- [x] Query\r\n - [x] ML\r\n - [x] Threshold\r\n- For Threshold, Query,
New terms rule type introduced Page view, where\r\neach loop of rule
execution is presented as a separate page\r\n- Only first 2 search
queries requests of each type are logged for\r\nperformance reasons(rule
can have very a large and multiple requests).\r\nThat's why property
**request** was made not mandatory
in\r\n`rule_preview.schema.yaml`\r\n\r\n\r\n###
DEMO\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/abfbd3ff-d06c-4892-b805-0f05084042ed\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"0f996c36151d2128f56246cb69d9315c8ea6d085","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["v9.0.0","Team:Detections
and Resp","Team:
SecuritySolution","release_note:feature","Team:Detection
Engine","backport:version","v8.18.0"],"title":"[Security
Solution][Detection Engine] adds preview logged requests for new terms,
threshold, query, ML rule
types","number":203320,"url":"https://github.com/elastic/kibana/pull/203320","mergeCommit":{"message":"[Security
Solution][Detection Engine] adds preview logged requests for new terms,
threshold, query, ML rule types (#203320)\n\n## Summary\r\n\r\n-
partially addresses
https://github.com/elastic/kibana/issues/202545\r\n(except of IM rule
type)\r\n- extends logged requests preview for:\r\n - [x] New terms\r\n
- [x] Query\r\n - [x] ML\r\n - [x] Threshold\r\n- For Threshold, Query,
New terms rule type introduced Page view, where\r\neach loop of rule
execution is presented as a separate page\r\n- Only first 2 search
queries requests of each type are logged for\r\nperformance reasons(rule
can have very a large and multiple requests).\r\nThat's why property
**request** was made not mandatory
in\r\n`rule_preview.schema.yaml`\r\n\r\n\r\n###
DEMO\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/abfbd3ff-d06c-4892-b805-0f05084042ed\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"0f996c36151d2128f56246cb69d9315c8ea6d085"}},"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/203320","number":203320,"mergeCommit":{"message":"[Security
Solution][Detection Engine] adds preview logged requests for new terms,
threshold, query, ML rule types (#203320)\n\n## Summary\r\n\r\n-
partially addresses
https://github.com/elastic/kibana/issues/202545\r\n(except of IM rule
type)\r\n- extends logged requests preview for:\r\n - [x] New terms\r\n
- [x] Query\r\n - [x] ML\r\n - [x] Threshold\r\n- For Threshold, Query,
New terms rule type introduced Page view, where\r\neach loop of rule
execution is presented as a separate page\r\n- Only first 2 search
queries requests of each type are logged for\r\nperformance reasons(rule
can have very a large and multiple requests).\r\nThat's why property
**request** was made not mandatory
in\r\n`rule_preview.schema.yaml`\r\n\r\n\r\n###
DEMO\r\n\r\n\r\n\r\nhttps://github.com/user-attachments/assets/abfbd3ff-d06c-4892-b805-0f05084042ed\r\n\r\n---------\r\n\r\nCo-authored-by:
kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"0f996c36151d2128f56246cb69d9315c8ea6d085"}},{"branch":"8.x","label":"v8.18.0","branchLabelMappingKey":"^v8.18.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Vitalii Dmyterko <92328789+vitaliidm@users.noreply.github.com>
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 release_note:feature Makes this part of the condensed release notes Team:Detection Engine Security Solution Detection Engine Area Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.18.0 v9.0.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants