Skip to content

Commit

Permalink
Add FT for TSVB support with MDS
Browse files Browse the repository at this point in the history
Signed-off-by: Emma Jin <amznyja@amazon.com>
  • Loading branch information
amznyja committed May 17, 2024
1 parent ed49fa5 commit 88a8f73
Show file tree
Hide file tree
Showing 8 changed files with 20,196 additions and 1 deletion.
20,000 changes: 20,000 additions & 0 deletions cypress/fixtures/dashboard/opensearch_dashboards/vis_type_tsvb/metrics.data.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { CURRENT_TENANT } from '../../../../../utils/commands';
import { DS_BASIC_AUTH_LABEL } from '../../../../../utils/dashboards/datasource-management-dashboards-plugin/constants';
import {
TSVB_INDEX_ID,
TSVB_PATH_INDEX_DATA,
TSVB_CREATE_URL,
VIS_APP_PATH,
TSVB_INDEX_START_TIME,
TSVB_INDEX_END_TIME,
TSVB_INDEX_PATTERN,
TSVB_VIS_TYPE,
} from '../../../../../utils/dashboards/vis_type_tsvb/constants';

describe('TSVB Visualization', () => {
before(() => {
CURRENT_TENANT.newTenant = 'global';
cy.fleshTenantSettings();
cy.deleteIndex(TSVB_INDEX_ID);
cy.bulkUploadDocs(TSVB_PATH_INDEX_DATA);

// Dashboards requires an index pattern to continue to the Create Visualization stage
cy.deleteIndexPattern(TSVB_INDEX_PATTERN);
cy.createIndexPattern(TSVB_INDEX_PATTERN, {
title: TSVB_INDEX_ID,
timeFieldName: 'timestamp',
});

cy.deleteSavedObjectByType(TSVB_VIS_TYPE, TSVB_INDEX_ID);

// Visit the page
cy.log('create a new tsvb visualization: ', TSVB_CREATE_URL);
cy.visit(TSVB_CREATE_URL);
cy.url().should('contain', VIS_APP_PATH);
cy.setTopNavDate(TSVB_INDEX_START_TIME, TSVB_INDEX_END_TIME);

// Wait for page to load
cy.waitForLoader();
});

if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
before(() => {
cy.deleteDataSourceIndexBasicAuth(TSVB_INDEX_ID);
cy.createDataSourceBasicAuth();
cy.bulkUploadDocsToDataSourceBasicAuth(TSVB_PATH_INDEX_DATA);
});

describe('When MDS is enabled', () => {
[
{
dataSourceName: DS_BASIC_AUTH_LABEL,
canvasExists: 'exist',
},
].forEach(({ dataSourceName, canvasExists }) => {
it(`should query data from ${dataSourceName} and resulting visualization should ${canvasExists}`, () => {
cy.contains('button', 'Panel options').click();
cy.contains('label', 'Data source');
// Click on the dropdown to open it
cy.get('[data-test-subj="dataSourceSelectorComboBox"]').click();

// Find the option you want to select by its text and click on it
cy.contains('[role="option"]', 'RemoteDataSourceBasicAuth').click();
cy.get('input[data-test-subj="metricsIndexPatternInput"]').type(
TSVB_INDEX_ID
);
cy.tsvbSaveVisualization();

cy.get('canvas').should(canvasExists);
});
});
});
} else {
describe('When MDS is disabled', () => {
it('should query from local cluster', () => {
cy.contains('button', 'Panel options').click();
cy.get('input[data-test-subj="metricsIndexPatternInput"]').type(
TSVB_INDEX_ID
);
cy.tsvbSaveVisualization();
// Visualization should be drawn; correct visualizations do not have warning messages
cy.get('canvas').should('exist');
});
});
}

after(() => {
cy.deleteIndex(TSVB_INDEX_ID);
cy.deleteIndexPattern(TSVB_INDEX_PATTERN);

if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
cy.deleteDataSourceIndexBasicAuth(TSVB_INDEX_ID);
cy.deleteAllDataSources();
}
});
});
1 change: 1 addition & 0 deletions cypress/utils/dashboards/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import './vis_builder/commands';
import './vis_type_table/commands';
import './vis-augmenter/commands';
import './vis_type_tsvb/commands';
import './data_explorer/commands';

Cypress.Commands.add('waitForLoader', () => {
Expand Down
1 change: 1 addition & 0 deletions cypress/utils/dashboards/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './vis_builder/constants';
export * from './vis_type_table/constants';
export * from './vis-augmenter/constants';
export * from './data_explorer/constants';
export * from './vis_type_tsvb/constants';
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import { BASE_PATH } from '../../base_constants';
import { DS_API } from './constants';
import { DS_API, DS_BASIC_AUTH_HEADER } from './constants';
import { MiscUtils } from '@opensearch-dashboards-test/opensearch-dashboards-test-library';

const miscUtils = new MiscUtils(cy);
Expand Down Expand Up @@ -107,3 +107,58 @@ Cypress.Commands.add('visitDataSourcesListingPage', () => {
{ timeout: 60000 }
);
});

Cypress.Commands.add(
'bulkUploadDocsToDataSourceBasicAuth',
(fixturePath, index) => {
const sendBulkAPIRequest = (ndjson) => {
const url = index
? `${Cypress.env('remoteDataSourceBasicAuthUrl')}/${index}/_bulk`
: `${Cypress.env('remoteDataSourceBasicAuthUrl')}/_bulk`;
cy.log('bulkUploadDocs')
.request({
method: 'POST',
url,
headers: {
'content-type': 'application/json;charset=UTF-8',
'osd-xsrf': true,
Authorization: DS_BASIC_AUTH_HEADER,
},
body: ndjson,
})
.then((response) => {
if (response.body.errors) {
console.error(response.body.items);
throw new Error('Bulk upload failed');
}
});
};

cy.fixture(fixturePath, 'utf8').then((ndjson) => {
sendBulkAPIRequest(ndjson);
});

cy.request({
method: 'POST',
url: `${Cypress.env('remoteDataSourceBasicAuthUrl')}/_all/_refresh`,
headers: {
Authorization: DS_BASIC_AUTH_HEADER,
},
});
}
);

Cypress.Commands.add(
'deleteDataSourceIndexBasicAuth',
(indexName, options = {}) => {
cy.request({
method: 'DELETE',
url: `${Cypress.env('remoteDataSourceBasicAuthUrl')}/${indexName}`,
headers: {
Authorization: DS_BASIC_AUTH_HEADER,
},
failOnStatusCode: false,
...options,
});
}
);
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export const DS_API = {
DELETE_DATA_SOURCE: `${DS_API_PREFIX}/data-source/`,
};

export const DS_BASIC_AUTH_HEADER = `Basic ${btoa(`${USERNAME}:${PASSWORD}`)}`;
export const DS_BASIC_AUTH_LABEL = 'RemoteDataSourceBasicAuth';

export const TIMEOUT_OPTS = { timeout: 60000 };
export const FORCE_CLICK_OPTS = { force: true };
export const DATASOURCE_DELAY = 1000;
Expand Down
13 changes: 13 additions & 0 deletions cypress/utils/dashboards/vis_type_tsvb/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { TSVB_INDEX_PATTERN } from './constants';

Cypress.Commands.add('tsvbSaveVisualization', () => {
cy.contains('button', 'Save').click();
// Type in a random name into the input field
cy.get('[data-test-subj="savedObjectTitle"]').type(TSVB_INDEX_PATTERN);
// Click the button with data-test-subj="confirmSaveSavedObjectButton"
cy.get('[data-test-subj="confirmSaveSavedObjectButton"]').click();
});
23 changes: 23 additions & 0 deletions cypress/utils/dashboards/vis_type_tsvb/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/
import { BASE_PATH } from '../../base_constants';

// Data
export const TSVB_INDEX_DATA = 'metrics.data.txt';
export const TSVB_PATH_FIXTURE =
'dashboard/opensearch_dashboards/vis_type_tsvb/';
export const TSVB_PATH_INDEX_DATA = TSVB_PATH_FIXTURE + TSVB_INDEX_DATA;

// Update the constants
export const TSVB_INDEX_START_TIME = 'May 16, 2010 @ 00:00:00.000';
export const TSVB_INDEX_END_TIME = 'May 16, 2024 @ 00:00:00.000';
export const TSVB_INDEX_ID = 'metrics';
export const TSVB_INDEX_PATTERN = 'index-pattern-vis-metrics';

export const TSVB_VIS_TYPE = 'visualization';

// App URL Paths
export const VIS_APP_PATH = '/app/visualize';
export const TSVB_CREATE_URL = `${BASE_PATH}${VIS_APP_PATH}#/create?type=metrics`;

0 comments on commit 88a8f73

Please sign in to comment.