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

[ResponseOps] API for reading/writing rule execution summary #135127

Closed
xcrzx opened this issue Jun 24, 2022 · 6 comments · Fixed by #147278
Closed

[ResponseOps] API for reading/writing rule execution summary #135127

xcrzx opened this issue Jun 24, 2022 · 6 comments · Fixed by #147278
Assignees
Labels
8.7 candidate Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Feature:Alerting/RulesManagement Issues related to the Rules Management UX Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.7.0

Comments

@xcrzx
Copy link
Contributor

xcrzx commented Jun 24, 2022

Based on: #112193, RFC: Consolidating rule statuses for RAC Rule Management / Monitoring (internal)
Related to: #136039

Summary

We need to design and implement an API that allows passing execution outcomes and metrics from rule executors.

As per RFC, the object containing the execution summary could look like the following:

{
  "outcome": "warning",
  "outcome_msg": "outcome description",
  "warning": ["list of execution warnings"],
  "metrics": {
    "total_search_duration_ms": 1234567890,
    "total_indexing_duration_ms": 123456789,
    "total_alerts_detected": 543,
    "total_alerts_created": 100,
    "gap_duration_s": 7
  }
}

A couple of things to mention:

  • The summary object is generated on the solution side at the end of rule execution. So we need to find a way to pass it from solution to alerting framework.
  • The number of metrics might vary from one rule type to another. Therefore, we should be able to extend it on the solution side if needed.
  • Rules should be filterable and sortable by metrics and execution outcome.
@xcrzx xcrzx added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Feature:Alerting/RulesManagement Issues related to the Rules Management UX Team:Detection Rule Management Security Detection Rule Management Team 8.4 candidate labels Jun 24, 2022
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

@elasticmachine
Copy link
Contributor

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

@peluja1012
Copy link
Contributor

Implementation ticket here #136039

@jpdjere
Copy link
Contributor

jpdjere commented Dec 7, 2022

@XavierM

I started work in this PR, that injects the RuleMonitoringService into the security rule wrapper, so as to update the rule monitoring data on the Security Solution side -during rule execution- before the final lastRun data is calculated by the Alerting Framework in the processRunResults method of the Task Runner, and saved to the rule SavedObject.

I expanded the RuleMonitoringService so as to be able to update the outcome, outcomeMsg and warning fields of the new lastRun field during rule execution, but found the following limitation:

The Alerting Framework currently calculates the values for the lastRun property at the end of rule execution, using the lastRunFromState function within processRunResults method of the TaskRunner, just before saving to the Rule Saved Object. I updated the lastRunFromState function so that it also takes the current state of the ruleMonitoringService as an additional parameter, in order to take into account the previous updates that we might have done to outcome, outcomeMsg and warning from the Security Solution side.

However, in the PR as I have it up to now, the lastRunFromState function can still overwrite outcome, outcomeMsg and warning in two particular cases based on the metrics generated by the Alerting Framework (the alert circuit breaker and the actions circuit breaker). It worries us that in these two cases, any previous value for outcome, outcomeMsg and warning set by us on the Security Solution side will be overwritten and could lead us to lose information that we need of what happened during the execution.

We though of two possibilities to counter this issue, but would like your input:

  • one simple solution would be for the Framework never to overwrite outcome or warning values that were generated from the Solution side. This would require us to add some additional logic but would completely solve our concerns. But we'd need your input if is possible.
  • have warning as an array. This would allow us to have both data generated by the Solution side and the Framework side, but still the outcome would be overwritten by the Framework (unless we do some additional changes to this logic as well, to prioritise the outcome set by the Security Solution).

jpdjere added a commit that referenced this issue Dec 21, 2022
Relates to #135127

## Summary

Creates `RuleResultService`, which can be used to set and get values for
the rules last execution: `errors`, `warnings` and `outcomeMessages`.

### Checklist

Delete any items that are not applicable to this PR.

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: kibanamachine <[email protected]>
@jpdjere jpdjere reopened this Dec 21, 2022
@banderror
Copy link
Contributor

Addressed in #136039 and #147278

crespocarlos pushed a commit to crespocarlos/kibana that referenced this issue Dec 23, 2022
Relates to elastic#135127

## Summary

Creates `RuleResultService`, which can be used to set and get values for
the rules last execution: `errors`, `warnings` and `outcomeMessages`.

### Checklist

Delete any items that are not applicable to this PR.

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: kibanamachine <[email protected]>
maximpn pushed a commit that referenced this issue Jan 27, 2023
…ead of saved object (#147035)

**Addresses:** #130966
**Based on:** #135127

## Summary

This PR deprecates the Sidecar SO of type `siem-detection-engine-rule-execution-info` in favour of storing Rule Execution Logging data within the rule itself, making use of the work previously done in the Alerting Framework:
- #140882
- #147278

Work done:
- **Pass execution statuses and metrics from rule executors to the Framework:** through the use of `RuleMonitoringService` and `RuleResultService` from within the rule execution log client for executor. `x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/client_for_executors/client.ts`
- **Fetch execution statuses and metrics from rules themselves instead of the sidecar `siem-detection-engine-rule-execution-info` saved objects**: through the use of the new function `createRuleExecutionSummary` in `x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/create_rule_execution_summary.ts`, which extracts last execution information from the rule itself.
- **Remove the siem-detection-engine-rule-execution-info saved objects type from the codebase. Mark it as deleted in Kibana Core:** added `siem-detection-engine-rule-execution-info` to `packages/core/saved-objects/core-saved-objects-migration-server-internal/src/core/unused_types.ts`; and got rid of the related Saved Object client.
- **Make sure to keep backward compatibility in the Detection API endpoints and rule execution events we write into the Event Log**: API compatibility is maintained. No breaking changes.


### Checklist

- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
kqualters-elastic pushed a commit to kqualters-elastic/kibana that referenced this issue Feb 6, 2023
…ead of saved object (elastic#147035)

**Addresses:** elastic#130966
**Based on:** elastic#135127

## Summary

This PR deprecates the Sidecar SO of type `siem-detection-engine-rule-execution-info` in favour of storing Rule Execution Logging data within the rule itself, making use of the work previously done in the Alerting Framework:
- elastic#140882
- elastic#147278

Work done:
- **Pass execution statuses and metrics from rule executors to the Framework:** through the use of `RuleMonitoringService` and `RuleResultService` from within the rule execution log client for executor. `x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/client_for_executors/client.ts`
- **Fetch execution statuses and metrics from rules themselves instead of the sidecar `siem-detection-engine-rule-execution-info` saved objects**: through the use of the new function `createRuleExecutionSummary` in `x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/create_rule_execution_summary.ts`, which extracts last execution information from the rule itself.
- **Remove the siem-detection-engine-rule-execution-info saved objects type from the codebase. Mark it as deleted in Kibana Core:** added `siem-detection-engine-rule-execution-info` to `packages/core/saved-objects/core-saved-objects-migration-server-internal/src/core/unused_types.ts`; and got rid of the related Saved Object client.
- **Make sure to keep backward compatibility in the Detection API endpoints and rule execution events we write into the Event Log**: API compatibility is maintained. No breaking changes.


### Checklist

- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
darnautov pushed a commit to darnautov/kibana that referenced this issue Feb 7, 2023
…ead of saved object (elastic#147035)

**Addresses:** elastic#130966
**Based on:** elastic#135127

## Summary

This PR deprecates the Sidecar SO of type `siem-detection-engine-rule-execution-info` in favour of storing Rule Execution Logging data within the rule itself, making use of the work previously done in the Alerting Framework:
- elastic#140882
- elastic#147278

Work done:
- **Pass execution statuses and metrics from rule executors to the Framework:** through the use of `RuleMonitoringService` and `RuleResultService` from within the rule execution log client for executor. `x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/client_for_executors/client.ts`
- **Fetch execution statuses and metrics from rules themselves instead of the sidecar `siem-detection-engine-rule-execution-info` saved objects**: through the use of the new function `createRuleExecutionSummary` in `x-pack/plugins/security_solution/server/lib/detection_engine/rule_monitoring/logic/rule_execution_log/create_rule_execution_summary.ts`, which extracts last execution information from the rule itself.
- **Remove the siem-detection-engine-rule-execution-info saved objects type from the codebase. Mark it as deleted in Kibana Core:** added `siem-detection-engine-rule-execution-info` to `packages/core/saved-objects/core-saved-objects-migration-server-internal/src/core/unused_types.ts`; and got rid of the related Saved Object client.
- **Make sure to keep backward compatibility in the Detection API endpoints and rule execution events we write into the Event Log**: API compatibility is maintained. No breaking changes.


### Checklist

- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.7 candidate Feature:Alerting/RulesFramework Issues related to the Alerting Rules Framework Feature:Alerting/RulesManagement Issues related to the Rules Management UX Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.7.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants