Skip to content

Commit

Permalink
[FEATURE] Add composite monitor type opensearch-project#573
Browse files Browse the repository at this point in the history
Signed-off-by: Jovan Cvetkovic <[email protected]>
  • Loading branch information
jovancvetkovic3006 committed Jun 20, 2023
1 parent 8e5723b commit 12f0e6f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 23 deletions.
55 changes: 32 additions & 23 deletions cypress/integration/composite_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ const clearAll = () => {
cy.deleteAllMonitors();
cy.deleteIndexByName(sample_index_1);
cy.deleteIndexByName(sample_index_2);
cy.deleteAllAlerts();

// wait until alerts index finishes writing docs
cy.wait(1000).then(() => cy.deleteAllAlerts());
};

describe('CompositeLevelMonitor', () => {
Expand Down Expand Up @@ -81,37 +83,44 @@ describe('CompositeLevelMonitor', () => {
// cy.get('[title="Notification 1"]').type('Channel name');

cy.intercept('api/alerting/workflows').as('createMonitorRequest');
cy.intercept('api/alerting/monitors').as('getMonitorsRequest');
cy.intercept(`api/alerting/monitors?*`).as('getMonitorsRequest');
cy.get('button').contains('Create').click({ force: true });

// Wait for monitor to be created
cy.wait('@createMonitorRequest').then((interceptor) => {
const monitorID = interceptor.response.body.resp._id;

cy.contains('Loading monitors');
cy.wait('@getMonitorsRequest');

// Let monitor's table render the rows before querying
cy.wait(1000).then(() => {
cy.get('table tbody td').contains(SAMPLE_VISUAL_EDITOR_MONITOR);

// Load sample data
cy.insertDocumentToIndex(
sample_index_1,
undefined,
sampleCompositeJson.sample_composite_associated_index_document
);
cy.insertDocumentToIndex(
sample_index_2,
undefined,
sampleCompositeJson.sample_composite_associated_index_document
);
cy.wait('@getMonitorsRequest').then((interceptor) => {
const monitors = interceptor.response.body.monitors;
const monitor1 = monitors.filter((monitor) => monitor.name === 'monitor_1');
const monitor2 = monitors.filter((monitor) => monitor.name === 'monitor_2');

// Let monitor's table render the rows before querying
cy.wait(1000).then(() => {
cy.executeCompositeMonitor(monitorID);

cy.get('[role="tab"]').contains('Alerts').click();
cy.get('table tbody td').contains('Composite trigger');
cy.get('table tbody td').contains(SAMPLE_VISUAL_EDITOR_MONITOR);

// Load sample data
cy.insertDocumentToIndex(
sample_index_1,
undefined,
sampleCompositeJson.sample_composite_associated_index_document
);
cy.insertDocumentToIndex(
sample_index_2,
undefined,
sampleCompositeJson.sample_composite_associated_index_document
);

cy.wait(1000).then(() => {
cy.executeCompositeMonitor(monitorID);
debugger;
monitor1[0] && cy.executeMonitor(monitor1[0].id);
monitor2[0] && cy.executeMonitor(monitor2[0].id);

cy.get('[role="tab"]').contains('Alerts').click();
cy.get('table tbody td').contains('Composite trigger');
});
});
});
});
Expand Down
4 changes: 4 additions & 0 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => {
);
});

Cypress.Commands.add('executeMonitor', (monitorID) => {
cy.request('POST', `${Cypress.env('opensearch')}${API.MONITOR_BASE}/${monitorID}/_execute`);
});

Cypress.Commands.add('executeCompositeMonitor', (monitorID) => {
cy.request('POST', `${Cypress.env('opensearch')}${API.WORKFLOW_BASE}/${monitorID}/_execute`);
});
Expand Down

0 comments on commit 12f0e6f

Please sign in to comment.