Skip to content

Commit

Permalink
allow users to unset the throttle of an alert (#60964) (#61088)
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris authored Mar 24, 2020
1 parent 8d39068 commit 96d235f
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import {
EuiButtonIcon,
EuiHorizontalRule,
} from '@elastic/eui';
import { some, filter, map, fold } from 'fp-ts/lib/Option';
import { pipe } from 'fp-ts/lib/pipeable';
import {
getDurationNumberInItsUnit,
getDurationUnitValue,
Expand Down Expand Up @@ -408,9 +410,23 @@ export const AlertForm = ({
name="throttle"
data-test-subj="throttleInput"
onChange={e => {
const throttle = e.target.value !== '' ? parseInt(e.target.value, 10) : null;
setAlertThrottle(throttle);
setAlertProperty('throttle', `${e.target.value}${alertThrottleUnit}`);
pipe(
some(e.target.value.trim()),
filter(value => value !== ''),
map(value => parseInt(value, 10)),
filter(value => !isNaN(value)),
fold(
() => {
// unset throttle
setAlertThrottle(null);
setAlertProperty('throttle', null);
},
throttle => {
setAlertThrottle(throttle);
setAlertProperty('throttle', `${throttle}${alertThrottleUnit}`);
}
)
);
}}
/>
</EuiFlexItem>
Expand Down
102 changes: 102 additions & 0 deletions x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alerts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,108 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
]);
});

it('should set an alert throttle', async () => {
const alertName = `edit throttle ${generateUniqueKey()}`;
const createdAlert = await createAlert({
alertTypeId: '.index-threshold',
name: alertName,
params: {
aggType: 'count',
termSize: 5,
thresholdComparator: '>',
timeWindowSize: 5,
timeWindowUnit: 'm',
groupBy: 'all',
threshold: [1000, 5000],
index: ['.kibana_1'],
timeField: 'alert',
},
});
await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);

const searchResults = await pageObjects.triggersActionsUI.getAlertsList();
expect(searchResults).to.eql([
{
name: createdAlert.name,
tagsText: 'foo, bar',
alertType: 'Index Threshold',
interval: '1m',
},
]);

const editLink = await testSubjects.findAll('alertsTableCell-editLink');
await editLink[0].click();

const throttleInputToSetInitialValue = await testSubjects.find('throttleInput');
await throttleInputToSetInitialValue.click();
await throttleInputToSetInitialValue.clearValue();
await throttleInputToSetInitialValue.type('1');

await find.clickByCssSelector('[data-test-subj="saveEditedAlertButton"]:not(disabled)');

expect(await pageObjects.common.closeToast()).to.eql(`Updated '${createdAlert.name}'`);

await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);
await (await testSubjects.findAll('alertsTableCell-editLink'))[0].click();
const throttleInput = await testSubjects.find('throttleInput');
expect(await throttleInput.getAttribute('value')).to.eql('1');
});

it('should unset an alert throttle', async () => {
const alertName = `edit throttle ${generateUniqueKey()}`;
const createdAlert = await createAlert({
alertTypeId: '.index-threshold',
name: alertName,
throttle: '10m',
params: {
aggType: 'count',
termSize: 5,
thresholdComparator: '>',
timeWindowSize: 5,
timeWindowUnit: 'm',
groupBy: 'all',
threshold: [1000, 5000],
index: ['.kibana_1'],
timeField: 'alert',
},
});
await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);

const searchResults = await pageObjects.triggersActionsUI.getAlertsList();
expect(searchResults).to.eql([
{
name: createdAlert.name,
tagsText: 'foo, bar',
alertType: 'Index Threshold',
interval: '1m',
},
]);

const editLink = await testSubjects.findAll('alertsTableCell-editLink');
await editLink[0].click();

const throttleInputToUnsetValue = await testSubjects.find('throttleInput');

expect(await throttleInputToUnsetValue.getAttribute('value')).to.eql('10');
await throttleInputToUnsetValue.click();
await throttleInputToUnsetValue.clearValueWithKeyboard();

expect(await throttleInputToUnsetValue.getAttribute('value')).to.eql('');

await find.clickByCssSelector('[data-test-subj="saveEditedAlertButton"]:not(disabled)');

expect(await pageObjects.common.closeToast()).to.eql(`Updated '${createdAlert.name}'`);

await pageObjects.common.navigateToApp('triggersActions');
await pageObjects.triggersActionsUI.searchAlerts(createdAlert.name);
await (await testSubjects.findAll('alertsTableCell-editLink'))[0].click();
const throttleInput = await testSubjects.find('throttleInput');
expect(await throttleInput.getAttribute('value')).to.eql('');
});

it('should reset alert when canceling an edit', async () => {
const createdAlert = await createAlert({
alertTypeId: '.index-threshold',
Expand Down

0 comments on commit 96d235f

Please sign in to comment.