-
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
[Security Solution][Detection Engine] move lists to data stream #162508
[Security Solution][Detection Engine] move lists to data stream #162508
Conversation
This reverts commit 245ba57.
# Conflicts: # x-pack/plugins/lists/server/routes/create_list_index_route.ts # x-pack/plugins/lists/server/routes/delete_list_index_route.ts # x-pack/plugins/lists/server/routes/read_list_index_route.ts
there is still one failing test: #163197 |
@kevinlog The |
hey @vitaliidm , are these changes affecting also the exceptions lists/items types or only the regular lists/items? Thanks! |
hey @dasansol92 , only |
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.
Great work! I left a few comments, let me know what you think about those.
// needs to be migrated to data stream if index exists | ||
if (!dataStreamExists) { | ||
const indexExists = await lists.getListIndexExists(); | ||
if (indexExists) { |
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.
what if it does not exist? or this is not possible?
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 is going to be handled down the function execution, few lines below this one
const list = await lists.patchList({ _version, description, id, meta, name, version });
if (list == null) {
return siemResponse.error({
body: `list id: "${id}" not found`,
``
// needs to be migrated to data stream if index exists | ||
if (!dataStreamExists) { | ||
const indexExists = await lists.getListIndexExists(); | ||
if (indexExists) { |
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.
same as my previous question
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.
|
||
await removeLegacyTemplatesIfExist(lists); | ||
|
||
if (listDataStreamExists && listItemDataStreamExists) { |
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 see that it was implemented this way earlier, but just curios whether we should do this check before setting templates above? since we know that this is an invalid request and we gonna return 409 error maybe we should not do any modifications and throw an exception earlier
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 don't know the reason it was done like this before, but I can guess, if there are any updates to templates, that would the only way to update them - by calling that API. Otherwise, if no updates were made to templates, that action won't have any effect
const listItemDataStreamExists = await lists.getListItemDataStreamExists(); | ||
|
||
// data streams exists, it means indices were migrated | ||
if (listDataStreamExists) { |
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.
Is it possible that listItemDataStreamExists = true
and listDataStreamExists = false
? In case of indices we check that both exist listIndexExists
and listItemIndexExists
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 think, this could only happen, if you use patch/update listItem API, before loading Security Solution page(which performs migration to DS). Very unlikely, because, you have to use direct API call, since these APIs are not used in UI.
And those migration in patch/update was added recently, after delete method was migrated.
Thanks for noticing, I have updated the code, so it will account for this
|
||
if (listIndexExists || listItemIndexExists) { | ||
if (listDataStreamExists || listItemDataStreamExists) { |
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.
These IF
statements are not going to work as initially intended.
First if (listDataStreamExists || listItemDataStreamExists) {
will handle three out of four possible cases:
- listDataStreamExists = true && listItemDataStreamExists = true
- listDataStreamExists = false && listItemDataStreamExists = true
- listDataStreamExists = true && listItemDataStreamExists = false
Then, second if (!listDataStreamExists && listItemDataStreamExists) {
statement will handle the last possible case:
- listDataStreamExists = false && listItemDataStreamExists = false
This means, that last two statements (if (!listItemDataStreamExists && listDataStreamExists) {
and final else
case) will never be called.
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.
Yes, you are right - I think, probably, its initial implementation meant to have the firs statement as AND
, in that case the rest of statements would make sense.
I will change it AND
, thanks for catching this
// needs to be migrated to data stream if index exists | ||
if (!dataStreamExists) { | ||
const indexExists = await lists.getListItemIndexExists(); | ||
if (indexExists) { |
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.
same as one of the previous questions about possibility of indexExists = false
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.
similar to same questions, it's going to be handled below these lines
const listItem = await lists.patchListItem({
_version,
id,
meta,
value,
});
if (listItem == null) {
return siemResponse.error({
body: `list item id: "${id}" not found`,
statusCode: 404,
});
} else {
// needs to be migrated to data stream if index exists | ||
if (!dataStreamExists) { | ||
const indexExists = await lists.getListItemIndexExists(); | ||
if (indexExists) { |
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.
same here
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.
…iidm/kibana into alerts_8_10/move-lists-to-ds
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!
For changes affecting exceptions items/lists, would be nice having this test passing in CI when it's enabled: #164473 |
💛 Build succeeded, but was flaky
Failed CI StepsTest Failures
Metrics [docs]Module Count
Public APIs missing comments
Async chunks
Unknown metric groupsAPI count
Unreferenced deprecated APIs
History
To update your PR or re-run it, just comment with: cc @vitaliidm |
Summary
@timestamp
mapping to indices mappingsversion
parameter in ESupdate
method w/o any changesTechnical detail on moving API to (update/delete)_by_query
update_by_query
,delete_by_query
do not support refresh=wait_for, only false/true values. Which might break some of the use cases on UI(when list is removed, we refetch all lists. Deleted list will be returned for some time. Default refresh time is 1s). So, we retry refetching deleted/updated document before finishing request, to return reindexed documentupdate_by_query
does not support OCC as update API.Which is supported in both list/list item updates through _version parameter.
_version is base64 encoded "_seq_no", "_primary_term" props used for OCC
So, to keep it without breaking changes: implemented check for version conflict within update method
Checklist
Delete any items that are not applicable to this PR.