forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Alert Summaries] [BE] Move “Notify When” and throttle from rule to a…
…ction (elastic#144130) * Add frequency props to actions and validate them on edit/create * Nullify undefined throttle * Update schema to allow for frequency param on actions * [CI] Auto-commit changed files from 'node scripts/precommit_hook.js --ref HEAD~1..HEAD --fix' * Commit missing file * Fix types * [CI] Auto-commit changed files from 'node scripts/eslint --no-cache --fix' * Fix types * Fix jest * Fix validating global freq params * Add tests for create and edit * Reset legacy api * Make notify and throttle optional in route schemas * Fix tests * Split missing frequency test cases Co-authored-by: kibanamachine <[email protected]> (cherry picked from commit 0c864fe)
- Loading branch information
Showing
19 changed files
with
533 additions
and
45 deletions.
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
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
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.