mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[ResponseOps][Rules] Allow to set notify when and throttle at rule level (#203235)
## Summary Fixes https://github.com/elastic/kibana/issues/199494 This PR allows to create and update rule with `notify_when` and `throttle` attributes at rule level instead of `action.frequency` level. ### How to test - create a rule via api where `notify_when` and `throttle` attributes are at rule level <details><summary>Example</summary> Note: use your existing connector for action ```typescript POST kbn:/api/alerting/rule { "tags": [], "params": { "searchConfiguration": { "query": { "query": "", "language": "kuery" }, "index": "ff959d40-b880-11e8-a6d9-e546fe2bba5f" }, "timeField": "order_date", "searchType": "searchSource", "timeWindowSize": 5, "timeWindowUnit": "d", "threshold": [ 10 ], "thresholdComparator": ">", "size": 100, "aggType": "count", "groupBy": "all", "termSize": 5, "excludeHitsFromPreviousRun": false, "sourceFields": [] }, "schedule": { "interval": "1m" }, "consumer": "stackAlerts", "name": "ES query rule from devtools", "rule_type_id": ".es-query", "notify_when": "onThrottleInterval", "throttle": "1h", "actions": [ { "group": "query matched", "id": "ad923c8a-d27d-41a9-8c71-d33d94db4abb", "params": { "documents": [ { "name": "{{rule.name}}" } ] } } ], "alert_delay": { "active": 1 } } ``` </details> - open the created rule - go to `settings` tab - verify that dropdowns reflect notify_when and throttle value correctly - update the rule via UI and verify the same - update the rule via API and verify the same ### Flaky test runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/7684 ### Checklist Check the PR satisfies following conditions. - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
This commit is contained in:
parent
fea598ea13
commit
a56227bf37
6 changed files with 25 additions and 8 deletions
|
@ -42,7 +42,7 @@ export const getDefaultFormData = ({
|
|||
ruleTypeId: RuleFormData['ruleTypeId'];
|
||||
name: RuleFormData['name'];
|
||||
consumer: RuleFormData['consumer'];
|
||||
actions: RuleFormData['actions'];
|
||||
actions?: RuleFormData['actions'];
|
||||
schedule?: RuleFormData['schedule'];
|
||||
}) => {
|
||||
return {
|
||||
|
@ -54,7 +54,7 @@ export const getDefaultFormData = ({
|
|||
consumer,
|
||||
ruleTypeId,
|
||||
name,
|
||||
actions,
|
||||
actions: actions ?? [],
|
||||
alertDelay: { active: 1 },
|
||||
};
|
||||
};
|
||||
|
|
|
@ -124,7 +124,6 @@ export const CreateRuleForm = (props: CreateRuleFormProps) => {
|
|||
params: newFormData.params,
|
||||
schedule: newFormData.schedule,
|
||||
actions: newFormData.actions,
|
||||
notifyWhen: newFormData.notifyWhen,
|
||||
alertDelay: newFormData.alertDelay,
|
||||
flapping: newFormData.flapping,
|
||||
},
|
||||
|
|
|
@ -101,7 +101,6 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
|
|||
schedule: newFormData.schedule,
|
||||
params: newFormData.params,
|
||||
actions: newFormData.actions,
|
||||
notifyWhen: newFormData.notifyWhen,
|
||||
alertDelay: newFormData.alertDelay,
|
||||
flapping: newFormData.flapping,
|
||||
},
|
||||
|
@ -162,6 +161,24 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
|
|||
);
|
||||
}
|
||||
|
||||
const actionsWithFrequency = fetchedFormData.actions.map((action) => {
|
||||
const isSystemAction = connectorTypes.some((connectorType) => {
|
||||
return connectorType.id === action.actionTypeId && connectorType.isSystemActionType;
|
||||
});
|
||||
|
||||
if (!isSystemAction && fetchedFormData.notifyWhen) {
|
||||
return {
|
||||
...action,
|
||||
frequency: {
|
||||
notifyWhen: fetchedFormData.notifyWhen ?? 'onActionGroupChange',
|
||||
throttle: fetchedFormData.throttle ?? null,
|
||||
summary: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
return action;
|
||||
});
|
||||
|
||||
return (
|
||||
<div data-test-subj="editRuleForm">
|
||||
<RuleFormStateProvider
|
||||
|
@ -177,6 +194,7 @@ export const EditRuleForm = (props: EditRuleFormProps) => {
|
|||
actions: fetchedFormData.actions,
|
||||
}),
|
||||
...fetchedFormData,
|
||||
actions: actionsWithFrequency,
|
||||
},
|
||||
id,
|
||||
plugins,
|
||||
|
|
|
@ -11,7 +11,7 @@ import React from 'react';
|
|||
import { render, screen } from '@testing-library/react';
|
||||
import { RuleActionsSettings } from './rule_actions_settings';
|
||||
import { getAction } from '../common/test_utils/actions_test_utils';
|
||||
import { RuleTypeModel } from '../common';
|
||||
import type { RuleTypeModel } from '@kbn/alerts-ui-shared';
|
||||
import { RuleType } from '@kbn/alerting-types';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import type { RuleActionsNotifyWhenProps } from './rule_actions_notify_when';
|
||||
|
|
|
@ -47,6 +47,7 @@ export interface RuleFormData<Params extends RuleTypeParams = RuleTypeParams> {
|
|||
actions: RuleUiAction[];
|
||||
alertDelay?: Rule<Params>['alertDelay'];
|
||||
notifyWhen?: Rule<Params>['notifyWhen'];
|
||||
throttle?: Rule<Params>['throttle'];
|
||||
ruleTypeId?: Rule<Params>['ruleTypeId'];
|
||||
flapping?: Rule<Params>['flapping'];
|
||||
}
|
||||
|
|
|
@ -499,8 +499,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
|
|||
});
|
||||
});
|
||||
|
||||
// bug with legacy notify_when values https://github.com/elastic/kibana/issues/199494
|
||||
describe.skip('Edit rule with legacy rule-level notify values', function () {
|
||||
describe('Edit rule with legacy rule-level notify values', function () {
|
||||
const testRunUuid = uuidv4();
|
||||
|
||||
afterEach(async () => {
|
||||
|
@ -556,7 +555,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
|
|||
await find.clickByCssSelector('[data-test-subj="rulePageFooterSaveButton"]:not(disabled)');
|
||||
|
||||
const toastTitle = await toasts.getTitleAndDismiss();
|
||||
expect(toastTitle).to.eql(`Updated '${rule.name}'`);
|
||||
expect(toastTitle).to.eql(`Updated "${updatedRuleName}"`);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue