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

[Cases] Case action: Phase 2 #169229

Merged
merged 45 commits into from
Nov 15, 2023
Merged

[Cases] Case action: Phase 2 #169229

merged 45 commits into from
Nov 15, 2023

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Oct 18, 2023

Summary

This PR is a continuation of the work for the Case action. This PR implements the basic logic of the case connector. Specifically:

  1. Group the alerts based on the grouping provided by the user
  2. Create the Oracle's SO IDs to fetch the records. If they do not exist they will get created and the counter will be set to 1.
  3. Create the cases' SO IDs to fetch the Cases. If they do not exist they will get created.
  4. Attach the alerts to the corresponding cases.

Not in this PR:

  • Handle errors
  • Retries on errors
  • Reopen cases
  • Time window
  • Race conditions
  • Circuit breakers

Depends on: #168370, #169484

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.12.0 labels Oct 18, 2023
@cnasikas cnasikas self-assigned this Oct 18, 2023
@cnasikas cnasikas changed the base branch from main to case_action October 21, 2023 12:37
@cnasikas cnasikas marked this pull request as ready for review November 10, 2023 11:19
@cnasikas cnasikas requested a review from a team as a code owner November 10, 2023 11:19
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

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

Code looks good 👍 just few questions to understand the feature.
I am assuming that we will be able to test it locally when the feature branch is ready, right?


type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;

interface OracleKeyAllRequired {
ruleId: string;
spaceId: string;
owner: string;
grouping: Record<string, string>;
grouping: Record<string, unknown>;
}

type OracleKeyWithOptionalKey = Optional<OracleKeyAllRequired, 'ruleId'>;
type OracleKeyWithOptionalGrouping = Optional<OracleKeyAllRequired, 'grouping'>;

export type OracleKey = ExclusiveUnion<OracleKeyWithOptionalKey, OracleKeyWithOptionalGrouping>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why don't we use io-ts here?

Copy link
Member Author

Choose a reason for hiding this comment

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

What kind of usage do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I saw ExclusiveUnion here and thought maybe we can use io-ts here.

Copy link
Member Author

Choose a reason for hiding this comment

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

io-ts is usually suited for runtime validation of data. In this case, it is not needed because we control the data.

Copy link
Contributor

@jcger jcger left a comment

Choose a reason for hiding this comment

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

LGTM

/**
* TODO: Add grouping info to
*/
return {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about the required custom fields?

Copy link
Member Author

@cnasikas cnasikas Nov 14, 2023

Choose a reason for hiding this comment

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

Great point. I need to think about it. We need the default value feature. I will put a TODO comment to not forget about it.

@cnasikas
Copy link
Member Author

cnasikas commented Nov 14, 2023

I am assuming that we will be able to test it locally when the feature branch is ready, right?

Thanks @js-jankisalvi! Yes, we are waiting for the System actions PR to get merged to be able to test the case action.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Nov 14, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #77 / EPM Endpoints Install endpoint package install should have installed the [endpoint.metadata_current-default] transform
  • [job] [logs] FTR Configs #57 / management index management index templates get all should list all the index templates with the expected parameters
  • [job] [logs] FTR Configs #57 / management index management index templates get all should list all the index templates with the expected parameters

Metrics [docs]

‼️ ERROR: no builds found for mergeBase sha [bc79e00]

History

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

cc @cnasikas

@cnasikas cnasikas merged commit 28cfcb2 into elastic:case_action Nov 15, 2023
27 of 30 checks passed
@cnasikas cnasikas deleted the ca_part_2 branch November 15, 2023 08:09
@cnasikas cnasikas mentioned this pull request Nov 29, 2023
3 tasks
cnasikas added a commit that referenced this pull request Apr 12, 2024
## Summary

Depends on: #166267,
#170326,
#169484,
#173740,
#173763,
#178068,
#178307,
#178600,
#180437

PRs:
- #168370
- #169229
- #171754
- #172709
- #173012
- #175107
- #175452
- #175505
- #177033
- #178277
- #177139
- #179796

Fixes: #153837

## Testing

Run Kibana with `--run-examples` if you want to use the "Always firing"
rule.

Create a rule with a case action in observability and the stack. The
security solution is not supported. You should not be able to assign a
case action in a security solution rule.

1. Test the "Reopen closed cases" configuration.
2. Test the "Grouping by" configuration. Only one field is allowed. Not
all fields are persisted in alerts. If you select a field not part of
the alert the case action will create a case where the grouping value is
set to `unknow`.
3. Test the "Time window" feature. You can comment out the validation to
test for shorter times.
4. Verify that the case action is experimental.
5. Verify that based on the rule type the case is created in the correct
solution.
6. Verify that you cannot create a rule with the case action on the
basic license.
7. Verify that the execution of the case action fails if you do not have
permission for cases. Pending work on the system actions framework level
to not allow users to create rules with system actions where they do not
have permission.
8. Stress test the case action by creating multiple rules.

### Checklist

Delete any items that are not applicable to this PR.

- [x]
[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

### For maintainers

- [x] 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)

## Release notes

Automatically create cases when an alert is triggered.

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: adcoelho <antonio.coelho@elastic.co>
Co-authored-by: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants