Skip to content

Commit ab6b9bd

Browse files
[MDS] Add dashboard assistant tests with multiple data source enabled (#1374) (#1385)
* Add dashboard assistant tests with multiple data source enabled Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> * optimize the code Signed-off-by: yubonluo <[email protected]> * add some annotation Signed-off-by: yubonluo <[email protected]> --------- Signed-off-by: yubonluo <[email protected]> (cherry picked from commit 8e7cf64) Co-authored-by: yuboluo <[email protected]>
1 parent 2b87a4a commit ab6b9bd

File tree

9 files changed

+113
-18
lines changed

9 files changed

+113
-18
lines changed

.github/workflows/assistant-release-e2e-workflow.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,13 @@ jobs:
3434
test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*'
3535
osd-serve-args: --assistant.chat.enabled=true
3636
security-enabled: false
37+
tests-with-multiple-data-source-and-disabled-local-cluster:
38+
needs: changes
39+
if: ${{ needs.changes.outputs.tests == 'true' }}
40+
uses: ./.github/workflows/release-e2e-workflow-template.yml
41+
with:
42+
test-name: dashboards assistant
43+
test-command: env CYPRESS_DISABLE_LOCAL_CLUSTER=true CYPRESS_DATASOURCE_MANAGEMENT_ENABLED=true CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/mds*.js'
44+
osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --data_source.hideLocalCluster=true --assistant.chat.enabled=true
45+
security-enabled: true
46+

cypress/integration/plugins/dashboards-assistant/chatbot_agent_framework_spec.js renamed to cypress/integration/plugins/dashboards-assistant/mds_chatbot_agent_framework_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,17 @@ import { BASE_PATH } from '../../../utils/constants';
77
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
88
describe('Assistant basic spec', () => {
99
before(() => {
10+
cy.setDefaultDataSourceForAssistant();
1011
// Set welcome screen tracking to false
1112
localStorage.setItem('home:welcome:show', 'false');
1213
// Set new theme modal to false
1314
localStorage.setItem('home:newThemeModal:show', 'false');
1415
});
1516

17+
after(() => {
18+
cy.clearDataSourceForAssistant();
19+
});
20+
1621
beforeEach(() => {
1722
// Visit ISM OSD
1823
cy.visit(`${BASE_PATH}/app/home`);

cypress/integration/plugins/dashboards-assistant/chatbot_interaction_trace_spec.js renamed to cypress/integration/plugins/dashboards-assistant/mds_chatbot_interaction_trace_spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { BASE_PATH } from '../../../utils/constants';
88
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
99
describe('Interaction trace spec', () => {
1010
before(() => {
11+
cy.setDefaultDataSourceForAssistant();
1112
// Set welcome screen tracking to false
1213
localStorage.setItem('home:welcome:show', 'false');
1314
// Set new theme modal to false
@@ -36,6 +37,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
3637

3738
// clean up localStorage items
3839
after(() => {
40+
cy.clearDataSourceForAssistant();
3941
localStorage.removeItem('home:welcome:show');
4042
localStorage.removeItem('home:newThemeModal:show');
4143
});

cypress/integration/plugins/dashboards-assistant/conversation_history_spec.js renamed to cypress/integration/plugins/dashboards-assistant/mds_conversation_history_spec.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
99
describe('Assistant conversation history spec', () => {
1010
let restoreShowHome;
1111
let restoreNewThemeModal;
12+
let dataSourceId;
1213

1314
before(() => {
15+
cy.setDefaultDataSourceForAssistant().then((id) => {
16+
dataSourceId = id;
17+
});
1418
// Set welcome screen tracking to false
1519
restoreShowHome = setStorageItem(
1620
localStorage,
@@ -37,6 +41,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
3741
cy.get('img[aria-label="toggle chat flyout icon"]').click();
3842
});
3943
after(() => {
44+
cy.clearDataSourceForAssistant();
4045
if (restoreShowHome) {
4146
restoreShowHome();
4247
}
@@ -106,13 +111,16 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
106111

107112
before(() => {
108113
// Create conversations data
109-
cy.sendAssistantMessage({
110-
input: {
111-
type: 'input',
112-
content: 'What are the indices in my cluster?',
113-
contentType: 'text',
114+
cy.sendAssistantMessage(
115+
{
116+
input: {
117+
type: 'input',
118+
content: 'What are the indices in my cluster?',
119+
contentType: 'text',
120+
},
114121
},
115-
}).then((result) => {
122+
dataSourceId
123+
).then((result) => {
116124
if (result.status !== 200) {
117125
throw result.body;
118126
}
@@ -123,7 +131,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
123131
after(() => {
124132
// Clear created conversations in tests
125133
conversations.map(({ conversationId }) =>
126-
cy.deleteConversation(conversationId)
134+
cy.deleteConversation(conversationId, dataSourceId)
127135
);
128136
});
129137

cypress/integration/plugins/dashboards-assistant/feedback_spec.js renamed to cypress/integration/plugins/dashboards-assistant/mds_feedback_spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { BASE_PATH } from '../../../utils/constants';
77
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
88
describe('Assistant feedback spec', () => {
99
before(() => {
10+
cy.setDefaultDataSourceForAssistant();
1011
// Set welcome screen tracking to false
1112
localStorage.setItem('home:welcome:show', 'false');
1213
// Set new theme modal to false
@@ -26,6 +27,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
2627

2728
// clean up localStorage items
2829
after(() => {
30+
cy.clearDataSourceForAssistant();
2931
localStorage.removeItem('home:welcome:show');
3032
localStorage.removeItem('home:newThemeModal:show');
3133
});

cypress/support/index.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import '../utils/plugins/notifications-dashboards/commands';
3333
import '../utils/plugins/dashboards-assistant/commands';
3434
import '../utils/dashboards/console/commands';
3535
import '../utils/dashboards/workspace-plugin/commands';
36+
import { currentBackendEndpoint } from '../utils/commands';
3637

3738
import 'cypress-real-events';
3839

@@ -64,7 +65,10 @@ if (Cypress.env('ENDPOINT_WITH_PROXY')) {
6465
* Make setup step in here so that all the test files in dashboards-assistant
6566
* won't need to call these commands.
6667
*/
67-
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
68+
if (
69+
Cypress.env('DASHBOARDS_ASSISTANT_ENABLED') &&
70+
!Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
71+
) {
6872
before(() => {
6973
cy.addAssistantRequiredSettings();
7074
cy.readOrRegisterRootAgent();
@@ -75,3 +79,28 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
7579
cy.stopDummyServer();
7680
});
7781
}
82+
83+
/**
84+
* Make setup step in here so that all the test with MDS files in dashboards-assistant
85+
* won't need to call these commands.
86+
*/
87+
if (
88+
Cypress.env('DASHBOARDS_ASSISTANT_ENABLED') &&
89+
Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
90+
) {
91+
before(() => {
92+
const originalBackendEndpoint = currentBackendEndpoint.get();
93+
currentBackendEndpoint.set(currentBackendEndpoint.REMOTE_NO_AUTH);
94+
cy.addAssistantRequiredSettings();
95+
cy.readOrRegisterRootAgent();
96+
currentBackendEndpoint.set(originalBackendEndpoint, false);
97+
cy.startDummyServer();
98+
});
99+
after(() => {
100+
const originalBackendEndpoint = currentBackendEndpoint.get();
101+
currentBackendEndpoint.set(currentBackendEndpoint.REMOTE_NO_AUTH);
102+
cy.cleanRootAgent();
103+
currentBackendEndpoint.set(originalBackendEndpoint, false);
104+
cy.stopDummyServer();
105+
});
106+
}

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,3 +348,18 @@ Cypress.Commands.add('ifElementExists', (selector, callback) => {
348348
}
349349
});
350350
});
351+
352+
Cypress.Commands.add('setDefaultDataSource', (dataSourceId) => {
353+
cy.request({
354+
method: 'POST',
355+
url: `${BASE_PATH}/api/opensearch-dashboards/settings`,
356+
headers: {
357+
'osd-xsrf': true,
358+
},
359+
body: {
360+
changes: {
361+
defaultDataSource: dataSourceId,
362+
},
363+
},
364+
});
365+
});

cypress/utils/plugins/dashboards-assistant/commands.js

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,11 @@ Cypress.Commands.add('registerRootAgent', () => {
135135
});
136136

137137
Cypress.Commands.add('putRootAgentId', (agentId) => {
138-
if (Cypress.env('SECURITY_ENABLED')) {
138+
// When enabling the DATASOURCE-MANAGEment-ENABLED flag, we need to config the root agent ID in a no auth data source.
139+
if (
140+
Cypress.env('SECURITY_ENABLED') &&
141+
!Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
142+
) {
139143
// The .plugins-ml-config index is a system index and need to call the API by using certificate file
140144
return cy.exec(
141145
`curl -k --cert <(cat <<EOF \n${certPublicKeyContent}\nEOF\n) --key <(cat <<EOF\n${certPrivateKeyContent}\nEOF\n) -XPUT '${BACKEND_BASE_PATH}${ML_COMMONS_API.UPDATE_ROOT_AGENT_CONFIG}' -H 'Content-Type: application/json' -d '{"type":"os_chat_root_agent","configuration":{"agent_id":"${agentId}"}}'`
@@ -193,13 +197,33 @@ Cypress.Commands.add('stopDummyServer', () => {
193197
});
194198
});
195199

196-
Cypress.Commands.add('sendAssistantMessage', (body) =>
197-
apiRequest(`${BASE_PATH}${ASSISTANT_API.SEND_MESSAGE}`, 'POST', body)
198-
);
200+
Cypress.Commands.add('sendAssistantMessage', (body, dataSourceId) => {
201+
const url = `${BASE_PATH}${ASSISTANT_API.SEND_MESSAGE}`;
202+
const qs = { dataSourceId: dataSourceId };
203+
apiRequest(url, 'POST', body, qs);
204+
});
199205

200-
Cypress.Commands.add('deleteConversation', (conversationId) =>
201-
apiRequest(
202-
`${BASE_PATH}${ASSISTANT_API.CONVERSATION}/${conversationId}`,
203-
'DELETE'
204-
)
205-
);
206+
Cypress.Commands.add('deleteConversation', (conversationId, dataSourceId) => {
207+
const url = `${BASE_PATH}${ASSISTANT_API.CONVERSATION}/${conversationId}`;
208+
const qs = { dataSourceId: dataSourceId };
209+
apiRequest(url, 'DELETE', undefined, qs);
210+
});
211+
212+
Cypress.Commands.add('setDefaultDataSourceForAssistant', () => {
213+
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
214+
cy.deleteAllDataSources();
215+
// create data source
216+
cy.createDataSourceNoAuth().then((result) => {
217+
const dataSourceId = result[0];
218+
// set default data source
219+
cy.setDefaultDataSource(dataSourceId);
220+
return cy.wrap(dataSourceId);
221+
});
222+
}
223+
});
224+
225+
Cypress.Commands.add('clearDataSourceForAssistant', () => {
226+
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
227+
cy.deleteAllDataSources();
228+
}
229+
});

0 commit comments

Comments
 (0)