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] Add the ability to filter cases by date in the find and status endpoints #128652

Merged
merged 12 commits into from
Mar 31, 2022

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented Mar 28, 2022

Summary

This PR

  • Extends the find cases endpoint to accept a date range by introducing the from and to query parameters.
  • Extends the status cases endpoint to accept a date range by introducing the from and to query parameters.
  • Exposes from the UI cases client two functions to find cases and get the statuses. Usage:
const { cases } = useKibana().services;

const allCases = cases.api.cases.find({
    status: 'open',
      from: 'now-1w',
      to: 'now'
    }
  });

const casesStatuses = cases.api.cases.getAllCasesMetrics({
    status: 'open',
      from: 'now-1w',
      to: 'now'
    }
  });

Closes: #128483

API usage

Find cases: /api/cases/_find?status=closed&from=now-1w&to=now
Get status: /api/cases/status?from=now-1M&to=now-1w

Docs Preview

https://kibana_128652.docs-preview.app.elstc.co/guide/en/kibana/master/cases-api-find-cases.html

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 backport:skip This commit does not require backporting Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature v8.3.0 labels Mar 28, 2022
@cnasikas cnasikas self-assigned this Mar 28, 2022
@cnasikas cnasikas marked this pull request as ready for review March 29, 2022 15:24
@cnasikas cnasikas requested a review from a team as a code owner March 29, 2022 15:24
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@cnasikas cnasikas requested a review from academo March 30, 2022 07:19
Copy link
Contributor

@academo academo left a comment

Choose a reason for hiding this comment

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

It all looks good to me though I have a remark: we are not testing error paths, when a malformed date is sent to the endpoint.

Can you add tests to cover those cases?

@cnasikas
Copy link
Member Author

It all looks good to me though I have a remark: we are not testing error paths, when a malformed date is sent to the endpoint.

Can you add tests to cover those cases?

Thanks, Esteban! I do in multiple places. For example here: https://github.com/elastic/kibana/pull/128652/files#diff-bbb2457715292047ff5e11bf70e6a6e560c2674d3dd2548cdcdd54fb45efa705R524. Do you have something else in mind?

@academo
Copy link
Contributor

academo commented Mar 30, 2022

It all looks good to me though I have a remark: we are not testing error paths, when a malformed date is sent to the endpoint.
Can you add tests to cover those cases?

Thanks, Esteban! I do in multiple places. For example here: #128652 (files). Do you have something else in mind?

Does it make any difference if you test more incorrect formats? If you feel this is enough then let's go with it.

@cnasikas
Copy link
Member Author

It all looks good to me though I have a remark: we are not testing error paths, when a malformed date is sent to the endpoint.
Can you add tests to cover those cases?

Thanks, Esteban! I do in multiple places. For example here: #128652 (files). Do you have something else in mind?

Does it make any difference if you test more incorrect formats? If you feel this is enough then let's go with it.

I think is fine because I mostly need to check if I catch the error correctly. I think by testing incorrect formats I will start testing the kibana core framework and in turn ES. Do you have any specific format in mind?

@cnasikas
Copy link
Member Author

@elasticmachine merge upstream

@cnasikas cnasikas enabled auto-merge (squash) March 31, 2022 08:01
@cnasikas
Copy link
Member Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cases 86.2KB 86.3KB +181.0B

History

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

cc @cnasikas

@cnasikas cnasikas merged commit 4246f3e into elastic:main Mar 31, 2022
@cnasikas cnasikas deleted the range_queries branch March 31, 2022 13:50
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.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cases] Provide apis to query cases from the UI
6 participants