Skip to content

Commit

Permalink
Integrate Alerting Dashboards with Notifications Plugin (#220)
Browse files Browse the repository at this point in the history
* Add NotificationsCallOut and NotificationsInfoCallOut components

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

* Add NotificationService

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

* Add NotificationsInfoCallOut on Destinations page and disable creating/editing Destination objects

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

* Add option to select both Destinations and Notification Channels when defining Action

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

* Disable unused buttons and fix issue with channels loading on existing Monitor

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

* Update Jest snapshots

Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>

* Remove Destination related Cypress tests

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

* Remove leftover deletion of Destinations in Cypress test clean-up

Signed-off-by: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com>

Co-authored-by: Ashish Agrawal <ashisagr@amazon.com>
  • Loading branch information
qreshi and lezzago committed Apr 19, 2022
1 parent 259335a commit fbea210
Show file tree
Hide file tree
Showing 52 changed files with 3,656 additions and 874 deletions.
6 changes: 5 additions & 1 deletion babel.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// babelrc doesn't respect NODE_PATH anymore but using require does.
// Alternative to install them locally in node_modules
module.exports = {
presets: [require('@babel/preset-env'), require('@babel/preset-react')],
presets: [
require('@babel/preset-env'),
require('@babel/preset-react'),
require('@babel/preset-typescript'),
],
plugins: [
require('@babel/plugin-proposal-class-properties'),
require('@babel/plugin-proposal-object-rest-spread'),
Expand Down
7 changes: 0 additions & 7 deletions cypress/fixtures/sample_destination_chime.json

This file was deleted.

10 changes: 0 additions & 10 deletions cypress/fixtures/sample_destination_custom_webhook.json

This file was deleted.

2 changes: 0 additions & 2 deletions cypress/integration/bucket_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import { INDEX, PLUGIN_NAME } from '../support/constants';
import sampleAggregationQuery from '../fixtures/sample_aggregation_query';
import sampleDestination from '../fixtures/sample_destination_custom_webhook';
import sampleExtractionQueryMonitor from '../fixtures/sample_extraction_query_bucket_level_monitor';
import sampleVisualEditorMonitor from '../fixtures/sample_visual_editor_bucket_level_monitor';

Expand Down Expand Up @@ -309,7 +308,6 @@ describe('Bucket-Level Monitors', () => {
after(() => {
// Delete all monitors and destinations
cy.deleteAllMonitors();
cy.deleteAllDestinations();

// Delete sample data
cy.deleteIndexByName(`${INDEX.SAMPLE_DATA_ECOMMERCE}`);
Expand Down
2 changes: 0 additions & 2 deletions cypress/integration/cluster_metrics_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0
*/

import sampleDestination from '../fixtures/sample_destination_custom_webhook';
import sampleClusterMetricsMonitor from '../fixtures/sample_cluster_metrics_monitor.json';
import { INDEX, PLUGIN_NAME } from '../../cypress/support/constants';

Expand Down Expand Up @@ -392,7 +391,6 @@ describe('ClusterMetricsMonitor', () => {
after(() => {
// Delete all monitors and destinations
cy.deleteAllMonitors();
cy.deleteAllDestinations();

// Delete sample data
cy.deleteIndexByName(`${INDEX.SAMPLE_DATA_ECOMMERCE}`);
Expand Down
137 changes: 0 additions & 137 deletions cypress/integration/destination_spec.js

This file was deleted.

2 changes: 0 additions & 2 deletions cypress/integration/query_level_monitor_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import _ from 'lodash';
import { INDEX, PLUGIN_NAME } from '../support/constants';
import sampleQueryLevelMonitor from '../fixtures/sample_query_level_monitor';
import sampleQueryLevelMonitorWithAlwaysTrueTrigger from '../fixtures/sample_query_level_monitor_with_always_true_trigger';
import sampleDestination from '../fixtures/sample_destination_custom_webhook.json';

const SAMPLE_MONITOR = 'sample_query_level_monitor';
const UPDATED_MONITOR = 'updated_query_level_monitor';
Expand Down Expand Up @@ -314,7 +313,6 @@ describe('Query-Level Monitors', () => {
after(() => {
// Delete all existing monitors and destinations
cy.deleteAllMonitors();
cy.deleteAllDestinations();

// Delete sample data
cy.deleteIndexByName(`${INDEX.SAMPLE_DATA_ECOMMERCE}`);
Expand Down
23 changes: 0 additions & 23 deletions cypress/support/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,6 @@ Cypress.Commands.add('createMonitor', (monitorJSON) => {
cy.request('POST', `${Cypress.env('opensearch')}${API.MONITOR_BASE}`, monitorJSON);
});

Cypress.Commands.add('createDestination', (destinationJSON) => {
cy.request('POST', `${Cypress.env('opensearch')}${API.DESTINATION_BASE}`, destinationJSON);
});

Cypress.Commands.add('createAndExecuteMonitor', (monitorJSON) => {
cy.request('POST', `${Cypress.env('opensearch')}${API.MONITOR_BASE}`, monitorJSON).then(
(response) => {
Expand Down Expand Up @@ -138,25 +134,6 @@ Cypress.Commands.add('deleteAllMonitors', () => {
});
});

Cypress.Commands.add('deleteAllDestinations', () => {
cy.request({
method: 'GET',
url: `${Cypress.env('opensearch')}${API.DESTINATION_BASE}?size=200`,
failOnStatusCode: false, // In case there is no alerting config index in cluster, where the status code is 404
}).then((response) => {
if (response.status === 200) {
for (let i = 0; i < response.body.totalDestinations; i++) {
cy.request(
'DELETE',
`${Cypress.env('opensearch')}${API.DESTINATION_BASE}/${response.body.destinations[i].id}`
);
}
} else {
cy.log('Failed to get all destinations.', response);
}
});
});

Cypress.Commands.add('createIndexByName', (indexName) => {
cy.request('PUT', `${Cypress.env('opensearch')}/${indexName}`);
});
Expand Down
16 changes: 11 additions & 5 deletions public/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ import 'react-vis/dist/style.css';
// import './less/main.less';
import Main from './pages/Main';
import { CoreContext } from './utils/CoreContext';
import { ServicesContext, NotificationService } from './services';

export function renderApp(coreStart, params) {
const isDarkMode = coreStart.uiSettings.get('theme:darkMode') || false;
const http = coreStart.http;
coreStart.chrome.setBreadcrumbs([{ text: 'Alerting' }]); // Set Breadcrumbs for the plugin
const notificationService = new NotificationService(http);
const services = { notificationService };

// Load Chart's dark mode CSS
if (isDarkMode) {
Expand All @@ -27,11 +31,13 @@ export function renderApp(coreStart, params) {
// render react to DOM
ReactDOM.render(
<Router>
<CoreContext.Provider
value={{ http: coreStart.http, isDarkMode, notifications: coreStart.notifications }}
>
<Route render={(props) => <Main title="Alerting" {...props} />} />
</CoreContext.Provider>
<ServicesContext.Provider value={services}>
<CoreContext.Provider
value={{ http: coreStart.http, isDarkMode, notifications: coreStart.notifications }}
>
<Route render={(props) => <Main title="Alerting" {...props} />} />
</CoreContext.Provider>
</ServicesContext.Provider>
</Router>,
params.element
);
Expand Down
10 changes: 10 additions & 0 deletions public/models/interfaces.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { NotificationService } from '../services';

export interface BrowserServices {
notificationService: NotificationService;
}
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ export default class CreateMonitor extends Component {
monitorToEdit,
notifications,
isDarkMode,
notificationService,
} = this.props;
const { initialValues, plugins } = this.state;

Expand Down Expand Up @@ -296,6 +297,8 @@ export default class CreateMonitor extends Component {
isDarkMode={this.props.isDarkMode}
httpClient={httpClient}
notifications={notifications}
notificationService={notificationService}
plugins={plugins}
/>
)}
</FieldArray>
Expand Down
Loading

0 comments on commit fbea210

Please sign in to comment.