From a0bde7988cd651cc5e8503a97c3028ada37ee1e6 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Tue, 21 Jan 2025 13:11:42 -0800 Subject: [PATCH] Cypress tests for query grouping (#55) (#58) (cherry picked from commit 626cb15ac45b4b3fcc2bec0bebbcfe3c03fc421e) Signed-off-by: Siddhant Deshmukh Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] --- cypress/e2e/3_configurations.cy.js | 56 +++++++++++++++- cypress/e2e/4_group_details.cy.js | 104 +++++++++++++++++++++++++++++ cypress/support/commands.js | 41 ++++++++++++ 3 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 cypress/e2e/4_group_details.cy.js diff --git a/cypress/e2e/3_configurations.cy.js b/cypress/e2e/3_configurations.cy.js index da71c6a..fe705b8 100644 --- a/cypress/e2e/3_configurations.cy.js +++ b/cypress/e2e/3_configurations.cy.js @@ -29,13 +29,13 @@ describe('Query Insights Configurations Page', () => { cy.contains('button', 'Top N queries').should('be.visible'); cy.contains('button', 'Configuration').should('have.class', 'euiTab-isSelected'); // Validate the panels - cy.get('.euiPanel').should('have.length', 4); // Two panels: configuration settings and statuses + cy.get('.euiPanel').should('have.length', 4); // 4 panels: Settings, Status, Group Settings, Group Status }); /** - * Validate the dropdown has 3 metrics + * Validate the metric type dropdown has 3 metrics */ - it('should display 3 metrics in the drop down', () => { + it('should display 3 metrics in the metric type drop down', () => { // Validate default value cy.get('select').first().find('option').should('have.length', 3); const expectedMetrics = ['Latency', 'CPU', 'Memory']; @@ -137,6 +137,56 @@ describe('Query Insights Configurations Page', () => { }); }); + /** + * Validate configuration settings panel for group by + */ + it('should display settings for configuration metrics for group by', () => { + cy.get('.euiPanel') + .eq(2) + .within(() => { + cy.get('h2').contains('Top n queries grouping configuration settings').should('be.visible'); + }); + }); + + /** + * Validate the group by drop-down has 2 options + */ + it('should display 2 metrics in the group by drop-down', () => { + cy.get('.euiPanel') + .eq(2) + .find('select') + .should('exist') + .then(($select) => { + cy.wrap($select).find('option').should('have.length', 2); + + const expectedMetrics = ['None', 'Similarity']; + + cy.wrap($select) + .find('option') + .each((option, index) => { + cy.wrap(option).should('have.text', expectedMetrics[index]); + }); + }); + }); + + /** + * Validate configuration status panel for group by + */ + it('should display configuration statuses for group by metrics', () => { + cy.get('.euiPanel') + .eq(3) + .within(() => { + cy.get('h2').should('be.visible').and('have.text', 'Statuses for group by'); + + const metrics = [{ name: 'Group By', status: 'Disabled' }]; + + metrics.forEach(({ name, status }) => { + cy.get('.euiText').contains(name).should('be.visible'); + cy.get('.euiHealth').contains(status).should('be.visible'); + }); + }); + }); + /** * Validate the save button, changes should be saved and redirect to overview * After saving the status panel should show the correct status diff --git a/cypress/e2e/4_group_details.cy.js b/cypress/e2e/4_group_details.cy.js new file mode 100644 index 0000000..d11f120 --- /dev/null +++ b/cypress/e2e/4_group_details.cy.js @@ -0,0 +1,104 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import sampleDocument from '../fixtures/sample_document.json'; + +const indexName = 'sample_index'; + +const clearAll = () => { + cy.deleteIndexByName(indexName); + cy.disableGrouping(); +}; + +describe('Query Group Details Page', () => { + beforeEach(() => { + clearAll(); + cy.createIndexByName(indexName, sampleDocument); + cy.enableGrouping(); + cy.searchOnIndex(indexName); + cy.searchOnIndex(indexName); + cy.searchOnIndex(indexName); + // waiting for the query insights queue to drain + cy.wait(10000); + cy.navigateToOverview(); + cy.get('.euiTableRow').first().find('button').first().click(); // Navigate to details + }); + + it('should display correct details on the group details page', () => { + cy.url().should('include', '/query-group-details'); + // Validate the page title + cy.get('h1').contains('Query group details').should('be.visible'); + + // Validate tooltip for query group details + cy.get('[aria-label="Details tooltip"]').eq(0).should('be.visible'); + + // Validate the Sample Query Details section + cy.get('h1').contains('Sample query details').should('be.visible'); + + // Validate tooltip for sample query details + cy.get('[aria-label="Details tooltip"]').eq(1).should('be.visible'); + + // Validate the presence of query source section + cy.get('.euiPanel').contains('Query').should('be.visible'); + + // Validate the presence of the latency chart + cy.get('#latency').should('be.visible'); + }); + + it('should validate the aggregate summary fields', () => { + const expectedLabels = [ + 'Id', + 'Average Latency', + 'Average CPU Time', + 'Average Memory Usage', + 'Group by', + ]; + + // Validate all field labels exist in the first EuiPanel + cy.get('.euiPanel') + .first() + .within(() => { + expectedLabels.forEach((label) => { + cy.contains('h4', label).should('be.visible'); + }); + }); + }); + + it('should validate the sample query summary panel fields', () => { + const expectedLabels = [ + 'Timestamp', + 'Indices', + 'Search Type', + 'Coordinator Node ID', + 'Total Shards', + ]; + + // Validate all field labels exist in the second EuiPanel + cy.get('.euiPanel') + .eq(1) + .within(() => { + expectedLabels.forEach((label) => { + cy.contains('h4', label).should('be.visible'); + }); + }); + }); + + it('should display the query source code block', () => { + // Validate the query source code block + cy.get('.euiCodeBlock').should('be.visible'); + }); + + it('should display the latency panel correctly', () => { + // Validate the fourth EuiPanel contains the Latency section + cy.get('.euiPanel') + .eq(3) + .within(() => { + cy.contains('h2', 'Latency').should('be.visible'); + cy.get('#latency').should('be.visible'); + }); + }); + + after(() => clearAll()); +}); diff --git a/cypress/support/commands.js b/cypress/support/commands.js index 3ebcbe1..cc98ee4 100644 --- a/cypress/support/commands.js +++ b/cypress/support/commands.js @@ -96,6 +96,47 @@ Cypress.Commands.add('disableTopQueries', (metric) => { }); }); +Cypress.Commands.add('enableGrouping', () => { + cy.request({ + method: 'PUT', + url: `${Cypress.env('openSearchUrl')}/_cluster/settings`, + body: { + persistent: { + 'search.insights.top_queries.latency.enabled': true, + 'search.insights.top_queries.cpu.enabled': true, + 'search.insights.top_queries.memory.enabled': true, + 'search.insights.top_queries.group_by': 'similarity', + 'search.insights.top_queries.max_groups_excluding_topn': 100, + 'search.insights.top_queries.grouping.attributes.field_name': true, + 'search.insights.top_queries.grouping.attributes.field_type': true, + 'search.insights.top_queries.latency.top_n_size': 5, + 'search.insights.top_queries.cpu.top_n_size': 5, + 'search.insights.top_queries.memory.top_n_size': 5, + 'search.insights.top_queries.latency.window_size': '1m', + 'search.insights.top_queries.cpu.window_size': '1m', + 'search.insights.top_queries.memory.window_size': '1m', + }, + }, + failOnStatusCode: false, + }); +}); + +Cypress.Commands.add('disableGrouping', () => { + cy.request({ + method: 'PUT', + url: `${Cypress.env('openSearchUrl')}/_cluster/settings`, + body: { + persistent: { + 'search.insights.top_queries.latency.enabled': false, + 'search.insights.top_queries.cpu.enabled': false, + 'search.insights.top_queries.memory.enabled': false, + 'search.insights.top_queries.group_by': 'none', + }, + }, + failOnStatusCode: false, + }); +}); + Cypress.Commands.add('createIndexByName', (indexName, body = {}) => { cy.request('POST', `${Cypress.env('openSearchUrl')}/${indexName}/_doc`, body); });