Skip to content

Commit 88a8f73

Browse files
committed
Add FT for TSVB support with MDS
Signed-off-by: Emma Jin <[email protected]>
1 parent ed49fa5 commit 88a8f73

File tree

8 files changed

+20196
-1
lines changed

8 files changed

+20196
-1
lines changed

cypress/fixtures/dashboard/opensearch_dashboards/vis_type_tsvb/metrics.data.txt

Lines changed: 20000 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { CURRENT_TENANT } from '../../../../../utils/commands';
7+
import { DS_BASIC_AUTH_LABEL } from '../../../../../utils/dashboards/datasource-management-dashboards-plugin/constants';
8+
import {
9+
TSVB_INDEX_ID,
10+
TSVB_PATH_INDEX_DATA,
11+
TSVB_CREATE_URL,
12+
VIS_APP_PATH,
13+
TSVB_INDEX_START_TIME,
14+
TSVB_INDEX_END_TIME,
15+
TSVB_INDEX_PATTERN,
16+
TSVB_VIS_TYPE,
17+
} from '../../../../../utils/dashboards/vis_type_tsvb/constants';
18+
19+
describe('TSVB Visualization', () => {
20+
before(() => {
21+
CURRENT_TENANT.newTenant = 'global';
22+
cy.fleshTenantSettings();
23+
cy.deleteIndex(TSVB_INDEX_ID);
24+
cy.bulkUploadDocs(TSVB_PATH_INDEX_DATA);
25+
26+
// Dashboards requires an index pattern to continue to the Create Visualization stage
27+
cy.deleteIndexPattern(TSVB_INDEX_PATTERN);
28+
cy.createIndexPattern(TSVB_INDEX_PATTERN, {
29+
title: TSVB_INDEX_ID,
30+
timeFieldName: 'timestamp',
31+
});
32+
33+
cy.deleteSavedObjectByType(TSVB_VIS_TYPE, TSVB_INDEX_ID);
34+
35+
// Visit the page
36+
cy.log('create a new tsvb visualization: ', TSVB_CREATE_URL);
37+
cy.visit(TSVB_CREATE_URL);
38+
cy.url().should('contain', VIS_APP_PATH);
39+
cy.setTopNavDate(TSVB_INDEX_START_TIME, TSVB_INDEX_END_TIME);
40+
41+
// Wait for page to load
42+
cy.waitForLoader();
43+
});
44+
45+
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
46+
before(() => {
47+
cy.deleteDataSourceIndexBasicAuth(TSVB_INDEX_ID);
48+
cy.createDataSourceBasicAuth();
49+
cy.bulkUploadDocsToDataSourceBasicAuth(TSVB_PATH_INDEX_DATA);
50+
});
51+
52+
describe('When MDS is enabled', () => {
53+
[
54+
{
55+
dataSourceName: DS_BASIC_AUTH_LABEL,
56+
canvasExists: 'exist',
57+
},
58+
].forEach(({ dataSourceName, canvasExists }) => {
59+
it(`should query data from ${dataSourceName} and resulting visualization should ${canvasExists}`, () => {
60+
cy.contains('button', 'Panel options').click();
61+
cy.contains('label', 'Data source');
62+
// Click on the dropdown to open it
63+
cy.get('[data-test-subj="dataSourceSelectorComboBox"]').click();
64+
65+
// Find the option you want to select by its text and click on it
66+
cy.contains('[role="option"]', 'RemoteDataSourceBasicAuth').click();
67+
cy.get('input[data-test-subj="metricsIndexPatternInput"]').type(
68+
TSVB_INDEX_ID
69+
);
70+
cy.tsvbSaveVisualization();
71+
72+
cy.get('canvas').should(canvasExists);
73+
});
74+
});
75+
});
76+
} else {
77+
describe('When MDS is disabled', () => {
78+
it('should query from local cluster', () => {
79+
cy.contains('button', 'Panel options').click();
80+
cy.get('input[data-test-subj="metricsIndexPatternInput"]').type(
81+
TSVB_INDEX_ID
82+
);
83+
cy.tsvbSaveVisualization();
84+
// Visualization should be drawn; correct visualizations do not have warning messages
85+
cy.get('canvas').should('exist');
86+
});
87+
});
88+
}
89+
90+
after(() => {
91+
cy.deleteIndex(TSVB_INDEX_ID);
92+
cy.deleteIndexPattern(TSVB_INDEX_PATTERN);
93+
94+
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
95+
cy.deleteDataSourceIndexBasicAuth(TSVB_INDEX_ID);
96+
cy.deleteAllDataSources();
97+
}
98+
});
99+
});

cypress/utils/dashboards/commands.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import './vis_builder/commands';
77
import './vis_type_table/commands';
88
import './vis-augmenter/commands';
9+
import './vis_type_tsvb/commands';
910
import './data_explorer/commands';
1011

1112
Cypress.Commands.add('waitForLoader', () => {

cypress/utils/dashboards/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ export * from './vis_builder/constants';
2222
export * from './vis_type_table/constants';
2323
export * from './vis-augmenter/constants';
2424
export * from './data_explorer/constants';
25+
export * from './vis_type_tsvb/constants';

cypress/utils/dashboards/datasource-management-dashboards-plugin/commands.js

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*/
55

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

1010
const miscUtils = new MiscUtils(cy);
@@ -107,3 +107,58 @@ Cypress.Commands.add('visitDataSourcesListingPage', () => {
107107
{ timeout: 60000 }
108108
);
109109
});
110+
111+
Cypress.Commands.add(
112+
'bulkUploadDocsToDataSourceBasicAuth',
113+
(fixturePath, index) => {
114+
const sendBulkAPIRequest = (ndjson) => {
115+
const url = index
116+
? `${Cypress.env('remoteDataSourceBasicAuthUrl')}/${index}/_bulk`
117+
: `${Cypress.env('remoteDataSourceBasicAuthUrl')}/_bulk`;
118+
cy.log('bulkUploadDocs')
119+
.request({
120+
method: 'POST',
121+
url,
122+
headers: {
123+
'content-type': 'application/json;charset=UTF-8',
124+
'osd-xsrf': true,
125+
Authorization: DS_BASIC_AUTH_HEADER,
126+
},
127+
body: ndjson,
128+
})
129+
.then((response) => {
130+
if (response.body.errors) {
131+
console.error(response.body.items);
132+
throw new Error('Bulk upload failed');
133+
}
134+
});
135+
};
136+
137+
cy.fixture(fixturePath, 'utf8').then((ndjson) => {
138+
sendBulkAPIRequest(ndjson);
139+
});
140+
141+
cy.request({
142+
method: 'POST',
143+
url: `${Cypress.env('remoteDataSourceBasicAuthUrl')}/_all/_refresh`,
144+
headers: {
145+
Authorization: DS_BASIC_AUTH_HEADER,
146+
},
147+
});
148+
}
149+
);
150+
151+
Cypress.Commands.add(
152+
'deleteDataSourceIndexBasicAuth',
153+
(indexName, options = {}) => {
154+
cy.request({
155+
method: 'DELETE',
156+
url: `${Cypress.env('remoteDataSourceBasicAuthUrl')}/${indexName}`,
157+
headers: {
158+
Authorization: DS_BASIC_AUTH_HEADER,
159+
},
160+
failOnStatusCode: false,
161+
...options,
162+
});
163+
}
164+
);

cypress/utils/dashboards/datasource-management-dashboards-plugin/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const DS_API = {
2121
DELETE_DATA_SOURCE: `${DS_API_PREFIX}/data-source/`,
2222
};
2323

24+
export const DS_BASIC_AUTH_HEADER = `Basic ${btoa(`${USERNAME}:${PASSWORD}`)}`;
25+
export const DS_BASIC_AUTH_LABEL = 'RemoteDataSourceBasicAuth';
26+
2427
export const TIMEOUT_OPTS = { timeout: 60000 };
2528
export const FORCE_CLICK_OPTS = { force: true };
2629
export const DATASOURCE_DELAY = 1000;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { TSVB_INDEX_PATTERN } from './constants';
6+
7+
Cypress.Commands.add('tsvbSaveVisualization', () => {
8+
cy.contains('button', 'Save').click();
9+
// Type in a random name into the input field
10+
cy.get('[data-test-subj="savedObjectTitle"]').type(TSVB_INDEX_PATTERN);
11+
// Click the button with data-test-subj="confirmSaveSavedObjectButton"
12+
cy.get('[data-test-subj="confirmSaveSavedObjectButton"]').click();
13+
});
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
import { BASE_PATH } from '../../base_constants';
6+
7+
// Data
8+
export const TSVB_INDEX_DATA = 'metrics.data.txt';
9+
export const TSVB_PATH_FIXTURE =
10+
'dashboard/opensearch_dashboards/vis_type_tsvb/';
11+
export const TSVB_PATH_INDEX_DATA = TSVB_PATH_FIXTURE + TSVB_INDEX_DATA;
12+
13+
// Update the constants
14+
export const TSVB_INDEX_START_TIME = 'May 16, 2010 @ 00:00:00.000';
15+
export const TSVB_INDEX_END_TIME = 'May 16, 2024 @ 00:00:00.000';
16+
export const TSVB_INDEX_ID = 'metrics';
17+
export const TSVB_INDEX_PATTERN = 'index-pattern-vis-metrics';
18+
19+
export const TSVB_VIS_TYPE = 'visualization';
20+
21+
// App URL Paths
22+
export const VIS_APP_PATH = '/app/visualize';
23+
export const TSVB_CREATE_URL = `${BASE_PATH}${VIS_APP_PATH}#/create?type=metrics`;

0 commit comments

Comments
 (0)