-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Core] [SOR] BWC bulkUpdate #171245
Conversation
@elasticmachine merge upstream |
…ers/kibana into kbn-165434-SOR-BWC-bulkUpdate
@elasticmachine merge upstream |
There was a problem hiding this comment.
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.
@elasticmachine merge upstream |
packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts
Outdated
Show resolved
Hide resolved
@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. |
There was a problem hiding this comment.
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.
@elasticmachine merge upstream |
@elasticmachine merge upstream |
@elasticmachine merge upstream |
packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts
Show resolved
Hide resolved
There was a problem hiding this 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 ?? []; |
There was a problem hiding this comment.
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++, |
There was a problem hiding this comment.
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({ |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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: { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)
@elasticmachine merge upstream |
@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? |
There was a problem hiding this 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.
packages/core/saved-objects/core-saved-objects-api-server-internal/src/lib/apis/bulk_update.ts
Outdated
Show resolved
Hide resolved
@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. |
@elasticmachine merge upstream |
💛 Build succeeded, but was flaky
Failed CI StepsThe 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: |
fix #165434
Summary
Bulk version of BWC update.
Checklist
Risk Matrix
For maintainers