-
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
[Alert Summaries] [BE] Move “Notify When” and throttle from rule to action #144130
Merged
Merged
Changes from 15 commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
52d3433
Add frequency props to actions and validate them on edit/create
Zacqary d077ea1
Nullify undefined throttle
Zacqary 378d4e8
Update schema to allow for frequency param on actions
Zacqary 11cd1d3
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine 4889023
Commit missing file
Zacqary 1a84f27
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary 4349c73
Fix types
Zacqary 1c869ab
Merge branch '143368-notify-migration' of https://github.com/Zacqary/…
Zacqary ef43549
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine cb3f976
Fix types
Zacqary 77711c2
Fix jest
Zacqary 3d23b1c
Merge branch '143368-notify-migration' of https://github.com/Zacqary/…
Zacqary 2abc7ae
Fix validating global freq params
Zacqary 66810ae
Add tests for create and edit
Zacqary adf815f
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary 20d4983
Reset legacy api
Zacqary 24fe88c
Make notify and throttle optional in route schemas
Zacqary b35150b
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary bed44bc
Fix tests
Zacqary 3b12f0f
Split missing frequency test cases
Zacqary b2bebdf
Handle xor undefined global frequency params
Zacqary e6b1843
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary 11e16a5
Fix typecheck
Zacqary dec2b1a
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary bed5753
Refactor global freq param validation and clarify error messages
Zacqary 26df5b5
Update jest snapshots
Zacqary cda3467
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary 023cb65
Fix bad merge
Zacqary 7a517e0
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary 36d0843
Remove extraneous file
Zacqary da42cd2
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary 4287aeb
Merge branch 'main' into 143368-notify-migration
kibanamachine 4cf5498
Merge branch 'main' into 143368-notify-migration
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
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
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/alerting/server/lib/validate_rule_frequency.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,24 @@ | ||
/* | ||
* 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 Boom from '@hapi/boom'; | ||
import { RuleTypeParams, RuleTypeParamsValidator } from '../types'; | ||
|
||
export function validateRuleTypeParams<Params extends RuleTypeParams>( | ||
params: Record<string, unknown>, | ||
validator?: RuleTypeParamsValidator<Params> | ||
): Params { | ||
if (!validator) { | ||
return params as Params; | ||
} | ||
|
||
try { | ||
return validator.validate(params); | ||
} catch (err) { | ||
throw Boom.badRequest(`params invalid: ${err.message}`); | ||
} | ||
} |
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
29 changes: 29 additions & 0 deletions
29
x-pack/plugins/alerting/server/routes/lib/actions_schema.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,29 @@ | ||
/* | ||
* 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 { schema } from '@kbn/config-schema'; | ||
import { validateDurationSchema } from '../../lib'; | ||
|
||
export const actionsSchema = schema.arrayOf( | ||
schema.object({ | ||
group: schema.string(), | ||
id: schema.string(), | ||
params: schema.recordOf(schema.string(), schema.any(), { defaultValue: {} }), | ||
frequency: schema.maybe( | ||
schema.object({ | ||
summary: schema.boolean(), | ||
notify_when: schema.oneOf([ | ||
schema.literal('onActionGroupChange'), | ||
schema.literal('onActiveAlert'), | ||
schema.literal('onThrottleInterval'), | ||
]), | ||
throttle: schema.nullable(schema.string({ validate: validateDurationSchema })), | ||
}) | ||
), | ||
}), | ||
{ defaultValue: [] } | ||
); |
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
32 changes: 32 additions & 0 deletions
32
x-pack/plugins/alerting/server/routes/lib/rewrite_actions.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,32 @@ | ||
/* | ||
* 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 { CamelToSnake, RewriteRequestCase } from './rewrite_request_case'; | ||
import { RuleAction } from '../../types'; | ||
|
||
type ReqRuleAction = Omit<RuleAction, 'actionTypeId' | 'frequency'> & { | ||
frequency?: { | ||
[K in keyof NonNullable<RuleAction['frequency']> as CamelToSnake<K>]: NonNullable< | ||
RuleAction['frequency'] | ||
>[K]; | ||
}; | ||
}; | ||
export const rewriteActions: ( | ||
actions?: ReqRuleAction[] | ||
) => Array<Omit<RuleAction, 'actionTypeId'>> = (actions) => { | ||
const rewriteFrequency: RewriteRequestCase<NonNullable<RuleAction['frequency']>> = ({ | ||
notify_when: notifyWhen, | ||
...rest | ||
}) => ({ ...rest, notifyWhen }); | ||
if (!actions) return []; | ||
return actions.map( | ||
(action) => | ||
({ | ||
...action, | ||
...(action.frequency ? { frequency: rewriteFrequency(action.frequency) } : {}), | ||
} as RuleAction) | ||
); | ||
}; |
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
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.
It looks like total copy of
x-pack/plugins/alerting/server/lib/validate_rule_type_params.ts
. With the same variables, types.Maybe better to reuse it?
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.
Ah looks like I committed this file by mistake