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

[Core] [SOR] BWC bulkUpdate #171245

Merged

Conversation

TinaHeiligers
Copy link
Contributor

@TinaHeiligers TinaHeiligers commented Nov 14, 2023

fix #165434

Summary

Bulk version of BWC update.

Checklist

  • Documentation was added for features that require explanation or tutorials (The API signature did not change, code comments will explain additional information deemed useful)
  • Unit or functional tests were updated or added to match the most common scenarios

Risk Matrix

Risk Probability Severity Mitigation/Notes
Kibana might suffer memory constraint issues when the document updates are complex and/or many objects are updated in a single bulk update request. Low Medium The cases Integration test most closely resembles updating multiple saved objects and we'll use that test as an indication of processing load.

For maintainers

@TinaHeiligers TinaHeiligers added Feature:Saved Objects release_note:skip Skip the PR/issue when compiling release notes Epic:ZDTmigrations Zero downtime migrations labels Nov 14, 2023
@TinaHeiligers TinaHeiligers changed the title [Core] [SOR] BWC bulkUpdate [Core] [SOR] BWC bulkUpdate [skip-ci] Nov 14, 2023
@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Splitting out the bulk_create tests from the main repository unit tests shouldn't be part of this PR.

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream


// eslint-disable-next-line @typescript-eslint/naming-convention
const { [type]: attributes, references, updated_at } = documentToSave;
const { [type]: attributes, references, updated_at } = documentToSave; // use the original request params ?? probably need to return the actual updated doc that exists in es now.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't want to change the signature of the API and optimistically assume that the updated documents are indexed.

@TinaHeiligers TinaHeiligers changed the title [Core] [SOR] BWC bulkUpdate [skip-ci] [Core] [SOR] BWC bulkUpdate Nov 21, 2023
@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor Author

@TinaHeiligers TinaHeiligers left a comment

Choose a reason for hiding this comment

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

Self review

@@ -106,7 +106,7 @@ export const executeUpdate = async <T>(
preflightDocResult,
});

const existingNamespaces = preflightDocNSResult?.savedObjectNamespaces ?? [];
const existingNamespaces = preflightDocNSResult.savedObjectNamespaces ?? [];
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is not needed for BWC bulkUpdate, it's left-over cleanup from reviewing the update API.

return right({
type,
id,
version,
documentToSave,
objectNamespace,
...(requiresNamespacesCheck && { esRequestIndex: bulkGetRequestIndexCounter++ }),
esRequestIndex: bulkGetRequestIndexCounter++,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before this PR, esRequestIndex was used as a filtering mechanism to only fetch when the SO type is multi-namespace. This PR implements fetching all the docs, regardless of their SO namespace type.

}

const typeDefinition = registry.getType(type)!;
const updatedAttributes = mergeForUpdate({
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The heart of this PR: update documents client side by merging the requested changes with the existing document to create an updated doc.

updated_at: time,
...(Array.isArray(documentToSave.references) && { references: documentToSave.references }),
});
const updatedMigratedDocumentToSave = serializer.savedObjectToRaw(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The updated document after applying the changes from the request.

};

bulkUpdateParams.push(
{
update: {
index: {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

index the updated doc


await repositoryV2.bulkUpdate([
{ type: 'my-test-type', id: doc.id, attributes: { count: 11, even: false } },
// @ts-expect-error cannot assign to partial
Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's probably a better way of explaining the type issue here:

Type '{ sum: number; isodd: true; }' is not assignable to type 'Partial<{ count: number; even: boolean; }>'.
  Object literal may only specify known properties, and 'sum' does not exist in type 'Partial<{ count: number; even: boolean; }>'.ts(2322)

@TinaHeiligers TinaHeiligers marked this pull request as ready for review November 24, 2023 23:54
@TinaHeiligers TinaHeiligers requested a review from a team as a code owner November 24, 2023 23:55
@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@TinaHeiligers
Copy link
Contributor Author

Kibana might suffer memory constraint issues when the document updates are complex and/or many objects are updated in a single bulk update request

@afharo ideally, we'd have a bench-mark against which to monitor the API performance w.r.t. 'hogging' memory. In your experience, what's the best option for us?

Copy link
Contributor

@pgayvallet pgayvallet left a comment

Choose a reason for hiding this comment

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

LGTM. Implementation looks great.

@afharo
Copy link
Member

afharo commented Nov 28, 2023

Kibana might suffer memory constraint issues when the document updates are complex and/or many objects are updated in a single bulk update request

@afharo ideally, we'd have a bench-mark against which to monitor the API performance w.r.t. 'hogging' memory. In your experience, what's the best option for us?

@TinaHeiligers, AFAIK, our scalability tests don't track the memory utilization at the moment. Unfortunately, I don't think we have any baseline to compare with. But probably @dmlemeshko knows best 😇

FWIW, most SOs are small enough to consider this an issue (unless they use large arrays). Some SO types tend to have large blobs stored in some fields. I guess we should recommend against using this API for those types.

@TinaHeiligers
Copy link
Contributor Author

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

The CI Stats report is too large to be displayed here, check out the CI build annotation for this information.

History

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

@TinaHeiligers TinaHeiligers merged commit 2ca730d into elastic:main Nov 28, 2023
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Nov 28, 2023
@TinaHeiligers TinaHeiligers deleted the kbn-165434-SOR-BWC-bulkUpdate branch November 28, 2023 19:39
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 Epic:ZDTmigrations Zero downtime migrations Feature:Saved Objects release_note:skip Skip the PR/issue when compiling release notes v8.12.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SOR: downward-compatible bulkUpdate
5 participants