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] Do not check for version conflicts when adding/updating comments to a case #173740

Merged
merged 2 commits into from
Dec 21, 2023

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Dec 20, 2023

Summary

When we add or update a comment (attachment) to a case we update the updatedAt and updatedBy attributes of the case. When we update the case we pass the version of the current case to the SO client for concurrency control. If the version of the current case is different from the one we updating (someone else updated the case) the SO client will throw an error. Although we always fetch the case before adding a comment it may be possible in some weird race conditions for one Kibana node to get the case and before updating another node to update the case. This is extremely difficult to produce when users interact but it may be possible (still rare) when we introduce the case action. This PR does not do any concurrency control when updating the updatedAt and updatedBy attributes of the case when adding/updating a comment.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas self-assigned this Dec 20, 2023
@cnasikas cnasikas added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.13.0 labels Dec 20, 2023
@cnasikas cnasikas mentioned this pull request Dec 20, 2023
3 tasks
@@ -160,7 +160,6 @@ export class CaseCommentModel {
updated_at: date,
updated_by: { ...this.params.user },
},
version: this.caseInfo.version,
Copy link
Member Author

Choose a reason for hiding this comment

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

Removing the version we tell the SO client to not throw on conflicts. It will retry automatically.

},
});

await createComment({
Copy link
Member Author

Choose a reason for hiding this comment

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

As we always get the case before adding the comment (and thus updating the case) the test does not simulate a race condition. It is a basic test to verify the correctness of a simple path and to avoid breaking something in the future.

@cnasikas cnasikas marked this pull request as ready for review December 20, 2023 13:30
@cnasikas cnasikas requested a review from a team as a code owner December 20, 2023 13:30
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@cnasikas cnasikas added the release_note:skip Skip the PR/issue when compiling release notes label Dec 20, 2023
@cnasikas
Copy link
Member Author

/ci

Copy link
Contributor

@adcoelho adcoelho left a comment

Choose a reason for hiding this comment

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

lgtm 👍

@@ -549,6 +551,48 @@ export default ({ getService }: FtrProviderContext): void => {
}
});

describe('partial updates', () => {
it('should not result to a version conflict (409) when adding a comment to an updated case', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be

Suggested change
it('should not result to a version conflict (409) when adding a comment to an updated case', async () => {
it('should not result to a version conflict (409) when updating a comment in an updated case', async () => {

right?

Copy link
Member Author

@cnasikas cnasikas Dec 21, 2023

Choose a reason for hiding this comment

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

Correct! I will fix it.

@adcoelho
Copy link
Contributor

adcoelho commented Dec 21, 2023

What is the value of case updatedBy for case actions btw?

@cnasikas
Copy link
Member Author

What is the value of case updatedBy for case actions btw?

This is a very good question. It would be the user that created the rule. I can explain offline why if you want.

@cnasikas cnasikas enabled auto-merge (squash) December 21, 2023 09:54
@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] Detection Engine - Security Solution Cypress Tests #4 / Timeline scope Alerts checkbox "before each" hook for "alerts checkbox behaves as expected" "before each" hook for "alerts checkbox behaves as expected"

Metrics [docs]

✅ unchanged

History

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

cc @cnasikas

@cnasikas cnasikas merged commit 9922453 into elastic:main Dec 21, 2023
38 checks passed
@cnasikas cnasikas deleted the pu_case_when_attaching branch December 21, 2023 10:59
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 21, 2023
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 <[email protected]>
Co-authored-by: adcoelho <[email protected]>
Co-authored-by: Janki Salvi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting 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.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants