Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport main] [MDS] Add dashboard assistant tests with multiple data source enabled #1385

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/assistant-release-e2e-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,13 @@ jobs:
test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*'
osd-serve-args: --assistant.chat.enabled=true
security-enabled: false
tests-with-multiple-data-source-and-disabled-local-cluster:
needs: changes
if: ${{ needs.changes.outputs.tests == 'true' }}
uses: ./.github/workflows/release-e2e-workflow-template.yml
with:
test-name: dashboards assistant
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'
osd-serve-args: --data_source.enabled=true --data_source.ssl.verificationMode=none --data_source.hideLocalCluster=true --assistant.chat.enabled=true
security-enabled: true

Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,17 @@ import { BASE_PATH } from '../../../utils/constants';
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
describe('Assistant basic spec', () => {
before(() => {
cy.setDefaultDataSourceForAssistant();
// Set welcome screen tracking to false
localStorage.setItem('home:welcome:show', 'false');
// Set new theme modal to false
localStorage.setItem('home:newThemeModal:show', 'false');
});

after(() => {
cy.clearDataSourceForAssistant();
});

beforeEach(() => {
// Visit ISM OSD
cy.visit(`${BASE_PATH}/app/home`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { BASE_PATH } from '../../../utils/constants';
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
describe('Interaction trace spec', () => {
before(() => {
cy.setDefaultDataSourceForAssistant();
// Set welcome screen tracking to false
localStorage.setItem('home:welcome:show', 'false');
// Set new theme modal to false
Expand Down Expand Up @@ -36,6 +37,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

// clean up localStorage items
after(() => {
cy.clearDataSourceForAssistant();
localStorage.removeItem('home:welcome:show');
localStorage.removeItem('home:newThemeModal:show');
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
describe('Assistant conversation history spec', () => {
let restoreShowHome;
let restoreNewThemeModal;
let dataSourceId;

before(() => {
cy.setDefaultDataSourceForAssistant().then((id) => {
dataSourceId = id;
});
// Set welcome screen tracking to false
restoreShowHome = setStorageItem(
localStorage,
Expand All @@ -37,6 +41,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
cy.get('img[aria-label="toggle chat flyout icon"]').click();
});
after(() => {
cy.clearDataSourceForAssistant();
if (restoreShowHome) {
restoreShowHome();
}
Expand Down Expand Up @@ -106,13 +111,16 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

before(() => {
// Create conversations data
cy.sendAssistantMessage({
input: {
type: 'input',
content: 'What are the indices in my cluster?',
contentType: 'text',
cy.sendAssistantMessage(
{
input: {
type: 'input',
content: 'What are the indices in my cluster?',
contentType: 'text',
},
},
}).then((result) => {
dataSourceId
).then((result) => {
if (result.status !== 200) {
throw result.body;
}
Expand All @@ -123,7 +131,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
after(() => {
// Clear created conversations in tests
conversations.map(({ conversationId }) =>
cy.deleteConversation(conversationId)
cy.deleteConversation(conversationId, dataSourceId)
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { BASE_PATH } from '../../../utils/constants';
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
describe('Assistant feedback spec', () => {
before(() => {
cy.setDefaultDataSourceForAssistant();
// Set welcome screen tracking to false
localStorage.setItem('home:welcome:show', 'false');
// Set new theme modal to false
Expand All @@ -26,6 +27,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

// clean up localStorage items
after(() => {
cy.clearDataSourceForAssistant();
localStorage.removeItem('home:welcome:show');
localStorage.removeItem('home:newThemeModal:show');
});
Expand Down
31 changes: 30 additions & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import '../utils/plugins/notifications-dashboards/commands';
import '../utils/plugins/dashboards-assistant/commands';
import '../utils/dashboards/console/commands';
import '../utils/dashboards/workspace-plugin/commands';
import { currentBackendEndpoint } from '../utils/commands';

import 'cypress-real-events';

Expand Down Expand Up @@ -64,7 +65,10 @@ if (Cypress.env('ENDPOINT_WITH_PROXY')) {
* Make setup step in here so that all the test files in dashboards-assistant
* won't need to call these commands.
*/
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
if (
Cypress.env('DASHBOARDS_ASSISTANT_ENABLED') &&
!Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
) {
before(() => {
cy.addAssistantRequiredSettings();
cy.readOrRegisterRootAgent();
Expand All @@ -75,3 +79,28 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
cy.stopDummyServer();
});
}

/**
* Make setup step in here so that all the test with MDS files in dashboards-assistant
* won't need to call these commands.
*/
if (
Cypress.env('DASHBOARDS_ASSISTANT_ENABLED') &&
Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
) {
before(() => {
const originalBackendEndpoint = currentBackendEndpoint.get();
currentBackendEndpoint.set(currentBackendEndpoint.REMOTE_NO_AUTH);
cy.addAssistantRequiredSettings();
cy.readOrRegisterRootAgent();
currentBackendEndpoint.set(originalBackendEndpoint, false);
cy.startDummyServer();
});
after(() => {
const originalBackendEndpoint = currentBackendEndpoint.get();
currentBackendEndpoint.set(currentBackendEndpoint.REMOTE_NO_AUTH);
cy.cleanRootAgent();
currentBackendEndpoint.set(originalBackendEndpoint, false);
cy.stopDummyServer();
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -348,3 +348,18 @@ Cypress.Commands.add('ifElementExists', (selector, callback) => {
}
});
});

Cypress.Commands.add('setDefaultDataSource', (dataSourceId) => {
cy.request({
method: 'POST',
url: `${BASE_PATH}/api/opensearch-dashboards/settings`,
headers: {
'osd-xsrf': true,
},
body: {
changes: {
defaultDataSource: dataSourceId,
},
},
});
});
44 changes: 34 additions & 10 deletions cypress/utils/plugins/dashboards-assistant/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ Cypress.Commands.add('registerRootAgent', () => {
});

Cypress.Commands.add('putRootAgentId', (agentId) => {
if (Cypress.env('SECURITY_ENABLED')) {
// When enabling the DATASOURCE-MANAGEment-ENABLED flag, we need to config the root agent ID in a no auth data source.
if (
Cypress.env('SECURITY_ENABLED') &&
!Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')
) {
// The .plugins-ml-config index is a system index and need to call the API by using certificate file
return cy.exec(
`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}"}}'`
Expand Down Expand Up @@ -193,13 +197,33 @@ Cypress.Commands.add('stopDummyServer', () => {
});
});

Cypress.Commands.add('sendAssistantMessage', (body) =>
apiRequest(`${BASE_PATH}${ASSISTANT_API.SEND_MESSAGE}`, 'POST', body)
);
Cypress.Commands.add('sendAssistantMessage', (body, dataSourceId) => {
const url = `${BASE_PATH}${ASSISTANT_API.SEND_MESSAGE}`;
const qs = { dataSourceId: dataSourceId };
apiRequest(url, 'POST', body, qs);
});

Cypress.Commands.add('deleteConversation', (conversationId) =>
apiRequest(
`${BASE_PATH}${ASSISTANT_API.CONVERSATION}/${conversationId}`,
'DELETE'
)
);
Cypress.Commands.add('deleteConversation', (conversationId, dataSourceId) => {
const url = `${BASE_PATH}${ASSISTANT_API.CONVERSATION}/${conversationId}`;
const qs = { dataSourceId: dataSourceId };
apiRequest(url, 'DELETE', undefined, qs);
});

Cypress.Commands.add('setDefaultDataSourceForAssistant', () => {
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
cy.deleteAllDataSources();
// create data source
cy.createDataSourceNoAuth().then((result) => {
const dataSourceId = result[0];
// set default data source
cy.setDefaultDataSource(dataSourceId);
return cy.wrap(dataSourceId);
});
}
});

Cypress.Commands.add('clearDataSourceForAssistant', () => {
if (Cypress.env('DATASOURCE_MANAGEMENT_ENABLED')) {
cy.deleteAllDataSources();
}
});
Loading