-
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] Improve find rule and find rule status route performance #99678
Merged
marshallmain
merged 15 commits into
elastic:master
from
marshallmain:rules-status-aggs-no-bulk
May 28, 2021
Merged
Changes from 8 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
361be5e
Fetch rule statuses using single aggregation instead of N separate re…
marshallmain 6ebe345
Optimize _find API and _find_statuses more
marshallmain 2ef8df5
Merge alerting framework errors into rule statuses
marshallmain f76456f
Extract shared function, remove console logs
marshallmain 391eec4
Remove AlertsClient getBulk experimental implementation
marshallmain 3773478
Cleanup types and tests
marshallmain 543f230
Remove commented code
marshallmain 5de081a
Merge branch 'master' into rules-status-aggs-no-bulk
kibanamachine 8700301
Fix unit tests
marshallmain b443b9f
Merge branch 'master' into rules-status-aggs-no-bulk
kibanamachine 292a360
Add sortSchema for top hits agg, update terms.order schema
marshallmain 17e72a0
Merge branch 'rules-status-aggs-no-bulk' of github.com:marshallmain/k…
marshallmain d7997e1
Remove unused import
marshallmain e8c4511
Merge branch 'master' into rules-status-aggs-no-bulk
kibanamachine 2316fae
Merge branch 'master' into rules-status-aggs-no-bulk
marshallmain 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
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
40 changes: 40 additions & 0 deletions
40
...y_solution/server/lib/detection_engine/rule_actions/get_bulk_rule_actions_saved_object.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,40 @@ | ||
/* | ||
* 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 { AlertServices } from '../../../../../alerting/server'; | ||
import { ruleActionsSavedObjectType } from './saved_object_mappings'; | ||
import { IRuleActionsAttributesSavedObjectAttributes } from './types'; | ||
import { getRuleActionsFromSavedObject } from './utils'; | ||
import { RulesActionsSavedObject } from './get_rule_actions_saved_object'; | ||
import { buildChunkedOrFilter } from '../signals/utils'; | ||
|
||
interface GetBulkRuleActionsSavedObject { | ||
alertIds: string[]; | ||
savedObjectsClient: AlertServices['savedObjectsClient']; | ||
} | ||
|
||
export const getBulkRuleActionsSavedObject = async ({ | ||
alertIds, | ||
savedObjectsClient, | ||
}: GetBulkRuleActionsSavedObject): Promise<Record<string, RulesActionsSavedObject>> => { | ||
const filter = buildChunkedOrFilter( | ||
`${ruleActionsSavedObjectType}.attributes.ruleAlertId`, | ||
alertIds | ||
); | ||
const { | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
saved_objects, | ||
} = await savedObjectsClient.find<IRuleActionsAttributesSavedObjectAttributes>({ | ||
type: ruleActionsSavedObjectType, | ||
perPage: 10000, | ||
filter, | ||
}); | ||
return saved_objects.reduce((acc: { [key: string]: RulesActionsSavedObject }, savedObject) => { | ||
acc[savedObject.attributes.ruleAlertId] = getRuleActionsFromSavedObject(savedObject); | ||
return acc; | ||
}, {}); | ||
}; |
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
Oops, something went wrong.
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.
The schema here was too strict - string values in
sort
are used as field names, so this only allowed sorting on fields namedasc
ordesc
. The JS Elasticsearch client types allow the full range ofSort
options for top hits aggs (https://github.com/elastic/elasticsearch-js/blob/master/api/types.d.ts#L11982)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.
Sorry, I would really like to avoid
any
in the aggregation schemas. I'm very fine changing thesort
schema to get closer to the real type (it do not need to be exhaustive here, only to match your needs), but the whole goal of the aggs validation is to not allow arbitrary values.From your code, it seems you're using the
SortContainer
formatI would introduce a
SortSchema
, and also use it in other aggregations where we have asort
options, e.gterms
.You can create a
src/core/server/saved_objects/service/lib/aggregations/aggs_types/common_schemas.ts
file for that.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.
No problem, thanks for the feedback! I added the file you suggested with some of the reusable sort schemas and used them to enhance the
terms.order
and top hits sort validation.