From d2e0c2ea4bfedde46f441c7bbb25762f63a7a716 Mon Sep 17 00:00:00 2001 From: Julia Rechkunova Date: Tue, 21 Feb 2023 14:46:42 +0100 Subject: [PATCH] [Discover] Fix Elasticsearch query rule for "KQL or Lucene" query without filters (#151632) Closes https://github.com/elastic/kibana/issues/151609 For testing: - Go to Rule Management page - Create a new Rule with "Elasticsearch query" type in "KQL or Lucene" format - Save and check the status after the rule finishes the creating process => It should say "Succeeded" (cherry picked from commit 17ab3a31dd8528d92d3c4a928b7e0923a48b037a) --- .../es_query/lib/fetch_search_source_query.ts | 2 +- .../discover/search_source_alert.ts | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/stack_alerts/server/rule_types/es_query/lib/fetch_search_source_query.ts b/x-pack/plugins/stack_alerts/server/rule_types/es_query/lib/fetch_search_source_query.ts index ac9df7a0c0f8d..13f4a49796b6d 100644 --- a/x-pack/plugins/stack_alerts/server/rule_types/es_query/lib/fetch_search_source_query.ts +++ b/x-pack/plugins/stack_alerts/server/rule_types/es_query/lib/fetch_search_source_query.ts @@ -188,7 +188,7 @@ async function generateLink( } function updateFilterReferences(filters: Filter[], fromDataView: string, toDataView: string) { - return filters.map((filter) => { + return (filters || []).map((filter) => { if (filter.meta.index === fromDataView) { return { ...filter, diff --git a/x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/discover/search_source_alert.ts b/x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/discover/search_source_alert.ts index bc8b39d4cecfd..acccceb2f8b89 100644 --- a/x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/discover/search_source_alert.ts +++ b/x-pack/test/functional_with_es_ssl/apps/discover_ml_uptime/discover/search_source_alert.ts @@ -32,6 +32,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { const filterBar = getService('filterBar'); const find = getService('find'); const toasts = getService('toasts'); + const kibanaServer = getService('kibanaServer'); const SOURCE_DATA_VIEW = 'search-source-alert'; const OUTPUT_DATA_VIEW = 'search-source-alert-output'; @@ -330,6 +331,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await deleteDataView(outputDataViewId); await deleteConnector(connectorId); await security.testUser.restoreDefaults(); + await kibanaServer.savedObjects.cleanStandardList(); }); it('should create an alert when there is no data view', async () => { @@ -535,5 +537,60 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) { await checkInitialRuleParamsState(SOURCE_DATA_VIEW); await checkInitialDataViewState(SOURCE_DATA_VIEW); }); + + it('should check that there are no errors detected after an alert is created', async () => { + const newAlert = 'New Alert for checking its status'; + await createDataView('search-source*'); + + await PageObjects.common.navigateToApp('management'); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await testSubjects.click('triggersActions'); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await testSubjects.click('createRuleButton'); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await retry.waitFor('rule name value is correct', async () => { + await testSubjects.setValue('ruleNameInput', newAlert); + const ruleName = await testSubjects.getAttribute('ruleNameInput', 'value'); + return ruleName === newAlert; + }); + + await testSubjects.click('.es-query-SelectOption'); + await PageObjects.header.waitUntilLoadingHasFinished(); + await testSubjects.click('queryFormType_searchSource'); + await PageObjects.header.waitUntilLoadingHasFinished(); + + await testSubjects.click('selectDataViewExpression'); + await testSubjects.click('indexPattern-switcher--input'); + if (await testSubjects.exists('clearSearchButton')) { + await testSubjects.click('clearSearchButton'); + } + const dataViewsElem = await testSubjects.find('euiSelectableList'); + const sourceDataViewOption = await dataViewsElem.findByCssSelector( + `[title="search-source*"]` + ); + await sourceDataViewOption.click(); + + await testSubjects.click('saveRuleButton'); + + await retry.waitFor('confirmation modal', async () => { + return await testSubjects.exists('confirmModalConfirmButton'); + }); + + await testSubjects.click('confirmModalConfirmButton'); + + await PageObjects.header.waitUntilLoadingHasFinished(); + + await openAlertRuleInManagement(newAlert); + + await retry.waitFor('success status', async () => { + await browser.refresh(); + await PageObjects.header.waitUntilLoadingHasFinished(); + + return await testSubjects.exists('ruleStatus-ok'); + }); + }); }); }