Skip to content

Commit 4b29e35

Browse files
ymao1kibanamachine
andauthored
[Alerting] Fixing bug with Index Threshold alert when selecting "Of" expression (#90174)
* Fixing bug * Updating functional test * Fixing functional test Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
1 parent d804f4f commit 4b29e35

File tree

5 files changed

+56
-15
lines changed

5 files changed

+56
-15
lines changed

x-pack/plugins/stack_alerts/public/alert_types/threshold/expression.tsx

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,13 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<
124124
});
125125

126126
if (indexArray.length > 0) {
127-
await refreshEsFields();
127+
await refreshEsFields(indexArray);
128128
}
129129
};
130130

131-
const refreshEsFields = async () => {
132-
if (indexArray.length > 0) {
133-
const currentEsFields = await getFields(http, indexArray);
134-
setEsFields(currentEsFields);
135-
}
131+
const refreshEsFields = async (indices: string[]) => {
132+
const currentEsFields = await getFields(http, indices);
133+
setEsFields(currentEsFields);
136134
};
137135

138136
useEffect(() => {
@@ -181,7 +179,7 @@ export const IndexThresholdAlertTypeExpression: React.FunctionComponent<
181179
timeField: '',
182180
});
183181
} else {
184-
await refreshEsFields();
182+
await refreshEsFields(indices);
185183
}
186184
}}
187185
onTimeFieldChange={(updatedTimeField: string) =>

x-pack/plugins/triggers_actions_ui/public/common/expression_items/of.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export const OfExpression = ({
9191
defaultMessage: 'of',
9292
}
9393
)}
94+
data-test-subj="ofExpressionPopover"
9495
display={display === 'inline' ? 'inline' : 'columns'}
9596
value={aggField || firstFieldOption.text}
9697
isActive={aggFieldPopoverOpen || !aggField}
@@ -119,6 +120,7 @@ export const OfExpression = ({
119120
<EuiFlexGroup>
120121
<EuiFlexItem grow={false} className="actOf__aggFieldContainer">
121122
<EuiFormRow
123+
id="ofField"
122124
fullWidth
123125
isInvalid={errors.aggField.length > 0 && aggField !== undefined}
124126
error={errors.aggField}

x-pack/plugins/triggers_actions_ui/public/common/expression_items/when.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('when expression', () => {
2020
<EuiSelect
2121
data-test-subj="whenExpressionSelect"
2222
fullWidth={true}
23+
id="aggTypeField"
2324
onChange={[Function]}
2425
options={
2526
Array [
@@ -77,6 +78,7 @@ describe('when expression', () => {
7778
<EuiSelect
7879
data-test-subj="whenExpressionSelect"
7980
fullWidth={true}
81+
id="aggTypeField"
8082
onChange={[Function]}
8183
options={
8284
Array [

x-pack/plugins/triggers_actions_ui/public/common/expression_items/when.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export const WhenExpression = ({
7979
</ClosablePopoverTitle>
8080
<EuiSelect
8181
data-test-subj="whenExpressionSelect"
82+
id="aggTypeField"
8283
value={aggType}
8384
fullWidth
8485
onChange={(e) => {

x-pack/test/functional_with_es_ssl/apps/triggers_actions_ui/alert_create_flyout.ts

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
1515
const supertest = getService('supertest');
1616
const find = getService('find');
1717
const retry = getService('retry');
18+
const comboBox = getService('comboBox');
1819

1920
async function getAlertsByName(name: string) {
2021
const {
@@ -30,15 +31,14 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
3031
});
3132
}
3233

33-
async function defineAlert(alertName: string, alertType?: string) {
34-
alertType = alertType || '.index-threshold';
34+
async function defineEsQueryAlert(alertName: string) {
3535
await pageObjects.triggersActionsUI.clickCreateAlertButton();
3636
await testSubjects.setValue('alertNameInput', alertName);
37-
await testSubjects.click(`${alertType}-SelectOption`);
37+
await testSubjects.click(`.es-query-SelectOption`);
3838
await testSubjects.click('selectIndexExpression');
39-
const comboBox = await find.byCssSelector('#indexSelectSearchBox');
40-
await comboBox.click();
41-
await comboBox.type('k');
39+
const indexComboBox = await find.byCssSelector('#indexSelectSearchBox');
40+
await indexComboBox.click();
41+
await indexComboBox.type('k');
4242
const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`);
4343
await filterSelectItem.click();
4444
await testSubjects.click('thresholdAlertTimeFieldSelect');
@@ -53,6 +53,44 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
5353
await nameInput.click();
5454
}
5555

56+
async function defineIndexThresholdAlert(alertName: string) {
57+
await pageObjects.triggersActionsUI.clickCreateAlertButton();
58+
await testSubjects.setValue('alertNameInput', alertName);
59+
await testSubjects.click(`.index-threshold-SelectOption`);
60+
await testSubjects.click('selectIndexExpression');
61+
const indexComboBox = await find.byCssSelector('#indexSelectSearchBox');
62+
await indexComboBox.click();
63+
await indexComboBox.type('k');
64+
const filterSelectItem = await find.byCssSelector(`.euiFilterSelectItem`);
65+
await filterSelectItem.click();
66+
await testSubjects.click('thresholdAlertTimeFieldSelect');
67+
await retry.try(async () => {
68+
const fieldOptions = await find.allByCssSelector('#thresholdTimeField option');
69+
expect(fieldOptions[1]).not.to.be(undefined);
70+
await fieldOptions[1].click();
71+
});
72+
await testSubjects.click('closePopover');
73+
// need this two out of popup clicks to close them
74+
const nameInput = await testSubjects.find('alertNameInput');
75+
await nameInput.click();
76+
77+
await testSubjects.click('whenExpression');
78+
await testSubjects.click('whenExpressionSelect');
79+
await retry.try(async () => {
80+
const aggTypeOptions = await find.allByCssSelector('#aggTypeField option');
81+
expect(aggTypeOptions[1]).not.to.be(undefined);
82+
await aggTypeOptions[1].click();
83+
});
84+
85+
await testSubjects.click('ofExpressionPopover');
86+
const ofComboBox = await find.byCssSelector('#ofField');
87+
await ofComboBox.click();
88+
const ofOptionsString = await comboBox.getOptionsList('availablefieldsOptionsComboBox');
89+
const ofOptions = ofOptionsString.trim().split('\n');
90+
expect(ofOptions.length > 0).to.be(true);
91+
await comboBox.set('availablefieldsOptionsComboBox', ofOptions[0]);
92+
}
93+
5694
async function defineAlwaysFiringAlert(alertName: string) {
5795
await pageObjects.triggersActionsUI.clickCreateAlertButton();
5896
await testSubjects.setValue('alertNameInput', alertName);
@@ -67,7 +105,7 @@ export default ({ getPageObjects, getService }: FtrProviderContext) => {
67105

68106
it('should create an alert', async () => {
69107
const alertName = generateUniqueKey();
70-
await defineAlert(alertName);
108+
await defineIndexThresholdAlert(alertName);
71109

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

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

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

0 commit comments

Comments
 (0)