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] Create new endpoints to replace the deprecated ones. #134344

Closed
cnasikas opened this issue Jun 14, 2022 · 12 comments
Closed

[Cases] Create new endpoints to replace the deprecated ones. #134344

cnasikas opened this issue Jun 14, 2022 · 12 comments
Labels
Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)

Comments

@cnasikas
Copy link
Member

cnasikas commented Jun 14, 2022

On 8.1 we deprecated the following endpoints:

We should create new endpoints in place of the deprecated ones:

  • GET /api/cases/<case_id>/user_actions/_find
  • GET /api/cases/<case_id>/attachments/_find
  • The metrics endpoint should support the status metric.

The GET /api/cases/<case_id>/attachments/_find should support the following query options:

  • page: The page of objects to return
  • perPage: The number of objects to return per page
  • types: The types of the comment
  • sortOrder: The sorting order. Valid options asc or desc

The GET /api/cases/<case_id>/user_actions/_find should support the following query options: (#148861)

  • page: The page of objects to return
  • perPage: The number of objects to return per page
  • types: The types of the user actions. This is an array. Valid options: all user action types plus action (subject to change), alert, user, and attachment. The action is used to group all user actions that are not of type comment.
  • action: The action of the user action
  • sortOrder: The sorting order. Valid options asc or desc

The owner will be deducted from the case

@cnasikas cnasikas added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature labels Jun 14, 2022
@elasticmachine
Copy link
Contributor

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

@jonathan-buttner
Copy link
Contributor

jonathan-buttner commented Jan 12, 2023

@cnasikas for the find APIs do we want to allow pagination using page and perPage? I thought we were going to implement this using search after to avoid the limit of 10k?

Or maybe the user actions find API uses search after but the comment API sticks with the traditional saved object core's find function?

@cnasikas
Copy link
Member Author

@jonathan-buttner I think it is fine to use page and perPage because we plan to put guardrails in the number of total user actions and comments. A case should not have more than 10K comments or user actions and the endpoints are per case.

@jonathan-buttner
Copy link
Contributor

Do you think it makes sense to have the type be an array of types that are or'd together? My thinking is that let say you want to retrieve all the assignees that were ever added to a case, we'd actually need to get type: create_case and then another request with type: assignees because the assignees could have been included when the case was initially created.

@cnasikas
Copy link
Member Author

Good catch. Make sense to me.

jonathan-buttner added a commit that referenced this issue Jan 23, 2023
This PR adds a new find API for retrieving a subset of the user actions
for a case.

Issue: #134344

```
GET /api/cases/<case_id>/user_actions/_find
Query Paramaters
{
  types?: Array of "assignees" | "comment" | "connector" | "description" | "pushed" | "tags" | "title" | "status" | "settings" | "severity" | "create_case" | "delete_case" | "action" | "alert" | "user" | "attachment"
  sortOrder?: "asc" | "desc"
  page?: number as a string
  perPage?: number as a string
}
```

<details><summary>Example request and response</summary>

Request
```
curl --location --request GET 'http://localhost:5601/api/cases/8df5fe00-96b1-11ed-9341-471c9630b5ec/user_actions/_find?types=create_case&sortOrder=asc' \
--header 'kbn-xsrf: hello' \
--header 'Authorization: Basic ZWxhc3RpYzpjaGFuZ2VtZQ==' \
--data-raw ''
```


Response
```
{
    "userActions": [
        {
            "created_at": "2023-01-17T21:54:45.527Z",
            "created_by": {
                "username": "elastic",
                "full_name": null,
                "email": null,
                "profile_uid": "u_mGBROF_q5bmFCATbLXAcCwKa0k8JvONAwSruelyKA5E_0"
            },
            "owner": "cases",
            "action": "create",
            "payload": {
                "title": "Awesome case",
                "tags": [],
                "severity": "low",
                "description": "super",
                "assignees": [],
                "connector": {
                    "name": "none",
                    "type": ".none",
                    "fields": null,
                    "id": "none"
                },
                "settings": {
                    "syncAlerts": false
                },
                "owner": "cases",
                "status": "open"
            },
            "type": "create_case",
            "id": "8e121180-96b1-11ed-9341-471c9630b5ec",
            "case_id": "8df5fe00-96b1-11ed-9341-471c9630b5ec",
            "comment_id": null
        }
    ],
    "page": 1,
    "perPage": 20,
    "total": 1
}
```

</details>

## Notable Changes
- Created the new `_find` route
- Created a new `UserActionFinder` class and moved the find* methods
from the `index.ts` file into there as well as the new find logic
- Extracted the transform logic to its own file since its shared between
multiple files now
- Extracted the user action related integration test functions to the
`user_action.ts` utility file

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: lcawl <lcawley@elastic.co>
@jonathan-buttner
Copy link
Contributor

@cnasikas with regards to the GET /api/cases/<case_id>/comments/_find API, I looked at our telemetry and I don't see any outside usage of the API it is also not document and not used in the UI. Do you think we can do breaking changes on the current implementation? Ideally we'd limit it to the query parameters you noted in the issue instead of what it supports right now.

@cnasikas
Copy link
Member Author

cnasikas commented Jan 30, 2023

@jonathan-buttner Yes, we can reshape the endpoint to our needs. It is not considered a breaking change. As you said, we never documented and it is not used by anyone. Btw, should we rename comments to attachments in the path?

@jonathan-buttner
Copy link
Contributor

Btw, should we rename comments to attachments in the path?

Sounds good to me, do we want it as an internal API for now?

@cnasikas
Copy link
Member Author

I think is better to make it public as we want to offer an alternative to the deprecated endpoint (GET: /api/cases/{case_id}/comments)

@jloleysens
Copy link
Contributor

Hey @cnasikas ! Is the intention to remove these deprecated APIs by 9.0?

@cnasikas
Copy link
Member Author

Yes, this is correct!

@cnasikas
Copy link
Member Author

Closing in favor of #194266.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Cases Cases feature Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams)
Projects
None yet
Development

No branches or pull requests

4 participants