-
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
[POC] [Response Ops] Onboard detection rules to use alerting framework summaries. #147539
Changes from all commits
600af4f
e64eb64
20e2ed1
0525af6
4204595
7d21829
3d137a1
7a8b83c
eda6aa3
441427f
f267e88
3728778
c0fdb1c
81b1a67
8281156
25213b6
526f376
66e1d4a
d7b8c43
b289217
b1c0cc9
e732c7b
24881f1
82fd509
9bd69a0
63393ed
acd919b
8320dd6
4d86684
6a27c94
650d275
dea0cdd
9406c5b
cf9be1e
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 |
---|---|---|
|
@@ -167,6 +167,16 @@ export interface IRuleTypeAlerts { | |
fieldMap: FieldMap; | ||
} | ||
|
||
export interface GetRuleUrlFnOpts<Params extends RuleTypeParams> { | ||
id: string; | ||
params: Params; | ||
spaceId: string; | ||
startMs?: number; | ||
endMs?: number; | ||
} | ||
export type GetRuleUrlFn<Params extends RuleTypeParams> = ( | ||
opts: GetRuleUrlFnOpts<Params> | ||
) => string | null; | ||
export interface RuleType< | ||
Params extends RuleTypeParams = never, | ||
ExtractedParams extends RuleTypeParams = never, | ||
|
@@ -212,6 +222,8 @@ export interface RuleType< | |
cancelAlertsOnRuleTimeout?: boolean; | ||
doesSetRecoveryContext?: boolean; | ||
getSummarizedAlerts?: GetSummarizedAlertsFn; | ||
getRuleUrl?: GetRuleUrlFn<Params>; | ||
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. allows rule types to specify custom function for building rule URLs |
||
|
||
alerts?: IRuleTypeAlerts; | ||
/** | ||
* Determines whether framework should | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -56,7 +56,7 @@ const mapAlertsToBulkCreate = <T>(alerts: Array<{ _id: string; _source: T }>) => | |||||||||||
}; | ||||||||||||
|
||||||||||||
export const createPersistenceRuleTypeWrapper: CreatePersistenceRuleTypeWrapper = | ||||||||||||
({ logger, ruleDataClient }) => | ||||||||||||
({ logger, ruleDataClient, formatAlert }) => | ||||||||||||
(type) => { | ||||||||||||
return { | ||||||||||||
...type, | ||||||||||||
|
@@ -160,17 +160,23 @@ export const createPersistenceRuleTypeWrapper: CreatePersistenceRuleTypeWrapper | |||||||||||
return { createdAlerts: [], errors: {}, alertsWereTruncated }; | ||||||||||||
} | ||||||||||||
|
||||||||||||
const createdAlerts = augmentedAlerts | ||||||||||||
.map((alert, idx) => { | ||||||||||||
const responseItem = response.body.items[idx].create; | ||||||||||||
return { | ||||||||||||
_id: responseItem?._id ?? '', | ||||||||||||
_index: responseItem?._index ?? '', | ||||||||||||
...alert._source, | ||||||||||||
}; | ||||||||||||
}) | ||||||||||||
.filter((_, idx) => response.body.items[idx].create?.status === 201); | ||||||||||||
|
||||||||||||
createdAlerts.forEach((alert) => | ||||||||||||
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. Reporting alerts 1-1 back to the framework. |
||||||||||||
options.services.alertFactory.create(alert._id).scheduleActions('default', {}) | ||||||||||||
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.
Suggested change
|
||||||||||||
); | ||||||||||||
|
||||||||||||
return { | ||||||||||||
createdAlerts: augmentedAlerts | ||||||||||||
.map((alert, idx) => { | ||||||||||||
const responseItem = response.body.items[idx].create; | ||||||||||||
return { | ||||||||||||
_id: responseItem?._id ?? '', | ||||||||||||
_index: responseItem?._index ?? '', | ||||||||||||
...alert._source, | ||||||||||||
}; | ||||||||||||
}) | ||||||||||||
.filter((_, idx) => response.body.items[idx].create?.status === 201), | ||||||||||||
createdAlerts, | ||||||||||||
errors: errorAggregator(response.body, [409]), | ||||||||||||
alertsWereTruncated, | ||||||||||||
}; | ||||||||||||
|
@@ -356,6 +362,7 @@ export const createPersistenceRuleTypeWrapper: CreatePersistenceRuleTypeWrapper | |||||||||||
ruleDataClient, | ||||||||||||
useNamespace: true, | ||||||||||||
isLifecycleAlert: false, | ||||||||||||
formatAlert, | ||||||||||||
})(), | ||||||||||||
}; | ||||||||||||
}; |
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.
Returns the time bounds for summarized alerts that can be used for building rule URLs. This ensures that the time bounds used to load alerts in the UI matches the time bounds for the alert summary so the alert counts match.
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.
Calculating it from the summarized alerts instead of using existing time bounds because when we query for alerts per rule execution UUID, we don't have existing time bounds.