-
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][Endpoint] Update list api summary endpoint to use filter #123476
Merged
ashokaditya
merged 11 commits into
elastic:main
from
ashokaditya:task/update_list_api_summary_endpoint_to_use_filter
Jan 26, 2022
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
7ee4e6e
update summary endpoint to use filters and use that for fleet event f…
ashokaditya c3980cc
update tests
ashokaditya 35d1ef9
update host isolation card to show total as the actual number of arti…
ashokaditya e56e24e
Merge branch 'main' into task/update_list_api_summary_endpoint_to_use…
ashokaditya 3d043fc
fix types
ashokaditya 4f5be8b
use named constant for isolation exception list
ashokaditya a08472e
Update fleet_integration_event_filters_card.tsx
ashokaditya 140ef7f
Merge branch 'main' into task/update_list_api_summary_endpoint_to_use…
kibanamachine e24628d
Merge branch 'main' into task/update_list_api_summary_endpoint_to_use…
kibanamachine bdc0c97
fix the total on summary api
ashokaditya 7e2cdb8
Merge branch 'main' into task/update_list_api_summary_endpoint_to_use…
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
x-pack/plugins/lists/common/schemas/response/exception_list_summary_schema.mock.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { ExceptionListSummarySchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
export const getSummaryExceptionListSchemaMock = ( | ||
overrides?: Partial<ExceptionListSummarySchema> | ||
): ExceptionListSummarySchema => { | ||
return { | ||
linux: 0, | ||
macos: 0, | ||
total: 0, | ||
windows: 0, | ||
...(overrides || {}), | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
x-pack/plugins/lists/server/services/exception_lists/get_exception_list_summary.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { ExceptionListSummarySchema } from '@kbn/securitysolution-io-ts-list-types'; | ||
|
||
import type { SavedObjectsClientContract } from '../../../../../../src/core/server'; | ||
import { savedObjectsClientMock } from '../../../../../../src/core/server/mocks'; | ||
|
||
import { getExceptionListSummary } from './get_exception_list_summary'; | ||
|
||
describe('get_exception_list_summary', () => { | ||
describe('getExceptionListSummary', () => { | ||
let savedObjectsClient: jest.Mocked<SavedObjectsClientContract>; | ||
|
||
beforeEach(() => { | ||
savedObjectsClient = savedObjectsClientMock.create(); | ||
}); | ||
|
||
test('it should aggregate items if not host isolation exception artifact', async () => { | ||
const savedObject = { | ||
aggregations: { | ||
by_os: { | ||
buckets: [ | ||
{ doc_count: 2, key: 'linux' }, | ||
{ doc_count: 3, key: 'macos' }, | ||
{ doc_count: 5, key: 'windows' }, | ||
], | ||
doc_count_error_upper_bound: 0, | ||
sum_other_doc_count: 0, | ||
}, | ||
}, | ||
page: 1, | ||
per_page: 0, | ||
saved_objects: [], | ||
total: 7, | ||
}; | ||
savedObjectsClient.find.mockResolvedValue(savedObject); | ||
|
||
const summary = (await getExceptionListSummary({ | ||
filter: undefined, | ||
id: undefined, | ||
listId: '', | ||
namespaceType: 'agnostic', | ||
savedObjectsClient, | ||
})) as ExceptionListSummarySchema; | ||
|
||
expect(summary.total).toEqual(10); | ||
}); | ||
|
||
test('it should NOT aggregate items if host isolation exception artifact', async () => { | ||
const savedObject = { | ||
aggregations: { | ||
by_os: { | ||
buckets: [ | ||
{ doc_count: 3, key: 'linux' }, | ||
{ doc_count: 3, key: 'macos' }, | ||
{ doc_count: 3, key: 'windows' }, | ||
], | ||
doc_count_error_upper_bound: 0, | ||
sum_other_doc_count: 0, | ||
}, | ||
}, | ||
page: 1, | ||
per_page: 0, | ||
saved_objects: [], | ||
total: 7, | ||
}; | ||
savedObjectsClient.find.mockResolvedValue(savedObject); | ||
|
||
const summary = (await getExceptionListSummary({ | ||
filter: undefined, | ||
id: undefined, | ||
listId: 'endpoint_host_isolation_exceptions', | ||
namespaceType: 'agnostic', | ||
savedObjectsClient, | ||
})) as ExceptionListSummarySchema; | ||
|
||
expect(summary.total).toEqual(3); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
|
||
import type { | ||
ExceptionListSummarySchema, | ||
FilterOrUndefined, | ||
IdOrUndefined, | ||
ListIdOrUndefined, | ||
NamespaceType, | ||
|
@@ -20,6 +21,7 @@ import { | |
import { ExceptionListSoSchema } from '../../schemas/saved_objects'; | ||
|
||
interface GetExceptionListSummaryOptions { | ||
filter: FilterOrUndefined; | ||
id: IdOrUndefined; | ||
listId: ListIdOrUndefined; | ||
savedObjectsClient: SavedObjectsClientContract; | ||
|
@@ -37,6 +39,7 @@ interface ByOsAggType { | |
} | ||
|
||
export const getExceptionListSummary = async ({ | ||
filter, | ||
id, | ||
listId, | ||
savedObjectsClient, | ||
|
@@ -67,7 +70,7 @@ export const getExceptionListSummary = async ({ | |
}, | ||
}, | ||
}, | ||
filter: `${savedObjectType}.attributes.list_type: item`, | ||
filter, | ||
perPage: 0, | ||
search: finalListId, | ||
searchFields: ['list_id'], | ||
|
@@ -84,7 +87,12 @@ export const getExceptionListSummary = async ({ | |
(acc, item: ByOsAggBucketType) => ({ | ||
...acc, | ||
[item.key]: item.doc_count, | ||
total: acc.total + item.doc_count, | ||
total: | ||
// Do not add up the items by OS if host isolation exception | ||
// As each host exception entry applies to all OSs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thanks for commenting the "why" here 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 😄 |
||
listId === 'endpoint_host_isolation_exceptions' | ||
ashokaditya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
? item.doc_count | ||
: acc.total + item.doc_count, | ||
}), | ||
{ linux: 0, macos: 0, total: 0, windows: 0 } | ||
); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not relevant but I think this total number should be 6 according the counters above
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.
@dasansol92 so this was because the API was returning +1 as total. I went looking for why that was and @paul-tavares helped me figure that out. We made the changes in bdc0c97 to fix that. Also updated the test mock to have the correct total.