Skip to content
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] [FE] Move “Notify When” and throttle from rule to action #145637

Merged
merged 113 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from 110 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
52d3433
Add frequency props to actions and validate them on edit/create
Zacqary Oct 27, 2022
d077ea1
Nullify undefined throttle
Zacqary Oct 27, 2022
378d4e8
Update schema to allow for frequency param on actions
Zacqary Oct 27, 2022
11cd1d3
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Oct 27, 2022
4889023
Commit missing file
Zacqary Oct 28, 2022
1a84f27
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Oct 28, 2022
4349c73
Fix types
Zacqary Oct 28, 2022
1c869ab
Merge branch '143368-notify-migration' of https://github.com/Zacqary/…
Zacqary Oct 28, 2022
ef43549
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine Oct 28, 2022
cb3f976
Fix types
Zacqary Oct 31, 2022
77711c2
Fix jest
Zacqary Oct 31, 2022
3d23b1c
Merge branch '143368-notify-migration' of https://github.com/Zacqary/…
Zacqary Oct 31, 2022
2abc7ae
Fix validating global freq params
Zacqary Oct 31, 2022
66810ae
Add tests for create and edit
Zacqary Oct 31, 2022
adf815f
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 1, 2022
20d4983
Reset legacy api
Zacqary Nov 2, 2022
24fe88c
Make notify and throttle optional in route schemas
Zacqary Nov 2, 2022
b35150b
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 3, 2022
bed44bc
Fix tests
Zacqary Nov 3, 2022
3b12f0f
Split missing frequency test cases
Zacqary Nov 4, 2022
b2bebdf
Handle xor undefined global frequency params
Zacqary Nov 7, 2022
e6b1843
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 7, 2022
11e16a5
Fix typecheck
Zacqary Nov 7, 2022
dec2b1a
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 8, 2022
bed5753
Refactor global freq param validation and clarify error messages
Zacqary Nov 9, 2022
26df5b5
Update jest snapshots
Zacqary Nov 9, 2022
cda3467
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 15, 2022
023cb65
Fix bad merge
Zacqary Nov 15, 2022
7a517e0
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 15, 2022
36d0843
Remove extraneous file
Zacqary Nov 15, 2022
da42cd2
Merge remote-tracking branch 'upstream/main' into 143368-notify-migra…
Zacqary Nov 16, 2022
62b4334
Move frequency controls into actions form
Zacqary Nov 10, 2022
54024f9
Add Integrate action frequency params with frontend
Zacqary Nov 17, 2022
62005c1
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Nov 17, 2022
1c8e2cf
Add action notification UI
Zacqary Nov 17, 2022
366e023
Add legacy notifywhen to action notification UI
Zacqary Nov 17, 2022
d6a2f34
Fix typecheck
Zacqary Nov 18, 2022
c59a399
Fix null throttle issue with tests
Zacqary Nov 21, 2022
22eed60
Fix validateActions route processing
Zacqary Nov 21, 2022
5830ba1
Fix i18n
Zacqary Nov 21, 2022
0205923
Fix types
Zacqary Nov 21, 2022
9d626f2
Fix update test
Zacqary Nov 21, 2022
074307e
Remove check for undefined throttle entirely
Zacqary Nov 21, 2022
8ea7895
Remove throttle value test
Zacqary Nov 21, 2022
5c578ca
Fix security solution action frequency typecheck
Zacqary Nov 21, 2022
6c577d6
Fix monitoring alerts creation and fix legacy tests
Zacqary Nov 22, 2022
bd6f4f1
Fix jest for create rule
Zacqary Nov 22, 2022
966d2ce
Fix update jest
Zacqary Nov 22, 2022
d3e9e60
Fix baseRule test
Zacqary Nov 22, 2022
4624d59
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Nov 22, 2022
63cec0d
Fix alert create flyout test
Zacqary Nov 22, 2022
0cb91c2
Fix rule details tests and editing legacy alerts
Zacqary Nov 22, 2022
1906ea8
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 5, 2022
969a963
Fix alerts list test 400 error
Zacqary Dec 5, 2022
275ee63
Update snapshots
Zacqary Dec 5, 2022
ca2b24c
Update snapshots
Zacqary Dec 5, 2022
302f6d8
Update security solution actions form
Zacqary Dec 6, 2022
6b32d1c
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 6, 2022
595653b
Fix bulk action editing
Zacqary Dec 6, 2022
2e88eea
Fix typecheck
Zacqary Dec 7, 2022
3441667
Fix request schema test
Zacqary Dec 7, 2022
71ce77b
Clean up try catch block
Zacqary Dec 7, 2022
8c0a66f
More security solution fixes
Zacqary Dec 8, 2022
b41ec91
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 12, 2022
eadef78
Fix i18n
Zacqary Dec 12, 2022
43f84e9
Fix bulk actions test
Zacqary Dec 13, 2022
44d95eb
Update registered types test
Zacqary Dec 13, 2022
49e5ff2
Fix bulk edit and security solution throttle transform
Zacqary Dec 13, 2022
1326885
Fix rule changed compare for notifyWhen
Zacqary Dec 13, 2022
6a36797
Fix lint
Zacqary Dec 13, 2022
ad90176
Fix group10 tests
Zacqary Dec 13, 2022
d839d89
Fix jest
Zacqary Dec 13, 2022
5a50078
Fix notifywhen type jest
Zacqary Dec 13, 2022
d1c330f
Fix group10 tests
Zacqary Dec 14, 2022
9ffa1a1
Fix functional tests
Zacqary Dec 14, 2022
265a6c1
Fix security solution bulk edit
Zacqary Dec 15, 2022
593fd95
Fix group10
Zacqary Dec 15, 2022
dfdf80f
Move Notify When field below Run When
Zacqary Dec 19, 2022
40ce55a
Lock throttle interval to check interval
Zacqary Dec 19, 2022
6e2a74a
[CI] Auto-commit changed files from 'node scripts/precommit_hook.js -…
kibanamachine Dec 19, 2022
cf1ba82
Remove unused import
Zacqary Dec 19, 2022
d489b24
Merge branch '143369-notify-fe-migration' of https://github.com/Zacqa…
Zacqary Dec 19, 2022
275a603
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 20, 2022
faa989c
Move interval outside actiontype conditional
Zacqary Dec 21, 2022
0b7980a
Fix rule form tests
Zacqary Dec 21, 2022
a359425
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 21, 2022
38dd49f
Fix rule_add tests
Zacqary Dec 21, 2022
5c35ec0
Fix rule actions test
Zacqary Dec 21, 2022
1b259c9
Update Rule API tests
Zacqary Dec 21, 2022
524a2c0
Add test for reducer
Zacqary Dec 22, 2022
72ffb30
Add test for minimum throttle
Zacqary Dec 22, 2022
1f36692
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 27, 2022
e4a6f17
Fix legacy throttle migration
Zacqary Dec 27, 2022
756edc6
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Dec 28, 2022
b846f90
Fix PR nits
Zacqary Jan 3, 2023
b1aaca6
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Jan 3, 2023
a4e2ff0
Fix double defined default frequency
Zacqary Jan 3, 2023
66f7156
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Jan 3, 2023
4f2e4b3
Merge branch 'main' into 143369-notify-fe-migration
kibanamachine Jan 3, 2023
c775791
Revert security solution APIs and add workarounds for frequency schema
Zacqary Jan 4, 2023
c64b8cc
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Jan 4, 2023
eb2d63d
Merge branch '143369-notify-fe-migration' of https://github.com/Zacqa…
Zacqary Jan 4, 2023
4f30e42
Revert bulk action test
Zacqary Jan 4, 2023
18e277a
Add comment about typedef discrepancy
Zacqary Jan 9, 2023
1d81b60
Merge remote-tracking branch 'upstream/main' into 143369-notify-fe-mi…
Zacqary Jan 9, 2023
f3acdda
Revert "Lock throttle interval to check interval"
Zacqary Jan 9, 2023
9d37ce7
Remove minimum throttle test
Zacqary Jan 9, 2023
2614f4a
Add setTimeout comment
Zacqary Jan 9, 2023
339c67e
Lint fix
Zacqary Jan 9, 2023
d748d54
Remove ruleThrottle state
Zacqary Jan 9, 2023
6006849
Lint fix
Zacqary Jan 9, 2023
c5dfe8a
Merge branch 'main' into 143369-notify-fe-migration
XavierM Jan 10, 2023
8c13b2e
Merge branch 'main' into 143369-notify-fe-migration
kibanamachine Jan 10, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions x-pack/plugins/alerting/common/rule_notify_when_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ export const RuleNotifyWhenTypeValues = [
] as const;
export type RuleNotifyWhenType = typeof RuleNotifyWhenTypeValues[number];

export enum RuleNotifyWhen {
CHANGE = 'onActionGroupChange',
ACTIVE = 'onActiveAlert',
THROTTLE = 'onThrottleInterval',
}

export function validateNotifyWhenType(notifyWhen: string) {
if (RuleNotifyWhenTypeValues.includes(notifyWhen as RuleNotifyWhenType)) {
return;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/alerting/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type {
RuleParamsAndRefs,
GetSummarizedAlertsFnOpts,
} from './types';
export { RuleNotifyWhen } from '../common';
export { DEFAULT_MAX_EPHEMERAL_ACTIONS_PER_ALERT } from './config';
export type { PluginSetupContract, PluginStartContract } from './plugin';
export type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ test(`should return 'onThrottleInterval' value if 'notifyWhen' is null and throt
expect(getRuleNotifyWhenType(null, '10m')).toEqual('onThrottleInterval');
});

test(`should return 'onActiveAlert' value if 'notifyWhen' is null and throttle is null`, () => {
expect(getRuleNotifyWhenType(null, null)).toEqual('onActiveAlert');
test(`should return null value if 'notifyWhen' is null and throttle is null`, () => {
expect(getRuleNotifyWhenType(null, null)).toEqual(null);
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { RuleNotifyWhenType } from '../types';
export function getRuleNotifyWhenType(
notifyWhen: RuleNotifyWhenType | null,
throttle: string | null
): RuleNotifyWhenType {
): RuleNotifyWhenType | null {
// We allow notifyWhen to be null for backwards compatibility. If it is null, determine its
// value based on whether the throttle is set to a value or null
return notifyWhen ? notifyWhen! : throttle ? 'onThrottleInterval' : 'onActiveAlert';
return notifyWhen ? notifyWhen! : throttle ? 'onThrottleInterval' : null;
}
ersin-erdal marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/routes/clone_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,12 @@ const rewriteBodyRes: RewriteResponseCase<PartialRule<RuleTypeParams>> = ({
: {}),
...(actions
? {
actions: actions.map(({ group, id, actionTypeId, params }) => ({
actions: actions.map(({ group, id, actionTypeId, params, frequency }) => ({
group,
id,
params,
connector_type_id: actionTypeId,
frequency,
})),
}
: {}),
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/routes/get_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,12 @@ const rewriteBodyRes: RewriteResponseCase<SanitizedRule<RuleTypeParams>> = ({
last_execution_date: executionStatus.lastExecutionDate,
last_duration: executionStatus.lastDuration,
},
actions: actions.map(({ group, id, actionTypeId, params }) => ({
actions: actions.map(({ group, id, actionTypeId, params, frequency }) => ({
group,
id,
params,
connector_type_id: actionTypeId,
frequency,
})),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/routes/legacy/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { verifyApiAccess } from '../../lib/license_api_access';
import { mockHandlerArguments } from '../_mock_handler_arguments';
import { rulesClientMock } from '../../rules_client.mock';
import { RuleTypeDisabledError } from '../../lib/errors/rule_type_disabled';
import { RuleNotifyWhenType } from '../../../common';
import { RuleNotifyWhen } from '../../../common';
import { trackLegacyRouteUsage } from '../../lib/track_legacy_route_usage';

const rulesClient = rulesClientMock.create();
Expand Down Expand Up @@ -50,7 +50,7 @@ describe('updateAlertRoute', () => {
},
},
],
notifyWhen: 'onActionGroupChange' as RuleNotifyWhenType,
notifyWhen: RuleNotifyWhen.CHANGE,
};

it('updates an alert with proper parameters', async () => {
Expand Down
5 changes: 1 addition & 4 deletions x-pack/plugins/alerting/server/routes/lib/rewrite_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ export const rewriteRule = ({
connector_type_id: actionTypeId,
...(frequency
? {
frequency: {
...frequency,
notify_when: frequency.notifyWhen,
},
frequency,
Copy link
Contributor

@XavierM XavierM Jan 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why we do not need to do remove notify_when ? I am confused sorry!
#145637 (comment)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixes a breaking test. Something is broken in the library that converts between camelCase and snake_case inside nested properties. I'll create an issue to investigate further, forgot to do that when I found this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes please do and let's fix it before this is going in the next release!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
: {}),
})),
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/routes/resolve_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ const rewriteBodyRes: RewriteResponseCase<ResolvedSanitizedRule<RuleTypeParams>>
last_execution_date: executionStatus.lastExecutionDate,
last_duration: executionStatus.lastDuration,
},
actions: actions.map(({ group, id, actionTypeId, params }) => ({
actions: actions.map(({ group, id, actionTypeId, params, frequency }) => ({
group,
id,
params,
connector_type_id: actionTypeId,
frequency,
})),
...(lastRun ? { last_run: rewriteRuleLastRun(lastRun) } : {}),
...(nextRun ? { next_run: nextRun } : {}),
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/alerting/server/routes/update_rule.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { mockHandlerArguments } from './_mock_handler_arguments';
import { UpdateOptions } from '../rules_client';
import { rulesClientMock } from '../rules_client.mock';
import { RuleTypeDisabledError } from '../lib/errors/rule_type_disabled';
import { RuleNotifyWhenType } from '../../common';
import { RuleNotifyWhen } from '../../common';
import { AsApiContract } from './lib';
import { PartialRule } from '../types';

Expand Down Expand Up @@ -50,7 +50,7 @@ describe('updateRuleRoute', () => {
},
},
],
notifyWhen: 'onActionGroupChange' as RuleNotifyWhenType,
notifyWhen: RuleNotifyWhen.CHANGE,
};

const updateRequest: AsApiContract<UpdateOptions<{ otherField: boolean }>['data']> = {
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/alerting/server/routes/update_rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,12 @@ const rewriteBodyRes: RewriteResponseCase<PartialRule<RuleTypeParams>> = ({
: {}),
...(actions
? {
actions: actions.map(({ group, id, actionTypeId, params }) => ({
actions: actions.map(({ group, id, actionTypeId, params, frequency }) => ({
group,
id,
params,
connector_type_id: actionTypeId,
frequency,
})),
}
: {}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,8 @@ export async function validateActions(
data: Pick<RawRule, 'notifyWhen' | 'throttle'> & { actions: NormalizedAlertAction[] }
): Promise<void> {
const { actions, notifyWhen, throttle } = data;
const hasNotifyWhen = typeof notifyWhen !== 'undefined';
const hasThrottle = typeof throttle !== 'undefined';
let usesRuleLevelFreqParams;
// I removed the below ` && hasThrottle` check temporarily.
// Currently the UI sends "throttle" as undefined but schema converts it to null, so they never become both undefined
// I changed the schema too, but as the UI (and tests) sends "notifyWhen" as string and "throttle" as undefined, they never become both defined.
// We should add it back when the UI is changed (https://github.com/elastic/kibana/issues/143369)
if (hasNotifyWhen) usesRuleLevelFreqParams = true;
else if (!hasNotifyWhen && !hasThrottle) usesRuleLevelFreqParams = false;
else {
throw Boom.badRequest(
i18n.translate('xpack.alerting.rulesClient.usesValidGlobalFreqParams.oneUndefined', {
defaultMessage:
'Rule-level notifyWhen and throttle must both be defined or both be undefined',
})
);
}

const hasRuleLevelNotifyWhen = typeof notifyWhen !== 'undefined';
const hasRuleLevelThrottle = Boolean(throttle);
if (actions.length === 0) {
return;
}
Expand Down Expand Up @@ -81,13 +65,13 @@ export async function validateActions(
}

// check for actions using frequency params if the rule has rule-level frequency params defined
if (usesRuleLevelFreqParams) {
if (hasRuleLevelNotifyWhen || hasRuleLevelThrottle) {
const actionsWithFrequency = actions.filter((action) => Boolean(action.frequency));
if (actionsWithFrequency.length) {
throw Boom.badRequest(
i18n.translate('xpack.alerting.rulesClient.validateActions.mixAndMatchFreqParams', {
defaultMessage:
'Cannot specify per-action frequency params when notify_when and throttle are defined at the rule level: {groups}',
'Cannot specify per-action frequency params when notify_when or throttle are defined at the rule level: {groups}',
values: {
groups: actionsWithFrequency.map((a) => a.group).join(', '),
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import pMap from 'p-map';
import Boom from '@hapi/boom';
import { cloneDeep } from 'lodash';
import { cloneDeep, omit } from 'lodash';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { KueryNode, nodeBuilder } from '@kbn/es-query';
import {
Expand Down Expand Up @@ -540,7 +540,20 @@ async function getUpdatedAttributesFromOperations(
// the `isAttributesUpdateSkipped` flag to false.
switch (operation.field) {
case 'actions': {
await validateActions(context, ruleType, { ...attributes, actions: operation.value });
try {
await validateActions(context, ruleType, {
...attributes,
actions: operation.value,
});
} catch (e) {
// If validateActions fails on the first attempt, it may be because of legacy rule-level frequency params
attributes = await attemptToMigrateLegacyFrequency(
Zacqary marked this conversation as resolved.
Show resolved Hide resolved
context,
operation,
attributes,
ruleType
);
}

const { modifiedAttributes, isAttributeModified } = applyBulkEditOperation(
operation,
Expand All @@ -550,6 +563,18 @@ async function getUpdatedAttributesFromOperations(
ruleActions = modifiedAttributes;
isAttributesUpdateSkipped = false;
}

// TODO https://github.com/elastic/kibana/issues/148414
// If any action-level frequencies get pushed into a SIEM rule, strip their frequencies
const firstFrequency = operation.value[0]?.frequency;
if (rule.attributes.consumer === AlertConsumers.SIEM && firstFrequency) {
ruleActions.actions = ruleActions.actions.map((action) => omit(action, 'frequency'));
if (!attributes.notifyWhen) {
attributes.notifyWhen = firstFrequency.notifyWhen;
attributes.throttle = firstFrequency.throttle;
}
}

break;
}
case 'snoozeSchedule': {
Expand Down Expand Up @@ -754,3 +779,21 @@ async function saveBulkUpdatedRules(

return { result, apiKeysToInvalidate };
}

async function attemptToMigrateLegacyFrequency(
context: RulesClientContext,
operation: BulkEditOperation,
attributes: SavedObjectsFindResult<RawRule>['attributes'],
ruleType: RuleType
) {
if (operation.field !== 'actions')
throw new Error('Can only perform frequency migration on an action operation');
// Try to remove the rule-level frequency params, and then validate actions
if (typeof attributes.notifyWhen !== 'undefined') attributes.notifyWhen = undefined;
if (attributes.throttle) attributes.throttle = undefined;
await validateActions(context, ruleType, {
...attributes,
actions: operation.value,
});
return attributes;
}
13 changes: 13 additions & 0 deletions x-pack/plugins/alerting/server/rules_client/methods/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
import Semver from 'semver';
import Boom from '@hapi/boom';
import { omit } from 'lodash';
import { AlertConsumers } from '@kbn/rule-data-utils';
import { SavedObjectsUtils } from '@kbn/core/server';
import { withSpan } from '@kbn/apm-utils';
import { parseDuration } from '../../../common/parse_duration';
Expand Down Expand Up @@ -91,6 +93,17 @@ export async function create<Params extends RuleTypeParams = never>(
throw Boom.badRequest(`Error creating rule: could not create API key - ${error.message}`);
}

// TODO https://github.com/elastic/kibana/issues/148414
// If any action-level frequencies get pushed into a SIEM rule, strip their frequencies
const firstFrequency = data.actions[0]?.frequency;
if (data.consumer === AlertConsumers.SIEM && firstFrequency) {
data.actions = data.actions.map((action) => omit(action, 'frequency'));
if (!data.notifyWhen) {
data.notifyWhen = firstFrequency.notifyWhen;
data.throttle = firstFrequency.throttle;
}
}

await validateActions(context, ruleType, data);
await withSpan({ name: 'validateActions', type: 'rules' }, () =>
validateActions(context, ruleType, data)
Expand Down
14 changes: 13 additions & 1 deletion x-pack/plugins/alerting/server/rules_client/methods/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
*/

import Boom from '@hapi/boom';
import { isEqual } from 'lodash';
import { isEqual, omit } from 'lodash';
import { SavedObject } from '@kbn/core/server';
import { AlertConsumers } from '@kbn/rule-data-utils';
import {
PartialRule,
RawRule,
Expand Down Expand Up @@ -142,6 +143,17 @@ async function updateAlert<Params extends RuleTypeParams>(
): Promise<PartialRule<Params>> {
const ruleType = context.ruleTypeRegistry.get(attributes.alertTypeId);

// TODO https://github.com/elastic/kibana/issues/148414
// If any action-level frequencies get pushed into a SIEM rule, strip their frequencies
const firstFrequency = data.actions[0]?.frequency;
if (attributes.consumer === AlertConsumers.SIEM && firstFrequency) {
data.actions = data.actions.map((action) => omit(action, 'frequency'));
if (!attributes.notifyWhen) {
attributes.notifyWhen = firstFrequency.notifyWhen;
attributes.throttle = firstFrequency.throttle;
}
}

// Validate
const validatedAlertTypeParams = validateRuleTypeParams(data.params, ruleType.validate?.params);
await validateActions(context, ruleType, data);
Expand Down
Loading