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][Cases] Set case alert attachment rule info to null #123094

Merged

Conversation

jonathan-buttner
Copy link
Contributor

@jonathan-buttner jonathan-buttner commented Jan 14, 2022

Fixes: #123089

This PR is the first step for fixing the above issue where we didn't migrate the rule.id field from the case attachment saved object into the saved object reference field. This solution incurs a performance hit since the frontend will have to look up the rule name for each alert. I don't anticipate this being much of an issue because we likely don't have many alerts attached to cases right now.

I talked with Brandon and Sophie and we thought this was a less drastic fix than migrating the field to the references. We also were concerned that if we moved the rule.id then when a user exports a case, it will also export the rule, and we weren't sure that's what users would want.

Testing

To test I would attach an alert to the case, then grab the alertId and case ID information to use with a postman request like this:

{
    "alertId": [<add a valid alertId here>],
    "index": [".internal.alerts-security.alerts-default-000001"],
    "rule": { "id": null, "name": null },
    "type": "alert",
    "owner": "securitySolution"
}

You should see the rule's name show up for both alerts and clicking on it should take you to the rule's page.

@jonathan-buttner jonathan-buttner added v8.0.0 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.1.0 labels Jan 14, 2022
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@jonathan-buttner jonathan-buttner added backport:skip This commit does not require backporting and removed v8.0.0 labels Jan 14, 2022
@cnasikas
Copy link
Member

@elasticmachine merge upstream

@cnasikas cnasikas added v8.0.0 and removed v8.0.0 labels Jan 17, 2022
@@ -15,7 +15,7 @@ export interface UserActions {
owner: string;
}

export interface UserActionUnmigratedConnectorDocument {
export interface UserActionVersion800 {
Copy link
Contributor Author

@jonathan-buttner jonathan-buttner Jan 18, 2022

Choose a reason for hiding this comment

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

I'm happy to name this something else, the reason I changed it is because it's being used for the new removeRuleInformation migration and a few other ones (it's not just a connectors thing anymore).

Copy link
Member

@cnasikas cnasikas Jan 19, 2022

Choose a reason for hiding this comment

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

Maybe we can give a name that distinguishes the old mapping (new_value, old_value) from the new one (payload: { connector, ... })

@jonathan-buttner
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
cases 311.3KB 311.3KB +18.0B
Unknown metric groups

ESLint disabled in files

id before after diff
cases 18 19 +1

Total ESLint disabled count

id before after diff
cases 89 90 +1

History

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

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

Tested by importing a 7.16 case and is working as expected! 🚀

@jonathan-buttner jonathan-buttner merged commit d1eb0df into elastic:main Jan 19, 2022
@jonathan-buttner jonathan-buttner deleted the cases-remove-rule-info branch January 19, 2022 14:30
FrankHassanabad added a commit that referenced this pull request Jan 25, 2022
## Summary

See this PR from here:
#123094

Where `"rule": { "id": null, "name": null },` can be null. This just adds guards around it to prevent possible errors. Note, I tested it first and there aren't errors with this even if we don't merge but that is not a guarantee that later NodeJS wouldn't cause errors if the implementation details of [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) change.

Note, I don't try to do any additional lookups if these are `null` as the release is coming very quickly and I do not want to overcomplicate telemetry and we don't have dashboards around the cases feature. Over time I would expect the telemetry to become more accurate again even if cases are `nulled` out.

**Manual testing**

Either create a true upgrade where all the id's changed by going to 7.16 and making a new space, then within that space outside of default creating cases and alerts and then do an upgrade to 8.0.0 ... or ... 

Downgrade a `case-comments` like so manually in dev tools:
```ts
# Get all case-comments to choose an id
GET .kibana/_search
{
  "query": {
    "term": {
      "type": "cases-comments"
    }
  }
}
```

```ts
# Downgrades a case comment of id "25554290-7a36-11ec-8d37-0d0e30a77b60"
POST .kibana/_update/cases-comments:25554290-7a36-11ec-8d37-0d0e30a77b60
{
  "script" : {
    "source": """
    ctx._source.migrationVersion['cases-comments'] = "7.16.3";
    """,
    "lang": "painless"
  }
}
```

Restart Kibana and you should query the same `case-comments` and see that the `"rule": { "id": null, "name": null },` are all null.

Either way once you have a null rule go to `Advanced Settings -> cluster data` and ensure that you still get metrics flowing and that one is no longer counted but if you create a new one everything still works as expected:
<img width="647" alt="Screen Shot 2022-01-24 at 11 48 39 AM" src="https://user-images.githubusercontent.com/1151048/150846789-d94ac212-6c45-44cc-a663-cd304bfda22e.png">

### Checklist

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

We still don't have this for the existing telemetry and are running out of time for 8.0.0 to add them. We might re-write this part of telemetry as well so I am not adding tests just yet.
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jan 25, 2022
…123643)

## Summary

See this PR from here:
elastic#123094

Where `"rule": { "id": null, "name": null },` can be null. This just adds guards around it to prevent possible errors. Note, I tested it first and there aren't errors with this even if we don't merge but that is not a guarantee that later NodeJS wouldn't cause errors if the implementation details of [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) change.

Note, I don't try to do any additional lookups if these are `null` as the release is coming very quickly and I do not want to overcomplicate telemetry and we don't have dashboards around the cases feature. Over time I would expect the telemetry to become more accurate again even if cases are `nulled` out.

**Manual testing**

Either create a true upgrade where all the id's changed by going to 7.16 and making a new space, then within that space outside of default creating cases and alerts and then do an upgrade to 8.0.0 ... or ...

Downgrade a `case-comments` like so manually in dev tools:
```ts
# Get all case-comments to choose an id
GET .kibana/_search
{
  "query": {
    "term": {
      "type": "cases-comments"
    }
  }
}
```

```ts
# Downgrades a case comment of id "25554290-7a36-11ec-8d37-0d0e30a77b60"
POST .kibana/_update/cases-comments:25554290-7a36-11ec-8d37-0d0e30a77b60
{
  "script" : {
    "source": """
    ctx._source.migrationVersion['cases-comments'] = "7.16.3";
    """,
    "lang": "painless"
  }
}
```

Restart Kibana and you should query the same `case-comments` and see that the `"rule": { "id": null, "name": null },` are all null.

Either way once you have a null rule go to `Advanced Settings -> cluster data` and ensure that you still get metrics flowing and that one is no longer counted but if you create a new one everything still works as expected:
<img width="647" alt="Screen Shot 2022-01-24 at 11 48 39 AM" src="https://user-images.githubusercontent.com/1151048/150846789-d94ac212-6c45-44cc-a663-cd304bfda22e.png">

### Checklist

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

We still don't have this for the existing telemetry and are running out of time for 8.0.0 to add them. We might re-write this part of telemetry as well so I am not adding tests just yet.

(cherry picked from commit 607feec)
kibanamachine added a commit that referenced this pull request Jan 25, 2022
…#123747)

## Summary

See this PR from here:
#123094

Where `"rule": { "id": null, "name": null },` can be null. This just adds guards around it to prevent possible errors. Note, I tested it first and there aren't errors with this even if we don't merge but that is not a guarantee that later NodeJS wouldn't cause errors if the implementation details of [Map](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) change.

Note, I don't try to do any additional lookups if these are `null` as the release is coming very quickly and I do not want to overcomplicate telemetry and we don't have dashboards around the cases feature. Over time I would expect the telemetry to become more accurate again even if cases are `nulled` out.

**Manual testing**

Either create a true upgrade where all the id's changed by going to 7.16 and making a new space, then within that space outside of default creating cases and alerts and then do an upgrade to 8.0.0 ... or ...

Downgrade a `case-comments` like so manually in dev tools:
```ts
# Get all case-comments to choose an id
GET .kibana/_search
{
  "query": {
    "term": {
      "type": "cases-comments"
    }
  }
}
```

```ts
# Downgrades a case comment of id "25554290-7a36-11ec-8d37-0d0e30a77b60"
POST .kibana/_update/cases-comments:25554290-7a36-11ec-8d37-0d0e30a77b60
{
  "script" : {
    "source": """
    ctx._source.migrationVersion['cases-comments'] = "7.16.3";
    """,
    "lang": "painless"
  }
}
```

Restart Kibana and you should query the same `case-comments` and see that the `"rule": { "id": null, "name": null },` are all null.

Either way once you have a null rule go to `Advanced Settings -> cluster data` and ensure that you still get metrics flowing and that one is no longer counted but if you create a new one everything still works as expected:
<img width="647" alt="Screen Shot 2022-01-24 at 11 48 39 AM" src="https://user-images.githubusercontent.com/1151048/150846789-d94ac212-6c45-44cc-a663-cd304bfda22e.png">

### Checklist

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

We still don't have this for the existing telemetry and are running out of time for 8.0.0 to add them. We might re-write this part of telemetry as well so I am not adding tests just yet.

(cherry picked from commit 607feec)

Co-authored-by: Frank Hassanabad <[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.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[ResponseOps][Cases] Alert attachments reference rule saved objects by id
7 participants