Skip to content

Commit

Permalink
[Discover] Unskip search alert serverless tests on MKI (#187771)
Browse files Browse the repository at this point in the history
- Closes #187069
- Closes #180101
- Closes #180100

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
jughosta and kibanamachine authored Jul 11, 2024
1 parent 48e2b57 commit ee35439
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
};

const deleteIndexes = (indexes: string[]) => {
indexes.forEach((current) => {
es.transport.request({
path: `/${current}`,
method: 'DELETE',
});
});
return Promise.all(
indexes.map((current) =>
es.transport.request({
path: `/${current}`,
method: 'DELETE',
})
)
);
};

const createConnector = async (): Promise<string> => {
Expand Down Expand Up @@ -164,6 +166,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
return await testSubjects.exists('alertActionAccordion-0');
});

await monacoEditor.waitCodeEditorReady('kibanaCodeEditor');
await monacoEditor.setCodeEditorValue(`{
"rule_id": "{{rule.id}}",
"rule_name": "{{rule.name}}",
Expand Down Expand Up @@ -215,7 +218,19 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
}

await filterBar.addFilter({ field: 'rule_id', operation: 'is', value: ruleId });
await PageObjects.discover.waitUntilSearchingHasFinished();

await retry.waitFor('results', async () => {
await PageObjects.header.waitUntilLoadingHasFinished();
await PageObjects.discover.waitUntilSearchingHasFinished();

const alreadyHasData = await testSubjects.exists('docTable');

if (!alreadyHasData) {
await testSubjects.click('querySubmitButton');
}

return alreadyHasData;
});

const link = await getResultsLink();
await filterBar.removeFilter('rule_id'); // clear filter bar
Expand All @@ -233,10 +248,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await testSubjects.click('triggersActions');
await PageObjects.header.waitUntilLoadingHasFinished();

const rulesList = await testSubjects.find('rulesList');
const alertRule = await rulesList.findByCssSelector(`[title="${ruleName}"]`);
await alertRule.click();
await PageObjects.header.waitUntilLoadingHasFinished();
let retries = 0;

await retry.try(async () => {
retries = retries + 1;
if (retries > 1) {
// It might take time for a rule to get created. Waiting for it.
await browser.refresh();
await PageObjects.header.waitUntilLoadingHasFinished();
}
const rulesList = await testSubjects.find('rulesList');
const alertRule = await rulesList.findByCssSelector(`[title="${ruleName}"]`);
await alertRule.click();
await PageObjects.header.waitUntilLoadingHasFinished();
});
};

const clickViewInApp = async (ruleName: string) => {
Expand Down Expand Up @@ -317,11 +342,28 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
});

after(async () => {
deleteIndexes([OUTPUT_DATA_VIEW, SOURCE_DATA_VIEW]);
const [{ id: adhocRuleId }] = await getAlertsByName(ADHOC_RULE_NAME);
await deleteAlerts([adhocRuleId]);
await deleteDataView(outputDataViewId);
await deleteConnector(connectorId);
// clean up what we can in case of failures in some tests which blocked the creation of the following objects
try {
await deleteIndexes([OUTPUT_DATA_VIEW, SOURCE_DATA_VIEW]);
} catch {
// continue
}
try {
const [{ id: adhocRuleId }] = await getAlertsByName(ADHOC_RULE_NAME);
await deleteAlerts([adhocRuleId]);
} catch {
// continue
}
try {
await deleteDataView(outputDataViewId);
} catch {
// continue
}
try {
await deleteConnector(connectorId);
} catch {
// continue
}
await security.testUser.restoreDefaults();
await kibanaServer.savedObjects.cleanStandardList();
});
Expand Down Expand Up @@ -351,10 +393,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await defineSearchSourceAlert(RULE_NAME);
await testSubjects.click('selectDataViewExpression');

await testSubjects.existOrFail('indexPattern-switcher--input');
await testSubjects.click('indexPattern-switcher--input');
const input = await find.activeElement();
// search-source-alert-output index does not have time field
await input.type('search-source-alert-o*');
await testSubjects.existOrFail('explore-matching-indices-button');
await testSubjects.click('explore-matching-indices-button');

await retry.waitFor('selection to happen', async () => {
Expand All @@ -371,17 +415,27 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('should navigate to alert results via view in app link', async () => {
await testSubjects.click('selectDataViewExpression');
await testSubjects.existOrFail('indexPattern-switcher--input');
await testSubjects.click('indexPattern-switcher--input');
if (await testSubjects.exists('clearSearchButton')) {
await testSubjects.click('clearSearchButton');
await testSubjects.missingOrFail('clearSearchButton');
}
const dataViewsElem = await testSubjects.find('euiSelectableList');
const sourceDataViewOption = await dataViewsElem.findByCssSelector(
`[title="${SOURCE_DATA_VIEW}"]`
);
await sourceDataViewOption.click();

await retry.waitFor('selection to happen', async () => {
const dataViewSelector = await testSubjects.find('selectDataViewExpression');
return (await dataViewSelector.getVisibleText()) === `DATA VIEW\n${SOURCE_DATA_VIEW}`;
});

await testSubjects.click('saveRuleButton');
await retry.try(async () => {
await testSubjects.missingOrFail('saveRuleButton');
});

await PageObjects.header.waitUntilLoadingHasFinished();

Expand Down Expand Up @@ -477,6 +531,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await openDiscoverAlertFlyout();
await defineSearchSourceAlert('test-adhoc-alert');
await testSubjects.click('saveRuleButton');
await retry.try(async () => {
await testSubjects.missingOrFail('saveRuleButton');
});
await PageObjects.header.waitUntilLoadingHasFinished();

await openAlertResults(ADHOC_RULE_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
*/

import expect from '@kbn/expect';
import { INGEST_SAVED_OBJECT_INDEX } from '@kbn/fleet-plugin/common/constants';
import { asyncForEach } from '@kbn/std';
import { FtrProviderContext } from '../../../../ftr_provider_context';

Expand Down Expand Up @@ -149,12 +148,14 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
};

const deleteIndexes = (indexes: string[]) => {
indexes.forEach((current) => {
es.transport.request({
path: `/${current}`,
method: 'DELETE',
});
});
return Promise.all(
indexes.map((current) =>
es.transport.request({
path: `/${current}`,
method: 'DELETE',
})
)
);
};

const createConnector = async (): Promise<string> => {
Expand Down Expand Up @@ -203,6 +204,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
return await testSubjects.exists('alertActionAccordion-0');
});

await monacoEditor.waitCodeEditorReady('kibanaCodeEditor');
await monacoEditor.setCodeEditorValue(`{
"rule_id": "{{rule.id}}",
"rule_name": "{{rule.name}}",
Expand Down Expand Up @@ -273,24 +275,31 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

// follow url provided by alert to see documents triggered the alert
const baseUrl = deployment.getHostPort();
// TODO: In Serverless `link` is a full URL instead of just a path as in stateful
const fullLink = link.startsWith(baseUrl) ? link : baseUrl + link;
// In Serverless `link` is a full URL instead of just a path as in stateful
const fullLink = link.startsWith('http') ? link : baseUrl + link;
await browser.navigateTo(fullLink);
await PageObjects.discover.waitUntilSearchingHasFinished();
};

const openAlertRuleInManagement = async (ruleName: string) => {
await PageObjects.common.navigateToApp('management');
await PageObjects.header.waitUntilLoadingHasFinished();

// TODO: Navigation to Rule Management is different in Serverless
// Navigation to Rule Management is different in Serverless
await PageObjects.common.navigateToApp('triggersActions');
await PageObjects.header.waitUntilLoadingHasFinished();

const rulesList = await testSubjects.find('rulesList');
const alertRule = await rulesList.findByCssSelector(`[title="${ruleName}"]`);
await alertRule.click();
await PageObjects.header.waitUntilLoadingHasFinished();
let retries = 0;

await retry.try(async () => {
retries = retries + 1;
if (retries > 1) {
// It might take time for a rule to get created. Waiting for it.
await browser.refresh();
await PageObjects.header.waitUntilLoadingHasFinished();
}
const rulesList = await testSubjects.find('rulesList');
const alertRule = await rulesList.findByCssSelector(`[title="${ruleName}"]`);
await alertRule.click();
await PageObjects.header.waitUntilLoadingHasFinished();
});
};

const clickViewInApp = async (ruleName: string) => {
Expand Down Expand Up @@ -355,9 +364,6 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
};

describe('Search source Alert', function () {
// fails on MKI, see https://github.com/elastic/kibana/issues/187069
this.tags(['failsOnMKI']);

before(async () => {
await security.testUser.setRoles(['discover_alert']);
await PageObjects.svlCommonPage.loginAsAdmin();
Expand All @@ -373,38 +379,38 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

log.debug('create connector');
connectorId = await createConnector();

// TODO: fetching connectors fails server side in Serverless with
// "index_not_found_exception: no such index [.kibana_ingest]"
if (!(await es.indices.exists({ index: INGEST_SAVED_OBJECT_INDEX }))) {
await es.indices.create({ index: INGEST_SAVED_OBJECT_INDEX });
}
});

after(async () => {
deleteIndexes([OUTPUT_DATA_VIEW, SOURCE_DATA_VIEW]);
const [{ id: adhocRuleId }] = await getAlertsByName(ADHOC_RULE_NAME);
await deleteAlerts([adhocRuleId]);
await deleteDataView(outputDataViewId);
await deleteConnector(connectorId);
// clean up what we can in case of failures in some tests which blocked the creation of the following objects
try {
await deleteIndexes([OUTPUT_DATA_VIEW, SOURCE_DATA_VIEW]);
} catch {
// continue
}
try {
const [{ id: adhocRuleId }] = await getAlertsByName(ADHOC_RULE_NAME);
await deleteAlerts([adhocRuleId]);
} catch {
// continue
}
try {
await deleteDataView(outputDataViewId);
} catch {
// continue
}
try {
await deleteConnector(connectorId);
} catch {
// continue
}
await security.testUser.restoreDefaults();
await kibanaServer.savedObjects.cleanStandardList();
});

it('should create an alert when there is no data view', async () => {
await openManagementAlertFlyout();

// should not have data view selected by default
const dataViewSelector = await testSubjects.find('selectDataViewExpression');
// TODO: Serverless Security and Search have an existing data view by default
const dataViewSelectorText = await dataViewSelector.getVisibleText();
if (
!dataViewSelectorText.includes('.alerts-security') &&
!dataViewSelectorText.includes('default:all-data')
) {
expect(await dataViewSelector.getVisibleText()).to.eql('DATA VIEW\nSelect a data view');
}

log.debug('create data views');
const sourceDataViewResponse = await createDataView(SOURCE_DATA_VIEW);
const outputDataViewResponse = await createDataView(OUTPUT_DATA_VIEW);
Expand All @@ -423,10 +429,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await defineSearchSourceAlert(RULE_NAME);
await testSubjects.click('selectDataViewExpression');

await testSubjects.existOrFail('indexPattern-switcher--input');
await testSubjects.click('indexPattern-switcher--input');
const input = await find.activeElement();
// search-source-alert-output index does not have time field
await input.type('search-source-alert-o*');
await testSubjects.existOrFail('explore-matching-indices-button');
await testSubjects.click('explore-matching-indices-button');

await retry.waitFor('selection to happen', async () => {
Expand All @@ -443,17 +451,27 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

it('should navigate to alert results via view in app link', async () => {
await testSubjects.click('selectDataViewExpression');
await testSubjects.existOrFail('indexPattern-switcher--input');
await testSubjects.click('indexPattern-switcher--input');
if (await testSubjects.exists('clearSearchButton')) {
await testSubjects.click('clearSearchButton');
await testSubjects.missingOrFail('clearSearchButton');
}
const dataViewsElem = await testSubjects.find('euiSelectableList');
const sourceDataViewOption = await dataViewsElem.findByCssSelector(
`[title="${SOURCE_DATA_VIEW}"]`
);
await sourceDataViewOption.click();

await retry.waitFor('selection to happen', async () => {
const dataViewSelector = await testSubjects.find('selectDataViewExpression');
return (await dataViewSelector.getVisibleText()) === `DATA VIEW\n${SOURCE_DATA_VIEW}`;
});

await testSubjects.click('saveRuleButton');
await retry.try(async () => {
await testSubjects.missingOrFail('saveRuleButton');
});

await PageObjects.header.waitUntilLoadingHasFinished();

Expand Down Expand Up @@ -549,6 +567,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await openDiscoverAlertFlyout();
await defineSearchSourceAlert('test-adhoc-alert');
await testSubjects.click('saveRuleButton');
await retry.try(async () => {
await testSubjects.missingOrFail('saveRuleButton');
});
await PageObjects.header.waitUntilLoadingHasFinished();

await openAlertResults(ADHOC_RULE_NAME);
Expand Down Expand Up @@ -610,10 +631,7 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
const newAlert = 'New Alert for checking its status';
await createDataView('search-source*');

await PageObjects.common.navigateToApp('management');
await PageObjects.header.waitUntilLoadingHasFinished();

// TODO: Navigation to Rule Management is different in Serverless
// Navigation to Rule Management is different in Serverless
await PageObjects.common.navigateToApp('triggersActions');
await PageObjects.header.waitUntilLoadingHasFinished();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export default async function ({ readConfigFile }: FtrConfigProviderContext) {
testFiles: [
require.resolve('../../common/discover/embeddable'),
require.resolve('../../common/discover/x_pack'),
// flaky for Security project, should be checked with Admin role permissions.
// https://github.com/elastic/kibana/issues/172365
// require.resolve('../../common/discover_ml_uptime/discover'),
require.resolve('../../common/discover_ml_uptime/discover'),
require.resolve('../../common/context'),
require.resolve('../../common/discover/esql'),
],
Expand Down
1 change: 0 additions & 1 deletion x-pack/test_serverless/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@
"@kbn/cloud-security-posture-plugin",
"@kbn/reporting-plugin",
"@kbn/management-settings-ids",
"@kbn/fleet-plugin",
"@kbn/apm-synthtrace",
"@kbn/apm-synthtrace-client",
"@kbn/reporting-export-types-csv-common",
Expand Down

0 comments on commit ee35439

Please sign in to comment.