Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
4a0eefa
Add error handling/retry logic for search source alert tests
lukasolson Oct 15, 2024
62a04a2
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Oct 16, 2024
7472416
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Oct 21, 2024
be39271
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Nov 6, 2024
2f76e19
Merge branch 'search_source_alert_ft_error_handling' of github.com:lu…
lukasolson Nov 6, 2024
7ef8a68
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Nov 19, 2024
cc4367f
Fix data-test-subj for MKI tests
lukasolson Nov 20, 2024
f38bb92
Merge remote-tracking branch 'upstream/main' into search_source_alert…
lukasolson Nov 20, 2024
e8450f2
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Nov 21, 2024
4a09619
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Nov 21, 2024
2eddc47
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Nov 26, 2024
e79b705
Merge branch 'main' of github.com:elastic/kibana into search_source_a…
lukasolson Dec 3, 2024
61540ad
Skip actual failing test
lukasolson Dec 5, 2024
96fc8ba
Merge branch 'search_source_alert_ft_error_handling' of github.com:lu…
lukasolson Dec 5, 2024
3cfd4ff
skip alert tests on serverless observability
lukasolson Dec 5, 2024
dd053d4
Merge branch 'main' into search_source_alert_ft_error_handling
lukasolson Dec 10, 2024
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 @@ -45,53 +45,59 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
let connectorId: string;

const createSourceIndex = () =>
es.index({
index: SOURCE_DATA_VIEW,
body: {
settings: { number_of_shards: 1 },
mappings: {
properties: {
'@timestamp': { type: 'date' },
message: { type: 'keyword' },
},
retry.try(() =>
createIndex(SOURCE_DATA_VIEW, {
'@timestamp': { type: 'date' },
message: { type: 'keyword' },
})
);

const createOutputDataIndex = () =>
retry.try(() =>
createIndex(OUTPUT_DATA_VIEW, {
rule_id: { type: 'text' },
rule_name: { type: 'text' },
alert_id: { type: 'text' },
context_link: { type: 'text' },
})
);

async function createIndex(index: string, properties: unknown) {
try {
await es.index({
index,
body: {
settings: { number_of_shards: 1 },
mappings: { properties },
},
},
});
});
} catch (e) {
log.error(`Failed to create index "${index}" with error "${e.message}"`);
}
}

const generateNewDocs = async (docsNumber: number) => {
async function generateNewDocs(docsNumber: number, index = SOURCE_DATA_VIEW) {
const mockMessages = Array.from({ length: docsNumber }, (_, i) => `msg-${i}`);
const dateNow = new Date();
const dateToSet = new Date(dateNow);
dateToSet.setMinutes(dateNow.getMinutes() - 10);
for (const message of mockMessages) {
await es.transport.request({
path: `/${SOURCE_DATA_VIEW}/_doc`,
method: 'POST',
body: {
'@timestamp': dateToSet.toISOString(),
message,
},
});
try {
await Promise.all(
mockMessages.map((message) =>
es.transport.request({
path: `/${index}/_doc`,
method: 'POST',
body: {
'@timestamp': dateToSet.toISOString(),
message,
},
})
)
);
} catch (e) {
log.error(`Failed to generate new docs in "${index}" with error "${e.message}"`);
}
};

const createOutputDataIndex = () =>
es.index({
index: OUTPUT_DATA_VIEW,
body: {
settings: {
number_of_shards: 1,
},
mappings: {
properties: {
rule_id: { type: 'text' },
rule_name: { type: 'text' },
alert_id: { type: 'text' },
context_link: { type: 'text' },
},
},
},
});
}

const deleteAlerts = (alertIds: string[]) =>
asyncForEach(alertIds, async (alertId: string) => {
Expand Down
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm guessing the conditionals for buttons and inputs are for O11y projects? We should probably consider splitting these out since they could diverge more, but let's get them unskipped for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

That's right, and yes I totally agree. There was already conditionals like these in these tests but I agree, it's probably time now to split these.

Original file line number Diff line number Diff line change
Expand Up @@ -48,53 +48,59 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
let connectorId: string;

const createSourceIndex = () =>
es.index({
index: SOURCE_DATA_VIEW,
body: {
settings: { number_of_shards: 1 },
mappings: {
properties: {
'@timestamp': { type: 'date' },
message: { type: 'keyword' },
},
retry.try(() =>
createIndex(SOURCE_DATA_VIEW, {
'@timestamp': { type: 'date' },
message: { type: 'keyword' },
})
);

const createOutputDataIndex = () =>
retry.try(() =>
createIndex(OUTPUT_DATA_VIEW, {
rule_id: { type: 'text' },
rule_name: { type: 'text' },
alert_id: { type: 'text' },
context_link: { type: 'text' },
})
);

async function createIndex(index: string, properties: unknown) {
try {
await es.index({
index,
body: {
settings: { number_of_shards: 1 },
mappings: { properties },
},
},
});
});
} catch (e) {
log.error(`Failed to create index "${index}" with error "${e.message}"`);
}
}

const generateNewDocs = async (docsNumber: number) => {
async function generateNewDocs(docsNumber: number, index = SOURCE_DATA_VIEW) {
const mockMessages = Array.from({ length: docsNumber }, (_, i) => `msg-${i}`);
const dateNow = new Date();
const dateToSet = new Date(dateNow);
dateToSet.setMinutes(dateNow.getMinutes() - 10);
for (const message of mockMessages) {
await es.transport.request({
path: `/${SOURCE_DATA_VIEW}/_doc`,
method: 'POST',
body: {
'@timestamp': dateToSet.toISOString(),
message,
},
});
try {
await Promise.all(
mockMessages.map((message) =>
es.transport.request({
path: `/${index}/_doc`,
method: 'POST',
body: {
'@timestamp': dateToSet.toISOString(),
message,
},
})
)
);
} catch (e) {
log.error(`Failed to generate new docs in "${index}" with error "${e.message}"`);
}
};

const createOutputDataIndex = () =>
es.index({
index: OUTPUT_DATA_VIEW,
body: {
settings: {
number_of_shards: 1,
},
mappings: {
properties: {
rule_id: { type: 'text' },
rule_name: { type: 'text' },
alert_id: { type: 'text' },
context_link: { type: 'text' },
},
},
},
});
}

const deleteAlerts = (alertIds: string[]) =>
asyncForEach(alertIds, async (alertId: string) => {
Expand Down Expand Up @@ -216,7 +222,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

const openDiscoverAlertFlyout = async () => {
await testSubjects.click('discoverAlertsButton');
await testSubjects.click('discoverCreateAlertButton');
// Different create rule buttons in serverless
if (await testSubjects.exists('discoverCreateAlertButton')) {
await testSubjects.click('discoverCreateAlertButton');
} else {
await testSubjects.click('discoverAppMenuCustomThresholdRule');
}
};

const openManagementAlertFlyout = async () => {
Expand Down Expand Up @@ -366,8 +377,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
};

describe('Search source Alert', function () {
// see details: https://github.com/elastic/kibana/issues/193842
this.tags(['failsOnMKI', 'skipSvlOblt']);
// Failing: https://github.com/elastic/kibana/issues/203045
this.tags(['skipSvlOblt']);

before(async () => {
await security.testUser.setRoles(['discover_alert']);
await PageObjects.svlCommonPage.loginAsAdmin();
Expand Down Expand Up @@ -502,7 +514,13 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

await testSubjects.click('thresholdPopover');
await testSubjects.setValue('alertThresholdInput0', '1');
await testSubjects.click('saveEditedRuleButton');

// Different save buttons in serverless
if (await testSubjects.exists('saveEditedRuleButton')) {
await testSubjects.click('saveEditedRuleButton');
} else {
await testSubjects.click('rulePageFooterSaveButton');
}
await PageObjects.header.waitUntilLoadingHasFinished();

await openAlertResults(RULE_NAME);
Expand Down Expand Up @@ -652,8 +670,15 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
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');
let ruleName;
// Rule name input is different in serverless
if (await testSubjects.exists('ruleNameInput')) {
await testSubjects.setValue('ruleNameInput', newAlert);
ruleName = await testSubjects.getAttribute('ruleNameInput', 'value');
} else {
await testSubjects.setValue('ruleDetailsNameInput', newAlert);
ruleName = await testSubjects.getAttribute('ruleDetailsNameInput', 'value');
}
return ruleName === newAlert;
});

Expand All @@ -677,7 +702,12 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
await comboBox.set('ruleFormConsumerSelect', 'Stack Rules');
}

await testSubjects.click('saveRuleButton');
// Save rule button is different in serverless
if (await testSubjects.exists('saveRuleButton')) {
await testSubjects.click('saveRuleButton');
} else {
await testSubjects.click('rulePageFooterSaveButton');
}

await retry.waitFor('confirmation modal', async () => {
return await testSubjects.exists('confirmModalConfirmButton');
Expand Down