Skip to content

Commit

Permalink
[Alerting] Fixing bug with Index Threshold alert when selecting "Of" …
Browse files Browse the repository at this point in the history
…expression (elastic#90174) (elastic#90643)

* Fixing bug

* Updating functional test

* Fixing functional test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
ymao1 and kibanamachine authored Feb 8, 2021
1 parent c5ab5cf commit 392ba21
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,13 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<
});

if (indexArray.length > 0) {
await refreshEsFields();
await refreshEsFields(indexArray);
}
};

const refreshEsFields = async () => {
if (indexArray.length > 0) {
const currentEsFields = await getFields(http, indexArray);
setEsFields(currentEsFields);
}
const refreshEsFields = async (indices: string[]) => {
const currentEsFields = await getFields(http, indices);
setEsFields(currentEsFields);
};

useEffect(() => {
Expand Down Expand Up @@ -181,7 +179,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<
timeField: '',
});
} else {
await refreshEsFields();
await refreshEsFields(indices);
}
}}
onTimeFieldChange={(updatedTimeField: string) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const OfExpression = ({
defaultMessage: 'of',
}
)}
data-test-subj="ofExpressionPopover"
display={display === 'inline' ? 'inline' : 'columns'}
value={aggField || firstFieldOption.text}
isActive={aggFieldPopoverOpen || !aggField}
Expand Down Expand Up @@ -119,6 +120,7 @@ export const OfExpression = ({
<EuiFlexGroup>
<EuiFlexItem grow={false} className="actOf__aggFieldContainer">
<EuiFormRow
id="ofField"
fullWidth
isInvalid={errors.aggField.length > 0 && aggField !== undefined}
error={errors.aggField}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('when expression', () => {
<EuiSelect
data-test-subj="whenExpressionSelect"
fullWidth={true}
id="aggTypeField"
onChange={[Function]}
options={
Array [
Expand Down Expand Up @@ -77,6 +78,7 @@ describe('when expression', () => {
<EuiSelect
data-test-subj="whenExpressionSelect"
fullWidth={true}
id="aggTypeField"
onChange={[Function]}
options={
Array [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const WhenExpression = ({
</ClosablePopoverTitle>
<EuiSelect
data-test-subj="whenExpressionSelect"
id="aggTypeField"
value={aggType}
fullWidth
onChange={(e) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
const supertest = getService('supertest');
const find = getService('find');
const retry = getService('retry');
const comboBox = getService('comboBox');

async function getAlertsByName(name: string) {
const {
Expand All @@ -30,15 +31,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
});
}

async function defineAlert(alertName: string, alertType?: string) {
alertType = alertType || '.index-threshold';
async function defineEsQueryAlert(alertName: string) {
await pageObjects.triggersActionsUI.clickCreateAlertButton();
await testSubjects.setValue('alertNameInput', alertName);
await testSubjects.click(`${alertType}-SelectOption`);
await testSubjects.click(`.es-query-SelectOption`);
await testSubjects.click('selectIndexExpression');
const comboBox = await find.byCssSelector('#indexSelectSearchBox');
await comboBox.click();
await comboBox.type('k');
const indexComboBox = await find.byCssSelector('#indexSelectSearchBox');
await indexComboBox.click();
await indexComboBox.type('k');
const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`);
await filterSelectItem.click();
await testSubjects.click('thresholdAlertTimeFieldSelect');
Expand All @@ -53,6 +53,44 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
await nameInput.click();
}

async function defineIndexThresholdAlert(alertName: string) {
await pageObjects.triggersActionsUI.clickCreateAlertButton();
await testSubjects.setValue('alertNameInput', alertName);
await testSubjects.click(`.index-threshold-SelectOption`);
await testSubjects.click('selectIndexExpression');
const indexComboBox = await find.byCssSelector('#indexSelectSearchBox');
await indexComboBox.click();
await indexComboBox.type('k');
const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`);
await filterSelectItem.click();
await testSubjects.click('thresholdAlertTimeFieldSelect');
await retry.try(async () => {
const fieldOptions = await find.allByCssSelector('#thresholdTimeField option');
expect(fieldOptions[1]).not.to.be(undefined);
await fieldOptions[1].click();
});
await testSubjects.click('closePopover');
// need this two out of popup clicks to close them
const nameInput = await testSubjects.find('alertNameInput');
await nameInput.click();

await testSubjects.click('whenExpression');
await testSubjects.click('whenExpressionSelect');
await retry.try(async () => {
const aggTypeOptions = await find.allByCssSelector('#aggTypeField option');
expect(aggTypeOptions[1]).not.to.be(undefined);
await aggTypeOptions[1].click();
});

await testSubjects.click('ofExpressionPopover');
const ofComboBox = await find.byCssSelector('#ofField');
await ofComboBox.click();
const ofOptionsString = await comboBox.getOptionsList('availablefieldsOptionsComboBox');
const ofOptions = ofOptionsString.trim().split('\n');
expect(ofOptions.length > 0).to.be(true);
await comboBox.set('availablefieldsOptionsComboBox', ofOptions[0]);
}

async function defineAlwaysFiringAlert(alertName: string) {
await pageObjects.triggersActionsUI.clickCreateAlertButton();
await testSubjects.setValue('alertNameInput', alertName);
Expand All @@ -67,7 +105,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

it('should create an alert', async () => {
const alertName = generateUniqueKey();
await defineAlert(alertName);
await defineIndexThresholdAlert(alertName);

await testSubjects.click('notifyWhenSelect');
await testSubjects.click('onThrottleInterval');
Expand Down Expand Up @@ -222,7 +260,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {

it('should successfully test valid es_query alert', async () => {
const alertName = generateUniqueKey();
await defineAlert(alertName, '.es-query');
await defineEsQueryAlert(alertName);

// Valid query
await testSubjects.setValue('queryJsonEditor', '{"query":{"match_all":{}}}', {
Expand Down

0 comments on commit 392ba21

Please sign in to comment.