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] Remove fields param from the bulk get cases internal API #156366

Merged
merged 8 commits into from
May 8, 2023

Conversation

cnasikas
Copy link
Member

@cnasikas cnasikas commented May 2, 2023

Summary

This PR removes the fields parameter from the bulk get cases internal API. It also returns a subset of the cases attributes.

Fixes: #156364

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@cnasikas cnasikas self-assigned this May 2, 2023
@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.9.0 labels May 2, 2023
@cnasikas cnasikas changed the title [Cases] Narrow bulk get [Cases] Remove fields param from the bulk get cases internal API May 2, 2023
@cnasikas cnasikas marked this pull request as ready for review May 2, 2023 12:07
@cnasikas cnasikas requested a review from a team as a code owner May 2, 2023 12:07
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

fields?: string[]
) => {
export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => {
const fields = Object.keys(CasesBulkGetResponseFieldsRt.props);
const typeToDecode = getTypeForCertainFieldsFromArray(CasesRt, fields);
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels a bit overly complicated. If we always return the same fields and we already have their types we don't need to generate fields and then create typeToDecode we might as well store that in a const and do away with the extra logic.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think something like rt.array(CasesBulkGetResponseFieldsRt).decode(res.cases) might work 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.

Good point!

@@ -68,7 +61,7 @@ describe('api', () => {
});

it('should have been called with the correct path', async () => {
await bulkGetCases({ http, params: { ids: ['test'], fields: ['title'] } });
await bulkGetCases({ http, params: { ids: ['test'] } });
expect(http.post).toHaveBeenCalledWith('/internal/cases/_bulk_get', {
body: '{"ids":["test"],"fields":["title"]}',
Copy link
Contributor

Choose a reason for hiding this comment

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

,"fields":["title"] This test still passes?

Copy link
Member Author

@cnasikas cnasikas May 2, 2023

Choose a reason for hiding this comment

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

They shouldn't 🙂. I missed that.

alerts: 0,
userComments: 0,
};

const flattenedCase = flattenCaseSavedObject({
savedObject: theCase,
totalComment: userComments,
totalAlerts: alerts,
});

if (!fields?.length) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need this? fields is always defined.

Copy link
Member Author

Choose a reason for hiding this comment

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

No, you are right.

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.

looks good 👍 one minor question.

pipe(typeToDecode.decode(res.cases), fold(throwErrors(createToasterPlainError), identity));
export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => {
pipe(
CasesBulkGetResponseFieldsRt.decode(res.cases),
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't CasesBulkGetResponseFieldsRt attribute types need to be verified with excess?

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a good question. We only care about excess parameters coming from external requests to our APIs. For responses, it is ok to not check about them. In the serverless world, we should use strict and remove any fields we do not recognize.

@cnasikas cnasikas requested review from adcoelho and js-jankisalvi May 3, 2023 13:22
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.

Nice work 👍

pipe(typeToDecode.decode(res.cases), fold(throwErrors(createToasterPlainError), identity));
export const decodeCasesBulkGetResponse = (res: CasesBulkGetResponse) => {
pipe(
CasesBulkGetResponseRt.props.cases.decode(res.cases),
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we want to use the entire CasesBulkGetResponseRt for this? We probably want to know if the errors are formatted correctly right?

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct! Before it was not possible because I was constructing the type dynamically.

const typeToEncode = getTypeForCertainFieldsFromArray(CasesRt, fields);
const casesToReturn = typeToEncode.encode(flattenedCases);

const casesToReturn = CasesBulkGetResponseRt.props.cases.encode(flattenedCases);
const errors = constructErrors(soBulkGetErrors, unauthorizedCases);

return { cases: casesToReturn, errors };
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we encode the entire response?

Copy link
Member Author

Choose a reason for hiding this comment

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

Again correct!

@cnasikas cnasikas requested a review from jonathan-buttner May 5, 2023 07:39
@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
triggersActionsUi 1.4MB 1.4MB -100.0B

Page load bundle

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

id before after diff
cases 166.4KB 165.9KB -560.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 398 401 +3
total +5

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 478 481 +3
total +5

History

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

cc @cnasikas

@cnasikas cnasikas merged commit 6493331 into elastic:main May 8, 2023
@cnasikas cnasikas deleted the narrow_bulk_get branch May 8, 2023 14:40
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label May 8, 2023
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.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cases] Bulk get cases API: Remove the fields params and return a subset of the Case fields.
7 participants