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]Comply with the root agent id config change in dashboards-assistant (#1053) #1062

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
14 changes: 12 additions & 2 deletions .github/workflows/assistant-release-e2e-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ jobs:
tests:
- 'cypress/**/dashboards-assistant/**'

tests:
tests-with-security:
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_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*'
osd-serve-args: --assistant.chat.enabled=true --assistant.chat.rootAgentName="Cypress test agent"
osd-serve-args: --assistant.chat.enabled=true

tests-without-security:
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_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
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"persistent": {
"plugins.ml_commons.only_run_on_ml_node": false,
"plugins.ml_commons.memory_feature_enabled": true,
"plugins.ml_commons.agent_framework_enabled": true,
"plugins.ml_commons.trusted_connector_endpoints_regex": [
"^http://127.0.0.1:3000$"
]
Expand Down
70 changes: 70 additions & 0 deletions cypress/fixtures/plugins/dashboards-assistant/security-cert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

/**
* This file should be somewhere else like plugins/security but as assistant is the only consumer of the content
* Would be better to keep within the directory of dashboards-assistant.
*/

export const certPublicKeyContent = `
-----BEGIN CERTIFICATE-----
MIIEmDCCA4CgAwIBAgIUZjrlDPP8azRDPZchA/XEsx0X2iYwDQYJKoZIhvcNAQEL
BQAwgY8xEzARBgoJkiaJk/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFt
cGxlMRkwFwYDVQQKDBBFeGFtcGxlIENvbSBJbmMuMSEwHwYDVQQLDBhFeGFtcGxl
IENvbSBJbmMuIFJvb3QgQ0ExITAfBgNVBAMMGEV4YW1wbGUgQ29tIEluYy4gUm9v
dCBDQTAeFw0yMzA4MjkyMDA2MzdaFw0zMzA4MjYyMDA2MzdaME0xCzAJBgNVBAYT
AmRlMQ0wCwYDVQQHDAR0ZXN0MQ8wDQYDVQQKDAZjbGllbnQxDzANBgNVBAsMBmNs
aWVudDENMAsGA1UEAwwEa2lyazCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
ggEBAJVcOAQlCiuB9emCljROAXnlsPbG7PE3kNz2sN+BbGuw686Wgyl3uToVHvVs
paMmLUqm1KYz9wMSWTIBZgpJ9hYaIbGxD4RBb7qTAJ8Q4ddCV2f7T4lxao/6ixI+
O0l/BG9E3mRGo/r0w+jtTQ3aR2p6eoxaOYbVyEMYtFI4QZTkcgGIPGxm05y8xonx
vV5pbSW9L7qAVDzQC8EYGQMMI4ccu0NcHKWtmTYJA/wDPE2JwhngHwbcIbc4cDz6
cG0S3FmgiKGuuSqUy35v/k3y7zMHQSdx7DSR2tzhH/bBL/9qGvpT71KKrxPtaxS0
bAqPcEkKWDo7IMlGGW7LaAWfGg8CAwEAAaOCASswggEnMAwGA1UdEwEB/wQCMAAw
DgYDVR0PAQH/BAQDAgXgMBYGA1UdJQEB/wQMMAoGCCsGAQUFBwMCMIHPBgNVHSME
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Jv6n69327MS4NG8L/gCU5
3pEm38hkUi8pVYU7in7rx4TCkrq94OkzWJYurAkCgYATQCL/rJLQAlJIGulp8s6h
mQGwy8vIqMjAdHGLrCS35sVYBXG13knS52LJHvbVee39AbD5/LlWvjJGlQMzCLrw
F7oILW5kXxhb8S73GWcuMbuQMFVHFONbZAZgn+C9FW4l7XyRdkrbR1MRZ2km8YMs
/AHmo368d4PSNRMMzLHw8Q==
-----END PRIVATE KEY-----
`;
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

describe('Interact with Agent framework', () => {
it('toggle Chatbot and enable to interact', () => {
// input question
cy.wait(1000);
cy.get(`input[placeholder="Ask question"]`)
.click()
.type('What are the indices in my cluster?{enter}');
// The header may render multiple times, wait for UI to be stable
cy.wait(5000);

// enable to toggle and show Chatbot
cy.get(`img[aria-label="toggle chat flyout icon"]`).click();

// click suggestions to generate response
cy.contains('What are the indices in my cluster?').click();

// should have a LLM Response
cy.contains(
Expand All @@ -39,6 +42,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

// should have a suggestion section
cy.get(`[aria-label="chat suggestions"]`).should('be.length', 1);
cy.contains('suggestion1');

// Click regenerate button
cy.get(`button[title="regenerate message"]`).click();
Expand All @@ -56,6 +60,7 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {

// should have a suggestion section
cy.get(`[aria-label="chat suggestions"]`).should('be.length', 1);
cy.contains('suggestion2');
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion cypress/support/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ if (Cypress.env('ENDPOINT_WITH_PROXY')) {
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
before(() => {
cy.addAssistantRequiredSettings();
cy.registerRootAgent();
cy.readOrRegisterRootAgent();
cy.startDummyServer();
});
after(() => {
Expand Down
45 changes: 42 additions & 3 deletions cypress/utils/plugins/dashboards-assistant/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
* SPDX-License-Identifier: Apache-2.0
*/

import { get } from 'lodash';
import FlowTemplateJSON from '../../../fixtures/plugins/dashboards-assistant/flow-template.json';
import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants';
import { ML_COMMONS_API, ASSISTANT_API } from './constants';
import clusterSettings from '../../../fixtures/plugins/dashboards-assistant/cluster_settings.json';
import { apiRequest } from '../../helpers';
import {
certPrivateKeyContent,
certPublicKeyContent,
} from '../../../fixtures/plugins/dashboards-assistant/security-cert';

Cypress.Commands.add('addAssistantRequiredSettings', () => {
cy.request('PUT', `${BACKEND_BASE_PATH}/_cluster/settings`, clusterSettings);
Expand All @@ -20,10 +25,23 @@ const agentParameters = {
rootAgentId: '',
};

Cypress.Commands.add('readOrRegisterRootAgent', () => {
cy.request({
url: `${BACKEND_BASE_PATH}${ML_COMMONS_API.AGENT_CONFIG}`,
method: 'GET',
failOnStatusCode: false,
}).then((resp) => {
const agentId = get(resp, 'body.configuration.agent_id');
if (agentId) {
cy.log(`Already initialized agent: ${agentId}, skip the initialize step`);
} else {
cy.log(`Agent id not initialized yet, set up agent`);
return cy.registerRootAgent();
}
});
});

Cypress.Commands.add('registerRootAgent', () => {
// ML needs 10 seconds to initialize its master key
// The ML encryption master key has not been initialized yet. Please retry after waiting for 10 seconds.
cy.wait(10000);
/**
* TODO use flow framework if the plugin get integrate in the future.
*/
Expand Down Expand Up @@ -112,9 +130,30 @@ Cypress.Commands.add('registerRootAgent', () => {
})
.then((resp) => {
agentParameters.rootAgentId = resp.body.agent_id;
return cy.putRootAgentId(agentParameters.rootAgentId);
});
});

Cypress.Commands.add('putRootAgentId', (agentId) => {
if (Cypress.env('SECURITY_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}"}}'`
);
} else {
return cy.request(
'PUT',
`${BACKEND_BASE_PATH}${ML_COMMONS_API.UPDATE_ROOT_AGENT_CONFIG}`,
{
type: 'os_chat_root_agent',
configuration: {
agent_id: agentId,
},
}
);
}
});

Cypress.Commands.add('cleanRootAgent', () => {
return;
/**
Expand Down
2 changes: 2 additions & 0 deletions cypress/utils/plugins/dashboards-assistant/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const ML_COMMONS_API = {
CREATE_CONNECTOR: `${ML_COMMONS_API_PREFIX}/connectors/_create`,
CREATE_MODEL: `${ML_COMMONS_API_PREFIX}/models/_register`,
CREATE_AGENT: `${ML_COMMONS_API_PREFIX}/agents/_register`,
UPDATE_ROOT_AGENT_CONFIG: `/.plugins-ml-config/_doc/os_chat`,
AGENT_CONFIG: `${ML_COMMONS_API_PREFIX}/config/os_chat`,
};

export const ASSISTANT_API_BASE = '/api/assistant';
Expand Down