-
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
Migrates security solution usage collector es client from legacy to new #86853
Changes from all commits
218b2b1
09bfdf0
ae5325d
a571842
ac17fb7
b566502
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,11 @@ | |
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { SearchParams } from 'elasticsearch'; | ||
|
||
import { | ||
LegacyAPICaller, | ||
ElasticsearchClient, | ||
SavedObjectsClientContract, | ||
KibanaRequest, | ||
SearchResponse, | ||
} from '../../../../../../src/core/server'; | ||
import { MlPluginSetup } from '../../../../ml/server'; | ||
import { SIGNALS_ID, INTERNAL_IMMUTABLE_KEY } from '../../../common/constants'; | ||
|
@@ -22,6 +21,26 @@ interface DetectionsMetric { | |
isEnabled: boolean; | ||
} | ||
|
||
interface RuleSearchBody { | ||
query: { | ||
bool: { | ||
filter: { | ||
term: { [key: string]: string }; | ||
}; | ||
}; | ||
}; | ||
} | ||
interface RuleSearchParams { | ||
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. Nit: since 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. I'll keep it explicit for now and leave it up to your team to remove if that's what you prefer. |
||
body: RuleSearchBody; | ||
filterPath: string[]; | ||
ignoreUnavailable: boolean; | ||
index: string; | ||
size: number; | ||
} | ||
interface RuleSearchResult { | ||
alert: { enabled: boolean; tags: string[] }; | ||
} | ||
|
||
const isElasticRule = (tags: string[]) => tags.includes(`${INTERNAL_IMMUTABLE_KEY}:true`); | ||
|
||
/** | ||
|
@@ -135,10 +154,10 @@ const updateMlJobsUsage = (jobMetric: DetectionsMetric, usage: MlJobsUsage): MlJ | |
|
||
export const getRulesUsage = async ( | ||
index: string, | ||
callCluster: LegacyAPICaller | ||
esClient: ElasticsearchClient | ||
): Promise<DetectionRulesUsage> => { | ||
let rulesUsage: DetectionRulesUsage = initialRulesUsage; | ||
const ruleSearchOptions: SearchParams = { | ||
const ruleSearchOptions: RuleSearchParams = { | ||
body: { query: { bool: { filter: { term: { 'alert.alertTypeId': SIGNALS_ID } } } } }, | ||
filterPath: ['hits.hits._source.alert.enabled', 'hits.hits._source.alert.tags'], | ||
ignoreUnavailable: true, | ||
|
@@ -147,8 +166,7 @@ export const getRulesUsage = async ( | |
}; | ||
|
||
try { | ||
const ruleResults = await callCluster<{ alert: { enabled: boolean; tags: string[] } }>( | ||
'search', | ||
const { body: ruleResults } = await esClient.search<SearchResponse<RuleSearchResult>>( | ||
ruleSearchOptions | ||
); | ||
|
||
|
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.
Guessing this was an accidental import @rylnd?
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.
Its use was replaced by the custom
RuleSearchParams
below!