From f5a464afb89cbf91020a44acf8714639dcb83e40 Mon Sep 17 00:00:00 2001 From: Suchit Sahoo Date: Thu, 18 Apr 2024 17:05:16 -0700 Subject: [PATCH] Add functional test for UI Metric Signed-off-by: Suchit Sahoo --- ...cypress-workflow-bundle-snapshot-based.yml | 4 +- .../apps/telemetry/ui_metric.spec.js | 59 +++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) create mode 100644 cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/telemetry/ui_metric.spec.js diff --git a/.github/workflows/cypress-workflow-bundle-snapshot-based.yml b/.github/workflows/cypress-workflow-bundle-snapshot-based.yml index f542887d7..1301c441d 100644 --- a/.github/workflows/cypress-workflow-bundle-snapshot-based.yml +++ b/.github/workflows/cypress-workflow-bundle-snapshot-based.yml @@ -26,7 +26,7 @@ jobs: with: test-name: Core Dashboards using Bundle Snapshot test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js' - osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true + osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true tests-without-security: needs: changes @@ -35,5 +35,5 @@ jobs: with: test-name: Core Dashboards using Bundle Snapshot test-command: env CYPRESS_NO_COMMAND_LOG=1 CYPRESS_ML_COMMONS_DASHBOARDS_ENABLED=true CYPRESS_VISBUILDER_ENABLED=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js' - osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true + osd-serve-args: --data_source.enabled=true --vis_builder.enabled=true --ml_commons_dashboards.enabled=true --usageCollection.uiMetric.enabled=true security-enabled: false diff --git a/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/telemetry/ui_metric.spec.js b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/telemetry/ui_metric.spec.js new file mode 100644 index 000000000..cdcd1cae5 --- /dev/null +++ b/cypress/integration/core-opensearch-dashboards/opensearch-dashboards/apps/telemetry/ui_metric.spec.js @@ -0,0 +1,59 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library'; +import { CURRENT_TENANT } from '../../../../../utils/commands'; + +const miscUtils = new MiscUtils(cy); + +describe('dev_console_ui_metric', () => { + before(() => { + CURRENT_TENANT.newTenant = 'global'; + miscUtils.visitPage('app/dev_tools#/console'); + + cy.get('[data-test-subj="help-close-button"]', { timeout: 30000 }).then( + ($btn) => { + if ($btn.is(':visible')) { + cy.wrap($btn).click({ force: true }); + } else { + cy.get('[type="button"]').contains('Console').click({ force: true }); + } + } + ); + + cy.intercept('POST', 'api/ui_metric/report').as('reportreq'); + + cy.wait(5000); // Intentional wait + }); + + it('check UI Metric are being recorded', function () { + miscUtils.visitPage('app/home#/'); + + cy.wait('@reportreq', { timeout: 100000 }) + .its('response.statusCode') + .should('equal', 200); + + // Now verify the response of api/stat + + cy.request( + 'GET', + `${ + Cypress.config().baseUrl + }/api/stats?extended=true&legacy=true&exclude_usage=false` + ).then((res) => { + expect(res.status).to.eq(200); + expect(res.body) + .to.have.property('usage') + .that.has.property('application_usage') + .that.has.property('dev_tools'); + expect(res.body) + .to.have.property('usage') + .that.has.property('ui_metric') + .that.has.property('console') + .that.has.property('length') + .that.is.gt(0); + }); + }); +});