Skip to content

Commit dbf086e

Browse files
committed
dynamically establish remote cluster name
Signed-off-by: Amit Galitzky <amgalitz@amazon.com>
1 parent 37ac7c7 commit dbf086e

File tree

1 file changed

+51
-24
lines changed

1 file changed

+51
-24
lines changed

cypress/integration/plugins/anomaly-detection-dashboards-plugin/create_remote_detector_spec.js

+51-24
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,6 @@ context('Create remote detector workflow', () => {
1818
const TEST_INDEX_NAME = 'sample-ad-index';
1919
const TEST_SECOND_INDEX_NAME = 'sample-ad-index-two';
2020
const TEST_REMOTE_INDEX = 'followCluster:sample-ad-index';
21-
const remoteClusterSettings = {
22-
persistent: {
23-
'cluster.remote.followCluster': {
24-
seeds: ['127.0.0.1:9301'],
25-
},
26-
},
27-
};
2821

2922
// Clean up created resources
3023
afterEach(() => {
@@ -35,7 +28,7 @@ context('Create remote detector workflow', () => {
3528
describe('Remote cluster tests', () => {
3629
before(function () {
3730
cy.visit(AD_URL.OVERVIEW, { timeout: 10000 });
38-
// Use `cy.exec()` to check cluster health before running tests
31+
3932
cy.exec(
4033
`
4134
node -e "
@@ -49,34 +42,59 @@ context('Create remote detector workflow', () => {
4942
).then((result) => {
5043
if (result.code !== 0) {
5144
Cypress.log({
52-
name: 'Cluster Health',
53-
message:
54-
'Remote cluster is unavailable - skipping all remote detector tests',
45+
message: 'Remote cluster is unavailable - skipping tests',
5546
});
56-
this.skip(); // Skip the entire test suite
47+
this.skip(); // Skip all tests if the cluster isn't available
5748
}
49+
50+
cy.request(
51+
`${Cypress.env('remoteDataSourceNoAuthUrl')}/_cluster/health`
52+
).then((response) => {
53+
Cypress.log({
54+
message: `Cluster health response: ${JSON.stringify(
55+
response.body
56+
)}`,
57+
});
58+
59+
if (!response.body || !response.body.cluster_name) {
60+
Cypress.log({ message: 'Cluster name not found - skipping tests' });
61+
this.skip();
62+
}
63+
Cypress.env('remoteClusterName', response.body.cluster_name);
64+
});
5865
});
5966
});
6067

61-
// apply remote cluster settings after cluster health check passes
6268
before(function () {
69+
const remoteClusterName = Cypress.env('remoteClusterName');
70+
71+
const remoteClusterSettings = {
72+
persistent: {
73+
[`cluster.remote.${remoteClusterName}`]: {
74+
seeds: ['127.0.0.1:9301'],
75+
},
76+
},
77+
};
78+
6379
cy.visit(AD_URL.OVERVIEW, { timeout: 10000 });
80+
6481
cy.request({
6582
method: 'PUT',
6683
url: `${BACKEND_BASE_PATH}/_cluster/settings`,
6784
headers: {
6885
'content-type': 'application/json',
69-
'osd-xsrf': true, // If your backend requires this header
86+
'osd-xsrf': true,
7087
},
7188
body: remoteClusterSettings,
7289
}).then((response) => {
73-
cy.log('Cluster settings update response:', response);
90+
Cypress.log({ message: 'Cluster settings updated successfully' });
7491
expect(response.status).to.eq(200);
7592
});
93+
7694
cy.wait(5000);
7795
});
7896

79-
// Index some sample data in follower cluster (remote)
97+
// Index some sample data in local and follower cluster (remote)
8098
beforeEach(() => {
8199
cy.visit(AD_URL.OVERVIEW, { timeout: 10000 });
82100
const remoteEndpointTestData = `${Cypress.env(
@@ -138,6 +156,8 @@ context('Create remote detector workflow', () => {
138156

139157
it('Full creation - based on remote index', () => {
140158
// Define detector step
159+
const remoteClusterName = Cypress.env('remoteClusterName');
160+
141161
cy.visit(AD_URL.CREATE_AD);
142162
cy.getElementByTestId('defineOrEditDetectorTitle').should('exist');
143163
cy.getElementByTestId('detectorNameTextInput').type(
@@ -151,7 +171,7 @@ context('Create remote detector workflow', () => {
151171
cy.getElementByTestId('clustersFilter').click();
152172
cy.contains(
153173
'.euiComboBoxOption__content',
154-
'followCluster (Remote)'
174+
`${remoteClusterName} (Remote)`
155175
).click();
156176

157177
cy.wait(3000);
@@ -160,7 +180,7 @@ context('Create remote detector workflow', () => {
160180
cy.wait(1000);
161181
cy.contains(
162182
'.euiComboBoxOption__content',
163-
'followCluster:sample-ad-index'
183+
`${remoteClusterName}:sample-ad-index`
164184
).click();
165185

166186
selectTopItemFromFilter('timestampFilter', false);
@@ -208,6 +228,8 @@ context('Create remote detector workflow', () => {
208228
});
209229

210230
it('Full creation - based on multiple indexes', () => {
231+
const remoteClusterName = Cypress.env('remoteClusterName');
232+
211233
// Define detector step
212234
cy.visit(AD_URL.CREATE_AD);
213235
cy.getElementByTestId('defineOrEditDetectorTitle').should('exist');
@@ -220,23 +242,26 @@ context('Create remote detector workflow', () => {
220242

221243
cy.getElementByTestId('clustersFilter').click();
222244
cy.getElementByTestId('clustersFilter').click();
245+
223246
cy.contains(
224247
'.euiComboBoxOption__content',
225-
'followCluster (Remote)'
248+
`${remoteClusterName} (Remote)`
226249
).click();
227250

228251
cy.wait(3000);
229252

230253
cy.getElementByTestId('indicesFilter').click();
231254
cy.wait(1000);
255+
232256
cy.contains(
233257
'.euiComboBoxOption__content',
234-
'followCluster:sample-ad-index'
258+
`${remoteClusterName}:sample-ad-index`
235259
).click();
236260
cy.contains('.euiComboBoxOption__content', 'sample-ad-index').click();
261+
237262
cy.contains(
238263
'.euiComboBoxOption__content',
239-
'followCluster:sample-ad-index-two'
264+
`${remoteClusterName}:sample-ad-index-two`
240265
).click();
241266

242267
selectTopItemFromFilter('timestampFilter', false);
@@ -297,8 +322,10 @@ context('Create remote detector workflow', () => {
297322
cy.contains('span.euiTableCellContent__text', 'Data connection').should(
298323
'be.visible'
299324
);
325+
cy.contains(`${remoteClusterName} (Remote)`).should('be.visible');
326+
300327
cy.contains('followCluster (Remote)').should('be.visible');
301-
cy.contains('leaderCluster (Local)').should('be.visible');
328+
cy.contains('(Local)').should('be.visible');
302329
cy.contains('sample-ad-index').should('be.visible');
303330

304331
cy.getElementByTestId('euiFlyoutCloseButton').click();
@@ -326,8 +353,8 @@ context('Create remote detector workflow', () => {
326353
cy.contains('span.euiTableCellContent__text', 'Data connection').should(
327354
'be.visible'
328355
);
329-
cy.contains('followCluster (Remote)').should('be.visible');
330-
cy.contains('leaderCluster (Local)').should('be.visible');
356+
cy.contains(`${remoteClusterName} (Remote)`).should('be.visible');
357+
cy.contains('(Local)').should('be.visible');
331358
cy.contains('sample-ad-index').should('be.visible');
332359
});
333360
});

0 commit comments

Comments
 (0)