-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[AO] - Add functional tests for the new Rules page #129349
Merged
fkanout
merged 34 commits into
elastic:main
from
fkanout:new-o11y-rules-page-functional-tests
May 18, 2022
Merged
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
ba4a1d6
WIP
fkanout 01170a1
Add permissions tests
fkanout 7544337
Clean up
fkanout b53c055
Clean up
fkanout 261bb50
Add create rule flyout test
fkanout edfbfba
Add rule creating and check rules table
fkanout b86f24a
Update wording
fkanout 8da061a
Enable tests
fkanout f584667
Add rules table tests
fkanout 7cd098e
Merge branch 'main' into new-o11y-rules-page-functional-tests
fkanout d967595
disable "only"
fkanout 35baf49
Merge branch 'main' into new-o11y-rules-page-functional-tests
fkanout cb5d3f1
Merge branch 'main' into new-o11y-rules-page-functional-tests
kibanamachine 86de56b
Add enabled/disabled test case
fkanout d2b3bd0
fix style
fkanout 33cc1d6
Merge branch 'main' into new-o11y-rules-page-functional-tests
fkanout 204718b
Fix failed test
fkanout 120e9cc
Code review
fkanout b3a8be9
Update permission
fkanout fd6adf6
Remove unwanted file
fkanout 986e656
Merge branch 'main' into new-o11y-rules-page-functional-tests
kibanamachine b71f30b
Update rule_add.tsx
fkanout d6572c8
Update rules_page.ts
fkanout 62ea3b5
Update to fix conflicts
fkanout 6c2c5ce
Merge branch 'main' into new-o11y-rules-page-functional-tests
fkanout 4eb22a1
[CI] Auto-commit changed files from 'node scripts/eslint --no-cache -…
kibanamachine 08ae944
Fix tests
fkanout c4db139
Fix failing tests
fkanout 94992f5
Use and the data test subj for ui triggersAction UI
fkanout dee22e1
remove unsed service
fkanout bbb4198
Merge branch 'main' into new-o11y-rules-page-functional-tests
kibanamachine 6532a14
Merge branch 'main' into new-o11y-rules-page-functional-tests
kibanamachine 89ad376
Code review
fkanout 9fb6aa5
Merge branch 'main' into new-o11y-rules-page-functional-tests
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
x-pack/test/functional/services/observability/alerts/rules_page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export function ObservabilityAlertsRulesProvider({ getService }: FtrProviderContext) { | ||
const testSubjects = getService('testSubjects'); | ||
|
||
const getManageRulesPageHref = async () => { | ||
const manageRulesPageButton = await testSubjects.find('manageRulesPageButton'); | ||
return manageRulesPageButton.getAttribute('href'); | ||
}; | ||
|
||
const clickCreateRuleButton = async () => { | ||
const createRuleButton = await testSubjects.find('createRuleButton'); | ||
return createRuleButton.click(); | ||
}; | ||
|
||
const clickRuleStatusDropDownMenu = async () => testSubjects.click('statusDropdown'); | ||
|
||
const clickDisableFromDropDownMenu = async () => testSubjects.click('statusDropdownDisabledItem'); | ||
|
||
return { | ||
getManageRulesPageHref, | ||
clickCreateRuleButton, | ||
clickRuleStatusDropDownMenu, | ||
clickDisableFromDropDownMenu, | ||
}; | ||
} |
177 changes: 177 additions & 0 deletions
177
x-pack/test/observability_functional/apps/observability/alerts/rules_page.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import expect from '@kbn/expect'; | ||
import { FtrProviderContext } from '../../../ftr_provider_context'; | ||
|
||
export default ({ getService }: FtrProviderContext) => { | ||
const esArchiver = getService('esArchiver'); | ||
const testSubjects = getService('testSubjects'); | ||
const supertest = getService('supertest'); | ||
const find = getService('find'); | ||
const retry = getService('retry'); | ||
const RULE_ENDPOINT = '/api/alerting/rule'; | ||
|
||
async function createRule(rule: any): Promise<string> { | ||
const ruleResponse = await supertest.post(RULE_ENDPOINT).set('kbn-xsrf', 'foo').send(rule); | ||
expect(ruleResponse.status).to.eql(200); | ||
return ruleResponse.body.id; | ||
} | ||
async function deleteRuleById(ruleId: string) { | ||
const ruleResponse = await supertest | ||
.delete(`${RULE_ENDPOINT}/${ruleId}`) | ||
.set('kbn-xsrf', 'foo'); | ||
expect(ruleResponse.status).to.eql(204); | ||
return true; | ||
} | ||
|
||
const getRulesList = async (tableRows: any[]) => { | ||
const rows = []; | ||
for (const euiTableRow of tableRows) { | ||
const $ = await euiTableRow.parseDomContent(); | ||
rows.push({ | ||
name: $.findTestSubjects('rulesTableCell-name').find('a').text(), | ||
enabled: $.findTestSubjects('rulesTableCell-ContextStatus').find('button').attr('title'), | ||
}); | ||
} | ||
return rows; | ||
}; | ||
|
||
describe('Observability Rules page', function () { | ||
this.tags('includeFirefox'); | ||
|
||
const observability = getService('observability'); | ||
|
||
before(async () => { | ||
await esArchiver.load('x-pack/test/functional/es_archives/observability/alerts'); | ||
await esArchiver.load('x-pack/test/functional/es_archives/infra/metrics_and_logs'); | ||
await observability.alerts.common.navigateWithoutFilter(); | ||
}); | ||
|
||
after(async () => { | ||
await esArchiver.unload('x-pack/test/functional/es_archives/observability/alerts'); | ||
await esArchiver.unload('x-pack/test/functional/es_archives/infra/metrics_and_logs'); | ||
}); | ||
|
||
describe('Feature flag', () => { | ||
// Related to the config inside x-pack/test/observability_functional/with_rac_write.config.ts | ||
it('Link point to O11y Rules pages by default or when "xpack.observability.unsafe.rules.enabled: true"', async () => { | ||
fkanout marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const manageRulesPageHref = await observability.alerts.rulesPage.getManageRulesPageHref(); | ||
expect(new URL(manageRulesPageHref).pathname).equal('/app/observability/alerts/rules'); | ||
}); | ||
}); | ||
|
||
describe('Create rule button', () => { | ||
it('Show Create Rule flyout when Create Rule button is clicked', async () => { | ||
await observability.alerts.common.navigateToRulesPage(); | ||
await retry.waitFor( | ||
'Create Rule button is visible', | ||
async () => await testSubjects.exists('createRuleButton') | ||
); | ||
await observability.alerts.rulesPage.clickCreateRuleButton(); | ||
await retry.waitFor( | ||
'Create Rule flyout is visible', | ||
async () => await testSubjects.exists('addRuleFlyoutTitle') | ||
); | ||
}); | ||
}); | ||
|
||
describe('Rules table', () => { | ||
let uptimeRuleId: string; | ||
let logThresholdRuleId: string; | ||
before(async () => { | ||
const uptimeRule = { | ||
params: { | ||
search: '', | ||
numTimes: 5, | ||
timerangeUnit: 'm', | ||
timerangeCount: 15, | ||
shouldCheckStatus: true, | ||
shouldCheckAvailability: true, | ||
availability: { range: 30, rangeUnit: 'd', threshold: '99' }, | ||
}, | ||
consumer: 'alerts', | ||
schedule: { interval: '1m' }, | ||
tags: [], | ||
name: 'uptime', | ||
rule_type_id: 'xpack.uptime.alerts.monitorStatus', | ||
notify_when: 'onActionGroupChange', | ||
actions: [], | ||
}; | ||
const logThresholdRule = { | ||
params: { | ||
timeSize: 5, | ||
timeUnit: 'm', | ||
count: { value: 75, comparator: 'more than' }, | ||
criteria: [{ field: 'log.level', comparator: 'equals', value: 'error' }], | ||
}, | ||
consumer: 'alerts', | ||
schedule: { interval: '1m' }, | ||
tags: [], | ||
name: 'error-log', | ||
rule_type_id: 'logs.alert.document.count', | ||
notify_when: 'onActionGroupChange', | ||
actions: [], | ||
}; | ||
uptimeRuleId = await createRule(uptimeRule); | ||
logThresholdRuleId = await createRule(logThresholdRule); | ||
await observability.alerts.common.navigateToRulesPage(); | ||
}); | ||
after(async () => { | ||
await deleteRuleById(uptimeRuleId); | ||
await deleteRuleById(logThresholdRuleId); | ||
}); | ||
|
||
it('shows the rules table ', async () => { | ||
await testSubjects.existOrFail('rulesList'); | ||
fkanout marked this conversation as resolved.
Show resolved
Hide resolved
|
||
await testSubjects.waitForDeleted('centerJustifiedSpinner'); | ||
const tableRows = await find.allByCssSelector('.euiTableRow'); | ||
const rows = await getRulesList(tableRows); | ||
expect(rows.length).to.be(2); | ||
expect(rows[0].name).to.be('error-log'); | ||
expect(rows[0].enabled).to.be('Enabled'); | ||
fkanout marked this conversation as resolved.
Show resolved
Hide resolved
|
||
expect(rows[1].name).to.be('uptime'); | ||
expect(rows[1].enabled).to.be('Enabled'); | ||
}); | ||
|
||
it('changes the rule status to "disabled"', async () => { | ||
await testSubjects.existOrFail('rulesList'); | ||
await observability.alerts.rulesPage.clickRuleStatusDropDownMenu(); | ||
await observability.alerts.rulesPage.clickDisableFromDropDownMenu(); | ||
await retry.waitFor('The rule to be disabled', async () => { | ||
const tableRows = await find.allByCssSelector('.euiTableRow'); | ||
const rows = await getRulesList(tableRows); | ||
expect(rows[0].enabled).to.be('Disabled'); | ||
return true; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('User permissions', () => { | ||
it('shows the Create Rule button when user has permissions', async () => { | ||
await observability.alerts.common.navigateToRulesPage(); | ||
await retry.waitFor( | ||
'Create rule button', | ||
async () => await testSubjects.exists('createRuleButton') | ||
); | ||
}); | ||
|
||
it(`shows the no permission prompt when the user has no permissions`, async () => { | ||
await observability.users.setTestUserRole( | ||
observability.users.defineBasicObservabilityRole({ | ||
logs: ['read'], | ||
}) | ||
); | ||
await observability.alerts.common.navigateToRulesPage(); | ||
await retry.waitFor( | ||
'No permissions prompt', | ||
async () => await testSubjects.exists('noPermissionPrompt') | ||
); | ||
}); | ||
}); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't run these tests but want to point out that in many cases when clicking to create something we need to wait for some indication that it completed. For example, there might be a loading indicator. While a test might pass without it, it can cause flakiness. Tests can also fail on Cloud if there is a bit more latency and the action doesn't complete very quickly.
You can simulate this to some extent by running the tests locally with
TEST_THROTTLE_NETWORK=1
as described here https://www.elastic.co/guide/en/kibana/master/development-tests.html#_running_functional_tests