Skip to content

Commit 2f5d2f0

Browse files
authored
Comply with the root agent id config change in dashboards-assistant (#1053) (#1062)
* feat: update agent id into config index Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: enable agent framework Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: update url Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: update settings Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: test in security disabled Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: run without security Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: optimize config retrieve logic Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: enable run when security enabled Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: enable run when security enabled Signed-off-by: SuZhou-Joe <suzhou@amazon.com> * feat: add some comment Signed-off-by: SuZhou-Joe <suzhou@amazon.com> --------- Signed-off-by: SuZhou-Joe <suzhou@amazon.com> (cherry picked from commit 7625e00)
1 parent 7b1a0e1 commit 2f5d2f0

File tree

7 files changed

+138
-11
lines changed

7 files changed

+138
-11
lines changed

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

+12-2
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@ jobs:
1515
tests:
1616
- 'cypress/**/dashboards-assistant/**'
1717
18-
tests:
18+
tests-with-security:
1919
needs: changes
2020
if: ${{ needs.changes.outputs.tests == 'true' }}
2121
uses: ./.github/workflows/release-e2e-workflow-template.yml
2222
with:
2323
test-name: dashboards assistant
2424
test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-with-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*'
25-
osd-serve-args: --assistant.chat.enabled=true --assistant.chat.rootAgentName="Cypress test agent"
25+
osd-serve-args: --assistant.chat.enabled=true
26+
27+
tests-without-security:
28+
needs: changes
29+
if: ${{ needs.changes.outputs.tests == 'true' }}
30+
uses: ./.github/workflows/release-e2e-workflow-template.yml
31+
with:
32+
test-name: dashboards assistant
33+
test-command: env CYPRESS_DASHBOARDS_ASSISTANT_ENABLED=true yarn cypress:run-without-security --browser chromium --spec 'cypress/integration/plugins/dashboards-assistant/*'
34+
osd-serve-args: --assistant.chat.enabled=true
35+
security-enabled: false

cypress/fixtures/plugins/dashboards-assistant/cluster_settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"persistent": {
33
"plugins.ml_commons.only_run_on_ml_node": false,
44
"plugins.ml_commons.memory_feature_enabled": true,
5+
"plugins.ml_commons.agent_framework_enabled": true,
56
"plugins.ml_commons.trusted_connector_endpoints_regex": [
67
"^http://127.0.0.1:3000$"
78
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* This file should be somewhere else like plugins/security but as assistant is the only consumer of the content
8+
* Would be better to keep within the directory of dashboards-assistant.
9+
*/
10+
11+
export const certPublicKeyContent = `
12+
-----BEGIN CERTIFICATE-----
13+
MIIEmDCCA4CgAwIBAgIUZjrlDPP8azRDPZchA/XEsx0X2iYwDQYJKoZIhvcNAQEL
14+
BQAwgY8xEzARBgoJkiaJk/IsZAEZFgNjb20xFzAVBgoJkiaJk/IsZAEZFgdleGFt
15+
cGxlMRkwFwYDVQQKDBBFeGFtcGxlIENvbSBJbmMuMSEwHwYDVQQLDBhFeGFtcGxl
16+
IENvbSBJbmMuIFJvb3QgQ0ExITAfBgNVBAMMGEV4YW1wbGUgQ29tIEluYy4gUm9v
17+
dCBDQTAeFw0yMzA4MjkyMDA2MzdaFw0zMzA4MjYyMDA2MzdaME0xCzAJBgNVBAYT
18+
AmRlMQ0wCwYDVQQHDAR0ZXN0MQ8wDQYDVQQKDAZjbGllbnQxDzANBgNVBAsMBmNs
19+
aWVudDENMAsGA1UEAwwEa2lyazCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
20+
ggEBAJVcOAQlCiuB9emCljROAXn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dqprr+ukYmjho76g6k5cQuRaB6MxqldzUg+2E7IHQP8MCF+co51uZq2nl33mtp
37+
RGr6JbdHXc96zsLTL3saJQ8AWEfu1gbTVrwyRA==
38+
-----END CERTIFICATE-----
39+
`;
40+
41+
export const certPrivateKeyContent = `
42+
-----BEGIN PRIVATE KEY-----
43+
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQCVXDgEJQorgfXp
44+
gpY0TgF55bD2xuzxN5Dc9rDfgWxrsOvOloMpd7k6FR71bKWjJi1KptSmM/cDElky
45+
AWYKSfYWGiGxsQ+EQW+6kwCfEOHXQldn+0+JcWqP+osSPjtJfwRvRN5kRqP69MPo
46+
7U0N2kdqenqMWjmG1chDGLRSOEGU5HIBiDxsZtOcvMaJ8b1eaW0lvS+6gFQ80AvB
47+
GBkDDCOHHLtDXBylrZk2CQP8AzxNicIZ4B8G3CG3OHA8+nBtEtxZoIihrrkqlMt+
48+
b/5N8u8zB0Encew0kdrc4R/2wS//ahr6U+9Siq8T7WsUtGwKj3BJClg6OyDJRhlu
49+
y2gFnxoPAgMBAAECggEAP5TOycDkx+megAWVoHV2fmgvgZXkBrlzQwUG/VZQi7V4
50+
ZGzBMBVltdqI38wc5MtbK3TCgHANnnKgor9iq02Z4wXDwytPIiti/ycV9CDRKvv0
51+
TnD2hllQFjN/IUh5n4thHWbRTxmdM7cfcNgX3aZGkYbLBVVhOMtn4VwyYu/Mxy8j
52+
xClZT2xKOHkxqwmWPmdDTbAeZIbSv7RkIGfrKuQyUGUaWhrPslvYzFkYZ0umaDgQ
53+
OAthZew5Bz3OfUGOMPLH61SVPuJZh9zN1hTWOvT65WFWfsPd2yStI+WD/5PU1Doo
54+
1RyeHJO7s3ug8JPbtNJmaJwHe9nXBb/HXFdqb976yQKBgQDNYhpu+MYSYupaYqjs
55+
9YFmHQNKpNZqgZ4ceRFZ6cMJoqpI5dpEMqToFH7tpor72Lturct2U9nc2WR0HeEs
56+
/6tiptyMPTFEiMFb1opQlXF2ae7LeJllntDGN0Q6vxKnQV+7VMcXA0Y8F7tvGDy3
57+
qJu5lfvB1mNM2I6y/eMxjBuQhwKBgQC6K41DXMFro0UnoO879pOQYMydCErJRmjG
58+
/tZSy3Wj4KA/QJsDSViwGfvdPuHZRaG9WtxdL6kn0w1exM9Rb0bBKl36lvi7o7xv
59+
M+Lw9eyXMkww8/F5d7YYH77gIhGo+RITkKI3+5BxeBaUnrGvmHrpmpgRXWmINqr0
60+
0jsnN3u0OQKBgCf45vIgItSjQb8zonLz2SpZjTFy4XQ7I92gxnq8X0Q5z3B+o7tQ
61+
K/4rNwTju/sGFHyXAJlX+nfcK4vZ4OBUJjP+C8CTjEotX4yTNbo3S6zjMyGQqDI5
62+
9aIOUY4pb+TzeUFJX7If5gR+DfGyQubvvtcg1K3GHu9u2l8FwLj87sRzAoGAflQF
63+
RHuRiG+/AngTPnZAhc0Zq0kwLkpH2Rid6IrFZhGLy8AUL/O6aa0IGoaMDLpSWUJp
64+
nBY2S57MSM11/MVslrEgGmYNnI4r1K25xlaqV6K6ztEJv6n69327MS4NG8L/gCU5
65+
3pEm38hkUi8pVYU7in7rx4TCkrq94OkzWJYurAkCgYATQCL/rJLQAlJIGulp8s6h
66+
mQGwy8vIqMjAdHGLrCS35sVYBXG13knS52LJHvbVee39AbD5/LlWvjJGlQMzCLrw
67+
F7oILW5kXxhb8S73GWcuMbuQMFVHFONbZAZgn+C9FW4l7XyRdkrbR1MRZ2km8YMs
68+
/AHmo368d4PSNRMMzLHw8Q==
69+
-----END PRIVATE KEY-----
70+
`;

cypress/integration/plugins/dashboards-assistant/chatbot_agent_framework_spec.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,14 @@ if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
2626

2727
describe('Interact with Agent framework', () => {
2828
it('toggle Chatbot and enable to interact', () => {
29-
// input question
30-
cy.wait(1000);
31-
cy.get(`input[placeholder="Ask question"]`)
32-
.click()
33-
.type('What are the indices in my cluster?{enter}');
29+
// The header may render multiple times, wait for UI to be stable
30+
cy.wait(5000);
31+
32+
// enable to toggle and show Chatbot
33+
cy.get(`img[aria-label="toggle chat flyout icon"]`).click();
34+
35+
// click suggestions to generate response
36+
cy.contains('What are the indices in my cluster?').click();
3437

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

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

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

5761
// should have a suggestion section
5862
cy.get(`[aria-label="chat suggestions"]`).should('be.length', 1);
63+
cy.contains('suggestion2');
5964
});
6065
});
6166
});

cypress/support/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ if (Cypress.env('ENDPOINT_WITH_PROXY')) {
6565
if (Cypress.env('DASHBOARDS_ASSISTANT_ENABLED')) {
6666
before(() => {
6767
cy.addAssistantRequiredSettings();
68-
cy.registerRootAgent();
68+
cy.readOrRegisterRootAgent();
6969
cy.startDummyServer();
7070
});
7171
after(() => {

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

+42-3
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
import { get } from 'lodash';
67
import FlowTemplateJSON from '../../../fixtures/plugins/dashboards-assistant/flow-template.json';
78
import { BACKEND_BASE_PATH, BASE_PATH } from '../../constants';
89
import { ML_COMMONS_API, ASSISTANT_API } from './constants';
910
import clusterSettings from '../../../fixtures/plugins/dashboards-assistant/cluster_settings.json';
1011
import { apiRequest } from '../../helpers';
12+
import {
13+
certPrivateKeyContent,
14+
certPublicKeyContent,
15+
} from '../../../fixtures/plugins/dashboards-assistant/security-cert';
1116

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

28+
Cypress.Commands.add('readOrRegisterRootAgent', () => {
29+
cy.request({
30+
url: `${BACKEND_BASE_PATH}${ML_COMMONS_API.AGENT_CONFIG}`,
31+
method: 'GET',
32+
failOnStatusCode: false,
33+
}).then((resp) => {
34+
const agentId = get(resp, 'body.configuration.agent_id');
35+
if (agentId) {
36+
cy.log(`Already initialized agent: ${agentId}, skip the initialize step`);
37+
} else {
38+
cy.log(`Agent id not initialized yet, set up agent`);
39+
return cy.registerRootAgent();
40+
}
41+
});
42+
});
43+
2344
Cypress.Commands.add('registerRootAgent', () => {
24-
// ML needs 10 seconds to initialize its master key
25-
// The ML encryption master key has not been initialized yet. Please retry after waiting for 10 seconds.
26-
cy.wait(10000);
2745
/**
2846
* TODO use flow framework if the plugin get integrate in the future.
2947
*/
@@ -112,9 +130,30 @@ Cypress.Commands.add('registerRootAgent', () => {
112130
})
113131
.then((resp) => {
114132
agentParameters.rootAgentId = resp.body.agent_id;
133+
return cy.putRootAgentId(agentParameters.rootAgentId);
115134
});
116135
});
117136

137+
Cypress.Commands.add('putRootAgentId', (agentId) => {
138+
if (Cypress.env('SECURITY_ENABLED')) {
139+
// The .plugins-ml-config index is a system index and need to call the API by using certificate file
140+
return cy.exec(
141+
`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}"}}'`
142+
);
143+
} else {
144+
return cy.request(
145+
'PUT',
146+
`${BACKEND_BASE_PATH}${ML_COMMONS_API.UPDATE_ROOT_AGENT_CONFIG}`,
147+
{
148+
type: 'os_chat_root_agent',
149+
configuration: {
150+
agent_id: agentId,
151+
},
152+
}
153+
);
154+
}
155+
});
156+
118157
Cypress.Commands.add('cleanRootAgent', () => {
119158
return;
120159
/**

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

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export const ML_COMMONS_API = {
1414
CREATE_CONNECTOR: `${ML_COMMONS_API_PREFIX}/connectors/_create`,
1515
CREATE_MODEL: `${ML_COMMONS_API_PREFIX}/models/_register`,
1616
CREATE_AGENT: `${ML_COMMONS_API_PREFIX}/agents/_register`,
17+
UPDATE_ROOT_AGENT_CONFIG: `/.plugins-ml-config/_doc/os_chat`,
18+
AGENT_CONFIG: `${ML_COMMONS_API_PREFIX}/config/os_chat`,
1719
};
1820

1921
export const ASSISTANT_API_BASE = '/api/assistant';

0 commit comments

Comments
 (0)