Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discover] Unskip search alert serverless tests on MKI #187771

Merged
merged 15 commits into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -203,6 +202,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 +273,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 +362,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 +377,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 {
deleteIndexes([OUTPUT_DATA_VIEW, SOURCE_DATA_VIEW]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Is it possible for deleteIndexes to throw? It doesn't look like the function returns the promise or awaits anything. Maybe we can either make the function return a promise and then await it here.

} 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 +427,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 +449,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 +565,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 +629,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