From 45ecc7488a9190b560b143b58171c99249b0c20a Mon Sep 17 00:00:00 2001 From: Nathan L Smith Date: Wed, 13 Oct 2021 09:57:42 -0500 Subject: [PATCH] Re-enable and fix APM E2E tests * Run previously disabled APM E2E tests on all PRs (we were previously only running them when APM files had changes.) * Remove `precise: true` from `getComparisonTypes` call which caused intermittent failures in date comparison tests. * Simplify error count alert tests to test the "happy path" (#79284 exists in order to expand to more tests for rule editing and creation) * Wait for alert list API request to complete before clicking "Create rule" button when running the test to create a rule from the Stack Management UI. I ran the e2e tests 100 times locally with no failures so I'm confident the flakiness has been addressed. Fixes #114419. Fixes #109205. --- .../power_user/rules/error_count.spec.ts | 64 +++++++------------ .../apm/ftr_e2e/cypress/support/commands.ts | 16 +++++ .../time_comparison/get_comparison_types.ts | 1 - 3 files changed, 38 insertions(+), 43 deletions(-) diff --git a/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/rules/error_count.spec.ts b/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/rules/error_count.spec.ts index 42da37aa7ef57..94cbbcddadde1 100644 --- a/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/rules/error_count.spec.ts +++ b/x-pack/plugins/apm/ftr_e2e/cypress/integration/power_user/rules/error_count.spec.ts @@ -20,51 +20,25 @@ describe('Rules', () => { describe('when created from Service Inventory', () => { before(() => { cy.loginAsPowerUser(); + cy.deleteAllRules(); }); - it('creates and updates a rule', () => { + after(() => { + cy.deleteAllRules(); + }); + + it('creates a rule', () => { // Create a rule in APM cy.visit('/app/apm/services'); cy.contains('Alerts and rules').click(); cy.contains('Error count').click(); cy.contains('Create threshold rule').click(); - // Change the environment to "testing" - cy.contains('Environment All').click(); - cy.get(comboBoxInputSelector).type('testing{enter}'); - // Save, with no actions cy.contains('button:not(:disabled)', 'Save').click(); cy.get(confirmModalButtonSelector).click(); cy.contains(`Created rule "${ruleName}`); - - // Go to Stack Management - cy.contains('Alerts and rules').click(); - cy.contains('Manage rules').click(); - - // Edit the rule, changing the environment to "All" - cy.get(editButtonSelector).click(); - cy.contains('Environment testing').click(); - cy.get(comboBoxInputSelector).type('All{enter}'); - cy.contains('button:not(:disabled)', 'Save').click(); - - cy.contains(`Updated '${ruleName}'`); - - // Wait for the table to be ready for next edit click - cy.get('.euiBasicTable').not('.euiBasicTable-loading'); - - // Ensure the rule now shows "All" for the environment - cy.get(editButtonSelector).click(); - cy.contains('Environment All'); - cy.contains('button', 'Cancel').click(); - - // Delete the rule - cy.get(deleteButtonSelector).click(); - cy.get(confirmModalButtonSelector).click(); - - // Ensure the table is empty - cy.contains('Create your first rule'); }); }); }); @@ -72,14 +46,30 @@ describe('Rules', () => { describe('when created from Stack management', () => { before(() => { cy.loginAsPowerUser(); + cy.deleteAllRules(); + cy.intercept( + 'GET', + '/api/alerting/rules/_find?page=1&per_page=10&default_search_operator=AND&sort_field=name&sort_order=asc' + ).as('list rules API call'); + }); + + after(() => { + cy.deleteAllRules(); }); it('creates a rule', () => { // Go to stack management cy.visit('/app/management/insightsAndAlerting/triggersActions/rules'); + // Wait for this call to finish so the create rule button does not disappear. + // The timeout is set high because at this point we're also waiting for the + // full page load. + cy.wait('@list rules API call', { timeout: 30000 }); + // Create a rule + cy.contains('button', 'Create rule'); cy.contains('button', 'Create rule').click(); + cy.get('[name=name]').type(ruleName); cy.contains('.euiFlyout button', ruleName).click(); @@ -92,16 +82,6 @@ describe('Rules', () => { cy.get(confirmModalButtonSelector).click(); cy.contains(`Created rule "${ruleName}`); - - // Wait for the table to be ready for next delete click - cy.get('.euiBasicTable').not('.euiBasicTable-loading'); - - // Delete the rule - cy.get(deleteButtonSelector).click(); - cy.get(confirmModalButtonSelector).click(); - - // Ensure the table is empty - cy.contains('Create your first rule'); }); }); }); diff --git a/x-pack/plugins/apm/ftr_e2e/cypress/support/commands.ts b/x-pack/plugins/apm/ftr_e2e/cypress/support/commands.ts index 93dbe4ba51226..06800c51222ea 100644 --- a/x-pack/plugins/apm/ftr_e2e/cypress/support/commands.ts +++ b/x-pack/plugins/apm/ftr_e2e/cypress/support/commands.ts @@ -7,6 +7,22 @@ import 'cypress-real-events/support'; import { Interception } from 'cypress/types/net-stubbing'; +Cypress.Commands.add('deleteAllRules', () => { + cy.request('/api/alerting/rules/_find').then(({ body }) => { + if (body.data.length > 0) { + cy.log(`Deleting rules`); + } + + body.data.map(({ id }) => { + cy.request({ + headers: { 'kbn-xsrf': 'true' }, + method: 'DELETE', + url: `/api/alerting/rule/${id}`, + }); + }); + }); +}); + Cypress.Commands.add('loginAsReadOnlyUser', () => { cy.loginAs({ username: 'apm_read_user', password: 'changeme' }); }); diff --git a/x-pack/plugins/apm/public/components/shared/time_comparison/get_comparison_types.ts b/x-pack/plugins/apm/public/components/shared/time_comparison/get_comparison_types.ts index a7520fa65a162..a0ddfc8ed997c 100644 --- a/x-pack/plugins/apm/public/components/shared/time_comparison/get_comparison_types.ts +++ b/x-pack/plugins/apm/public/components/shared/time_comparison/get_comparison_types.ts @@ -23,7 +23,6 @@ export function getComparisonTypes({ start: momentStart, end: momentEnd, unitOfTime: 'days', - precise: true, }); // Less than or equals to one day