Skip to content

Commit e4ff621

Browse files
authored
remove legacy and ppl alerting separation (#1392)
* remove legacy and ppl alerting separation Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * update unit tests Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * fix acknowledge_alerts_modal.spec.js cypress test Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * fix alert.spec.js cypress test Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * fix alerts_dashboard_flyout.spec.js cypress test Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> * fix bucket level monitor spec cypress test Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com> --------- Signed-off-by: KashKondaka <37753523+KashKondaka@users.noreply.github.com>
1 parent 8468812 commit e4ff621

File tree

41 files changed

+857
-2677
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+857
-2677
lines changed

.cypress/integration/acknowledge_alerts_modal.spec.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const TWENTY_SECONDS = 20000;
1818
const SIXTY_SECONDS = 60000;
1919

2020
describe('AcknowledgeAlertsModal', () => {
21+
let monitorIds = [];
22+
2123
before(() => {
2224
// Delete any existing monitors
2325
cy.deleteAllAlerts();
@@ -26,28 +28,36 @@ describe('AcknowledgeAlertsModal', () => {
2628
// Load sample data
2729
cy.loadSampleEcommerceData();
2830

29-
// Create the test monitors
30-
cy.createMonitor(sampleAlertsFlyoutBucketMonitor);
31-
cy.createMonitor(sampleAlertsFlyoutQueryMonitor);
31+
// Create monitors and execute once so initial alerts exist.
32+
cy.createMonitorsAndExecute([
33+
sampleAlertsFlyoutBucketMonitor,
34+
sampleAlertsFlyoutQueryMonitor,
35+
]).then((ids) => {
36+
monitorIds = ids;
37+
});
3238

3339
// Visit Alerting OpenSearch Dashboards
34-
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors`, { timeout: SIXTY_SECONDS });
40+
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors`, {
41+
timeout: SIXTY_SECONDS,
42+
});
3543

3644
// Confirm test monitors were created successfully
3745
cy.contains(BUCKET_MONITOR, { timeout: SIXTY_SECONDS });
3846
cy.contains(QUERY_MONITOR, { timeout: SIXTY_SECONDS });
39-
40-
// Wait 1 minute for the test monitors to trigger alerts, then go to the 'Alerts by trigger' dashboard page to view alerts
41-
cy.wait(60000);
4247
});
4348

4449
beforeEach(() => {
50+
// Execute monitors before each test so dashboard rows are deterministic.
51+
cy.executeMonitors(monitorIds);
52+
4553
// Reloading the page to close any modals that were not closed by other tests that had failures.
4654
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/dashboard`);
55+
cy.get('[data-test-subj="alertsDashboard_table"]', { timeout: TWENTY_SECONDS }).should('exist');
56+
cy.wait(5000);
4757

48-
// Confirm dashboard is displaying rows for the test monitors.
49-
cy.contains(BUCKET_MONITOR, { timeout: SIXTY_SECONDS });
50-
cy.contains(QUERY_MONITOR, { timeout: SIXTY_SECONDS });
58+
// Confirm dashboard is displaying rows for the test triggers.
59+
cy.contains(BUCKET_TRIGGER, { timeout: SIXTY_SECONDS });
60+
cy.contains(QUERY_TRIGGER, { timeout: SIXTY_SECONDS });
5161
});
5262

5363
it('Acknowledge button disabled when more than 1 trigger selected', () => {

.cypress/integration/alert.spec.js

Lines changed: 53 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import sampleQueryLevelMonitorWithAlwaysTrueTrigger from '../fixtures/sample_que
88
import sampleQueryLevelMonitorWorkflow from '../fixtures/sample_query_level_monitor_workflow';
99

1010
const TESTING_INDEX = 'alerting_test';
11+
const cloneFixture = (fixture) => JSON.parse(JSON.stringify(fixture));
1112

1213
describe('Alerts', () => {
1314
beforeEach(() => {
@@ -22,26 +23,28 @@ describe('Alerts', () => {
2223
});
2324

2425
describe("can be in 'Active' state", () => {
26+
let uniqueNumber;
27+
let monitorId;
28+
2529
before(() => {
2630
cy.deleteAllMonitors();
2731
// Generate a unique number in every test by getting a unix timestamp in milliseconds
28-
Cypress.config('unique_number', `${Date.now()}`);
29-
// Modify the monitor name to be unique
30-
sampleQueryLevelMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
31-
cy.createMonitor(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
32+
uniqueNumber = `${Date.now()}`;
33+
const monitor = cloneFixture(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
34+
monitor.name = `${monitor.name}-${uniqueNumber}`;
35+
cy.createMonitor(monitor).then((response) => {
36+
monitorId = response.body._id;
37+
});
3238
});
3339

3440
it('after the monitor starts running', () => {
35-
// Wait for 1 minute
36-
cy.wait(60000);
41+
cy.executeMonitors([monitorId]);
3742

3843
// Reload the page
3944
cy.reload();
4045

4146
// Type in monitor name in search box to filter out the alert
42-
cy.get(`input[type="search"]`)
43-
.focus()
44-
.type(`${Cypress.config('unique_number')}`);
47+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
4548

4649
// Confirm we can see one and only alert in Active state
4750
cy.get('tbody > tr').should(($tr) => {
@@ -52,19 +55,19 @@ describe('Alerts', () => {
5255
});
5356

5457
describe("can be in 'Acknowledged' state", () => {
58+
let uniqueNumber;
59+
5560
before(() => {
5661
cy.deleteAllMonitors();
57-
Cypress.config('unique_number', `${Date.now()}`);
58-
// Modify the monitor name to be unique
59-
sampleQueryLevelMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
60-
cy.createAndExecuteMonitor(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
62+
uniqueNumber = `${Date.now()}`;
63+
const monitor = cloneFixture(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
64+
monitor.name = `${monitor.name}-${uniqueNumber}`;
65+
cy.createAndExecuteMonitor(monitor);
6166
});
6267

6368
it('by clicking the button in Dashboard', () => {
6469
// Type in monitor name in search box to filter out the alert
65-
cy.get(`input[type="search"]`)
66-
.focus()
67-
.type(`${Cypress.config('unique_number')}`);
70+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
6871

6972
//Confirm there is an active alert
7073
cy.contains('Active');
@@ -82,21 +85,27 @@ describe('Alerts', () => {
8285
});
8386

8487
describe("can be in 'Completed' state", () => {
88+
let uniqueNumber;
89+
let monitorId;
90+
8591
before(() => {
8692
cy.deleteAllMonitors();
8793
// Delete the target indices defined in 'sample_monitor_workflow.json'
8894
cy.deleteIndexByName('alerting*');
89-
Cypress.config('unique_number', `${Date.now()}`);
90-
// Modify the monitor name to be unique
91-
sampleQueryLevelMonitorWorkflow.name += `-${Cypress.config('unique_number')}`;
92-
cy.createAndExecuteMonitor(sampleQueryLevelMonitorWorkflow);
95+
uniqueNumber = `${Date.now()}`;
96+
const monitor = cloneFixture(sampleQueryLevelMonitorWorkflow);
97+
monitor.name = `${monitor.name}-${uniqueNumber}`;
98+
cy.createMonitor(monitor).then((response) => {
99+
monitorId = response.body._id;
100+
});
101+
cy.then(() => {
102+
cy.executeMonitors([monitorId]);
103+
});
93104
});
94105

95106
it('when the trigger condition is not met after met once', () => {
96107
// Type in monitor name in search box to filter out the alert
97-
cy.get(`input[type="search"]`)
98-
.focus()
99-
.type(`${Cypress.config('unique_number')}`);
108+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
100109

101110
// Confirm there is an active alert
102111
cy.contains('Active');
@@ -109,16 +118,16 @@ describe('Alerts', () => {
109118
// Insert a document
110119
cy.insertDocumentToIndex('test', 1, {});
111120

112-
// Wait for 1 minute
113-
cy.wait(60000);
121+
// Execute monitor again after document insertion so the alert transitions to Completed.
122+
cy.then(() => {
123+
cy.executeMonitor(monitorId);
124+
});
114125

115126
// Reload the page
116127
cy.reload();
117128

118129
// Type in monitor name in search box to filter out the alert
119-
cy.get(`input[type="search"]`)
120-
.focus()
121-
.type(`${Cypress.config('unique_number')}`);
130+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
122131

123132
// Confirm we can see the alert is in 'Completed' state
124133
cy.contains('Completed');
@@ -131,43 +140,43 @@ describe('Alerts', () => {
131140
});
132141

133142
describe("can be in 'Error' state", () => {
143+
let uniqueNumber;
144+
134145
before(() => {
135146
cy.deleteAllMonitors();
147+
const monitor = cloneFixture(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
136148
// modify the JSON object to make an error alert when executing the monitor
137-
sampleQueryLevelMonitorWithAlwaysTrueTrigger.triggers[0].actions = [
149+
monitor.triggers[0].actions = [
138150
{ name: '', destination_id: '', message_template: { source: '' } },
139151
];
140-
Cypress.config('unique_number', `${Date.now()}`);
141-
// Modify the monitor name to be unique
142-
sampleQueryLevelMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
143-
cy.createAndExecuteMonitor(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
152+
uniqueNumber = `${Date.now()}`;
153+
monitor.name = `${monitor.name}-${uniqueNumber}`;
154+
cy.createAndExecuteMonitor(monitor);
144155
});
145156

146157
it('by using a wrong destination', () => {
147158
// Type in monitor name in search box to filter out the alert
148-
cy.get(`input[type="search"]`)
149-
.focus()
150-
.type(`${Cypress.config('unique_number')}`);
159+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
151160

152161
// Confirm we can see the alert is in 'Error' state
153162
cy.contains('Error');
154163
});
155164
});
156165

157166
describe("can be in 'Deleted' state", () => {
167+
let uniqueNumber;
168+
158169
before(() => {
159170
cy.deleteAllMonitors();
160-
Cypress.config('unique_number', `${Date.now()}`);
161-
// Modify the monitor name to be unique
162-
sampleQueryLevelMonitorWithAlwaysTrueTrigger.name += `-${Cypress.config('unique_number')}`;
163-
cy.createAndExecuteMonitor(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
171+
uniqueNumber = `${Date.now()}`;
172+
const monitor = cloneFixture(sampleQueryLevelMonitorWithAlwaysTrueTrigger);
173+
monitor.name = `${monitor.name}-${uniqueNumber}`;
174+
cy.createAndExecuteMonitor(monitor);
164175
});
165176

166177
it('by deleting the monitor', () => {
167178
// Type in monitor name in search box to filter out the alert
168-
cy.get(`input[type="search"]`)
169-
.focus()
170-
.type(`${Cypress.config('unique_number')}`);
179+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
171180

172181
//Confirm there is an active alert
173182
cy.contains('Active');
@@ -179,9 +188,7 @@ describe('Alerts', () => {
179188
cy.reload();
180189

181190
// Type in monitor name in search box to filter out the alert
182-
cy.get(`input[type="search"]`)
183-
.focus()
184-
.type(`${Cypress.config('unique_number')}`);
191+
cy.get(`input[type="search"]`).focus().type(uniqueNumber);
185192

186193
// Confirm we can see the alert is in 'Deleted' state
187194
cy.contains('Deleted');

.cypress/integration/alerts_dashboard_flyout.spec.js

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const QUERY_TRIGGER = 'sample_alerts_flyout_query_level_trigger';
1515
const TWENTY_SECONDS = 20000;
1616

1717
describe('Alerts by trigger flyout', () => {
18+
let monitorIds = [];
19+
1820
before(() => {
1921
// Delete any existing monitors
2022
cy.deleteAllMonitors();
@@ -28,9 +30,13 @@ describe('Alerts by trigger flyout', () => {
2830
timeout: TWENTY_SECONDS,
2931
});
3032

31-
// Create the test monitors
32-
cy.createMonitor(sampleAlertsFlyoutBucketMonitor);
33-
cy.createMonitor(sampleAlertsFlyoutQueryMonitor);
33+
// Create monitors and execute once so initial alerts exist.
34+
cy.createMonitorsAndExecute([
35+
sampleAlertsFlyoutBucketMonitor,
36+
sampleAlertsFlyoutQueryMonitor,
37+
]).then((ids) => {
38+
monitorIds = ids;
39+
});
3440

3541
// Visit Alerting OpenSearch Dashboards
3642
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/monitors`);
@@ -39,12 +45,12 @@ describe('Alerts by trigger flyout', () => {
3945
// Confirm test monitors were created successfully
4046
cy.contains(BUCKET_MONITOR, { timeout: TWENTY_SECONDS });
4147
cy.contains(QUERY_MONITOR, { timeout: TWENTY_SECONDS });
42-
43-
// Wait 1 minutes for the test monitors to trigger alerts, then go to the 'Alerts by trigger' dashboard page to view alerts
44-
cy.wait(60000);
4548
});
4649

4750
beforeEach(() => {
51+
// Re-execute monitors so each test gets fresh alert rows.
52+
cy.executeMonitors(monitorIds);
53+
4854
// Reloading the page to close any flyouts that were not closed by other tests that had failures.
4955
cy.visit(`${Cypress.env('opensearch_dashboards')}/app/${PLUGIN_NAME}#/dashboard`);
5056
cy.get('[data-test-subj="alertsDashboard_table"]', {

.cypress/integration/bucket_level_monitor.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ describe('Bucket-Level Monitors', () => {
321321

322322
describe('when defined by visual editor', () => {
323323
beforeEach(() => {
324-
cy.createMonitor(sampleVisualEditorMonitor);
324+
cy.createMonitors([sampleVisualEditorMonitor]);
325325
cy.reload();
326326
});
327327

.cypress/support/commands.js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,18 @@ Cypress.Commands.add('createMonitor', (monitorJSON) => {
7575
method: 'POST',
7676
url: `${Cypress.env('opensearch')}${API.MONITOR_BASE}`,
7777
body: monitorJSON,
78-
timeout: 60000
78+
timeout: 60000,
79+
});
80+
});
81+
82+
Cypress.Commands.add('createMonitors', (monitorJSONList = []) => {
83+
const monitorIDs = [];
84+
monitorJSONList.forEach((monitorJSON) => {
85+
cy.createMonitor(monitorJSON).then((response) => {
86+
monitorIDs.push(response.body._id);
87+
});
7988
});
89+
return cy.then(() => cy.wrap(monitorIDs));
8090
});
8191

8292
Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => {
@@ -94,6 +104,27 @@ Cypress.Commands.add('executeMonitor', (monitorID) => {
94104
cy.request('POST', `${Cypress.env('opensearch')}${API.MONITOR_BASE}/${monitorID}/_execute`);
95105
});
96106

107+
Cypress.Commands.add('executeMonitors', (monitorIDs = []) => {
108+
monitorIDs.forEach((monitorID) => {
109+
cy.executeMonitor(monitorID);
110+
});
111+
});
112+
113+
Cypress.Commands.add('createMonitorsAndExecute', (monitorJSONList = []) => {
114+
const monitorIDs = [];
115+
monitorJSONList.forEach((monitorJSON) => {
116+
cy.createMonitor(monitorJSON).then((response) => {
117+
monitorIDs.push(response.body._id);
118+
});
119+
});
120+
121+
return cy
122+
.then(() => {
123+
cy.executeMonitors(monitorIDs);
124+
})
125+
.then(() => cy.wrap(monitorIDs));
126+
});
127+
97128
Cypress.Commands.add('executeCompositeMonitor', (monitorID) => {
98129
cy.request('POST', `${Cypress.env('opensearch')}${API.WORKFLOW_BASE}/${monitorID}/_execute`);
99130
});

0 commit comments

Comments
 (0)