From 24e0bc74014325de63d194f1a0b2dfb59007cb93 Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Tue, 7 Sep 2021 17:45:37 -0700 Subject: [PATCH 01/29] Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md (#101) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md Signed-off-by: Annie Lee * Update opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md Signed-off-by: Annie Lee * Update comments Signed-off-by: Annie Lee --- .../CreateTrigger/utils/triggerToFormik.js | 2 +- .../MonitorHistory/MonitorHistory.js | 2 +- ...dashboards-plugin.release-notes-1.1.0.0.md | 49 +++++++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md diff --git a/public/pages/CreateTrigger/containers/CreateTrigger/utils/triggerToFormik.js b/public/pages/CreateTrigger/containers/CreateTrigger/utils/triggerToFormik.js index 21569c533..c3aacb16b 100644 --- a/public/pages/CreateTrigger/containers/CreateTrigger/utils/triggerToFormik.js +++ b/public/pages/CreateTrigger/containers/CreateTrigger/utils/triggerToFormik.js @@ -187,7 +187,7 @@ export function bucketLevelTriggerToFormik(trigger, monitor) { anomalyDetector: { /*If trigger type doesn't exist fallback to query trigger with following reasons 1. User has changed monitory type from normal monitor to AD monitor. - 2. User has created / updated from API and visiting Kibana to do other operations. + 2. User has created / updated from API and visiting OpenSearch Dashboards to do other operations. */ triggerType: triggerType ? triggerType : TRIGGER_TYPE.ALERT_TRIGGER, anomalyGradeThresholdValue, diff --git a/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js b/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js index 1efcbc922..0c7c8d085 100644 --- a/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js +++ b/public/pages/MonitorDetails/containers/MonitorHistory/MonitorHistory.js @@ -185,7 +185,7 @@ class MonitorHistory extends PureComponent { /* brushAreaStart Duration is to defined the start point for smaller window over zoomer on which time line will be displayed. Duration will default to what interval has been - computed to ES bucket in case it is too small, + computed to OpenSearch bucket in case it is too small, just scale it so that customer can have better experience */ const { diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md new file mode 100644 index 000000000..8070f916f --- /dev/null +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -0,0 +1,49 @@ +## Version 1.1.0.0 2021-09-07 + +Compatible with OpenSearch Dashboards 1.1.0 + +### Features + +* Bucket level alerting create monitor page refactor ([#62](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/62)) +* Add DefineBucketLevelTrigger component ([#63](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/63)) +* Refactor CreateTrigger components to support single-page experience ([#64](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/64)) +* Update CreateMonitor to incorporate new single-page experience ([#65](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/65)) +* Update Monitor overview page ([#66](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/66)) +* Alert dashboard table column update ([#67](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/67)) +* Refactored query and bucket-level trigger definitions to align with new mocks ([#68](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/68)) +* Alert dashboard update on monitor ([#72](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/72)) +* Create monitor page, bucket level monitor showing bar graph ([#73](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/73)) +* Use destination api to validate destination name ([#69](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/69)) +* Update Monitor Details panel ([#75](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/75)) +* Flyout panel on alert dashboard page ([#78](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/78)) +* Add button to refresh graph , add accordion to expand/collapse graph view ([#79](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/79)) +* Add success toast message for create and update monitor ([#80](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/80)) +* Refactored trigger condition popover to dropdown menu. Refactored actions panel to hide throttling for 'per execution' ([#81](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/81)) +* Added Export JSON button and modal to create/edit Monitor page ([#82](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/82)) +* Added Monitor state EuiHealth element, replaced state item in overview with Monitor level type ([#83](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/83)) +* Update alert history graph for bucket-level monitors ([#84](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/84)) +* Refactored query trigger definition components to align with mocks. ([#85](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/85)) +* Removed the close button from the top-right of the alert dashboard flyout. Refactored monitor details page for anomaly detection monitors. ([#86](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/86)) +* Several changes in query panel ([#87](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/87)) +* Implemented test message toast. Fixed alerts dashboard severity display bug. ([#88](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/88)) +* Refactored Dashboard::getMonitors to function without using the from and size parameters from getAlerts ([#89](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/89)) +* Query level monitor updates ([#90](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/90)) +* Changes of metrics expression and graph ([#95](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/95)) +* Update formik conversion for Bucket-Level Trigger to handle throttle change ([#97](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/97)) +* Implemented View alert details, and logic for landing page alerts dashboard. ([#98](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/98)) +* Added limit text, adjusted spacing/sizing/text, etc. ([#100](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/100)) +* Remove pagination and set default size of alerts pert trigger to 10000 ([#99](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/99)) + +### Enhancements + +* Show Error Toast Message whenever action execution fails from backend due to incorrect configurations ([#22](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/22)) +* Bucket level alerting dev UX review feedback ([#93](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/93)) + +### Maintenance + +* Commit the updated yarn lock to maintain consistency. ([#26](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/26)) +* Add Integtest.sh for OpenSearch integtest setups ([#28](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/28)) +* Allow for custom endpoints for cypress tests ([#29](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/29)) +* Add Cypress tests for Bucket-Level Alerting ([#91](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/91)) +* Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) +* Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md #101 ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) \ No newline at end of file From 148066127689c80657534dc41fd86350c168e06f Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Wed, 8 Sep 2021 10:43:21 -0700 Subject: [PATCH 02/29] Update version in package.json (#102) * Update package.json * Update opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md Signed-off-by: Annie Lee * Update opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md Signed-off-by: Annie Lee --- package.json | 2 +- ...nsearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 410e8e107..d8e333370 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "opensearch-alerting-dashboards", - "version": "1.0.0.0", + "version": "1.1.0.0", "description": "OpenSearch Dashboards Alerting Plugin", "main": "index.js", "license": "Apache-2.0", diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index 8070f916f..08a5d3ce9 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -46,4 +46,5 @@ Compatible with OpenSearch Dashboards 1.1.0 * Allow for custom endpoints for cypress tests ([#29](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/29)) * Add Cypress tests for Bucket-Level Alerting ([#91](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/91)) * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) -* Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md #101 ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) \ No newline at end of file +* Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) +* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) \ No newline at end of file From 7e781aa476f465d9669a7e860d86145bfd2415e4 Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Fri, 10 Sep 2021 11:25:02 -0700 Subject: [PATCH 03/29] Text updates (#105) * Add icon tooltip * Update text and rename MonitorDefinitionCard directory * Update Schedule.js * Update Schedule.js Signed-off-by: Annie Lee * Update opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md * Remove license Signed-off-by: Annie Lee --- public/components/IconToolTip/IconToolTip.js | 28 +++++++++++++++++++ public/components/IconToolTip/index.js | 14 ++++++++++ .../MonitorDefinitionCard.js | 0 .../index.js | 0 .../expressions/ForExpression.js | 5 +++- .../expressions/GroupByExpression.js | 10 +++++-- .../expressions/MetricExpression.js | 11 ++++++-- .../expressions/WhereExpression.js | 10 +++++-- .../components/MonitorType/MonitorType.js | 6 ++-- .../components/Schedule/Schedule.js | 6 ++-- .../CreateMonitor/utils/constants.js | 6 ++++ .../MonitorDetails/MonitorDetails.js | 3 +- ...dashboards-plugin.release-notes-1.1.0.0.md | 1 + 13 files changed, 84 insertions(+), 16 deletions(-) create mode 100644 public/components/IconToolTip/IconToolTip.js create mode 100644 public/components/IconToolTip/index.js rename public/pages/CreateMonitor/components/{MonitorDefinitionCards => MonitorDefinitionCard}/MonitorDefinitionCard.js (100%) rename public/pages/CreateMonitor/components/{MonitorDefinitionCards => MonitorDefinitionCard}/index.js (100%) diff --git a/public/components/IconToolTip/IconToolTip.js b/public/components/IconToolTip/IconToolTip.js new file mode 100644 index 000000000..bc9ac2366 --- /dev/null +++ b/public/components/IconToolTip/IconToolTip.js @@ -0,0 +1,28 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import PropTypes from 'prop-types'; +import { EuiIcon, EuiToolTip } from '@elastic/eui'; + +const IconToolTip = ({ iconType, content, position = 'top' }) => ( + + + +); + +IconToolTip.propTypes = { + iconType: PropTypes.string.isRequired, + content: PropTypes.string, + position: PropTypes.string, +}; + +export default IconToolTip; diff --git a/public/components/IconToolTip/index.js b/public/components/IconToolTip/index.js new file mode 100644 index 000000000..7421fd0a2 --- /dev/null +++ b/public/components/IconToolTip/index.js @@ -0,0 +1,14 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import IconToolTip from './IconToolTip'; + +export default IconToolTip; diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCards/MonitorDefinitionCard.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js similarity index 100% rename from public/pages/CreateMonitor/components/MonitorDefinitionCards/MonitorDefinitionCard.js rename to public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCards/index.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/index.js similarity index 100% rename from public/pages/CreateMonitor/components/MonitorDefinitionCards/index.js rename to public/pages/CreateMonitor/components/MonitorDefinitionCard/index.js diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/ForExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/ForExpression.js index d1e6233be..ad3c2204e 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/ForExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/ForExpression.js @@ -29,13 +29,16 @@ import { EuiText, EuiFlexGroup, EuiFlexItem, EuiSpacer } from '@elastic/eui'; import { UNITS_OF_TIME } from './utils/constants'; import { FormikFieldNumber, FormikSelect } from '../../../../../components/FormControls'; import { hasError, isInvalid, validatePositiveInteger } from '../../../../../utils/validate'; +import IconToolTip from '../../../../../components/IconToolTip'; +import { TIME_RANGE_TOOLTIP_TEXT } from '../../../containers/CreateMonitor/utils/constants'; class ForExpression extends Component { render() { return (
- Time range for the last + Time range for the last + diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js index 3d6722678..34fdaa97b 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js @@ -33,6 +33,11 @@ import GroupByItem from './GroupByItem'; import { GROUP_BY_ERROR } from './utils/constants'; import { MONITOR_TYPE } from '../../../../../utils/constants'; import { inputLimitText } from '../../../../../utils/helpers'; +import { + GROUP_BY_TOOLTIP_TEXT, + TIME_RANGE_TOOLTIP_TEXT, +} from '../../../containers/CreateMonitor/utils/constants'; +import IconToolTip from '../../../../../components/IconToolTip'; export const MAX_NUM_QUERY_LEVEL_GROUP_BYS = 1; export const MAX_NUM_BUCKET_LEVEL_GROUP_BYS = 2; @@ -103,8 +108,9 @@ class GroupByExpression extends Component { return (
- Group by - {!isBucketLevelMonitor ? - optional : null} + Group by + {!isBucketLevelMonitor ? - optional : null} + diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js index 223ef2ffa..495808e26 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js @@ -26,14 +26,18 @@ import React, { Component } from 'react'; import { connect } from 'formik'; -import { EuiText, EuiButtonEmpty, EuiSpacer, EuiBadge } from '@elastic/eui'; +import { EuiText, EuiButtonEmpty, EuiSpacer, EuiBadge, EuiToolTip, EuiIcon } from '@elastic/eui'; import { getIndexFields } from './utils/dataTypes'; import { getMetricExpressionAllowedTypes, validateAggregationsDuplicates } from './utils/helpers'; import _ from 'lodash'; -import { FORMIK_INITIAL_AGG_VALUES } from '../../../containers/CreateMonitor/utils/constants'; +import { + FORMIK_INITIAL_AGG_VALUES, + METRIC_TOOLTIP_TEXT, +} from '../../../containers/CreateMonitor/utils/constants'; import { MetricItem } from './index'; import { MONITOR_TYPE } from '../../../../../utils/constants'; import { inputLimitText } from '../../../../../utils/helpers'; +import IconToolTip from '../../../../../components/IconToolTip'; export const MAX_NUM_QUERY_LEVEL_METRICS = 1; export const MAX_NUM_BUCKET_LEVEL_METRICS = 5; @@ -111,7 +115,8 @@ class MetricExpression extends Component {
Metrics - - optional + - optional + diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index ca8499fb0..68d112a8b 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -63,7 +63,11 @@ import { FormikFieldText, } from '../../../../../components/FormControls'; import { getFilteredIndexFields, getIndexFields } from './utils/dataTypes'; -import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; +import { + FILTERS_TOOLTIP_TEXT, + FORMIK_INITIAL_VALUES, + TIME_RANGE_TOOLTIP_TEXT, +} from '../../../containers/CreateMonitor/utils/constants'; import { DATA_TYPES } from '../../../../../utils/constants'; import { TRIGGER_COMPARISON_OPERATORS, @@ -71,6 +75,7 @@ import { } from '../../../../CreateTrigger/containers/DefineBucketLevelTrigger/DefineBucketLevelTrigger'; import { FORMIK_INITIAL_TRIGGER_VALUES } from '../../../../CreateTrigger/containers/CreateTrigger/utils/constants'; import { inputLimitText } from '../../../../../utils/helpers'; +import IconToolTip from '../../../../../components/IconToolTip'; const propTypes = { formik: PropTypes.object.isRequired, @@ -243,7 +248,8 @@ class WhereExpression extends Component {
{whereFilterHeader} - - optional + - optional + diff --git a/public/pages/CreateMonitor/components/MonitorType/MonitorType.js b/public/pages/CreateMonitor/components/MonitorType/MonitorType.js index 4d0752f8a..cdefd5147 100644 --- a/public/pages/CreateMonitor/components/MonitorType/MonitorType.js +++ b/public/pages/CreateMonitor/components/MonitorType/MonitorType.js @@ -44,14 +44,14 @@ const onChangeDefinition = (e, form) => { const queryLevelDescription = ( - Per query monitors run a specified query and allow you to define triggers based on the result of - that query. + Per query monitors run a specified query and define triggers that check the results of that + query. ); const bucketLevelDescription = ( - Per bucket monitors allow you to group results into buckets and define triggers that run per + Per bucket monitors allow you to group results into buckets and define triggers that check each bucket. ); diff --git a/public/pages/CreateMonitor/components/Schedule/Schedule.js b/public/pages/CreateMonitor/components/Schedule/Schedule.js index d186ca9dd..0eff9e68f 100644 --- a/public/pages/CreateMonitor/components/Schedule/Schedule.js +++ b/public/pages/CreateMonitor/components/Schedule/Schedule.js @@ -38,9 +38,9 @@ const Schedule = ({ isAd }) => ( {isAd ? (

- Define how often the monitor collects data and determines how often you may receive - alerts. We recommend scheduling the monitor at least twice the detector interval to avoid - missing anomaly results. + Define how often the monitor collects data and how often you may receive alerts. We + recommend setting this frequency to two times the detector interval to avoid missing + anomalous results from delayed processing time.

) : null} diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/utils/constants.js b/public/pages/CreateMonitor/containers/CreateMonitor/utils/constants.js index bbca91e9d..d71ca3790 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/utils/constants.js +++ b/public/pages/CreateMonitor/containers/CreateMonitor/utils/constants.js @@ -75,3 +75,9 @@ export const FORMIK_INITIAL_AGG_VALUES = { }; export const DEFAULT_COMPOSITE_AGG_SIZE = 50; + +export const METRIC_TOOLTIP_TEXT = 'Extracted statistics such as simple calculations of data.'; +export const TIME_RANGE_TOOLTIP_TEXT = 'The time frame of data the plugin should monitor.'; +export const FILTERS_TOOLTIP_TEXT = + 'Use a filter to retrieve a subset of the original data source.'; +export const GROUP_BY_TOOLTIP_TEXT = 'Specify a field whose every unique value can trigger alerts.'; diff --git a/public/pages/CreateMonitor/containers/MonitorDetails/MonitorDetails.js b/public/pages/CreateMonitor/containers/MonitorDetails/MonitorDetails.js index 7687ab738..3a60d073e 100644 --- a/public/pages/CreateMonitor/containers/MonitorDetails/MonitorDetails.js +++ b/public/pages/CreateMonitor/containers/MonitorDetails/MonitorDetails.js @@ -30,7 +30,7 @@ import ContentPanel from '../../../../components/ContentPanel'; import FormikFieldText from '../../../../components/FormControls/FormikFieldText'; import { hasError, isInvalid, required, validateMonitorName } from '../../../../utils/validate'; import Schedule from '../../components/Schedule'; -import MonitorDefinitionCard from '../../components/MonitorDefinitionCards'; +import MonitorDefinitionCard from '../../components/MonitorDefinitionCard'; import MonitorType from '../../components/MonitorType'; import AnomalyDetectors from '../AnomalyDetectors/AnomalyDetectors'; @@ -62,7 +62,6 @@ function renderEmptyMessage(message) { ); } -// TODO: Make sure that resetResponse is defined in Query and passed to MonitorDetails const MonitorDetails = ({ values, errors, diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index 08a5d3ce9..1069c108e 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -38,6 +38,7 @@ Compatible with OpenSearch Dashboards 1.1.0 * Show Error Toast Message whenever action execution fails from backend due to incorrect configurations ([#22](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/22)) * Bucket level alerting dev UX review feedback ([#93](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/93)) +* Text updates ([#105](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/105)) ### Maintenance From 588114c7dbdb019bac116f595eab39e892753ae5 Mon Sep 17 00:00:00 2001 From: AWSHurneyt <79280347+AWSHurneyt@users.noreply.github.com> Date: Fri, 10 Sep 2021 14:06:35 -0700 Subject: [PATCH 04/29] Added badges to the package README, and the Uploads coverage job to the unit tests workflow. (#104) * Added badges to the package README, and the Uploads coverage job to the unit tests workflow. * Removing code coverage upload token. --- .github/workflows/unit-tests-workflow.yml | 4 +++- README.md | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/unit-tests-workflow.yml b/.github/workflows/unit-tests-workflow.yml index 1a156a396..d89b763e1 100644 --- a/.github/workflows/unit-tests-workflow.yml +++ b/.github/workflows/unit-tests-workflow.yml @@ -45,4 +45,6 @@ jobs: - name: Run tests run: | cd OpenSearch-Dashboards/plugins/alerting-dashboards-plugin - yarn run test:jest + yarn run test:jest --coverage + - name: Uploads coverage + uses: codecov/codecov-action@v1 diff --git a/README.md b/README.md index f1bcb71b5..132ec2046 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +[![Unit tests](https://github.com/opensearch-project/alerting-dashboards-plugin/workflows/Unit%20tests%20workflow/badge.svg)](https://github.com/opensearch-project/alerting-dashboards-plugin/actions?query=workflow%3A%22Unit+tests+workflow%22) +[![Integration tests](https://github.com/opensearch-project/alerting-dashboards-plugin/workflows/E2E%20Cypress%20tests/badge.svg)](https://github.com/opensearch-project/alerting-dashboards-plugin/actions?query=workflow%3A%22E2E+Cypress+tests%22) +[![codecov](https://codecov.io/gh/opensearch-project/alerting-dashboards-plugin/branch/main/graph/badge.svg)](https://codecov.io/gh/opensearch-project/alerting-dashboards-plugin) +[![Documentation](https://img.shields.io/badge/doc-reference-blue)](https://opensearch.org/docs/monitoring-plugins/alerting/index/) +[![Forum](https://img.shields.io/badge/chat-on%20forums-blue)](https://discuss.opendistrocommunity.dev/c/Use-this-category-for-all-questions-around-machine-learning-plugins) +![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success) + - [OpenSearch Alerting Dashboards](#opensearch-alerting-dashboards) From ae789280740d7000d1f13245019414abeedfc286 Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Tue, 14 Sep 2021 17:48:58 -0700 Subject: [PATCH 05/29] Update jest unit tests (#112) * Update .opensearch_dashboards-plugin-helpers.json * Update snapshots * Update whereExpression.test and some snapshots * Update whereExpression.test and some snapshots Signed-off-by: Annie Lee * Update snapshots * Update formikToTrigger.test.js * Update formikToTrigger.test.js * Update formikToTrigger.test.js * Add icon tooltip * Add test * Update tests * remove license * Update TriggerExpressions.test.js * Update Triggers.test.js * Update validation test * Update getOverviewStats.test.js * Update validate.test.js * Update helpers.test.js and remove unused import * Update Triggers.test.js * Update helpers.js * Update CreateMonitor test and clean up code * Update CreateMonitor test and clean up code Signed-off-by: Annie Lee * Update release note and adding more tests * Add test and modify cypress common-utils branch * Update MonitorDefinitionCard.test.js.snap * Update cypress-workflow.yml --- .github/workflows/cypress-workflow.yml | 4 +- .../__snapshots__/Breadcrumbs.test.js.snap | 2 +- .../__snapshots__/ContentPanel.test.js.snap | 8 + .../Flyout/__snapshots__/Flyout.test.js.snap | 1 + .../__snapshots__/flyouts.test.js.snap | 1 + .../FormikCheckableCard.test.js | 38 ++ .../FormikCheckableCard.test.js.snap | 70 +++ .../FormikCodeEditor/FormikCodeEditor.test.js | 12 +- .../FormikCodeEditor.test.js.snap | 70 +++ .../IconToolTip/IconToolTip.test.js | 22 + .../__snapshots__/IconToolTip.test.js.snap | 11 + .../FeatureChart/FeatureChart.test.js | 50 ++ .../__snapshots__/FeatureChart.test.js.snap | 3 + .../ExtractionQuery/ExtractionQuery.test.js | 10 +- .../ExtractionQuery.test.js.snap | 111 ++++ .../MonitorDefinition.test.js.snap | 82 +-- .../MonitorDefinitionCard.js | 2 +- .../MonitorDefinitionCard.test.js | 39 ++ .../MonitorDefinitionCard.test.js.snap | 303 ++++++++++ .../MonitorExpressions.test.js | 2 +- .../MonitorExpressions.test.js.snap | 343 +++++++++--- .../expressions/WhereExpression.test.js | 7 +- .../__snapshots__/ForExpression.test.js.snap | 109 +++- .../WhereExpression.test.js.snap | 63 ++- .../MonitorTimeField/MonitorTimeField.test.js | 2 +- .../MonitorTimeField.test.js.snap | 114 ++-- .../MonitorType/MonitorType.test.js | 27 + .../__snapshots__/MonitorType.test.js.snap | 158 ++++++ .../QueryPerformance.test.js.snap | 151 +++-- .../__snapshots__/Frequencies.test.js.snap | 22 +- .../components/VisualGraph/VisualGraph.js | 1 - .../__snapshots__/VisualGraph.test.js.snap | 10 +- .../VisualGraph/utils/helpers.test.js | 53 +- .../AnomalyDetector.test.js.snap | 48 ++ .../CreateMonitor/CreateMonitor.test.js | 11 +- .../__snapshots__/CreateMonitor.test.js.snap | 8 + .../formikToMonitor.test.js.snap | 40 +- .../__snapshots__/DefineMonitor.test.js.snap | 239 ++++---- .../__snapshots__/MonitorIndex.test.js.snap | 44 +- .../__snapshots__/Message.test.js.snap | 204 ++++--- .../TriggerExpressions.test.js | 40 -- .../TriggerExpressions.test.js.snap | 106 +--- .../__snapshots__/TriggerQuery.test.js.snap | 159 +++--- .../utils/formikToTrigger.test.js | 32 +- .../DefineTrigger/utils/validation.js | 1 + .../DefineTrigger/utils/validation.test.js | 11 +- .../DashboardControls.test.js.snap | 10 +- .../__snapshots__/Dashboard.test.js.snap | 527 +++++++++++++----- .../DestinationsList.test.js.snap | 228 +++++++- .../Home/__snapshots__/Home.test.js.snap | 2 +- .../Main/__snapshots__/Main.test.js.snap | 2 +- .../__snapshots__/EmptyHistory.test.js.snap | 4 +- .../MonitorOverview.test.js.snap | 14 +- .../utils/getOverviewStats.test.js | 4 +- .../containers/Triggers/Triggers.js | 1 + .../containers/Triggers/Triggers.test.js | 25 +- .../__snapshots__/Triggers.test.js.snap | 45 +- public/utils/validate.test.js | 29 +- ...dashboards-plugin.release-notes-1.1.0.0.md | 3 +- test/utils/helpers.js | 31 +- 60 files changed, 2779 insertions(+), 990 deletions(-) create mode 100644 public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js create mode 100644 public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap create mode 100644 public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap create mode 100644 public/components/IconToolTip/IconToolTip.test.js create mode 100644 public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap create mode 100644 public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js create mode 100644 public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap create mode 100644 public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap create mode 100644 public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js create mode 100644 public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap create mode 100644 public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js create mode 100644 public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 69c741ab7..727245837 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -30,7 +30,7 @@ jobs: with: repository: opensearch-project/OpenSearch path: OpenSearch - ref: '1.x' + ref: '1.1' - name: Build OpenSearch working-directory: ./OpenSearch run: ./gradlew publishToMavenLocal @@ -40,7 +40,7 @@ jobs: with: repository: opensearch-project/common-utils path: common-utils - ref: 'main' + ref: '1.1' - name: Build common-utils working-directory: ./common-utils run: ./gradlew publishToMavenLocal -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} diff --git a/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap b/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap index cfb18b3a6..b3464dafd 100644 --- a/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap +++ b/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap @@ -38,7 +38,7 @@ Object { exports[`getBreadcrumb returns correct constant breadcrumbs 3`] = ` Object { "href": "/dashboard", - "text": "Dashboard", + "text": "Alerts", } `; diff --git a/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap b/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap index b7314cf62..96b1926d8 100644 --- a/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap +++ b/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap @@ -30,6 +30,14 @@ exports[`ContentPanel renders 1`] = `
+
+
+

diff --git a/public/components/Flyout/__snapshots__/Flyout.test.js.snap b/public/components/Flyout/__snapshots__/Flyout.test.js.snap index 9c9f5c7f1..5b62ba8f3 100644 --- a/public/components/Flyout/__snapshots__/Flyout.test.js.snap +++ b/public/components/Flyout/__snapshots__/Flyout.test.js.snap @@ -48,6 +48,7 @@ exports[`Flyout renders 1`] = `
  • diff --git a/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap b/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap index d720a4c16..0fc5f3de4 100644 --- a/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap +++ b/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap @@ -18,6 +18,7 @@ Object {
    • diff --git a/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js b/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js new file mode 100644 index 000000000..90c9f8efd --- /dev/null +++ b/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; +import { Formik } from 'formik'; + +import FormikCheckableCard from './FormikCheckableCard'; + +describe('FormikCheckableCard', () => { + test('render formRow', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('render', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap b/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap new file mode 100644 index 000000000..0bda3fa43 --- /dev/null +++ b/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FormikCheckableCard render 1`] = ` +
      +
      +
      +
      + +
      +
      +
      +
      +
      +`; + +exports[`FormikCheckableCard render formRow 1`] = ` +
      +
      +
      +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +`; diff --git a/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js b/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js index 71459fb57..95013b9e6 100644 --- a/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js +++ b/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js @@ -29,10 +29,20 @@ import { render } from 'enzyme'; import { Formik } from 'formik'; import FormikCodeEditor from './FormikCodeEditor'; +import FormikCheckableCard from '../FormikCheckableCard'; // FIXME: This has an issue where EuiCodeEditor is generating a random HTML id and failing snapshot test -describe.skip('FormikCodeEditor', () => { +describe('FormikCodeEditor', () => { + test('render formRow', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); test('renders', () => { const component = ( diff --git a/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap b/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap new file mode 100644 index 000000000..c044cb2f4 --- /dev/null +++ b/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FormikCodeEditor render formRow 1`] = ` +
      +
      +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +
      +
      +`; + +exports[`FormikCodeEditor renders 1`] = ` +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +`; diff --git a/public/components/IconToolTip/IconToolTip.test.js b/public/components/IconToolTip/IconToolTip.test.js new file mode 100644 index 000000000..942ecaaa7 --- /dev/null +++ b/public/components/IconToolTip/IconToolTip.test.js @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import IconToolTip from './IconToolTip'; + +describe('IconToolTip', () => { + test('renders', () => { + const component = ; + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap b/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap new file mode 100644 index 000000000..26f77365e --- /dev/null +++ b/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`IconToolTip renders 1`] = ` + +
      + EuiIconMock +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js new file mode 100644 index 000000000..d834b5cd9 --- /dev/null +++ b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { mount, render } from 'enzyme'; +import { FeatureChart } from './FeatureChart'; +import AlertingFakes from '../../../../../../test/utils/helpers'; + +const alertingFakes = new AlertingFakes('random seed'); + +function getMountWrapper(customProps = {}) { + return mount( + + ); +} + +describe('FeatureChart', () => { + test('renders ', () => { + const component = ( + + ); + expect(render(component)).toMatchSnapshot(); + }); + + test('go to page ', () => { + const mountWrapper = getMountWrapper(); + mountWrapper.instance().goToPage(1); + expect(mountWrapper.instance().state.activePage).toBe(1); + }); +}); diff --git a/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap new file mode 100644 index 000000000..306ae56b2 --- /dev/null +++ b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FeatureChart renders 1`] = `null`; diff --git a/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js b/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js index 20cb76414..87a3a006e 100644 --- a/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js +++ b/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js @@ -28,10 +28,16 @@ import React from 'react'; import { render } from 'enzyme'; import ExtractionQuery from './ExtractionQuery'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; -describe.skip('ExtractionQuery', () => { +describe('ExtractionQuery', () => { test('renders', () => { - const component = ; + const component = ( + + {() => } + + ); expect(render(component)).toMatchSnapshot(); }); diff --git a/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap b/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap new file mode 100644 index 000000000..f9fd88ebb --- /dev/null +++ b/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ExtractionQuery renders 1`] = ` +
      +
      +
      +
      + +
      +
      +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      +
      +

      + Press Enter to start editing. +

      +

      + When you're done, press Escape to stop editing. +

      +
      +
      +
      +
      +
      +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap b/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap index 45264816d..c30d92122 100644 --- a/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap @@ -1,56 +1,58 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MonitorDefinition renders 1`] = ` -
      +
      - -
      -
      + +
      -
      - + + + +
      -
      - EuiIconMock -
      - + +
      + EuiIconMock +
      +
      +
      diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js index cab7ee08b..02a5278d5 100644 --- a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js @@ -40,7 +40,7 @@ const onChangeDefinition = (e, form) => { form.setFieldValue('searchType', type, false); }; -const MonitorDefinitionCard = ({ values, resetResponse, plugins }) => { +const MonitorDefinitionCard = ({ values, plugins }) => { const hasADPlugin = plugins.indexOf(OS_AD_PLUGIN) !== -1; const isBucketLevelMonitor = values.monitor_type === MONITOR_TYPE.BUCKET_LEVEL; diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js new file mode 100644 index 000000000..a0f006265 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import MonitorDefinitionCard from './MonitorDefinitionCard'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; +import { OS_AD_PLUGIN } from '../../../../utils/constants'; + +describe('MonitorDefinitionCard', () => { + test('renders without AD plugin', () => { + const component = ( + + {() => } + + ); + + expect(render(component)).toMatchSnapshot(); + }); + test('renders without AD plugin', () => { + const component = ( + + {() => } + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap b/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap new file mode 100644 index 000000000..906c9d308 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap @@ -0,0 +1,303 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MonitorDefinitionCard renders without AD plugin 1`] = ` +
      +
      +

      + Monitor defining method +

      +
      +
      +
      + Specify the way you want to define your query and triggers. + + Learn more +
      + EuiIconMock +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +`; + +exports[`MonitorDefinitionCard renders without AD plugin 2`] = ` +
      +
      +

      + Monitor defining method +

      +
      +
      +
      + Specify the way you want to define your query and triggers. + + Learn more +
      + EuiIconMock +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js b/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js index 0304babd3..195f6f937 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js @@ -35,7 +35,7 @@ describe('MonitorExpressions', () => { test('renders', () => { const component = ( - {() => {}} dataTypes={[]} ofEnabled={false} />} + {() => {}} dataTypes={[]} errors={{}} />} ); diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap index 443f5a876..f7f943fab 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap @@ -1,120 +1,317 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MonitorExpressions renders 1`] = ` -
      +
      -
      + Metrics + + + - optional + + +
      + EuiIconMock +
      +
      +
      +
      + + - + + + +
      +
      +
      +
      + +
      +
      + You can add up to 1 metric.
      + class="euiSpacer euiSpacer--m" + /> +
      +
      + + Time range for the last + + +
      + EuiIconMock +
      +
      +
      +
      -
      +
      +
      +
      +
      +
      +
      - all documents - - + +
      + +
      + EuiIconMock +
      +
      +
      +
      +
      + class="euiSpacer euiSpacer--l" + /> +
      + + Data filter + + + - optional + + +
      + EuiIconMock +
      +
      +
      +
      +
      -
      + + + Add filter + + + +
      +
      + You can add up to 1 data filter.
      +
      + + Group by + + + - optional + + +
      + EuiIconMock +
      +
      +
      +
      +
      + No group bys defined. +
      +
      +
      + + + Add group by + + + +
      +
      +
      +
      +
      + You can add up to 1 group by.
      +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js index 45720aba2..1c2acd5d0 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js @@ -27,7 +27,7 @@ import React from 'react'; import { Formik } from 'formik'; import { render, mount } from 'enzyme'; -import { EuiExpression } from '@elastic/eui'; +import { EuiPopover } from '@elastic/eui'; import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; import WhereExpression from './WhereExpression'; @@ -65,7 +65,7 @@ describe('WhereExpression', () => { }); test('calls openExpression when clicking expression', () => { const wrapper = mount(getMountWrapper()); - const button = wrapper.find(EuiExpression); + const button = wrapper.find('[data-test-subj="where.addFilterButton"]').first(); button.simulate('click'); wrapper.update(); expect(openExpression).toHaveBeenCalled(); @@ -73,8 +73,7 @@ describe('WhereExpression', () => { test('calls closeExpression when closing popover', () => { const wrapper = mount(getMountWrapper(true)); - const button = wrapper.find(EuiExpression); - button.simulate('keyDown', { keyCode: 27 }); + wrapper.find(EuiPopover).simulate('keyDown', { keyCode: 27 }); expect(closeExpression).toHaveBeenCalled(); }); test('should render text input for the text data types', async () => { diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap index 3a8f93a33..d4ade7d01 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap @@ -1,28 +1,103 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ForExpression renders 1`] = ` -
      +
      -
      + +
      +
      +
      +
      +
      - for the last - - - +
      +
      + +
      +
      +
      +
      +
      +
      +
      - 1 hour(s) - - +
      + +
      + +
      + EuiIconMock +
      +
      +
      +
      +
      +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap index 5bee81de7..f437f13da 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap @@ -1,28 +1,59 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`WhereExpression renders 1`] = ` -
      +
      -
      +
      +
      +
      + No filters defined. +
      +
      + + + +
      +
      + You can add up to 1 data filter. +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js b/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js index 12a491208..e47595a26 100644 --- a/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js +++ b/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js @@ -31,7 +31,7 @@ import { Formik } from 'formik'; import MonitorTimeField from './MonitorTimeField'; describe('MonitorTimeField', () => { - test.skip('renders', () => { + test('renders', () => { const component = ( {}}> diff --git a/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap b/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap index 4b2aa0069..97e5f5159 100644 --- a/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap @@ -3,68 +3,86 @@ exports[`MonitorTimeField renders 1`] = `
      - + +
      -
      -
      - Choose the time field you want to use for your x-axis +
      + Choose the time field you want to use for your x-axis +
      `; diff --git a/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js b/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js new file mode 100644 index 000000000..c62ef4a07 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import MonitorType from './MonitorType'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; + +describe('MonitorType', () => { + test('renders', () => { + const component = ( + {() => } + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap b/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap new file mode 100644 index 000000000..97be8378c --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap @@ -0,0 +1,158 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MonitorType renders 1`] = ` +
      +
      +
      +
      + +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      + Per query monitors run a specified query and define triggers that check the results of that query. +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      + +
      +
      +
      + +
      +
      +
      +
      +
      +
      + Per bucket monitors allow you to group results into buckets and define triggers that check each bucket. +
      +
      +
      +
      +
      +
      +
      +
      +
      +`; diff --git a/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap b/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap index 2466a1bfa..6e89b5f99 100644 --- a/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap +++ b/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap @@ -1,84 +1,119 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`QueryPerformance renders 1`] = ` -Array [ -

      - Query performance -

      , -
      , +
      - - Check the performance of your query and make sure to follow best practices. - +

      - Learn more - - -

      , + Query performance + +
      +
      +
      +
      +
      +
      +
      , + class="euiText euiText--extraSmall" + style="padding:0px 10px" + > +
      + + Check the performance of your query and make sure to follow best practices. + + Learn more +
      + EuiIconMock +
      +
      +
      +
      +
      +
      +
      - - Query duration - - - 5 ms - + + Query duration + + + 5 ms + +
      -
      -
      - - Request duration - - - - - + + Request duration + + + - + +
      -
      -
      - - Hits - - - 15 - + + Hits + + + 15 + +
      -
      , -] +
      +
      `; diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap index 03f432348..4e44c245b 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap @@ -3,7 +3,7 @@ exports[`Frequencies renders CustomCron 1`] = `
      - Every + Run every
      cron expressions +
      + EuiIconMock +
      for complex schedules
      @@ -137,7 +140,6 @@ exports[`Frequencies renders Frequency 1`] = `
      - Every + Run every
      - Every + Run every
      -
      -
      - There is no data for the current selections. -
      +
      + There is no data for the current selections.
      `; diff --git a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js index e4588a058..d899abd23 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js +++ b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js @@ -40,12 +40,13 @@ import { } from './helpers'; import { DEFAULT_MARK_SIZE } from './constants'; import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; +import { MONITOR_TYPE } from '../../../../../utils/constants'; describe('getYTitle', () => { test('returns count when empty array, undefined, or null', () => { - expect(getYTitle([])).toBe('count'); - expect(getYTitle(undefined)).toBe('count'); - expect(getYTitle(null)).toBe('count'); + expect(getYTitle([])).toBe('doc_count'); + expect(getYTitle(undefined)).toBe('doc_count'); + expect(getYTitle(null)).toBe('doc_count'); }); }); @@ -154,24 +155,6 @@ describe('getMarkData', () => { }); }); -describe('getAggregationTitle', () => { - test('gets count aggregation type title', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); - expect(getAggregationTitle(formikValues)).toBe( - 'WHEN count() OVER all documents FOR THE LAST 1 hour(s)' - ); - }); - - test('gets avg aggregation type title', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); - formikValues.aggregationType = 'avg'; - formikValues.fieldName = [{ label: 'bytes' }]; - expect(getAggregationTitle(formikValues)).toBe( - 'WHEN average() OF bytes OVER all documents FOR THE LAST 1 hour(s)' - ); - }); -}); - describe('getDataFromResponse', () => { test('gets empty array when no response', () => { expect(getDataFromResponse(null)).toEqual([]); @@ -188,67 +171,67 @@ describe('getDataFromResponse', () => { from_as_string: '2018-10-31T18:00:00.000-07:00', key: 1541034000000, doc_count: 32, - when: { value: 5705.40625 }, + metric: { value: 5705.40625 }, }, { key_as_string: '2018-10-31T19:00:00.000-07:00', from_as_string: '2018-10-31T19:00:00.000-07:00', key: 1541037600000, doc_count: 67, - when: { value: 6185.373134328358 }, + metric: { value: 6185.373134328358 }, }, { key_as_string: '2018-10-31T20:00:00.000-07:00', from_as_string: '2018-10-31T20:00:00.000-07:00', key: 1541041200000, doc_count: 79, - when: { value: -2439.9367088607596 }, + metric: { value: -2439.9367088607596 }, }, { key_as_string: '2018-10-31T21:00:00.000-07:00', from_as_string: '2018-10-31T21:00:00.000-07:00', key: 1541044800000, doc_count: 31, - when: { value: null }, + metric: { value: null }, }, { key_as_string: '2018-10-31T22:00:00.000-07:00', from_as_string: '2018-10-31T22:00:00.000-07:00', key: 1541048400000, doc_count: 18, - when: { value: 4651.5 }, + metric: { value: 4651.5 }, }, { key_as_string: '2018-10-31T23:00:00.000-07:00', from_as_string: '2018-10-31T23:00:00.000-07:00', key: 1541052000000, doc_count: 3, - when: { value: 4410.666666666667 }, + metric: { value: 4410.666666666667 }, }, ], }, }, }; - expect(getDataFromResponse(response)).toEqual([ + expect(getDataFromResponse(response, 'metric', MONITOR_TYPE.QUERY_LEVEL)).toEqual([ { x: new Date(response.aggregations.over.buckets[0].from_as_string), - y: response.aggregations.over.buckets[0].when.value, + y: response.aggregations.over.buckets[0].metric.value, }, { x: new Date(response.aggregations.over.buckets[1].from_as_string), - y: response.aggregations.over.buckets[1].when.value, + y: response.aggregations.over.buckets[1].metric.value, }, { x: new Date(response.aggregations.over.buckets[2].from_as_string), - y: response.aggregations.over.buckets[2].when.value, + y: response.aggregations.over.buckets[2].metric.value, }, { x: new Date(response.aggregations.over.buckets[4].from_as_string), - y: response.aggregations.over.buckets[4].when.value, + y: response.aggregations.over.buckets[4].metric.value, }, { x: new Date(response.aggregations.over.buckets[5].from_as_string), - y: response.aggregations.over.buckets[5].when.value, + y: response.aggregations.over.buckets[5].metric.value, }, ]); }); @@ -261,11 +244,11 @@ describe('getXYValues', () => { from_as_string: '2018-10-31T18:00:00.000-07:00', key: 1541034000000, doc_count: 32, - when: { value: 5705.40625 }, + metric: { value: 5705.40625 }, }; expect(getXYValues(whenBucket)).toEqual({ x: new Date(whenBucket.from_as_string), - y: whenBucket.when.value, + y: whenBucket.metric.value, }); }); diff --git a/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap b/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap index a89b72633..741d3566c 100644 --- a/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap +++ b/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap @@ -5,6 +5,7 @@ exports[`AnomalyDetectors renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -13,9 +14,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -59,6 +67,7 @@ exports[`AnomalyDetectors renders 1`] = ` values={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -67,9 +76,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -174,6 +190,7 @@ exports[`AnomalyDetectors renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -182,9 +199,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -247,6 +271,7 @@ exports[`AnomalyDetectors renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -255,9 +280,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -368,6 +400,7 @@ exports[`AnomalyDetectors renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -376,9 +409,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -441,6 +481,7 @@ exports[`AnomalyDetectors renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -449,9 +490,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js index 826f971ff..6729d35d2 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js +++ b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js @@ -32,6 +32,7 @@ import { historyMock, httpClientMock } from '../../../../../test/mocks'; import { FORMIK_INITIAL_VALUES } from './utils/constants'; import AlertingFakes from '../../../../../test/utils/helpers'; import { SEARCH_TYPE } from '../../../../utils/constants'; +import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants'; const alertingFakes = new AlertingFakes('CreateMonitor random seed'); @@ -179,9 +180,10 @@ describe('CreateMonitor', () => { }); describe('onUpdate', () => { - test('calls updateMonitor with monitor with no triggers key', () => { + // Query-level monitor + test('calls updateMonitor with monitor', () => { const monitor = alertingFakes.randomMonitor(); - const trigger = alertingFakes.randomTrigger(); + const trigger = alertingFakes.randomTrigger(TRIGGER_TYPE.QUERY_LEVEL); monitor.triggers = [trigger]; const wrapper = shallow( { ); wrapper.instance().onUpdate(monitor, formikBag); expect(updateMonitor).toHaveBeenCalledTimes(1); - // The updatedMonitor that is passed in should NOT have the trigger key - const updatedMonitor = { ...monitor }; - delete updatedMonitor.triggers; - expect(updateMonitor).toHaveBeenCalledWith(updatedMonitor); + expect(updateMonitor).toHaveBeenCalledWith(monitor); }); test('logs error when updateMonitor rejects', async () => { diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap b/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap index 59ec5a38e..b65783ed8 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap @@ -12,6 +12,7 @@ exports[`CreateMonitor renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -20,9 +21,16 @@ exports[`CreateMonitor renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap b/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap index 086712815..a898d4d74 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap @@ -123,6 +123,7 @@ Object { }, }, ], + "monitor_type": "query_level_monitor", "name": "random_name", "schedule": Object { "period": Object { @@ -133,6 +134,7 @@ Object { "triggers": Array [], "type": "monitor", "ui_metadata": Object { + "monitor_type": "query_level_monitor", "schedule": Object { "cronExpression": "0 */1 * * *", "daily": 0, @@ -157,13 +159,10 @@ Object { }, }, "search": Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "", "where": Object { @@ -290,13 +289,10 @@ Object { exports[`formikToUiSearch can build ui search 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -311,13 +307,10 @@ Object { exports[`formikToUiSearch can build ui search with range where field 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -336,13 +329,10 @@ Object { exports[`formikToUiSearch can build ui search with term where field 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -360,12 +350,4 @@ Object { exports[`formikToWhenAggregation can build when (count) aggregation 1`] = `Object {}`; -exports[`formikToWhenAggregation can build when aggregation 1`] = ` -Object { - "when": Object { - "avg": Object { - "field": "bytes", - }, - }, -} -`; +exports[`formikToWhenAggregation can build when aggregation 1`] = `Object {}`; diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap index 4945154f9..667ce9e32 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap @@ -1,104 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DefineMonitor renders 1`] = ` - - - - -
      -
      -
      -
      - You must specify an index. -
      -
      -
      -
      - - -
      -`; - -exports[`DefineMonitor should show warning in case of Ad monitor and plugin is not installed 1`] = ` - - - - -
      - +
      + +
      - + +
      +
      +
      +
      + You must specify an index. +
      +
      +
      +
      +
      +
      +`; + +exports[`DefineMonitor should show warning in case of Ad monitor and plugin is not installed 1`] = ` +
      + + Run + , + ] + } + bodyStyles={ + Object { + "padding": "initial", + } + } + panelStyles={ + Object { + "paddingLeft": "10px", + "paddingRight": "10px", + } + } + title="Query" + titleSize="s" + > + + +
      +
      +
      +
      + You must specify an index. +
      +
      +
      +
      + + +
      +
      `; diff --git a/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap b/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap index daf14fde0..84940ee25 100644 --- a/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap +++ b/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap @@ -5,6 +5,7 @@ exports[`MonitorIndex renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -13,9 +14,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -97,7 +105,6 @@ exports[`MonitorIndex renders 1`] = ` "label": "Index", "style": Object { "paddingLeft": "10px", - "textAlign": "center", }, } } @@ -132,6 +139,7 @@ exports[`MonitorIndex renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -140,9 +148,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -205,6 +220,7 @@ exports[`MonitorIndex renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -213,9 +229,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -263,7 +286,6 @@ exports[`MonitorIndex renders 1`] = ` "label": "Index", "style": Object { "paddingLeft": "10px", - "textAlign": "center", }, } } @@ -282,7 +304,6 @@ exports[`MonitorIndex renders 1`] = ` style={ Object { "paddingLeft": "10px", - "textAlign": "center", } } > @@ -292,7 +313,6 @@ exports[`MonitorIndex renders 1`] = ` style={ Object { "paddingLeft": "10px", - "textAlign": "center", } } > @@ -345,6 +365,7 @@ exports[`MonitorIndex renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -353,9 +374,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -418,6 +446,7 @@ exports[`MonitorIndex renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -426,9 +455,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap b/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap index 571472c2a..bfc62b2ed 100644 --- a/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap +++ b/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap @@ -4,7 +4,8 @@ exports[`Message renders 1`] = `
      Message subject @@ -21,14 +22,15 @@ exports[`Message renders 1`] = ` class="euiFormRow__fieldWrapper" >
      @@ -37,7 +39,7 @@ exports[`Message renders 1`] = `
      - - Message - -
      +
      - - - Info - - - + Learn more +
      + EuiIconMock +
      + +
      +
      @@ -74,50 +87,64 @@ exports[`Message renders 1`] = ` > -
      +

      + Action configuration +

      -
      - - Action throttling - - -
      + Throttling
      @@ -254,39 +238,39 @@ exports[`Message renders 1`] = ` >
      minutes
      - Throttle value must be greater than 0 and less than 1440 + Throttle value must be greater than 0 and less than 1440.
      diff --git a/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js b/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js index 2f8076c98..e9037ec65 100644 --- a/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js +++ b/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js @@ -41,44 +41,4 @@ describe('TriggerExpressions', () => { const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); - - test('calls openExpression when clicking expression', () => { - const wrapper = mount( } />); - const openExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'openExpression' - ); - const button = wrapper.find(EuiExpression); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe( - false - ); - button.simulate('click'); - wrapper.update(); - expect(openExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe(true); - }); - - test('calls closeExpression when closing popover', async () => { - const wrapper = mount( } />); - const openExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'openExpression' - ); - const closeExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'closeExpression' - ); - const button = wrapper.find(EuiExpression); - button.simulate('click'); - wrapper.update(); - expect(openExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe(true); - await new Promise((res) => setTimeout(() => res())); - button.simulate('keyDown', { keyCode: 27 }); - wrapper.update(); - expect(closeExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe( - false - ); - }); }); diff --git a/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap b/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap index 35abc84bf..445297f3b 100644 --- a/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap +++ b/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap @@ -1,83 +1,37 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TriggerExpressions renders 1`] = ` - - - - - - } - closePopover={[Function]} - display="inlineBlock" - hasArrow={true} - id="trigger-popover" - isOpen={false} - ownFocus={true} - panelPaddingSize="none" - withTitle={true} + -
      - - - - - - - - - - - - -
      -
      -
      -
      + + + + + + + + + + + `; diff --git a/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap b/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap index c8bc024be..9a2b588b5 100644 --- a/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap +++ b/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap @@ -1,84 +1,95 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TriggerQuery renders 1`] = ` -
      - - - - - - - - - - - - - - - - - - - + + + +
      + + + + + Trigger condition response + + + } + labelType="label" + > + + + + + + - - - Run - - - -
      + Run for condition response + + + `; diff --git a/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js b/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js index 712051d8f..005f2fa25 100644 --- a/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js +++ b/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js @@ -27,8 +27,9 @@ import _ from 'lodash'; import { formikToTrigger, formikToTriggerUiMetadata, formikToCondition } from './formikToTrigger'; -import { FORMIK_INITIAL_TRIGGER_VALUES } from './constants'; -import { SEARCH_TYPE } from '../../../../../utils/constants'; +import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from './constants'; +import { MONITOR_TYPE, SEARCH_TYPE } from '../../../../../utils/constants'; +import { FORMIK_INITIAL_VALUES } from '../../../../CreateMonitor/containers/CreateMonitor/utils/constants'; describe('formikToTrigger', () => { test('can create trigger', () => { @@ -46,13 +47,18 @@ describe('formikToTrigger', () => { describe('formikToTriggerUiMetadata', () => { test('can create trigger metadata for AD monitors', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_TRIGGER_VALUES); + let formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); + _.set(formikValues, 'triggerDefinitions', [FORMIK_INITIAL_TRIGGER_VALUES]); + _.set(formikValues, 'triggerDefinitions.trigger_type', TRIGGER_TYPE.AD); expect( - formikToTriggerUiMetadata(formikValues, { search: { searchType: SEARCH_TYPE.AD } }) + formikToTriggerUiMetadata(formikValues, { + search: { searchType: SEARCH_TYPE.AD }, + monitor_type: MONITOR_TYPE.QUERY_LEVEL, + }) ).toEqual({ [formikValues.name]: { - value: formikValues.thresholdValue, - enum: formikValues.thresholdEnum, + value: formikValues.triggerDefinitions[0].thresholdValue, + enum: formikValues.triggerDefinitions[0].thresholdEnum, adTriggerMetadata: { triggerType: 'anomaly_detector_trigger', anomalyGrade: { @@ -69,13 +75,17 @@ describe('formikToTriggerUiMetadata', () => { }); test('can create metadata', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_TRIGGER_VALUES); + let formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); + _.set(formikValues, 'triggerDefinitions', [FORMIK_INITIAL_TRIGGER_VALUES]); expect( - formikToTriggerUiMetadata(formikValues, { search: { searchType: SEARCH_TYPE.QUERY } }) + formikToTriggerUiMetadata(formikValues, { + search: { searchType: SEARCH_TYPE.QUERY }, + monitor_type: MONITOR_TYPE.QUERY_LEVEL, + }) ).toEqual({ [formikValues.name]: { - value: formikValues.thresholdValue, - enum: formikValues.thresholdEnum, + value: formikValues.triggerDefinitions[0].thresholdValue, + enum: formikValues.triggerDefinitions[0].thresholdEnum, }, }); }); @@ -119,7 +129,7 @@ describe('formikToCondition', () => { ).toEqual({ script: { lang: 'painless', - source: `return ctx.results[0].aggregations.when.value == null ? false : ctx.results[0].aggregations.when.value > 10000`, + source: 'ctx.results[0].hits.total.value > 10000', }, }); }); diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js index a668ea4b3..ee7ecb215 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js @@ -23,6 +23,7 @@ * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ +import _ from 'lodash'; import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js index 503b0f6a6..4a6b3a068 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js @@ -25,6 +25,7 @@ */ import { validateTriggerName } from './validation'; +import { TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; describe('validateTriggerName', () => { test('returns undefined if no error', () => { @@ -36,12 +37,16 @@ describe('validateTriggerName', () => { expect(validateTriggerName([], {})('')).toBe('Required'); }); test('returns false if name already exists in monitor while creates new trigger', () => { - const triggers = [{ id: '123', name: 'Test' }]; - expect(validateTriggerName(triggers, {})('Test')).toBe('Trigger name already used'); + const triggers = [{ [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123', name: 'Test' } }]; + expect(validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: {} })('Test')).toBe( + 'Trigger name already used' + ); }); test('returns undefined if editing trigger and name is the same', () => { const triggers = [{ id: '123', name: 'Test' }]; - expect(validateTriggerName(triggers, { id: '123' })('Test')).toBeUndefined(); + expect( + validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123' } })('Test') + ).toBeUndefined(); }); }); diff --git a/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap b/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap index bae503fda..03257100b 100644 --- a/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap +++ b/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap @@ -55,27 +55,27 @@ exports[`DashboardControls renders 1`] = `
      + View alert details + , + Acknowledge @@ -64,7 +71,7 @@ exports[`Dashboard renders 1`] = ` "padding": "initial", } } - title="Alerts" + title="Alerts by triggers" titleSize="l" > - Alerts + Alerts by triggers
      @@ -136,18 +143,66 @@ exports[`Dashboard renders 1`] = ` className="euiFlexItem" > + + + + +
      + + +
      +
      + +
      + +
      + +
      + - 1 + 1 (Highest) @@ -774,28 +857,29 @@ exports[`Dashboard renders 1`] = ` columns={ Array [ Object { - "dataType": "date", - "field": "start_time", - "name": "Alert start time", + "field": "total", + "name": "Alerts", "render": [Function], "sortable": true, "truncateText": false, }, Object { - "dataType": "date", - "field": "end_time", - "name": "Alert end time", - "render": [Function], + "field": "ACTIVE", + "name": "Active", "sortable": true, "truncateText": false, }, Object { - "field": "monitor_name", - "name": "Monitor name", - "render": [Function], + "field": "ACKNOWLEDGED", + "name": "Acknowledged", "sortable": true, - "textOnly": true, - "truncateText": true, + "truncateText": false, + }, + Object { + "field": "ERROR", + "name": "Errors", + "sortable": true, + "truncateText": false, }, Object { "field": "trigger_name", @@ -805,25 +889,34 @@ exports[`Dashboard renders 1`] = ` "truncateText": true, }, Object { - "field": "severity", - "name": "Severity", - "sortable": false, + "dataType": "date", + "field": "start_time", + "name": "Trigger start time", + "render": [Function], + "sortable": true, "truncateText": false, }, Object { - "field": "state", - "name": "State", + "dataType": "date", + "field": "last_notification_time", + "name": "Trigger last updated", "render": [Function], + "sortable": true, + "truncateText": true, + }, + Object { + "field": "severity", + "name": "Severity", "sortable": false, "truncateText": false, }, Object { - "dataType": "date", - "field": "acknowledged_time", - "name": "Time acknowledged", + "field": "monitor_name", + "name": "Monitor name", "render": [Function], "sortable": true, - "truncateText": false, + "textOnly": true, + "truncateText": true, }, ] } @@ -832,19 +925,6 @@ exports[`Dashboard renders 1`] = ` items={Array []} noItemsMessage={} onChange={[Function]} - pagination={ - Object { - "pageIndex": 0, - "pageSize": 20, - "pageSizeOptions": Array [ - 5, - 10, - 20, - 50, - ], - "totalItemCount": 0, - } - } responsive={true} selection={ Object { @@ -935,38 +1015,59 @@ exports[`Dashboard renders 1`] = ` items={ Array [ Object { - "isSortAscending": false, - "isSorted": true, - "key": "_data_s_start_time_0", - "name": "Alert start time", + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_total_0", + "name": "Alerts", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_end_time_1", - "name": "Alert end time", + "key": "_data_s_ACTIVE_1", + "name": "Active", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_monitor_name_2", - "name": "Monitor name", + "key": "_data_s_ACKNOWLEDGED_2", + "name": "Acknowledged", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_trigger_name_3", + "key": "_data_s_ERROR_3", + "name": "Errors", + "onSort": [Function], + }, + Object { + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_trigger_name_4", "name": "Trigger name", "onSort": [Function], }, + Object { + "isSortAscending": false, + "isSorted": true, + "key": "_data_s_start_time_5", + "name": "Trigger start time", + "onSort": [Function], + }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_acknowledged_time_6", - "name": "Time acknowledged", + "key": "_data_s_last_notification_time_6", + "name": "Trigger last updated", + "onSort": [Function], + }, + Object { + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_monitor_name_8", + "name": "Monitor name", "onSort": [Function], }, ] @@ -1151,17 +1252,16 @@ exports[`Dashboard renders 1`] = ` + + + + + + + + + + - State + Severity
      @@ -1488,16 +1751,16 @@ exports[`Dashboard renders 1`] = ` - Time acknowledged + Monitor name @@ -1561,12 +1824,12 @@ exports[`Dashboard renders 1`] = ` >
      + +
      + +
      + +
      + @@ -1158,9 +1201,74 @@ exports[`DestinationsList renders 1`] = ` + + + + +
      + +
      + +
      + +
      + @@ -2398,9 +2549,74 @@ exports[`DestinationsList renders when email is disallowed 1`] = ` + + + + + - Dashboard + Alerts
      @@ -36,7 +36,7 @@ exports[` renders 1`] = ` - Create trigger + Edit monitor diff --git a/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap b/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap index 92ed72756..71a3418ab 100644 --- a/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap +++ b/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap @@ -30,6 +30,14 @@ exports[`MonitorOverview renders 1`] = `
      +
      +
      +

      @@ -46,10 +54,10 @@ exports[`MonitorOverview renders 1`] = ` class="euiText euiText--extraSmall" > - State + Monitor type
      - Enabled + Per query monitor
      @@ -145,7 +153,7 @@ exports[`MonitorOverview renders 1`] = ` Last updated by
      - N/A + -
      diff --git a/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js b/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js index 4cb5ceba3..20d4ca5fd 100644 --- a/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js +++ b/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js @@ -40,8 +40,8 @@ describe('getOverviewStats', () => { const activeCount = 17; expect(getOverviewStats(monitor, monitorId, monitorVersion, activeCount)).toEqual([ { - header: 'State', - value: 'Enabled', + header: 'Monitor type', + value: 'Per query monitor', }, { header: 'Monitor definition type', diff --git a/public/pages/MonitorDetails/containers/Triggers/Triggers.js b/public/pages/MonitorDetails/containers/Triggers/Triggers.js index 61c782cb7..f92399abc 100644 --- a/public/pages/MonitorDetails/containers/Triggers/Triggers.js +++ b/public/pages/MonitorDetails/containers/Triggers/Triggers.js @@ -28,6 +28,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import uuidv4 from 'uuid/v4'; import { EuiInMemoryTable } from '@elastic/eui'; +import _ from 'lodash'; import ContentPanel from '../../../../components/ContentPanel'; import { MONITOR_TYPE } from '../../../../utils/constants'; diff --git a/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js b/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js index 512a30bf2..8d2672ddc 100644 --- a/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js +++ b/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js @@ -28,6 +28,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import Triggers from './Triggers'; +import { MONITOR_TYPE } from '../../../../utils/constants'; +import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants'; const props = { monitor: { @@ -79,16 +81,31 @@ describe('Triggers', () => { test('onDelete calls updateMonitor with triggers to keep', () => { const onDelete = jest.spyOn(Triggers.prototype, 'onDelete'); const monitor = { + monitor_type: MONITOR_TYPE.QUERY_LEVEL, triggers: [ - { name: 'one', severity: 1, actions: [{ name: 'one action' }] }, - { name: 'two', severity: 2, actions: [{ name: 'two action' }] }, + { + [TRIGGER_TYPE.QUERY_LEVEL]: { + name: 'one', + severity: 1, + actions: [{ name: 'one action' }], + }, + }, + { + [TRIGGER_TYPE.QUERY_LEVEL]: { + name: 'two', + severity: 2, + actions: [{ name: 'two action' }], + }, + }, ], }; const wrapper = getShallowWrapper({ monitor }); - wrapper.setState({ selectedItems: [monitor.triggers[0]] }); + wrapper.setState({ selectedItems: [monitor.triggers[0][TRIGGER_TYPE.QUERY_LEVEL]] }); wrapper.instance().onDelete(); expect(onDelete).toHaveBeenCalled(); expect(props.updateMonitor).toHaveBeenCalled(); - expect(props.updateMonitor).toHaveBeenCalledWith({ triggers: [monitor.triggers[1]] }); + expect(props.updateMonitor).toHaveBeenCalledWith({ + triggers: [monitor.triggers[1][TRIGGER_TYPE.QUERY_LEVEL]], + }); }); }); diff --git a/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap b/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap index 2f0cdd59f..7d508b089 100644 --- a/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap +++ b/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap @@ -2,35 +2,12 @@ exports[`Triggers renders 1`] = ` - Edit - , - - Delete - , - - Create - , - ] - } bodyStyles={ Object { "padding": "initial", } } - title="Triggers" + title="Triggers (1)" titleSize="s" > { describe('validateActionName', () => { const trigger = { name: 'trigger_name', - actions: [{ name: 'foo' }, { name: 'bar' }], + [TRIGGER_TYPE.QUERY_LEVEL]: { actions: [{ name: 'foo' }, { name: 'bar' }] }, }; + const monitor = FORMIK_INITIAL_VALUES; test('returns undefined if no error', () => { - expect(validateActionName(trigger)('valid action name')).toBeUndefined(); + expect(validateActionName(monitor, trigger)('valid action name')).toBeUndefined(); }); test('returns Required string if falsy value', () => { - expect(validateActionName(trigger)()).toBe('Required'); - expect(validateActionName(trigger)('')).toBe('Required'); + expect(validateActionName(monitor, trigger)()).toBe('Required.'); + expect(validateActionName(monitor, trigger)('')).toBe('Required.'); }); - trigger.actions.push({ name: 'foo' }); + trigger[TRIGGER_TYPE.QUERY_LEVEL].actions.push({ name: 'foo' }); test('returns already used if action name is already used', () => { - expect(validateActionName(trigger)('foo')).toBe('Action name is already used'); + expect(validateActionName(monitor, trigger)('foo')).toBe('Action name is already used.'); }); }); @@ -112,8 +115,8 @@ describe('validateMonitorName', () => { }); test('returns Required string if falsy value', () => { - validateMonitorName(httpClient, {})().catch((err) => expect(err).toEqual('Required')); - validateMonitorName(httpClient, {})('').catch((err) => expect(err).toEqual('Required')); + validateMonitorName(httpClient, {})().catch((err) => expect(err).toEqual('Required.')); + validateMonitorName(httpClient, {})('').catch((err) => expect(err).toEqual('Required.')); }); }); @@ -124,7 +127,7 @@ describe('validatePositiveInteger', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be a positive integer'; + const invalidText = 'Must be a positive integer.'; expect(validatePositiveInteger(-5)).toBe(invalidText); expect(validatePositiveInteger(0)).toBe(invalidText); expect(validatePositiveInteger(1.5)).toBe(invalidText); @@ -142,7 +145,7 @@ describe('validateUnit', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be one of minutes, hours, days'; + const invalidText = 'Must be one of minutes, hours, days.'; expect(validateUnit(5)).toBe(invalidText); expect(validateUnit('RANDOM')).toBe(invalidText); expect(validateUnit(null)).toBe(invalidText); @@ -159,7 +162,7 @@ describe('validateMonthlyDay', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be a positive integer between 1-31'; + const invalidText = 'Must be a positive integer between 1-31.'; expect(validateMonthlyDay(-5)).toBe(invalidText); expect(validateMonthlyDay(0)).toBe(invalidText); expect(validateMonthlyDay(1.5)).toBe(invalidText); @@ -202,7 +205,7 @@ describe('validateIndex', () => { }); test('returns error string if non array is passed in', () => { - const invalidText = 'Must specify an index'; + const invalidText = 'Must specify an index.'; expect(validateIndex(1)).toBe(invalidText); expect(validateIndex(null)).toBe(invalidText); expect(validateIndex('test')).toBe(invalidText); @@ -210,7 +213,7 @@ describe('validateIndex', () => { }); test('returns error string if empty array', () => { - const invalidText = 'Must specify an index'; + const invalidText = 'Must specify an index.'; expect(validateIndex([])).toBe(invalidText); }); diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index 1069c108e..b1584f384 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -48,4 +48,5 @@ Compatible with OpenSearch Dashboards 1.1.0 * Add Cypress tests for Bucket-Level Alerting ([#91](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/91)) * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) -* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) \ No newline at end of file +* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) +* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) \ No newline at end of file diff --git a/test/utils/helpers.js b/test/utils/helpers.js index dd6f6cdf3..d413bf4b9 100644 --- a/test/utils/helpers.js +++ b/test/utils/helpers.js @@ -9,6 +9,8 @@ * GitHub history for details. */ +import { TRIGGER_TYPE } from '../../public/pages/CreateTrigger/containers/CreateTrigger/utils/constants'; + const Chance = require('chance'); class AlertingFakes { @@ -31,6 +33,7 @@ class AlertingFakes { this.randomInputs = this.randomInputs.bind(this); this.randomMonitorEnabled = this.randomMonitorEnabled.bind(this); this.randomMonitor = this.randomMonitor.bind(this); + this.randomTime = this.randomTime.bind(this); } randomEmailDestination() { @@ -106,20 +109,22 @@ class AlertingFakes { }; } - randomTrigger() { + randomTrigger(type = TRIGGER_TYPE.QUERY_LEVEL) { return { - id: this.chance.guid().slice(0, 20), - name: this.chance.word(), - severity: this.chance.string({ length: 1, pool: '12345' }), - condition: { - script: { - lang: 'painless', - source: `return ${this.chance.bool()}`, + [type]: { + id: this.chance.guid().slice(0, 20), + name: this.chance.word(), + severity: this.chance.string({ length: 1, pool: '12345' }), + condition: { + script: { + lang: 'painless', + source: `return ${this.chance.bool()}`, + }, }, + actions: new Array(this.chance.natural({ max: 10 })) + .fill(null) + .map(() => this.randomAction()), }, - actions: new Array(this.chance.natural({ max: 10 })) - .fill(null) - .map(() => this.randomAction()), }; } @@ -184,6 +189,10 @@ class AlertingFakes { .map(() => this.randomTrigger()), }; } + + randomTime() { + return this.chance.timestamp(); + } } module.exports = AlertingFakes; From ed6fad5b234d5ea0521169493baefc0309894b69 Mon Sep 17 00:00:00 2001 From: Annie Lee <71157062+leeyun-amzn@users.noreply.github.com> Date: Tue, 14 Sep 2021 17:48:58 -0700 Subject: [PATCH 06/29] Update jest unit tests (#112) * Update .opensearch_dashboards-plugin-helpers.json * Update snapshots * Update whereExpression.test and some snapshots * Update whereExpression.test and some snapshots Signed-off-by: Annie Lee * Update snapshots * Update formikToTrigger.test.js * Update formikToTrigger.test.js * Update formikToTrigger.test.js * Add icon tooltip * Add test * Update tests * remove license * Update TriggerExpressions.test.js * Update Triggers.test.js * Update validation test * Update getOverviewStats.test.js * Update validate.test.js * Update helpers.test.js and remove unused import * Update Triggers.test.js * Update helpers.js * Update CreateMonitor test and clean up code * Update CreateMonitor test and clean up code Signed-off-by: Annie Lee * Update release note and adding more tests * Add test and modify cypress common-utils branch * Update MonitorDefinitionCard.test.js.snap * Update cypress-workflow.yml Signed-off-by: Annie Lee --- .github/workflows/cypress-workflow.yml | 4 +- .../__snapshots__/Breadcrumbs.test.js.snap | 2 +- .../__snapshots__/ContentPanel.test.js.snap | 8 + .../Flyout/__snapshots__/Flyout.test.js.snap | 1 + .../__snapshots__/flyouts.test.js.snap | 1 + .../FormikCheckableCard.test.js | 38 ++ .../FormikCheckableCard.test.js.snap | 70 +++ .../FormikCodeEditor/FormikCodeEditor.test.js | 12 +- .../FormikCodeEditor.test.js.snap | 70 +++ .../IconToolTip/IconToolTip.test.js | 22 + .../__snapshots__/IconToolTip.test.js.snap | 11 + .../FeatureChart/FeatureChart.test.js | 50 ++ .../__snapshots__/FeatureChart.test.js.snap | 3 + .../ExtractionQuery/ExtractionQuery.test.js | 10 +- .../ExtractionQuery.test.js.snap | 111 ++++ .../MonitorDefinition.test.js.snap | 82 +-- .../MonitorDefinitionCard.js | 2 +- .../MonitorDefinitionCard.test.js | 39 ++ .../MonitorDefinitionCard.test.js.snap | 303 ++++++++++ .../MonitorExpressions.test.js | 2 +- .../MonitorExpressions.test.js.snap | 343 +++++++++--- .../expressions/WhereExpression.test.js | 7 +- .../__snapshots__/ForExpression.test.js.snap | 109 +++- .../WhereExpression.test.js.snap | 63 ++- .../MonitorTimeField/MonitorTimeField.test.js | 2 +- .../MonitorTimeField.test.js.snap | 114 ++-- .../MonitorType/MonitorType.test.js | 27 + .../__snapshots__/MonitorType.test.js.snap | 158 ++++++ .../QueryPerformance.test.js.snap | 151 +++-- .../__snapshots__/Frequencies.test.js.snap | 22 +- .../components/VisualGraph/VisualGraph.js | 1 - .../__snapshots__/VisualGraph.test.js.snap | 10 +- .../VisualGraph/utils/helpers.test.js | 53 +- .../AnomalyDetector.test.js.snap | 48 ++ .../CreateMonitor/CreateMonitor.test.js | 11 +- .../__snapshots__/CreateMonitor.test.js.snap | 8 + .../formikToMonitor.test.js.snap | 40 +- .../__snapshots__/DefineMonitor.test.js.snap | 239 ++++---- .../__snapshots__/MonitorIndex.test.js.snap | 44 +- .../__snapshots__/Message.test.js.snap | 204 ++++--- .../TriggerExpressions.test.js | 40 -- .../TriggerExpressions.test.js.snap | 106 +--- .../__snapshots__/TriggerQuery.test.js.snap | 159 +++--- .../utils/formikToTrigger.test.js | 32 +- .../DefineTrigger/utils/validation.js | 1 + .../DefineTrigger/utils/validation.test.js | 11 +- .../DashboardControls.test.js.snap | 10 +- .../__snapshots__/Dashboard.test.js.snap | 527 +++++++++++++----- .../DestinationsList.test.js.snap | 228 +++++++- .../Home/__snapshots__/Home.test.js.snap | 2 +- .../Main/__snapshots__/Main.test.js.snap | 2 +- .../__snapshots__/EmptyHistory.test.js.snap | 4 +- .../MonitorOverview.test.js.snap | 14 +- .../utils/getOverviewStats.test.js | 4 +- .../containers/Triggers/Triggers.js | 1 + .../containers/Triggers/Triggers.test.js | 25 +- .../__snapshots__/Triggers.test.js.snap | 45 +- public/utils/validate.test.js | 29 +- ...dashboards-plugin.release-notes-1.1.0.0.md | 3 +- test/utils/helpers.js | 31 +- 60 files changed, 2779 insertions(+), 990 deletions(-) create mode 100644 public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js create mode 100644 public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap create mode 100644 public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap create mode 100644 public/components/IconToolTip/IconToolTip.test.js create mode 100644 public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap create mode 100644 public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js create mode 100644 public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap create mode 100644 public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap create mode 100644 public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js create mode 100644 public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap create mode 100644 public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js create mode 100644 public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap diff --git a/.github/workflows/cypress-workflow.yml b/.github/workflows/cypress-workflow.yml index 69c741ab7..727245837 100644 --- a/.github/workflows/cypress-workflow.yml +++ b/.github/workflows/cypress-workflow.yml @@ -30,7 +30,7 @@ jobs: with: repository: opensearch-project/OpenSearch path: OpenSearch - ref: '1.x' + ref: '1.1' - name: Build OpenSearch working-directory: ./OpenSearch run: ./gradlew publishToMavenLocal @@ -40,7 +40,7 @@ jobs: with: repository: opensearch-project/common-utils path: common-utils - ref: 'main' + ref: '1.1' - name: Build common-utils working-directory: ./common-utils run: ./gradlew publishToMavenLocal -Dopensearch.version=${{ env.OPENSEARCH_VERSION }} diff --git a/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap b/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap index cfb18b3a6..b3464dafd 100644 --- a/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap +++ b/public/components/Breadcrumbs/__snapshots__/Breadcrumbs.test.js.snap @@ -38,7 +38,7 @@ Object { exports[`getBreadcrumb returns correct constant breadcrumbs 3`] = ` Object { "href": "/dashboard", - "text": "Dashboard", + "text": "Alerts", } `; diff --git a/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap b/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap index b7314cf62..96b1926d8 100644 --- a/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap +++ b/public/components/ContentPanel/__snapshots__/ContentPanel.test.js.snap @@ -30,6 +30,14 @@ exports[`ContentPanel renders 1`] = `
      +
      +
      +

      diff --git a/public/components/Flyout/__snapshots__/Flyout.test.js.snap b/public/components/Flyout/__snapshots__/Flyout.test.js.snap index 9c9f5c7f1..5b62ba8f3 100644 --- a/public/components/Flyout/__snapshots__/Flyout.test.js.snap +++ b/public/components/Flyout/__snapshots__/Flyout.test.js.snap @@ -48,6 +48,7 @@ exports[`Flyout renders 1`] = `
      • diff --git a/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap b/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap index d720a4c16..0fc5f3de4 100644 --- a/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap +++ b/public/components/Flyout/flyouts/__snapshots__/flyouts.test.js.snap @@ -18,6 +18,7 @@ Object {
        • diff --git a/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js b/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js new file mode 100644 index 000000000..90c9f8efd --- /dev/null +++ b/public/components/FormControls/FormikCheckableCard/FormikCheckableCard.test.js @@ -0,0 +1,38 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; +import { Formik } from 'formik'; + +import FormikCheckableCard from './FormikCheckableCard'; + +describe('FormikCheckableCard', () => { + test('render formRow', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); + + test('render', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap b/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap new file mode 100644 index 000000000..0bda3fa43 --- /dev/null +++ b/public/components/FormControls/FormikCheckableCard/__snapshots__/FormikCheckableCard.test.js.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FormikCheckableCard render 1`] = ` +
          +
          +
          +
          + +
          +
          +
          +
          +
          +`; + +exports[`FormikCheckableCard render formRow 1`] = ` +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +`; diff --git a/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js b/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js index 71459fb57..95013b9e6 100644 --- a/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js +++ b/public/components/FormControls/FormikCodeEditor/FormikCodeEditor.test.js @@ -29,10 +29,20 @@ import { render } from 'enzyme'; import { Formik } from 'formik'; import FormikCodeEditor from './FormikCodeEditor'; +import FormikCheckableCard from '../FormikCheckableCard'; // FIXME: This has an issue where EuiCodeEditor is generating a random HTML id and failing snapshot test -describe.skip('FormikCodeEditor', () => { +describe('FormikCodeEditor', () => { + test('render formRow', () => { + const component = ( + + + + ); + + expect(render(component)).toMatchSnapshot(); + }); test('renders', () => { const component = ( diff --git a/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap b/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap new file mode 100644 index 000000000..c044cb2f4 --- /dev/null +++ b/public/components/FormControls/FormikCodeEditor/__snapshots__/FormikCodeEditor.test.js.snap @@ -0,0 +1,70 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FormikCodeEditor render formRow 1`] = ` +
          +
          +
          +
          +

          + Press Enter to start editing. +

          +

          + When you're done, press Escape to stop editing. +

          +
          +
          +
          +
          +
          +`; + +exports[`FormikCodeEditor renders 1`] = ` +
          +
          +

          + Press Enter to start editing. +

          +

          + When you're done, press Escape to stop editing. +

          +
          +
          +
          +`; diff --git a/public/components/IconToolTip/IconToolTip.test.js b/public/components/IconToolTip/IconToolTip.test.js new file mode 100644 index 000000000..942ecaaa7 --- /dev/null +++ b/public/components/IconToolTip/IconToolTip.test.js @@ -0,0 +1,22 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import IconToolTip from './IconToolTip'; + +describe('IconToolTip', () => { + test('renders', () => { + const component = ; + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap b/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap new file mode 100644 index 000000000..26f77365e --- /dev/null +++ b/public/components/IconToolTip/__snapshots__/IconToolTip.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`IconToolTip renders 1`] = ` + +
          + EuiIconMock +
          +
          +`; diff --git a/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js new file mode 100644 index 000000000..d834b5cd9 --- /dev/null +++ b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/FeatureChart.test.js @@ -0,0 +1,50 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { mount, render } from 'enzyme'; +import { FeatureChart } from './FeatureChart'; +import AlertingFakes from '../../../../../../test/utils/helpers'; + +const alertingFakes = new AlertingFakes('random seed'); + +function getMountWrapper(customProps = {}) { + return mount( + + ); +} + +describe('FeatureChart', () => { + test('renders ', () => { + const component = ( + + ); + expect(render(component)).toMatchSnapshot(); + }); + + test('go to page ', () => { + const mountWrapper = getMountWrapper(); + mountWrapper.instance().goToPage(1); + expect(mountWrapper.instance().state.activePage).toBe(1); + }); +}); diff --git a/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap new file mode 100644 index 000000000..306ae56b2 --- /dev/null +++ b/public/pages/CreateMonitor/components/AnomalyDetectors/FeatureChart/__snapshots__/FeatureChart.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FeatureChart renders 1`] = `null`; diff --git a/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js b/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js index 20cb76414..87a3a006e 100644 --- a/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js +++ b/public/pages/CreateMonitor/components/ExtractionQuery/ExtractionQuery.test.js @@ -28,10 +28,16 @@ import React from 'react'; import { render } from 'enzyme'; import ExtractionQuery from './ExtractionQuery'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; -describe.skip('ExtractionQuery', () => { +describe('ExtractionQuery', () => { test('renders', () => { - const component = ; + const component = ( + + {() => } + + ); expect(render(component)).toMatchSnapshot(); }); diff --git a/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap b/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap new file mode 100644 index 000000000..f9fd88ebb --- /dev/null +++ b/public/pages/CreateMonitor/components/ExtractionQuery/__snapshots__/ExtractionQuery.test.js.snap @@ -0,0 +1,111 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`ExtractionQuery renders 1`] = ` +
          +
          +
          +
          + +
          +
          +
          +
          +

          + Press Enter to start editing. +

          +

          + When you're done, press Escape to stop editing. +

          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          +
          +

          + Press Enter to start editing. +

          +

          + When you're done, press Escape to stop editing. +

          +
          +
          +
          +
          +
          +
          +
          +`; diff --git a/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap b/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap index 45264816d..c30d92122 100644 --- a/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorDefinition/__snapshots__/MonitorDefinition.test.js.snap @@ -1,56 +1,58 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MonitorDefinition renders 1`] = ` -
          +
          - -
          -
          + +
          -
          - + + + +
          -
          - EuiIconMock -
          - + +
          + EuiIconMock +
          +
          +
          diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js index cab7ee08b..02a5278d5 100644 --- a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.js @@ -40,7 +40,7 @@ const onChangeDefinition = (e, form) => { form.setFieldValue('searchType', type, false); }; -const MonitorDefinitionCard = ({ values, resetResponse, plugins }) => { +const MonitorDefinitionCard = ({ values, plugins }) => { const hasADPlugin = plugins.indexOf(OS_AD_PLUGIN) !== -1; const isBucketLevelMonitor = values.monitor_type === MONITOR_TYPE.BUCKET_LEVEL; diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js new file mode 100644 index 000000000..a0f006265 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/MonitorDefinitionCard.test.js @@ -0,0 +1,39 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import MonitorDefinitionCard from './MonitorDefinitionCard'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; +import { OS_AD_PLUGIN } from '../../../../utils/constants'; + +describe('MonitorDefinitionCard', () => { + test('renders without AD plugin', () => { + const component = ( + + {() => } + + ); + + expect(render(component)).toMatchSnapshot(); + }); + test('renders without AD plugin', () => { + const component = ( + + {() => } + + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap b/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap new file mode 100644 index 000000000..906c9d308 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorDefinitionCard/__snapshots__/MonitorDefinitionCard.test.js.snap @@ -0,0 +1,303 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MonitorDefinitionCard renders without AD plugin 1`] = ` +
          +
          +

          + Monitor defining method +

          +
          +
          +
          + Specify the way you want to define your query and triggers. + + Learn more +
          + EuiIconMock +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +`; + +exports[`MonitorDefinitionCard renders without AD plugin 2`] = ` +
          +
          +

          + Monitor defining method +

          +
          +
          +
          + Specify the way you want to define your query and triggers. + + Learn more +
          + EuiIconMock +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +`; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js b/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js index 0304babd3..195f6f937 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/MonitorExpressions.test.js @@ -35,7 +35,7 @@ describe('MonitorExpressions', () => { test('renders', () => { const component = ( - {() => {}} dataTypes={[]} ofEnabled={false} />} + {() => {}} dataTypes={[]} errors={{}} />} ); diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap index 443f5a876..f7f943fab 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/__snapshots__/MonitorExpressions.test.js.snap @@ -1,120 +1,317 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`MonitorExpressions renders 1`] = ` -
          +
          -
          + Metrics + + + - optional + + +
          + EuiIconMock +
          +
          +
          +
          + + - + + + +
          +
          +
          +
          + +
          +
          + You can add up to 1 metric.
          + class="euiSpacer euiSpacer--m" + /> +
          +
          + + Time range for the last + + +
          + EuiIconMock +
          +
          +
          +
          -
          +
          +
          +
          +
          +
          +
          - all documents - - + +
          + +
          + EuiIconMock +
          +
          +
          +
          +
          + class="euiSpacer euiSpacer--l" + /> +
          + + Data filter + + + - optional + + +
          + EuiIconMock +
          +
          +
          +
          +
          -
          + + + Add filter + + + +
          +
          + You can add up to 1 data filter.
          +
          + + Group by + + + - optional + + +
          + EuiIconMock +
          +
          +
          +
          +
          + No group bys defined. +
          +
          +
          + + + Add group by + + + +
          +
          +
          +
          +
          + You can add up to 1 group by.
          +
          `; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js index 45720aba2..1c2acd5d0 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.test.js @@ -27,7 +27,7 @@ import React from 'react'; import { Formik } from 'formik'; import { render, mount } from 'enzyme'; -import { EuiExpression } from '@elastic/eui'; +import { EuiPopover } from '@elastic/eui'; import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; import WhereExpression from './WhereExpression'; @@ -65,7 +65,7 @@ describe('WhereExpression', () => { }); test('calls openExpression when clicking expression', () => { const wrapper = mount(getMountWrapper()); - const button = wrapper.find(EuiExpression); + const button = wrapper.find('[data-test-subj="where.addFilterButton"]').first(); button.simulate('click'); wrapper.update(); expect(openExpression).toHaveBeenCalled(); @@ -73,8 +73,7 @@ describe('WhereExpression', () => { test('calls closeExpression when closing popover', () => { const wrapper = mount(getMountWrapper(true)); - const button = wrapper.find(EuiExpression); - button.simulate('keyDown', { keyCode: 27 }); + wrapper.find(EuiPopover).simulate('keyDown', { keyCode: 27 }); expect(closeExpression).toHaveBeenCalled(); }); test('should render text input for the text data types', async () => { diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap index 3a8f93a33..d4ade7d01 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/ForExpression.test.js.snap @@ -1,28 +1,103 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`ForExpression renders 1`] = ` -
          +
          -
          + +
          +
          +
          +
          +
          - for the last - - - +
          +
          + +
          +
          +
          +
          +
          +
          +
          - 1 hour(s) - - +
          + +
          + +
          + EuiIconMock +
          +
          +
          +
          +
          +
          `; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap index 5bee81de7..f437f13da 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/__snapshots__/WhereExpression.test.js.snap @@ -1,28 +1,59 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`WhereExpression renders 1`] = ` -
          +
          -
          +
          +
          +
          + No filters defined. +
          +
          + + + +
          +
          + You can add up to 1 data filter. +
          `; diff --git a/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js b/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js index 12a491208..e47595a26 100644 --- a/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js +++ b/public/pages/CreateMonitor/components/MonitorTimeField/MonitorTimeField.test.js @@ -31,7 +31,7 @@ import { Formik } from 'formik'; import MonitorTimeField from './MonitorTimeField'; describe('MonitorTimeField', () => { - test.skip('renders', () => { + test('renders', () => { const component = ( {}}> diff --git a/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap b/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap index 4b2aa0069..97e5f5159 100644 --- a/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap +++ b/public/pages/CreateMonitor/components/MonitorTimeField/__snapshots__/MonitorTimeField.test.js.snap @@ -3,68 +3,86 @@ exports[`MonitorTimeField renders 1`] = `
          - + +
          -
          -
          - Choose the time field you want to use for your x-axis +
          + Choose the time field you want to use for your x-axis +
          `; diff --git a/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js b/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js new file mode 100644 index 000000000..c62ef4a07 --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorType/MonitorType.test.js @@ -0,0 +1,27 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from 'react'; +import { render } from 'enzyme'; + +import MonitorType from './MonitorType'; +import { Formik } from 'formik'; +import { FORMIK_INITIAL_VALUES } from '../../containers/CreateMonitor/utils/constants'; + +describe('MonitorType', () => { + test('renders', () => { + const component = ( + {() => } + ); + + expect(render(component)).toMatchSnapshot(); + }); +}); diff --git a/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap b/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap new file mode 100644 index 000000000..97be8378c --- /dev/null +++ b/public/pages/CreateMonitor/components/MonitorType/__snapshots__/MonitorType.test.js.snap @@ -0,0 +1,158 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`MonitorType renders 1`] = ` +
          +
          +
          +
          + +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +
          + Per query monitors run a specified query and define triggers that check the results of that query. +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          +
          + +
          +
          +
          + +
          +
          +
          +
          +
          +
          + Per bucket monitors allow you to group results into buckets and define triggers that check each bucket. +
          +
          +
          +
          +
          +
          +
          +
          +
          +`; diff --git a/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap b/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap index 2466a1bfa..6e89b5f99 100644 --- a/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap +++ b/public/pages/CreateMonitor/components/QueryPerformance/__snapshots__/QueryPerformance.test.js.snap @@ -1,84 +1,119 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`QueryPerformance renders 1`] = ` -Array [ -

          - Query performance -

          , -
          , +
          - - Check the performance of your query and make sure to follow best practices. - +

          - Learn more - - -

          , + Query performance + +
          +
          +
          +
          +
          +
          +
          , + class="euiText euiText--extraSmall" + style="padding:0px 10px" + > +
          + + Check the performance of your query and make sure to follow best practices. + + Learn more +
          + EuiIconMock +
          +
          +
          +
          +
          +
          +
          - - Query duration - - - 5 ms - + + Query duration + + + 5 ms + +
          -
          -
          - - Request duration - - - - - + + Request duration + + + - + +
          -
          -
          - - Hits - - - 15 - + + Hits + + + 15 + +
          -
          , -] +
          +
          `; diff --git a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap index 03f432348..4e44c245b 100644 --- a/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap +++ b/public/pages/CreateMonitor/components/Schedule/Frequencies/__snapshots__/Frequencies.test.js.snap @@ -3,7 +3,7 @@ exports[`Frequencies renders CustomCron 1`] = `
          - Every + Run every
          cron expressions +
          + EuiIconMock +
          for complex schedules
          @@ -137,7 +140,6 @@ exports[`Frequencies renders Frequency 1`] = `
          - Every + Run every
          - Every + Run every
          -
          -
          - There is no data for the current selections. -
          +
          + There is no data for the current selections.
          `; diff --git a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js index e4588a058..d899abd23 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js +++ b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.test.js @@ -40,12 +40,13 @@ import { } from './helpers'; import { DEFAULT_MARK_SIZE } from './constants'; import { FORMIK_INITIAL_VALUES } from '../../../containers/CreateMonitor/utils/constants'; +import { MONITOR_TYPE } from '../../../../../utils/constants'; describe('getYTitle', () => { test('returns count when empty array, undefined, or null', () => { - expect(getYTitle([])).toBe('count'); - expect(getYTitle(undefined)).toBe('count'); - expect(getYTitle(null)).toBe('count'); + expect(getYTitle([])).toBe('doc_count'); + expect(getYTitle(undefined)).toBe('doc_count'); + expect(getYTitle(null)).toBe('doc_count'); }); }); @@ -154,24 +155,6 @@ describe('getMarkData', () => { }); }); -describe('getAggregationTitle', () => { - test('gets count aggregation type title', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); - expect(getAggregationTitle(formikValues)).toBe( - 'WHEN count() OVER all documents FOR THE LAST 1 hour(s)' - ); - }); - - test('gets avg aggregation type title', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); - formikValues.aggregationType = 'avg'; - formikValues.fieldName = [{ label: 'bytes' }]; - expect(getAggregationTitle(formikValues)).toBe( - 'WHEN average() OF bytes OVER all documents FOR THE LAST 1 hour(s)' - ); - }); -}); - describe('getDataFromResponse', () => { test('gets empty array when no response', () => { expect(getDataFromResponse(null)).toEqual([]); @@ -188,67 +171,67 @@ describe('getDataFromResponse', () => { from_as_string: '2018-10-31T18:00:00.000-07:00', key: 1541034000000, doc_count: 32, - when: { value: 5705.40625 }, + metric: { value: 5705.40625 }, }, { key_as_string: '2018-10-31T19:00:00.000-07:00', from_as_string: '2018-10-31T19:00:00.000-07:00', key: 1541037600000, doc_count: 67, - when: { value: 6185.373134328358 }, + metric: { value: 6185.373134328358 }, }, { key_as_string: '2018-10-31T20:00:00.000-07:00', from_as_string: '2018-10-31T20:00:00.000-07:00', key: 1541041200000, doc_count: 79, - when: { value: -2439.9367088607596 }, + metric: { value: -2439.9367088607596 }, }, { key_as_string: '2018-10-31T21:00:00.000-07:00', from_as_string: '2018-10-31T21:00:00.000-07:00', key: 1541044800000, doc_count: 31, - when: { value: null }, + metric: { value: null }, }, { key_as_string: '2018-10-31T22:00:00.000-07:00', from_as_string: '2018-10-31T22:00:00.000-07:00', key: 1541048400000, doc_count: 18, - when: { value: 4651.5 }, + metric: { value: 4651.5 }, }, { key_as_string: '2018-10-31T23:00:00.000-07:00', from_as_string: '2018-10-31T23:00:00.000-07:00', key: 1541052000000, doc_count: 3, - when: { value: 4410.666666666667 }, + metric: { value: 4410.666666666667 }, }, ], }, }, }; - expect(getDataFromResponse(response)).toEqual([ + expect(getDataFromResponse(response, 'metric', MONITOR_TYPE.QUERY_LEVEL)).toEqual([ { x: new Date(response.aggregations.over.buckets[0].from_as_string), - y: response.aggregations.over.buckets[0].when.value, + y: response.aggregations.over.buckets[0].metric.value, }, { x: new Date(response.aggregations.over.buckets[1].from_as_string), - y: response.aggregations.over.buckets[1].when.value, + y: response.aggregations.over.buckets[1].metric.value, }, { x: new Date(response.aggregations.over.buckets[2].from_as_string), - y: response.aggregations.over.buckets[2].when.value, + y: response.aggregations.over.buckets[2].metric.value, }, { x: new Date(response.aggregations.over.buckets[4].from_as_string), - y: response.aggregations.over.buckets[4].when.value, + y: response.aggregations.over.buckets[4].metric.value, }, { x: new Date(response.aggregations.over.buckets[5].from_as_string), - y: response.aggregations.over.buckets[5].when.value, + y: response.aggregations.over.buckets[5].metric.value, }, ]); }); @@ -261,11 +244,11 @@ describe('getXYValues', () => { from_as_string: '2018-10-31T18:00:00.000-07:00', key: 1541034000000, doc_count: 32, - when: { value: 5705.40625 }, + metric: { value: 5705.40625 }, }; expect(getXYValues(whenBucket)).toEqual({ x: new Date(whenBucket.from_as_string), - y: whenBucket.when.value, + y: whenBucket.metric.value, }); }); diff --git a/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap b/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap index a89b72633..741d3566c 100644 --- a/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap +++ b/public/pages/CreateMonitor/containers/AnomalyDetectors/__tests__/__snapshots__/AnomalyDetector.test.js.snap @@ -5,6 +5,7 @@ exports[`AnomalyDetectors renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -13,9 +14,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -59,6 +67,7 @@ exports[`AnomalyDetectors renders 1`] = ` values={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -67,9 +76,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -174,6 +190,7 @@ exports[`AnomalyDetectors renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -182,9 +199,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -247,6 +271,7 @@ exports[`AnomalyDetectors renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -255,9 +280,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -368,6 +400,7 @@ exports[`AnomalyDetectors renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -376,9 +409,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -441,6 +481,7 @@ exports[`AnomalyDetectors renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -449,9 +490,16 @@ exports[`AnomalyDetectors renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js index 826f971ff..6729d35d2 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js +++ b/public/pages/CreateMonitor/containers/CreateMonitor/CreateMonitor.test.js @@ -32,6 +32,7 @@ import { historyMock, httpClientMock } from '../../../../../test/mocks'; import { FORMIK_INITIAL_VALUES } from './utils/constants'; import AlertingFakes from '../../../../../test/utils/helpers'; import { SEARCH_TYPE } from '../../../../utils/constants'; +import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants'; const alertingFakes = new AlertingFakes('CreateMonitor random seed'); @@ -179,9 +180,10 @@ describe('CreateMonitor', () => { }); describe('onUpdate', () => { - test('calls updateMonitor with monitor with no triggers key', () => { + // Query-level monitor + test('calls updateMonitor with monitor', () => { const monitor = alertingFakes.randomMonitor(); - const trigger = alertingFakes.randomTrigger(); + const trigger = alertingFakes.randomTrigger(TRIGGER_TYPE.QUERY_LEVEL); monitor.triggers = [trigger]; const wrapper = shallow( { ); wrapper.instance().onUpdate(monitor, formikBag); expect(updateMonitor).toHaveBeenCalledTimes(1); - // The updatedMonitor that is passed in should NOT have the trigger key - const updatedMonitor = { ...monitor }; - delete updatedMonitor.triggers; - expect(updateMonitor).toHaveBeenCalledWith(updatedMonitor); + expect(updateMonitor).toHaveBeenCalledWith(monitor); }); test('logs error when updateMonitor rejects', async () => { diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap b/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap index 59ec5a38e..b65783ed8 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/CreateMonitor/__snapshots__/CreateMonitor.test.js.snap @@ -12,6 +12,7 @@ exports[`CreateMonitor renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -20,9 +21,16 @@ exports[`CreateMonitor renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap b/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap index 086712815..a898d4d74 100644 --- a/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/CreateMonitor/utils/__snapshots__/formikToMonitor.test.js.snap @@ -123,6 +123,7 @@ Object { }, }, ], + "monitor_type": "query_level_monitor", "name": "random_name", "schedule": Object { "period": Object { @@ -133,6 +134,7 @@ Object { "triggers": Array [], "type": "monitor", "ui_metadata": Object { + "monitor_type": "query_level_monitor", "schedule": Object { "cronExpression": "0 */1 * * *", "daily": 0, @@ -157,13 +159,10 @@ Object { }, }, "search": Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "", "where": Object { @@ -290,13 +289,10 @@ Object { exports[`formikToUiSearch can build ui search 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -311,13 +307,10 @@ Object { exports[`formikToUiSearch can build ui search with range where field 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -336,13 +329,10 @@ Object { exports[`formikToUiSearch can build ui search with term where field 1`] = ` Object { - "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, - "fieldName": "bytes", - "groupedOverFieldName": "bytes", - "groupedOverTop": 5, - "overDocuments": "all documents", + "groupBy": Array [], "searchType": "graph", "timeField": "@timestamp", "where": Object { @@ -360,12 +350,4 @@ Object { exports[`formikToWhenAggregation can build when (count) aggregation 1`] = `Object {}`; -exports[`formikToWhenAggregation can build when aggregation 1`] = ` -Object { - "when": Object { - "avg": Object { - "field": "bytes", - }, - }, -} -`; +exports[`formikToWhenAggregation can build when aggregation 1`] = `Object {}`; diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap index 4945154f9..667ce9e32 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap +++ b/public/pages/CreateMonitor/containers/DefineMonitor/__snapshots__/DefineMonitor.test.js.snap @@ -1,104 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`DefineMonitor renders 1`] = ` - - - - -
          -
          -
          -
          - You must specify an index. -
          -
          -
          -
          - - -
          -`; - -exports[`DefineMonitor should show warning in case of Ad monitor and plugin is not installed 1`] = ` - - - - -
          - +
          + +
          - + +
          +
          +
          +
          + You must specify an index. +
          +
          +
          +
          +
          +
          +`; + +exports[`DefineMonitor should show warning in case of Ad monitor and plugin is not installed 1`] = ` +
          + + Run + , + ] + } + bodyStyles={ + Object { + "padding": "initial", + } + } + panelStyles={ + Object { + "paddingLeft": "10px", + "paddingRight": "10px", + } + } + title="Query" + titleSize="s" + > + + +
          +
          +
          +
          + You must specify an index. +
          +
          +
          +
          + + +
          +
          `; diff --git a/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap b/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap index daf14fde0..84940ee25 100644 --- a/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap +++ b/public/pages/CreateMonitor/containers/MonitorIndex/__snapshots__/MonitorIndex.test.js.snap @@ -5,6 +5,7 @@ exports[`MonitorIndex renders 1`] = ` initialValues={ Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -13,9 +14,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -97,7 +105,6 @@ exports[`MonitorIndex renders 1`] = ` "label": "Index", "style": Object { "paddingLeft": "10px", - "textAlign": "center", }, } } @@ -132,6 +139,7 @@ exports[`MonitorIndex renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -140,9 +148,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -205,6 +220,7 @@ exports[`MonitorIndex renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -213,9 +229,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -263,7 +286,6 @@ exports[`MonitorIndex renders 1`] = ` "label": "Index", "style": Object { "paddingLeft": "10px", - "textAlign": "center", }, } } @@ -282,7 +304,6 @@ exports[`MonitorIndex renders 1`] = ` style={ Object { "paddingLeft": "10px", - "textAlign": "center", } } > @@ -292,7 +313,6 @@ exports[`MonitorIndex renders 1`] = ` style={ Object { "paddingLeft": "10px", - "textAlign": "center", } } > @@ -345,6 +365,7 @@ exports[`MonitorIndex renders 1`] = ` "initialTouched": Object {}, "initialValues": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -353,9 +374,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", @@ -418,6 +446,7 @@ exports[`MonitorIndex renders 1`] = ` "validateOnMount": false, "values": Object { "aggregationType": "count", + "aggregations": Array [], "bucketUnitOfTime": "h", "bucketValue": 1, "cronExpression": "0 */1 * * *", @@ -426,9 +455,16 @@ exports[`MonitorIndex renders 1`] = ` "disabled": false, "fieldName": Array [], "frequency": "interval", + "groupBy": Array [], + "groupByField": Array [ + Object { + "label": "", + }, + ], "groupedOverFieldName": "bytes", "groupedOverTop": 5, "index": Array [], + "monitor_type": "query_level_monitor", "monthly": Object { "day": 1, "type": "day", diff --git a/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap b/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap index 571472c2a..bfc62b2ed 100644 --- a/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap +++ b/public/pages/CreateTrigger/components/Action/actions/__snapshots__/Message.test.js.snap @@ -4,7 +4,8 @@ exports[`Message renders 1`] = `
          Message subject @@ -21,14 +22,15 @@ exports[`Message renders 1`] = ` class="euiFormRow__fieldWrapper" >
          @@ -37,7 +39,7 @@ exports[`Message renders 1`] = `
          - - Message - -
          +
          - - - Info - - - + Learn more +
          + EuiIconMock +
          + +
          +
          @@ -74,50 +87,64 @@ exports[`Message renders 1`] = ` > -
          +

          + Action configuration +

          -
          - - Action throttling - - -
          + Throttling
          @@ -254,39 +238,39 @@ exports[`Message renders 1`] = ` >
          minutes
          - Throttle value must be greater than 0 and less than 1440 + Throttle value must be greater than 0 and less than 1440.
          diff --git a/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js b/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js index 2f8076c98..e9037ec65 100644 --- a/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js +++ b/public/pages/CreateTrigger/components/TriggerExpressions/TriggerExpressions.test.js @@ -41,44 +41,4 @@ describe('TriggerExpressions', () => { const wrapper = shallow(); expect(wrapper).toMatchSnapshot(); }); - - test('calls openExpression when clicking expression', () => { - const wrapper = mount( } />); - const openExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'openExpression' - ); - const button = wrapper.find(EuiExpression); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe( - false - ); - button.simulate('click'); - wrapper.update(); - expect(openExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe(true); - }); - - test('calls closeExpression when closing popover', async () => { - const wrapper = mount( } />); - const openExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'openExpression' - ); - const closeExpression = jest.spyOn( - wrapper.find(TriggerExpressions).instance(), - 'closeExpression' - ); - const button = wrapper.find(EuiExpression); - button.simulate('click'); - wrapper.update(); - expect(openExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe(true); - await new Promise((res) => setTimeout(() => res())); - button.simulate('keyDown', { keyCode: 27 }); - wrapper.update(); - expect(closeExpression).toHaveBeenCalled(); - expect(wrapper.find(TriggerExpressions).state().openedStates[Expressions.THRESHOLD]).toBe( - false - ); - }); }); diff --git a/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap b/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap index 35abc84bf..445297f3b 100644 --- a/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap +++ b/public/pages/CreateTrigger/components/TriggerExpressions/__snapshots__/TriggerExpressions.test.js.snap @@ -1,83 +1,37 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TriggerExpressions renders 1`] = ` - - - - - - } - closePopover={[Function]} - display="inlineBlock" - hasArrow={true} - id="trigger-popover" - isOpen={false} - ownFocus={true} - panelPaddingSize="none" - withTitle={true} + -
          - - - - - - - - - - - - -
          -
          -
          -
          + + + + + + + + + + + `; diff --git a/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap b/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap index c8bc024be..9a2b588b5 100644 --- a/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap +++ b/public/pages/CreateTrigger/components/TriggerQuery/__snapshots__/TriggerQuery.test.js.snap @@ -1,84 +1,95 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`TriggerQuery renders 1`] = ` -
          - - - - - - - - - - - - - - - - - - - + + + +
          + + + + + Trigger condition response + + + } + labelType="label" + > + + + + + + - - - Run - - - -
          + Run for condition response + + + `; diff --git a/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js b/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js index 712051d8f..005f2fa25 100644 --- a/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js +++ b/public/pages/CreateTrigger/containers/CreateTrigger/utils/formikToTrigger.test.js @@ -27,8 +27,9 @@ import _ from 'lodash'; import { formikToTrigger, formikToTriggerUiMetadata, formikToCondition } from './formikToTrigger'; -import { FORMIK_INITIAL_TRIGGER_VALUES } from './constants'; -import { SEARCH_TYPE } from '../../../../../utils/constants'; +import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from './constants'; +import { MONITOR_TYPE, SEARCH_TYPE } from '../../../../../utils/constants'; +import { FORMIK_INITIAL_VALUES } from '../../../../CreateMonitor/containers/CreateMonitor/utils/constants'; describe('formikToTrigger', () => { test('can create trigger', () => { @@ -46,13 +47,18 @@ describe('formikToTrigger', () => { describe('formikToTriggerUiMetadata', () => { test('can create trigger metadata for AD monitors', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_TRIGGER_VALUES); + let formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); + _.set(formikValues, 'triggerDefinitions', [FORMIK_INITIAL_TRIGGER_VALUES]); + _.set(formikValues, 'triggerDefinitions.trigger_type', TRIGGER_TYPE.AD); expect( - formikToTriggerUiMetadata(formikValues, { search: { searchType: SEARCH_TYPE.AD } }) + formikToTriggerUiMetadata(formikValues, { + search: { searchType: SEARCH_TYPE.AD }, + monitor_type: MONITOR_TYPE.QUERY_LEVEL, + }) ).toEqual({ [formikValues.name]: { - value: formikValues.thresholdValue, - enum: formikValues.thresholdEnum, + value: formikValues.triggerDefinitions[0].thresholdValue, + enum: formikValues.triggerDefinitions[0].thresholdEnum, adTriggerMetadata: { triggerType: 'anomaly_detector_trigger', anomalyGrade: { @@ -69,13 +75,17 @@ describe('formikToTriggerUiMetadata', () => { }); test('can create metadata', () => { - const formikValues = _.cloneDeep(FORMIK_INITIAL_TRIGGER_VALUES); + let formikValues = _.cloneDeep(FORMIK_INITIAL_VALUES); + _.set(formikValues, 'triggerDefinitions', [FORMIK_INITIAL_TRIGGER_VALUES]); expect( - formikToTriggerUiMetadata(formikValues, { search: { searchType: SEARCH_TYPE.QUERY } }) + formikToTriggerUiMetadata(formikValues, { + search: { searchType: SEARCH_TYPE.QUERY }, + monitor_type: MONITOR_TYPE.QUERY_LEVEL, + }) ).toEqual({ [formikValues.name]: { - value: formikValues.thresholdValue, - enum: formikValues.thresholdEnum, + value: formikValues.triggerDefinitions[0].thresholdValue, + enum: formikValues.triggerDefinitions[0].thresholdEnum, }, }); }); @@ -119,7 +129,7 @@ describe('formikToCondition', () => { ).toEqual({ script: { lang: 'painless', - source: `return ctx.results[0].aggregations.when.value == null ? false : ctx.results[0].aggregations.when.value > 10000`, + source: 'ctx.results[0].hits.total.value > 10000', }, }); }); diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js index a668ea4b3..ee7ecb215 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js @@ -23,6 +23,7 @@ * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ +import _ from 'lodash'; import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js index 503b0f6a6..4a6b3a068 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js @@ -25,6 +25,7 @@ */ import { validateTriggerName } from './validation'; +import { TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; describe('validateTriggerName', () => { test('returns undefined if no error', () => { @@ -36,12 +37,16 @@ describe('validateTriggerName', () => { expect(validateTriggerName([], {})('')).toBe('Required'); }); test('returns false if name already exists in monitor while creates new trigger', () => { - const triggers = [{ id: '123', name: 'Test' }]; - expect(validateTriggerName(triggers, {})('Test')).toBe('Trigger name already used'); + const triggers = [{ [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123', name: 'Test' } }]; + expect(validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: {} })('Test')).toBe( + 'Trigger name already used' + ); }); test('returns undefined if editing trigger and name is the same', () => { const triggers = [{ id: '123', name: 'Test' }]; - expect(validateTriggerName(triggers, { id: '123' })('Test')).toBeUndefined(); + expect( + validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123' } })('Test') + ).toBeUndefined(); }); }); diff --git a/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap b/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap index bae503fda..03257100b 100644 --- a/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap +++ b/public/pages/Dashboard/components/DashboardControls/__snapshots__/DashboardControls.test.js.snap @@ -55,27 +55,27 @@ exports[`DashboardControls renders 1`] = `
          + View alert details + , + Acknowledge @@ -64,7 +71,7 @@ exports[`Dashboard renders 1`] = ` "padding": "initial", } } - title="Alerts" + title="Alerts by triggers" titleSize="l" > - Alerts + Alerts by triggers
          @@ -136,18 +143,66 @@ exports[`Dashboard renders 1`] = ` className="euiFlexItem" > + + + + +
          + + +
          +
          + +
          + +
          + +
          + - 1 + 1 (Highest) @@ -774,28 +857,29 @@ exports[`Dashboard renders 1`] = ` columns={ Array [ Object { - "dataType": "date", - "field": "start_time", - "name": "Alert start time", + "field": "total", + "name": "Alerts", "render": [Function], "sortable": true, "truncateText": false, }, Object { - "dataType": "date", - "field": "end_time", - "name": "Alert end time", - "render": [Function], + "field": "ACTIVE", + "name": "Active", "sortable": true, "truncateText": false, }, Object { - "field": "monitor_name", - "name": "Monitor name", - "render": [Function], + "field": "ACKNOWLEDGED", + "name": "Acknowledged", "sortable": true, - "textOnly": true, - "truncateText": true, + "truncateText": false, + }, + Object { + "field": "ERROR", + "name": "Errors", + "sortable": true, + "truncateText": false, }, Object { "field": "trigger_name", @@ -805,25 +889,34 @@ exports[`Dashboard renders 1`] = ` "truncateText": true, }, Object { - "field": "severity", - "name": "Severity", - "sortable": false, + "dataType": "date", + "field": "start_time", + "name": "Trigger start time", + "render": [Function], + "sortable": true, "truncateText": false, }, Object { - "field": "state", - "name": "State", + "dataType": "date", + "field": "last_notification_time", + "name": "Trigger last updated", "render": [Function], + "sortable": true, + "truncateText": true, + }, + Object { + "field": "severity", + "name": "Severity", "sortable": false, "truncateText": false, }, Object { - "dataType": "date", - "field": "acknowledged_time", - "name": "Time acknowledged", + "field": "monitor_name", + "name": "Monitor name", "render": [Function], "sortable": true, - "truncateText": false, + "textOnly": true, + "truncateText": true, }, ] } @@ -832,19 +925,6 @@ exports[`Dashboard renders 1`] = ` items={Array []} noItemsMessage={} onChange={[Function]} - pagination={ - Object { - "pageIndex": 0, - "pageSize": 20, - "pageSizeOptions": Array [ - 5, - 10, - 20, - 50, - ], - "totalItemCount": 0, - } - } responsive={true} selection={ Object { @@ -935,38 +1015,59 @@ exports[`Dashboard renders 1`] = ` items={ Array [ Object { - "isSortAscending": false, - "isSorted": true, - "key": "_data_s_start_time_0", - "name": "Alert start time", + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_total_0", + "name": "Alerts", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_end_time_1", - "name": "Alert end time", + "key": "_data_s_ACTIVE_1", + "name": "Active", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_monitor_name_2", - "name": "Monitor name", + "key": "_data_s_ACKNOWLEDGED_2", + "name": "Acknowledged", "onSort": [Function], }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_trigger_name_3", + "key": "_data_s_ERROR_3", + "name": "Errors", + "onSort": [Function], + }, + Object { + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_trigger_name_4", "name": "Trigger name", "onSort": [Function], }, + Object { + "isSortAscending": false, + "isSorted": true, + "key": "_data_s_start_time_5", + "name": "Trigger start time", + "onSort": [Function], + }, Object { "isSortAscending": undefined, "isSorted": false, - "key": "_data_s_acknowledged_time_6", - "name": "Time acknowledged", + "key": "_data_s_last_notification_time_6", + "name": "Trigger last updated", + "onSort": [Function], + }, + Object { + "isSortAscending": undefined, + "isSorted": false, + "key": "_data_s_monitor_name_8", + "name": "Monitor name", "onSort": [Function], }, ] @@ -1151,17 +1252,16 @@ exports[`Dashboard renders 1`] = ` + + + + + + + + + + - State + Severity
          @@ -1488,16 +1751,16 @@ exports[`Dashboard renders 1`] = ` - Time acknowledged + Monitor name @@ -1561,12 +1824,12 @@ exports[`Dashboard renders 1`] = ` >
          + +
          + +
          + +
          + @@ -1158,9 +1201,74 @@ exports[`DestinationsList renders 1`] = ` + + + + +
          + +
          + +
          + +
          + @@ -2398,9 +2549,74 @@ exports[`DestinationsList renders when email is disallowed 1`] = ` + + + + + - Dashboard + Alerts
          @@ -36,7 +36,7 @@ exports[` renders 1`] = ` - Create trigger + Edit monitor diff --git a/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap b/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap index 92ed72756..71a3418ab 100644 --- a/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap +++ b/public/pages/MonitorDetails/components/MonitorOverview/__snapshots__/MonitorOverview.test.js.snap @@ -30,6 +30,14 @@ exports[`MonitorOverview renders 1`] = `
          +
          +
          +

          @@ -46,10 +54,10 @@ exports[`MonitorOverview renders 1`] = ` class="euiText euiText--extraSmall" > - State + Monitor type
          - Enabled + Per query monitor
          @@ -145,7 +153,7 @@ exports[`MonitorOverview renders 1`] = ` Last updated by
          - N/A + -
          diff --git a/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js b/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js index 4cb5ceba3..20d4ca5fd 100644 --- a/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js +++ b/public/pages/MonitorDetails/components/MonitorOverview/utils/getOverviewStats.test.js @@ -40,8 +40,8 @@ describe('getOverviewStats', () => { const activeCount = 17; expect(getOverviewStats(monitor, monitorId, monitorVersion, activeCount)).toEqual([ { - header: 'State', - value: 'Enabled', + header: 'Monitor type', + value: 'Per query monitor', }, { header: 'Monitor definition type', diff --git a/public/pages/MonitorDetails/containers/Triggers/Triggers.js b/public/pages/MonitorDetails/containers/Triggers/Triggers.js index 61c782cb7..f92399abc 100644 --- a/public/pages/MonitorDetails/containers/Triggers/Triggers.js +++ b/public/pages/MonitorDetails/containers/Triggers/Triggers.js @@ -28,6 +28,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; import uuidv4 from 'uuid/v4'; import { EuiInMemoryTable } from '@elastic/eui'; +import _ from 'lodash'; import ContentPanel from '../../../../components/ContentPanel'; import { MONITOR_TYPE } from '../../../../utils/constants'; diff --git a/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js b/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js index 512a30bf2..8d2672ddc 100644 --- a/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js +++ b/public/pages/MonitorDetails/containers/Triggers/Triggers.test.js @@ -28,6 +28,8 @@ import React from 'react'; import { shallow } from 'enzyme'; import Triggers from './Triggers'; +import { MONITOR_TYPE } from '../../../../utils/constants'; +import { TRIGGER_TYPE } from '../../../CreateTrigger/containers/CreateTrigger/utils/constants'; const props = { monitor: { @@ -79,16 +81,31 @@ describe('Triggers', () => { test('onDelete calls updateMonitor with triggers to keep', () => { const onDelete = jest.spyOn(Triggers.prototype, 'onDelete'); const monitor = { + monitor_type: MONITOR_TYPE.QUERY_LEVEL, triggers: [ - { name: 'one', severity: 1, actions: [{ name: 'one action' }] }, - { name: 'two', severity: 2, actions: [{ name: 'two action' }] }, + { + [TRIGGER_TYPE.QUERY_LEVEL]: { + name: 'one', + severity: 1, + actions: [{ name: 'one action' }], + }, + }, + { + [TRIGGER_TYPE.QUERY_LEVEL]: { + name: 'two', + severity: 2, + actions: [{ name: 'two action' }], + }, + }, ], }; const wrapper = getShallowWrapper({ monitor }); - wrapper.setState({ selectedItems: [monitor.triggers[0]] }); + wrapper.setState({ selectedItems: [monitor.triggers[0][TRIGGER_TYPE.QUERY_LEVEL]] }); wrapper.instance().onDelete(); expect(onDelete).toHaveBeenCalled(); expect(props.updateMonitor).toHaveBeenCalled(); - expect(props.updateMonitor).toHaveBeenCalledWith({ triggers: [monitor.triggers[1]] }); + expect(props.updateMonitor).toHaveBeenCalledWith({ + triggers: [monitor.triggers[1][TRIGGER_TYPE.QUERY_LEVEL]], + }); }); }); diff --git a/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap b/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap index 2f0cdd59f..7d508b089 100644 --- a/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap +++ b/public/pages/MonitorDetails/containers/Triggers/__snapshots__/Triggers.test.js.snap @@ -2,35 +2,12 @@ exports[`Triggers renders 1`] = ` - Edit - , - - Delete - , - - Create - , - ] - } bodyStyles={ Object { "padding": "initial", } } - title="Triggers" + title="Triggers (1)" titleSize="s" > { describe('validateActionName', () => { const trigger = { name: 'trigger_name', - actions: [{ name: 'foo' }, { name: 'bar' }], + [TRIGGER_TYPE.QUERY_LEVEL]: { actions: [{ name: 'foo' }, { name: 'bar' }] }, }; + const monitor = FORMIK_INITIAL_VALUES; test('returns undefined if no error', () => { - expect(validateActionName(trigger)('valid action name')).toBeUndefined(); + expect(validateActionName(monitor, trigger)('valid action name')).toBeUndefined(); }); test('returns Required string if falsy value', () => { - expect(validateActionName(trigger)()).toBe('Required'); - expect(validateActionName(trigger)('')).toBe('Required'); + expect(validateActionName(monitor, trigger)()).toBe('Required.'); + expect(validateActionName(monitor, trigger)('')).toBe('Required.'); }); - trigger.actions.push({ name: 'foo' }); + trigger[TRIGGER_TYPE.QUERY_LEVEL].actions.push({ name: 'foo' }); test('returns already used if action name is already used', () => { - expect(validateActionName(trigger)('foo')).toBe('Action name is already used'); + expect(validateActionName(monitor, trigger)('foo')).toBe('Action name is already used.'); }); }); @@ -112,8 +115,8 @@ describe('validateMonitorName', () => { }); test('returns Required string if falsy value', () => { - validateMonitorName(httpClient, {})().catch((err) => expect(err).toEqual('Required')); - validateMonitorName(httpClient, {})('').catch((err) => expect(err).toEqual('Required')); + validateMonitorName(httpClient, {})().catch((err) => expect(err).toEqual('Required.')); + validateMonitorName(httpClient, {})('').catch((err) => expect(err).toEqual('Required.')); }); }); @@ -124,7 +127,7 @@ describe('validatePositiveInteger', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be a positive integer'; + const invalidText = 'Must be a positive integer.'; expect(validatePositiveInteger(-5)).toBe(invalidText); expect(validatePositiveInteger(0)).toBe(invalidText); expect(validatePositiveInteger(1.5)).toBe(invalidText); @@ -142,7 +145,7 @@ describe('validateUnit', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be one of minutes, hours, days'; + const invalidText = 'Must be one of minutes, hours, days.'; expect(validateUnit(5)).toBe(invalidText); expect(validateUnit('RANDOM')).toBe(invalidText); expect(validateUnit(null)).toBe(invalidText); @@ -159,7 +162,7 @@ describe('validateMonthlyDay', () => { }); test('returns error string if invalid value', () => { - const invalidText = 'Must be a positive integer between 1-31'; + const invalidText = 'Must be a positive integer between 1-31.'; expect(validateMonthlyDay(-5)).toBe(invalidText); expect(validateMonthlyDay(0)).toBe(invalidText); expect(validateMonthlyDay(1.5)).toBe(invalidText); @@ -202,7 +205,7 @@ describe('validateIndex', () => { }); test('returns error string if non array is passed in', () => { - const invalidText = 'Must specify an index'; + const invalidText = 'Must specify an index.'; expect(validateIndex(1)).toBe(invalidText); expect(validateIndex(null)).toBe(invalidText); expect(validateIndex('test')).toBe(invalidText); @@ -210,7 +213,7 @@ describe('validateIndex', () => { }); test('returns error string if empty array', () => { - const invalidText = 'Must specify an index'; + const invalidText = 'Must specify an index.'; expect(validateIndex([])).toBe(invalidText); }); diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index 1069c108e..b1584f384 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -48,4 +48,5 @@ Compatible with OpenSearch Dashboards 1.1.0 * Add Cypress tests for Bucket-Level Alerting ([#91](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/91)) * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) -* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) \ No newline at end of file +* Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) +* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) \ No newline at end of file diff --git a/test/utils/helpers.js b/test/utils/helpers.js index dd6f6cdf3..d413bf4b9 100644 --- a/test/utils/helpers.js +++ b/test/utils/helpers.js @@ -9,6 +9,8 @@ * GitHub history for details. */ +import { TRIGGER_TYPE } from '../../public/pages/CreateTrigger/containers/CreateTrigger/utils/constants'; + const Chance = require('chance'); class AlertingFakes { @@ -31,6 +33,7 @@ class AlertingFakes { this.randomInputs = this.randomInputs.bind(this); this.randomMonitorEnabled = this.randomMonitorEnabled.bind(this); this.randomMonitor = this.randomMonitor.bind(this); + this.randomTime = this.randomTime.bind(this); } randomEmailDestination() { @@ -106,20 +109,22 @@ class AlertingFakes { }; } - randomTrigger() { + randomTrigger(type = TRIGGER_TYPE.QUERY_LEVEL) { return { - id: this.chance.guid().slice(0, 20), - name: this.chance.word(), - severity: this.chance.string({ length: 1, pool: '12345' }), - condition: { - script: { - lang: 'painless', - source: `return ${this.chance.bool()}`, + [type]: { + id: this.chance.guid().slice(0, 20), + name: this.chance.word(), + severity: this.chance.string({ length: 1, pool: '12345' }), + condition: { + script: { + lang: 'painless', + source: `return ${this.chance.bool()}`, + }, }, + actions: new Array(this.chance.natural({ max: 10 })) + .fill(null) + .map(() => this.randomAction()), }, - actions: new Array(this.chance.natural({ max: 10 })) - .fill(null) - .map(() => this.randomAction()), }; } @@ -184,6 +189,10 @@ class AlertingFakes { .map(() => this.randomTrigger()), }; } + + randomTime() { + return this.chance.timestamp(); + } } module.exports = AlertingFakes; From 0ba0ece4a48cdf67cc2e356892e4e1e323b07061 Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Thu, 30 Sep 2021 15:55:29 -0700 Subject: [PATCH 07/29] Fixed a few bugs --- .../components/VisualGraph/VisualGraph.js | 2 +- .../components/VisualGraph/utils/helpers.js | 23 ++++++++++++------- .../containers/DefineMonitor/DefineMonitor.js | 2 +- .../DefineTrigger/utils/validation.js | 4 ++-- .../DefineTrigger/utils/validation.test.js | 6 ++--- public/utils/validate.js | 2 +- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js b/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js index cde9b9768..aa61530df 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js +++ b/public/pages/CreateMonitor/components/VisualGraph/VisualGraph.js @@ -128,7 +128,7 @@ export default class VisualGraph extends Component { renderAggregationXYPlot = (data, groupedData) => { const { annotation, thresholdValue, values, fieldName, aggregationType } = this.props; const { hint } = this.state; - const xDomain = getBufferedXDomain(data); + const xDomain = getBufferedXDomain(data, values); const yDomain = getYDomain(data); const annotations = getAnnotationData(xDomain, yDomain, thresholdValue); const xTitle = values.timeField; diff --git a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.js b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.js index 2db08b0bc..4d9a72d64 100644 --- a/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.js +++ b/public/pages/CreateMonitor/components/VisualGraph/utils/helpers.js @@ -25,6 +25,7 @@ */ import _ from 'lodash'; +import moment from 'moment'; import { selectOptionValueToText } from '../../MonitorExpressions/expressions/utils/helpers'; import { @@ -61,10 +62,14 @@ export function getXDomain(data) { return [minDate.x, maxDate.x]; } -export function getBufferedXDomain(data) { +export function getBufferedXDomain(data, values) { + const { bucketValue, bucketUnitOfTime } = values; const minDate = data[0].x; const maxDate = data[data.length - 1].x; - const timeRange = maxDate - minDate; + // If minDate equals to maxDate, then use bucketValue and bucketUnitOfTime as timeRange. + let timeRange = maxDate - minDate; + if (!timeRange) timeRange = moment.duration(bucketValue, bucketUnitOfTime); + const minDateBuffer = minDate - timeRange * X_DOMAIN_BUFFER; const maxDateBuffer = maxDate.getTime() + timeRange * X_DOMAIN_BUFFER; return [minDateBuffer, maxDateBuffer]; @@ -111,13 +116,13 @@ export function getDataFromResponse(response, fieldName, monitorType) { } } -// Function for aggregation type monitors to get Map of data. -// The current response gives a large number of data aggregated in buckets, and this function returns the top n results with highest count of data points. -// The number n is based on the constant BAY_KEY_COUNT. +// Function for aggregation type monitors to get Map of data. +// The current response gives a large number of data aggregated in buckets, and this function returns the top n results with highest count of data points. +// The number n is based on the constant BAY_KEY_COUNT. export function getMapDataFromResponse(response, fieldName, groupByFields) { if (!response) return []; const buckets = _.get(response, 'aggregations.composite_agg.buckets', []); - let allData = new Map(); + const allData = new Map(); buckets.map((bucket) => { const dataPoint = getXYValuesByFieldName(bucket, fieldName); // Key of object is the string concat by group by field values @@ -126,7 +131,7 @@ export function getMapDataFromResponse(response, fieldName, groupByFields) { ? allData.set(key, [dataPoint, ...allData.get(key)]) : allData.set(key, [dataPoint]); }); - let entryLength = []; + const entryLength = []; for (const [key, value] of allData.entries()) { allData.set(key, _.filter(value, filterInvalidYValues)); entryLength.push({ key, length: value.length }); @@ -141,7 +146,9 @@ export function getMapDataFromResponse(response, fieldName, groupByFields) { export function getXYValuesByFieldName(bucket, fieldName) { const x = new Date(bucket.key.date); - const path = bucket[fieldName] ? `${fieldName}.value` : 'doc_count'; + // Parse the fieldName containing "." to "_" + const parsedFieldName = fieldName.replace(/\./g, '_'); + const path = bucket[parsedFieldName] ? `${parsedFieldName}.value` : 'doc_count'; const y = _.get(bucket, path, null); return { x, y }; } diff --git a/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js b/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js index a3f56e899..7f3afed98 100644 --- a/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js +++ b/public/pages/CreateMonitor/containers/DefineMonitor/DefineMonitor.js @@ -182,7 +182,7 @@ class DefineMonitor extends Component { // Default `count of documents` graph when using Bucket-level monitor let graphs = [ - , + , ]; diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js index ee7ecb215..26620bd72 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.js @@ -28,7 +28,7 @@ import _ from 'lodash'; import { FORMIK_INITIAL_TRIGGER_VALUES, TRIGGER_TYPE } from '../../CreateTrigger/utils/constants'; export const validateTriggerName = (triggers, triggerToEdit, fieldPath) => (value) => { - if (!value) return 'Required'; + if (!value) return 'Required.'; const nameExists = triggers.filter((trigger) => { const triggerId = _.get( trigger, @@ -44,7 +44,7 @@ export const validateTriggerName = (triggers, triggerToEdit, fieldPath) => (valu return triggerToEditId !== triggerId && triggerName.toLowerCase() === value.toLowerCase(); }); if (nameExists.length > 0) { - return 'Trigger name already used'; + return 'Trigger name already used.'; } // TODO: character restrictions // TODO: character limits diff --git a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js index 4a6b3a068..f141d1936 100644 --- a/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js +++ b/public/pages/CreateTrigger/containers/DefineTrigger/utils/validation.test.js @@ -33,13 +33,13 @@ describe('validateTriggerName', () => { }); test('returns Required string if falsy value', () => { - expect(validateTriggerName([], {})()).toBe('Required'); - expect(validateTriggerName([], {})('')).toBe('Required'); + expect(validateTriggerName([], {})()).toBe('Required.'); + expect(validateTriggerName([], {})('')).toBe('Required.'); }); test('returns false if name already exists in monitor while creates new trigger', () => { const triggers = [{ [TRIGGER_TYPE.QUERY_LEVEL]: { id: '123', name: 'Test' } }]; expect(validateTriggerName(triggers, { [TRIGGER_TYPE.QUERY_LEVEL]: {} })('Test')).toBe( - 'Trigger name already used' + 'Trigger name already used.' ); }); diff --git a/public/utils/validate.js b/public/utils/validate.js index 9f1757268..d5bc44268 100644 --- a/public/utils/validate.js +++ b/public/utils/validate.js @@ -74,7 +74,7 @@ export const required = (value) => { }; export const validateRequiredNumber = (value) => { - if (_.isEmpty(value)) return 'Provide a value.'; + if (value === undefined || typeof value == 'string') return 'Provide a value.'; }; export const validateMonitorName = (httpClient, monitorToEdit) => async (value) => { From 3473d510101145c0d80130ed3181afb60dfb1e96 Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Thu, 30 Sep 2021 16:04:31 -0700 Subject: [PATCH 08/29] Update opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md Signed-off-by: Annie Lee --- ...earch-alerting-dashboards-plugin.release-notes-1.1.0.0.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index b1584f384..074b518ce 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -49,4 +49,7 @@ Compatible with OpenSearch Dashboards 1.1.0 * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) * Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) -* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) \ No newline at end of file +* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) + +### Bug Fixes +* A few bug fix for create monitor ([#121](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/121)) \ No newline at end of file From ebda05c7db8ac2611791740b39f0e3e72ef84422 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Fri, 1 Oct 2021 00:34:54 -0700 Subject: [PATCH 09/29] Fixed a bug that displayed all alerts for a monitor on individual trigger flyouts. Fixed a bug that diplayed incorrect source for the condition field on the alerts flyout. Fixed a bug that diplaying incorrect severity on the alerts flyout. --- public/components/Flyout/flyouts/alertsDashboard.js | 8 +++++--- public/pages/Dashboard/containers/Dashboard.js | 4 +++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/public/components/Flyout/flyouts/alertsDashboard.js b/public/components/Flyout/flyouts/alertsDashboard.js index 3e5b28763..17bf4df95 100644 --- a/public/components/Flyout/flyouts/alertsDashboard.js +++ b/public/components/Flyout/flyouts/alertsDashboard.js @@ -80,6 +80,7 @@ const getBucketLevelGraphFilter = (trigger) => { const alertsDashboard = (payload) => { const { + alerts, history, httpClient, last_notification_time, @@ -90,9 +91,8 @@ const alertsDashboard = (payload) => { monitor_name, notifications, setFlyout, - severity, start_time, - triggerId, + triggerID, trigger_name, } = payload; const monitor = _.get(_.find(monitors, { _id: monitor_id }), '_source'); @@ -104,10 +104,11 @@ const alertsDashboard = (payload) => { monitorType === MONITOR_TYPE.QUERY_LEVEL ? TRIGGER_TYPE.QUERY_LEVEL : TRIGGER_TYPE.BUCKET_LEVEL; let trigger = _.get(monitor, 'triggers', []).find((trigger) => { - return trigger[triggerType].triggerId === triggerId; + return trigger[triggerType].id === triggerID; }); trigger = _.get(trigger, triggerType); + const severity = _.get(trigger, 'severity'); const groupBy = _.get(monitor, MONITOR_GROUP_BY); const condition = @@ -260,6 +261,7 @@ const alertsDashboard = (payload) => { monitorType={monitorType} perAlertView={true} groupBy={groupBy} + flyoutAlerts={alerts} /> diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index 64d834766..2760be98a 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -486,7 +486,9 @@ export default class Dashboard extends Component { Date: Fri, 1 Oct 2021 00:45:31 -0700 Subject: [PATCH 10/29] Updated release notes to reflect PR 122 bug fix. --- ...earch-alerting-dashboards-plugin.release-notes-1.1.0.0.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index b1584f384..ff91b4f5c 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -49,4 +49,7 @@ Compatible with OpenSearch Dashboards 1.1.0 * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) * Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) -* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) \ No newline at end of file +* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) + +### Bug Fixes +* Fixed a bug that displayed all alerts for a monitor on individual triggers' flyouts. Fixed a bug that displayed incorrect source for the condition field on the alerts flyout. Fixed a bug that displayed incorrect severity on the alerts flyout.([#122](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/122)) \ No newline at end of file From 6c00fb58bb16582d91f0ebdfb11a122fcfbacefd Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Fri, 1 Oct 2021 12:58:08 -0700 Subject: [PATCH 11/29] Fixing number of alerts displayed on Monitors tab. --- .../pages/Dashboard/containers/Dashboard.js | 6 +++ .../Monitors/containers/Monitors/Monitors.js | 46 +++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index 2760be98a..27e86d9c2 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -96,6 +96,7 @@ export default class Dashboard extends Component { sortField, monitorIds, } = this.state; + console.info(`hurneyt componentDidMount::monitorIds = ${JSON.stringify(monitorIds)}`); this.getAlerts( page * size, size, @@ -122,6 +123,7 @@ export default class Dashboard extends Component { alertState, monitorIds, } = this.state; + console.info(`hurneyt componentDidUpdate::monitorIds = ${JSON.stringify(monitorIds)}`); this.getAlerts( page * size, size, @@ -191,6 +193,7 @@ export default class Dashboard extends Component { alertState, monitorIds, }; + console.info(`hurneyt getAlerts::monitorIds = ${JSON.stringify(monitorIds)}`); const queryParamsString = queryString.stringify(params); location.search; const { httpClient, history, notifications, perAlertView } = this.props; @@ -198,6 +201,8 @@ export default class Dashboard extends Component { httpClient.get('../api/alerting/alerts', { query: params }).then((resp) => { if (resp.ok) { const { alerts, totalAlerts } = resp; + console.info(`hurneyt alerts = ${JSON.stringify(resp, null, 4)}`); + console.info(`hurneyt Dashboard::alertState = ${JSON.stringify(alertState)}`); this.setState({ alerts, totalAlerts, @@ -293,6 +298,7 @@ export default class Dashboard extends Component { alertState, monitorIds, } = this.state; + console.info(`hurneyt acknowledgeAlert::monitorIds = ${JSON.stringify(monitorIds)}`); this.getAlerts( page * size, size, diff --git a/public/pages/Monitors/containers/Monitors/Monitors.js b/public/pages/Monitors/containers/Monitors/Monitors.js index 910a69429..00a559e1a 100644 --- a/public/pages/Monitors/containers/Monitors/Monitors.js +++ b/public/pages/Monitors/containers/Monitors/Monitors.js @@ -69,6 +69,7 @@ export default class Monitors extends Component { }; this.getMonitors = _.debounce(this.getMonitors.bind(this), 500, { leading: true }); + // this.getAlerts = _.debounce(this.getAlerts.bind(this), 500, { loading: true }); this.onTableChange = this.onTableChange.bind(this); this.onMonitorStateChange = this.onMonitorStateChange.bind(this); this.onSelectionChange = this.onSelectionChange.bind(this); @@ -158,6 +159,10 @@ export default class Monitors extends Component { const response = await httpClient.get('../api/alerting/monitors', { query: params }); if (response.ok) { const { monitors, totalMonitors } = response; + console.info(`hurneyt monitors = ${JSON.stringify(monitors)}`); + monitors.map((monitor) => + this.getAlerts(from, size, '', sortField, sortDirection, 'ALL', 'ALL', monitor.id) + ); this.setState({ monitors, totalMonitors }); } else { console.log('error getting monitors:', response); @@ -170,6 +175,46 @@ export default class Monitors extends Component { this.setState({ loadingMonitors: false }); } + getAlerts = _.debounce( + (from, size, search, sortField, sortDirection, severityLevel, alertState, monitorId) => { + console.info(`hurneyt from = ${JSON.stringify(from)}`); + console.info(`hurneyt size = ${JSON.stringify(size)}`); + console.info(`hurneyt search = ${JSON.stringify(search)}`); + console.info(`hurneyt sortField = ${JSON.stringify(sortField)}`); + console.info(`hurneyt sortDirection = ${JSON.stringify(sortDirection)}`); + console.info(`hurneyt severityLevel = ${JSON.stringify(severityLevel)}`); + console.info(`hurneyt alertState = ${JSON.stringify(alertState)}`); + console.info(`hurneyt monitorId = ${JSON.stringify(monitorId)}`); + this.setState({ loadingMonitors: true }); + try { + const { httpClient, history } = this.props; + const params = { + from, + size, + search, + sortField, + sortDirection, + severityLevel, + alertState, + monitorId, + }; + + const queryParamsString = queryString.stringify(params); + history.replace({ ...this.props.location, search: queryParamsString }); + httpClient.get('../api/alerting/alerts', { query: params }).then((resp) => { + if (resp.ok) { + console.info(`hurneyt resp = ${JSON.stringify(resp)}`); + } + }); + } catch (err) { + console.info(`hurneyt resp ERROR = ${JSON.stringify(resp)}`); + } + this.setState({ loadingMonitors: false }); + }, + 500, + { leading: true } + ); + onTableChange({ page: tablePage = {}, sort = {} }) { const { index: page, size } = tablePage; const { field: sortField, direction: sortDirection } = sort; @@ -398,6 +443,7 @@ export default class Monitors extends Component { selectableMessage: (selectable) => (selectable ? undefined : undefined), }; + console.info(`hurneyt monitors = ${JSON.stringify(monitors)}`); return ( Date: Thu, 30 Sep 2021 16:04:31 -0700 Subject: [PATCH 12/29] Update opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md Signed-off-by: Annie Lee --- ...earch-alerting-dashboards-plugin.release-notes-1.1.0.0.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index b1584f384..074b518ce 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -49,4 +49,7 @@ Compatible with OpenSearch Dashboards 1.1.0 * Update cypress-workflow.yml to use environment variable for OS and OS dashboard versions ([#96](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/96)) * Create opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md ([#101](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/101)) * Update version in package.json ([#102](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/102)) -* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) \ No newline at end of file +* Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) + +### Bug Fixes +* A few bug fix for create monitor ([#121](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/121)) \ No newline at end of file From 9ac8b2d69f0007e6a40be4527c4ba5cdadbc5fb4 Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Fri, 1 Oct 2021 15:43:32 -0700 Subject: [PATCH 13/29] More bug fix Signed-off-by: Annie Lee --- .../MonitorExpressions/expressions/GroupByExpression.js | 4 +++- .../MonitorExpressions/expressions/GroupByItem.js | 1 + .../MonitorExpressions/expressions/utils/constants.js | 1 + public/pages/Dashboard/containers/Dashboard.js | 6 +++++- .../Monitors/components/MonitorActions/MonitorActions.js | 5 ++++- 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js index 34fdaa97b..bd3322a8d 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByExpression.js @@ -30,7 +30,7 @@ import { EuiText, EuiButtonEmpty, EuiSpacer } from '@elastic/eui'; import { getIndexFields } from './utils/dataTypes'; import { getGroupByExpressionAllowedTypes } from './utils/helpers'; import GroupByItem from './GroupByItem'; -import { GROUP_BY_ERROR } from './utils/constants'; +import { GROUP_BY_ERROR, QUERY_TYPE_GROUP_BY_ERROR } from './utils/constants'; import { MONITOR_TYPE } from '../../../../../utils/constants'; import { inputLimitText } from '../../../../../utils/helpers'; import { @@ -86,6 +86,8 @@ class GroupByExpression extends Component { const isBucketLevelMonitor = values.monitor_type === MONITOR_TYPE.BUCKET_LEVEL; if (!values.groupBy.length && isBucketLevelMonitor) { errors.groupBy = GROUP_BY_ERROR; + } else if (!isBucketLevelMonitor && values.groupBy.length > MAX_NUM_QUERY_LEVEL_GROUP_BYS) { + errors.groupBy = QUERY_TYPE_GROUP_BY_ERROR; } else { delete errors.groupBy; } diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js index 7e11c9edb..b185fdb73 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js @@ -18,6 +18,7 @@ export default function GroupByItem( ) { const [isPopoverOpen, setIsPopoverOpen] = useState(groupByItem === ''); const closePopover = () => { + if (groupByItem === '') arrayHelpers.remove(index); setIsPopoverOpen(false); }; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js index 377633d09..4151faae5 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js @@ -114,3 +114,4 @@ export const AGGREGATION_TYPES = [ ]; export const GROUP_BY_ERROR = 'Must specify at least 1 group by expression.'; +export const QUERY_TYPE_GROUP_BY_ERROR = 'Can have a maximum of 1 group by selections.'; diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index 64d834766..5a2c1a115 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -413,8 +413,12 @@ export default class Dashboard extends Component { }; const actions = () => { + // The acknowledge button is disabled when viewing by per alerts, and no item selected or per trigger view and item selected is not 1. const actions = [ - + Acknowledge , ]; diff --git a/public/pages/Monitors/components/MonitorActions/MonitorActions.js b/public/pages/Monitors/components/MonitorActions/MonitorActions.js index d7f0d8f69..842aad00f 100644 --- a/public/pages/Monitors/components/MonitorActions/MonitorActions.js +++ b/public/pages/Monitors/components/MonitorActions/MonitorActions.js @@ -43,7 +43,8 @@ export default class MonitorActions extends Component { }; getActions = () => { - return [ + const { isEditDisabled } = this.props; + const actions = [ , ]; + if (isEditDisabled) actions.splice(0, 1); + return actions; }; onCloseActions = () => { From c865807a578966aaca335ab4872d98955c95c5e1 Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Fri, 1 Oct 2021 15:56:05 -0700 Subject: [PATCH 14/29] Skip test based on modification Signed-off-by: Annie Lee --- .../pages/Monitors/components/MonitorActions/MonitorActions.js | 2 ++ .../Monitors/components/MonitorActions/MonitorActions.test.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/public/pages/Monitors/components/MonitorActions/MonitorActions.js b/public/pages/Monitors/components/MonitorActions/MonitorActions.js index 842aad00f..b34ffe163 100644 --- a/public/pages/Monitors/components/MonitorActions/MonitorActions.js +++ b/public/pages/Monitors/components/MonitorActions/MonitorActions.js @@ -43,6 +43,8 @@ export default class MonitorActions extends Component { }; getActions = () => { + // TODO: Support bulk acknowledge alerts across multiple monitors after figuring out the correct parameter for getAlerts API. + // Disabling the acknowledge button for now when more than 1 monitors selected. const { isEditDisabled } = this.props; const actions = [ { expect(wrapper.state('isActionsOpen')).toBe(false); }); - test('calls onCloseActions and onBulkAcknowledge when clicking Acknowledge item', () => { + test.skip('calls onCloseActions and onBulkAcknowledge when clicking Acknowledge item', () => { const instance = wrapper.instance(); jest.spyOn(instance, 'onCloseActions'); wrapper.find('[data-test-subj="actionsButton"]').hostNodes().simulate('click'); From 1ae2215f31102a976b2997822918200507e4d222 Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Fri, 1 Oct 2021 15:56:05 -0700 Subject: [PATCH 15/29] Skip test based on modification Signed-off-by: Annie Lee --- .../pages/Monitors/components/MonitorActions/MonitorActions.js | 2 ++ .../Monitors/components/MonitorActions/MonitorActions.test.js | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/public/pages/Monitors/components/MonitorActions/MonitorActions.js b/public/pages/Monitors/components/MonitorActions/MonitorActions.js index 842aad00f..b34ffe163 100644 --- a/public/pages/Monitors/components/MonitorActions/MonitorActions.js +++ b/public/pages/Monitors/components/MonitorActions/MonitorActions.js @@ -43,6 +43,8 @@ export default class MonitorActions extends Component { }; getActions = () => { + // TODO: Support bulk acknowledge alerts across multiple monitors after figuring out the correct parameter for getAlerts API. + // Disabling the acknowledge button for now when more than 1 monitors selected. const { isEditDisabled } = this.props; const actions = [ { expect(wrapper.state('isActionsOpen')).toBe(false); }); - test('calls onCloseActions and onBulkAcknowledge when clicking Acknowledge item', () => { + test.skip('calls onCloseActions and onBulkAcknowledge when clicking Acknowledge item', () => { const instance = wrapper.instance(); jest.spyOn(instance, 'onCloseActions'); wrapper.find('[data-test-subj="actionsButton"]').hostNodes().simulate('click'); From d2058b14d23fc53cbe5230018e535ad8fc0838ff Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Fri, 1 Oct 2021 16:20:45 -0700 Subject: [PATCH 16/29] Update popover windows to remove item when filed is not defined --- .../components/MonitorExpressions/expressions/MetricItem.js | 1 + .../MonitorExpressions/expressions/WhereExpression.js | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js index d72735f6b..cf8f2ab43 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js @@ -18,6 +18,7 @@ export default function MetricItem( ) { const [isPopoverOpen, setIsPopoverOpen] = useState(aggregation.fieldName === ''); const closePopover = () => { + if (aggregation.fieldName === '') arrayHelpers.remove(index); setIsPopoverOpen(false); }; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index 68d112a8b..66281eb59 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -123,9 +123,11 @@ class WhereExpression extends Component { } = this.props; // Explicitly invoking validation, this component unmount after it closes. const fieldName = _.get(values, `${fieldPath}where.fieldName`, ''); + const fieldValue = _.get(values, `${fieldPath}where.fieldValue`, ''); if (fieldName > 0) { await this.props.formik.validateForm(); } + if (_.isEmpty(fieldName) || _.isEmpty(fieldValue)) this.resetValues(); closeExpression(Expressions.WHERE); }; @@ -267,7 +269,7 @@ class WhereExpression extends Component { iconSide="right" iconType="cross" iconOnClick={() => this.resetValues()} - iconOnClickAriaLabel="Remove where filter" + iconOnClickAriaLabel="Remove filter" onClick={() => { openExpression(Expressions.WHERE); }} From 756793c2ffc3dd98b3dec8a4f387c401e60e1cb6 Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Fri, 1 Oct 2021 16:57:20 -0700 Subject: [PATCH 17/29] Update field validation --- .../components/MonitorExpressions/expressions/GroupByItem.js | 3 ++- .../components/MonitorExpressions/expressions/MetricItem.js | 3 ++- .../MonitorExpressions/expressions/WhereExpression.js | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js index b185fdb73..ac092fd70 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/GroupByItem.js @@ -10,6 +10,7 @@ */ import React, { useState } from 'react'; +import _ from 'lodash'; import { EuiPopover, EuiBadge, EuiPopoverTitle } from '@elastic/eui'; import { GroupByPopover } from './index'; @@ -18,7 +19,7 @@ export default function GroupByItem( ) { const [isPopoverOpen, setIsPopoverOpen] = useState(groupByItem === ''); const closePopover = () => { - if (groupByItem === '') arrayHelpers.remove(index); + if (_.isEmpty(groupByItem)) arrayHelpers.remove(index); setIsPopoverOpen(false); }; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js index cf8f2ab43..cf0459ada 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricItem.js @@ -10,6 +10,7 @@ */ import React, { useState } from 'react'; +import _ from 'lodash'; import { EuiPopover, EuiBadge, EuiPopoverTitle } from '@elastic/eui'; import MetricPopover from './MetricPopover'; @@ -18,7 +19,7 @@ export default function MetricItem( ) { const [isPopoverOpen, setIsPopoverOpen] = useState(aggregation.fieldName === ''); const closePopover = () => { - if (aggregation.fieldName === '') arrayHelpers.remove(index); + if (_.isEmpty(aggregation.fieldName)) arrayHelpers.remove(index); setIsPopoverOpen(false); }; diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index 66281eb59..8bb735399 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -127,7 +127,7 @@ class WhereExpression extends Component { if (fieldName > 0) { await this.props.formik.validateForm(); } - if (_.isEmpty(fieldName) || _.isEmpty(fieldValue)) this.resetValues(); + if (_.isEmpty(fieldName) || _.isEmpty(fieldValue.toString())) this.resetValues(); closeExpression(Expressions.WHERE); }; From 559fb68a534574079bff761aaccfb17130b8ddb7 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Fri, 1 Oct 2021 18:05:00 -0700 Subject: [PATCH 18/29] Fixed a bug that prevented selecting query-level monitor alerts 1 by 1. Removed experimental code and comments. --- .../pages/Dashboard/containers/Dashboard.js | 8 +--- .../Monitors/containers/Monitors/Monitors.js | 43 ------------------- ...dashboards-plugin.release-notes-1.1.0.0.md | 2 +- 3 files changed, 2 insertions(+), 51 deletions(-) diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index 6f163353e..adfa7bd24 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -96,7 +96,6 @@ export default class Dashboard extends Component { sortField, monitorIds, } = this.state; - console.info(`hurneyt componentDidMount::monitorIds = ${JSON.stringify(monitorIds)}`); this.getAlerts( page * size, size, @@ -123,7 +122,6 @@ export default class Dashboard extends Component { alertState, monitorIds, } = this.state; - console.info(`hurneyt componentDidUpdate::monitorIds = ${JSON.stringify(monitorIds)}`); this.getAlerts( page * size, size, @@ -193,7 +191,6 @@ export default class Dashboard extends Component { alertState, monitorIds, }; - console.info(`hurneyt getAlerts::monitorIds = ${JSON.stringify(monitorIds)}`); const queryParamsString = queryString.stringify(params); location.search; const { httpClient, history, notifications, perAlertView } = this.props; @@ -201,8 +198,6 @@ export default class Dashboard extends Component { httpClient.get('../api/alerting/alerts', { query: params }).then((resp) => { if (resp.ok) { const { alerts, totalAlerts } = resp; - console.info(`hurneyt alerts = ${JSON.stringify(resp, null, 4)}`); - console.info(`hurneyt Dashboard::alertState = ${JSON.stringify(alertState)}`); this.setState({ alerts, totalAlerts, @@ -298,7 +293,6 @@ export default class Dashboard extends Component { alertState, monitorIds, } = this.state; - console.info(`hurneyt acknowledgeAlert::monitorIds = ${JSON.stringify(monitorIds)}`); this.getAlerts( page * size, size, @@ -469,7 +463,7 @@ export default class Dashboard extends Component { }; const getItemId = (item) => { - if (perAlertView && isBucketMonitor) return item.id; + if (perAlertView) return isBucketMonitor ? item.id : `${item.id}-${item.version}`; return `${item.triggerID}-${item.version}`; }; diff --git a/public/pages/Monitors/containers/Monitors/Monitors.js b/public/pages/Monitors/containers/Monitors/Monitors.js index 00a559e1a..81d5739dc 100644 --- a/public/pages/Monitors/containers/Monitors/Monitors.js +++ b/public/pages/Monitors/containers/Monitors/Monitors.js @@ -69,7 +69,6 @@ export default class Monitors extends Component { }; this.getMonitors = _.debounce(this.getMonitors.bind(this), 500, { leading: true }); - // this.getAlerts = _.debounce(this.getAlerts.bind(this), 500, { loading: true }); this.onTableChange = this.onTableChange.bind(this); this.onMonitorStateChange = this.onMonitorStateChange.bind(this); this.onSelectionChange = this.onSelectionChange.bind(this); @@ -159,7 +158,6 @@ export default class Monitors extends Component { const response = await httpClient.get('../api/alerting/monitors', { query: params }); if (response.ok) { const { monitors, totalMonitors } = response; - console.info(`hurneyt monitors = ${JSON.stringify(monitors)}`); monitors.map((monitor) => this.getAlerts(from, size, '', sortField, sortDirection, 'ALL', 'ALL', monitor.id) ); @@ -175,46 +173,6 @@ export default class Monitors extends Component { this.setState({ loadingMonitors: false }); } - getAlerts = _.debounce( - (from, size, search, sortField, sortDirection, severityLevel, alertState, monitorId) => { - console.info(`hurneyt from = ${JSON.stringify(from)}`); - console.info(`hurneyt size = ${JSON.stringify(size)}`); - console.info(`hurneyt search = ${JSON.stringify(search)}`); - console.info(`hurneyt sortField = ${JSON.stringify(sortField)}`); - console.info(`hurneyt sortDirection = ${JSON.stringify(sortDirection)}`); - console.info(`hurneyt severityLevel = ${JSON.stringify(severityLevel)}`); - console.info(`hurneyt alertState = ${JSON.stringify(alertState)}`); - console.info(`hurneyt monitorId = ${JSON.stringify(monitorId)}`); - this.setState({ loadingMonitors: true }); - try { - const { httpClient, history } = this.props; - const params = { - from, - size, - search, - sortField, - sortDirection, - severityLevel, - alertState, - monitorId, - }; - - const queryParamsString = queryString.stringify(params); - history.replace({ ...this.props.location, search: queryParamsString }); - httpClient.get('../api/alerting/alerts', { query: params }).then((resp) => { - if (resp.ok) { - console.info(`hurneyt resp = ${JSON.stringify(resp)}`); - } - }); - } catch (err) { - console.info(`hurneyt resp ERROR = ${JSON.stringify(resp)}`); - } - this.setState({ loadingMonitors: false }); - }, - 500, - { leading: true } - ); - onTableChange({ page: tablePage = {}, sort = {} }) { const { index: page, size } = tablePage; const { field: sortField, direction: sortDirection } = sort; @@ -443,7 +401,6 @@ export default class Monitors extends Component { selectableMessage: (selectable) => (selectable ? undefined : undefined), }; - console.info(`hurneyt monitors = ${JSON.stringify(monitors)}`); return ( Date: Sun, 3 Oct 2021 16:29:31 -0700 Subject: [PATCH 19/29] Merge remote-tracking branch 'thomas/alertFlyoutBugFix' into bug-fix --- .../components/Flyout/flyouts/alertsDashboard.js | 8 +++++--- public/pages/Dashboard/containers/Dashboard.js | 14 ++++++++++---- ...ting-dashboards-plugin.release-notes-1.1.0.0.md | 3 ++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/public/components/Flyout/flyouts/alertsDashboard.js b/public/components/Flyout/flyouts/alertsDashboard.js index 3e5b28763..17bf4df95 100644 --- a/public/components/Flyout/flyouts/alertsDashboard.js +++ b/public/components/Flyout/flyouts/alertsDashboard.js @@ -80,6 +80,7 @@ const getBucketLevelGraphFilter = (trigger) => { const alertsDashboard = (payload) => { const { + alerts, history, httpClient, last_notification_time, @@ -90,9 +91,8 @@ const alertsDashboard = (payload) => { monitor_name, notifications, setFlyout, - severity, start_time, - triggerId, + triggerID, trigger_name, } = payload; const monitor = _.get(_.find(monitors, { _id: monitor_id }), '_source'); @@ -104,10 +104,11 @@ const alertsDashboard = (payload) => { monitorType === MONITOR_TYPE.QUERY_LEVEL ? TRIGGER_TYPE.QUERY_LEVEL : TRIGGER_TYPE.BUCKET_LEVEL; let trigger = _.get(monitor, 'triggers', []).find((trigger) => { - return trigger[triggerType].triggerId === triggerId; + return trigger[triggerType].id === triggerID; }); trigger = _.get(trigger, triggerType); + const severity = _.get(trigger, 'severity'); const groupBy = _.get(monitor, MONITOR_GROUP_BY); const condition = @@ -260,6 +261,7 @@ const alertsDashboard = (payload) => { monitorType={monitorType} perAlertView={true} groupBy={groupBy} + flyoutAlerts={alerts} /> diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index 5a2c1a115..b7ef0d519 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -310,7 +310,8 @@ export default class Dashboard extends Component { const { index: page, size } = tablePage; const { field: sortField, direction: sortDirection } = sort; - + //debug use + console.log('page: ' + page + ' size: ' + size); this.setState({ page, size, @@ -370,7 +371,7 @@ export default class Dashboard extends Component { notifications, isAlertsFlyout = false, } = this.props; - const totalItems = perAlertView ? totalAlerts : totalTriggers; + let totalItems = perAlertView ? totalAlerts : totalTriggers; const isBucketMonitor = monitorType === MONITOR_TYPE.BUCKET_LEVEL; let columnType = perAlertView @@ -387,7 +388,10 @@ export default class Dashboard extends Component { setFlyout ); - if (isAlertsFlyout) columnType = removeColumns(['severity', 'trigger_name'], columnType); + if (isAlertsFlyout) { + totalItems = this.props.flyoutAlerts.length; + columnType = removeColumns(['severity', 'trigger_name'], columnType); + } const pagination = { pageIndex: page, @@ -490,7 +494,9 @@ export default class Dashboard extends Component { Date: Sun, 3 Oct 2021 16:56:22 -0700 Subject: [PATCH 20/29] Update Dashboard.js --- public/pages/Dashboard/containers/Dashboard.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index b7ef0d519..6dd2d0ea5 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -77,6 +77,7 @@ export default class Dashboard extends Component { sortField, totalAlerts: 0, totalTriggers: 0, + trimmedFlyoutAlerts: this.props.flyoutAlerts ? this.props.flyoutAlerts.slice(0, 10) : [], }; } @@ -307,17 +308,23 @@ export default class Dashboard extends Component { }; onTableChange = ({ page: tablePage = {}, sort = {} }) => { + const { isAlertsFlyout } = this.props; const { index: page, size } = tablePage; const { field: sortField, direction: sortDirection } = sort; - //debug use - console.log('page: ' + page + ' size: ' + size); this.setState({ page, size, sortField, sortDirection, }); + + // If the table is in flyout, return the trimmed array of alerts. + if (isAlertsFlyout) { + const { flyoutAlerts } = this.props; + const trimmedFlyoutAlerts = flyoutAlerts.slice(page * size, page * size + size); + this.setState({ trimmedFlyoutAlerts }); + } }; onSeverityLevelChange = (e) => { @@ -356,6 +363,7 @@ export default class Dashboard extends Component { sortField, totalAlerts, totalTriggers, + trimmedFlyoutAlerts, } = this.state; const { monitorIds, @@ -494,9 +502,7 @@ export default class Dashboard extends Component { Date: Sun, 3 Oct 2021 21:49:57 -0700 Subject: [PATCH 21/29] Support data filter when using null operator --- .../expressions/WhereExpression.js | 12 +++++++++--- public/utils/validate.js | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index 8bb735399..e2c600b59 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -105,9 +105,10 @@ class WhereExpression extends Component { } }; - handleOperatorChange = (e, field) => { + handleOperatorChange = (e, field, form) => { this.props.onMadeChanges(); field.onChange(e); + form.setFieldError('where', undefined); }; handleChangeWrapper = (e, field) => { @@ -117,17 +118,22 @@ class WhereExpression extends Component { handleClosePopOver = async () => { const { - formik: { values }, + formik: { values, errors, touched }, closeExpression, fieldPath = '', } = this.props; // Explicitly invoking validation, this component unmount after it closes. const fieldName = _.get(values, `${fieldPath}where.fieldName`, ''); const fieldValue = _.get(values, `${fieldPath}where.fieldValue`, ''); + const fieldOperator = _.get(values, `${fieldPath}where.operator`, 'is'); if (fieldName > 0) { await this.props.formik.validateForm(); } - if (_.isEmpty(fieldName) || _.isEmpty(fieldValue.toString())) this.resetValues(); + if ( + _.isEmpty(fieldName) || + (!isNullOperator(fieldOperator) && _.isEmpty(fieldValue.toString())) + ) + this.resetValues(); closeExpression(Expressions.WHERE); }; diff --git a/public/utils/validate.js b/public/utils/validate.js index d5bc44268..6f66edcab 100644 --- a/public/utils/validate.js +++ b/public/utils/validate.js @@ -74,7 +74,7 @@ export const required = (value) => { }; export const validateRequiredNumber = (value) => { - if (value === undefined || typeof value == 'string') return 'Provide a value.'; + if (value === undefined || typeof value === 'string') return 'Provide a value.'; }; export const validateMonitorName = (httpClient, monitorToEdit) => async (value) => { From 78916c2afc3d8eef2aefa0c21d13e1490748750f Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Sun, 3 Oct 2021 21:59:55 -0700 Subject: [PATCH 22/29] Update WhereExpression.js --- .../MonitorExpressions/expressions/WhereExpression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index e2c600b59..f4038878a 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -118,7 +118,7 @@ class WhereExpression extends Component { handleClosePopOver = async () => { const { - formik: { values, errors, touched }, + formik: { values }, closeExpression, fieldPath = '', } = this.props; From 63f20e1d79443c79199175884ee2364b82d4f0dc Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 4 Oct 2021 10:34:55 -0700 Subject: [PATCH 23/29] Fixed a bug that was causing incorrect pagination display on alerts flyout. --- .../pages/Dashboard/containers/Dashboard.js | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/public/pages/Dashboard/containers/Dashboard.js b/public/pages/Dashboard/containers/Dashboard.js index adfa7bd24..7641d700d 100644 --- a/public/pages/Dashboard/containers/Dashboard.js +++ b/public/pages/Dashboard/containers/Dashboard.js @@ -49,7 +49,7 @@ export default class Dashboard extends Component { constructor(props) { super(props); - const { isAlertsFlyout = false, perAlertView } = props; + const { flyoutAlerts, isAlertsFlyout = false, perAlertView } = props; const { alertState, @@ -77,6 +77,7 @@ export default class Dashboard extends Component { sortField, totalAlerts: 0, totalTriggers: 0, + trimmedFlyoutAlerts: flyoutAlerts ? flyoutAlerts.slice(0, 10) : [], }; } @@ -307,16 +308,23 @@ export default class Dashboard extends Component { }; onTableChange = ({ page: tablePage = {}, sort = {} }) => { + const { isAlertsFlyout } = this.props; const { index: page, size } = tablePage; const { field: sortField, direction: sortDirection } = sort; - this.setState({ page, size, sortField, sortDirection, }); + + // If the table is in flyout, return the trimmed array of alerts. + if (isAlertsFlyout) { + const { flyoutAlerts } = this.props; + const trimmedFlyoutAlerts = flyoutAlerts.slice(page * size, page * size + size); + this.setState({ trimmedFlyoutAlerts }); + } }; onSeverityLevelChange = (e) => { @@ -355,6 +363,7 @@ export default class Dashboard extends Component { sortField, totalAlerts, totalTriggers, + trimmedFlyoutAlerts, } = this.state; const { monitorIds, @@ -370,7 +379,7 @@ export default class Dashboard extends Component { notifications, isAlertsFlyout = false, } = this.props; - const totalItems = perAlertView ? totalAlerts : totalTriggers; + let totalItems = perAlertView ? totalAlerts : totalTriggers; const isBucketMonitor = monitorType === MONITOR_TYPE.BUCKET_LEVEL; let columnType = perAlertView @@ -387,7 +396,10 @@ export default class Dashboard extends Component { setFlyout ); - if (isAlertsFlyout) columnType = removeColumns(['severity', 'trigger_name'], columnType); + if (isAlertsFlyout) { + totalItems = this.props.flyoutAlerts.length; + columnType = removeColumns(['severity', 'trigger_name'], columnType); + } const pagination = { pageIndex: page, @@ -490,9 +502,7 @@ export default class Dashboard extends Component { Date: Mon, 4 Oct 2021 10:36:04 -0700 Subject: [PATCH 24/29] Removed redundant validation from filter values that was generating error messages that prevented preview graphs from displaying data. --- .../expressions/WhereExpression.js | 27 ++++++++++--------- public/utils/validate.js | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index 8bb735399..2f04a27be 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -50,12 +50,7 @@ import { isNullOperator, isRangeOperator, } from './utils/whereHelpers'; -import { - hasError, - isInvalid, - required, - validateRequiredNumber, -} from '../../../../../utils/validate'; +import { hasError, isInvalid } from '../../../../../utils/validate'; import { FormikComboBox, FormikSelect, @@ -66,7 +61,6 @@ import { getFilteredIndexFields, getIndexFields } from './utils/dataTypes'; import { FILTERS_TOOLTIP_TEXT, FORMIK_INITIAL_VALUES, - TIME_RANGE_TOOLTIP_TEXT, } from '../../../containers/CreateMonitor/utils/constants'; import { DATA_TYPES } from '../../../../../utils/constants'; import { @@ -105,9 +99,10 @@ class WhereExpression extends Component { } }; - handleOperatorChange = (e, field) => { + handleOperatorChange = (e, field, form) => { this.props.onMadeChanges(); field.onChange(e); + form.setFieldError('where', undefined); }; handleChangeWrapper = (e, field) => { @@ -123,11 +118,16 @@ class WhereExpression extends Component { } = this.props; // Explicitly invoking validation, this component unmount after it closes. const fieldName = _.get(values, `${fieldPath}where.fieldName`, ''); + const fieldOperator = _.get(values, `${fieldPath}where.operator`, 'is'); const fieldValue = _.get(values, `${fieldPath}where.fieldValue`, ''); if (fieldName > 0) { await this.props.formik.validateForm(); } - if (_.isEmpty(fieldName) || _.isEmpty(fieldValue.toString())) this.resetValues(); + if ( + _.isEmpty(fieldName) || + (!isNullOperator(fieldOperator) && _.isEmpty(fieldValue.toString())) + ) + this.resetValues(); closeExpression(Expressions.WHERE); }; @@ -177,14 +177,17 @@ class WhereExpression extends Component { }; renderValueField = (fieldType, fieldOperator) => { - const { fieldPath = '' } = this.props; + const { + fieldPath = '', + formik: { values }, + } = this.props; + const fieldNameValue = _.get(values, `${fieldPath}where.fieldName`); if (fieldType === DATA_TYPES.NUMBER) { return isRangeOperator(fieldOperator) ? ( this.renderBetweenAnd() ) : ( ); diff --git a/public/utils/validate.js b/public/utils/validate.js index d5bc44268..6f66edcab 100644 --- a/public/utils/validate.js +++ b/public/utils/validate.js @@ -74,7 +74,7 @@ export const required = (value) => { }; export const validateRequiredNumber = (value) => { - if (value === undefined || typeof value == 'string') return 'Provide a value.'; + if (value === undefined || typeof value === 'string') return 'Provide a value.'; }; export const validateMonitorName = (httpClient, monitorToEdit) => async (value) => { From c6fb682f735e715c7d40af903f53d79875f1d5f8 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 4 Oct 2021 10:36:04 -0700 Subject: [PATCH 25/29] Removed redundant validation from filter values that was generating error messages that prevented preview graphs from displaying data. --- .../expressions/WhereExpression.js | 21 ++++++++----------- public/utils/validate.js | 2 +- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index 8bb735399..046b23dcd 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -50,12 +50,7 @@ import { isNullOperator, isRangeOperator, } from './utils/whereHelpers'; -import { - hasError, - isInvalid, - required, - validateRequiredNumber, -} from '../../../../../utils/validate'; +import { hasError, isInvalid } from '../../../../../utils/validate'; import { FormikComboBox, FormikSelect, @@ -66,7 +61,6 @@ import { getFilteredIndexFields, getIndexFields } from './utils/dataTypes'; import { FILTERS_TOOLTIP_TEXT, FORMIK_INITIAL_VALUES, - TIME_RANGE_TOOLTIP_TEXT, } from '../../../containers/CreateMonitor/utils/constants'; import { DATA_TYPES } from '../../../../../utils/constants'; import { @@ -105,9 +99,10 @@ class WhereExpression extends Component { } }; - handleOperatorChange = (e, field) => { + handleOperatorChange = (e, field, form) => { this.props.onMadeChanges(); field.onChange(e); + form.setFieldError('where', undefined); }; handleChangeWrapper = (e, field) => { @@ -123,11 +118,16 @@ class WhereExpression extends Component { } = this.props; // Explicitly invoking validation, this component unmount after it closes. const fieldName = _.get(values, `${fieldPath}where.fieldName`, ''); + const fieldOperator = _.get(values, `${fieldPath}where.operator`, 'is'); const fieldValue = _.get(values, `${fieldPath}where.fieldValue`, ''); if (fieldName > 0) { await this.props.formik.validateForm(); } - if (_.isEmpty(fieldName) || _.isEmpty(fieldValue.toString())) this.resetValues(); + if ( + _.isEmpty(fieldName) || + (!isNullOperator(fieldOperator) && _.isEmpty(fieldValue.toString())) + ) + this.resetValues(); closeExpression(Expressions.WHERE); }; @@ -184,7 +184,6 @@ class WhereExpression extends Component { ) : ( ); diff --git a/public/utils/validate.js b/public/utils/validate.js index d5bc44268..6f66edcab 100644 --- a/public/utils/validate.js +++ b/public/utils/validate.js @@ -74,7 +74,7 @@ export const required = (value) => { }; export const validateRequiredNumber = (value) => { - if (value === undefined || typeof value == 'string') return 'Provide a value.'; + if (value === undefined || typeof value === 'string') return 'Provide a value.'; }; export const validateMonitorName = (httpClient, monitorToEdit) => async (value) => { From 49348e72b8ef5bf06538757bee1b57b2dd72916c Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Mon, 4 Oct 2021 12:09:32 -0700 Subject: [PATCH 26/29] Update metric error for query monitors --- .../MonitorExpressions/expressions/MetricExpression.js | 8 +++++++- .../MonitorExpressions/expressions/utils/constants.js | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js index 495808e26..9b6255a33 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js @@ -27,9 +27,9 @@ import React, { Component } from 'react'; import { connect } from 'formik'; import { EuiText, EuiButtonEmpty, EuiSpacer, EuiBadge, EuiToolTip, EuiIcon } from '@elastic/eui'; +import _ from 'lodash'; import { getIndexFields } from './utils/dataTypes'; import { getMetricExpressionAllowedTypes, validateAggregationsDuplicates } from './utils/helpers'; -import _ from 'lodash'; import { FORMIK_INITIAL_AGG_VALUES, METRIC_TOOLTIP_TEXT, @@ -38,6 +38,7 @@ import { MetricItem } from './index'; import { MONITOR_TYPE } from '../../../../../utils/constants'; import { inputLimitText } from '../../../../../utils/helpers'; import IconToolTip from '../../../../../components/IconToolTip'; +import { QUERY_TYPE_METRIC_ERROR } from './utils/constants'; export const MAX_NUM_QUERY_LEVEL_METRICS = 1; export const MAX_NUM_BUCKET_LEVEL_METRICS = 5; @@ -107,6 +108,11 @@ class MetricExpression extends Component { if (validateAggregationsDuplicates(aggregations)) { errors.aggregations = `You have defined duplicated metrics.`; + } else if ( + MONITOR_TYPE.QUERY_LEVEL === monitorType && + aggregations.length > MAX_NUM_QUERY_LEVEL_METRICS + ) { + errors.groupBy = QUERY_TYPE_METRIC_ERROR; } else { delete errors.aggregations; } diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js index 4151faae5..c83c8daa1 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/utils/constants.js @@ -115,3 +115,5 @@ export const AGGREGATION_TYPES = [ export const GROUP_BY_ERROR = 'Must specify at least 1 group by expression.'; export const QUERY_TYPE_GROUP_BY_ERROR = 'Can have a maximum of 1 group by selections.'; + +export const QUERY_TYPE_METRIC_ERROR = 'Can have a maximum of 1 metric selections.'; From ddfc6011eb289d43bfb37f30eea195a296a6683f Mon Sep 17 00:00:00 2001 From: Annie Lee Date: Mon, 4 Oct 2021 12:30:15 -0700 Subject: [PATCH 27/29] Update MetricExpression.js --- .../MonitorExpressions/expressions/MetricExpression.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js index 9b6255a33..2731237c1 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/MetricExpression.js @@ -112,7 +112,7 @@ class MetricExpression extends Component { MONITOR_TYPE.QUERY_LEVEL === monitorType && aggregations.length > MAX_NUM_QUERY_LEVEL_METRICS ) { - errors.groupBy = QUERY_TYPE_METRIC_ERROR; + errors.aggregations = QUERY_TYPE_METRIC_ERROR; } else { delete errors.aggregations; } From dc37a6ff5957908ad7c0b65efda5cc87972692e0 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 4 Oct 2021 12:32:42 -0700 Subject: [PATCH 28/29] Removed experimental dev code. --- .../MonitorExpressions/expressions/WhereExpression.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js index 2f04a27be..046b23dcd 100644 --- a/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js +++ b/public/pages/CreateMonitor/components/MonitorExpressions/expressions/WhereExpression.js @@ -177,11 +177,7 @@ class WhereExpression extends Component { }; renderValueField = (fieldType, fieldOperator) => { - const { - fieldPath = '', - formik: { values }, - } = this.props; - const fieldNameValue = _.get(values, `${fieldPath}where.fieldName`); + const { fieldPath = '' } = this.props; if (fieldType === DATA_TYPES.NUMBER) { return isRangeOperator(fieldOperator) ? ( this.renderBetweenAnd() From 4fadf6407e3b22953128b39cf81646a8cbc45ff5 Mon Sep 17 00:00:00 2001 From: AWSHurneyt Date: Mon, 4 Oct 2021 13:02:48 -0700 Subject: [PATCH 29/29] Updated release notes. --- ...nsearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md index 2e9232479..f09d42a6e 100644 --- a/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md +++ b/release-notes/opensearch-alerting-dashboards-plugin.release-notes-1.1.0.0.md @@ -52,5 +52,4 @@ Compatible with OpenSearch Dashboards 1.1.0 * Update jest unit tests ([#112](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/112)) ### Bug Fixes -* A few bug fix for create monitor ([#121](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/121)) -* Fixed a bug that displayed all alerts for a monitor on individual triggers' flyouts. Fixed a bug that displayed incorrect source for the condition field on the alerts flyout. Fixed a bug that displayed incorrect severity on the alerts flyout. Fixed a bug that prevented selecting query-level monitor alerts 1 by 1. ([#122](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/122)) \ No newline at end of file +* Fixed a bug that displayed all alerts for a monitor on individual triggers' flyouts. Fixed a bug that displayed incorrect source for the condition field on the alerts flyout. Fixed a bug that displayed incorrect severity on the alerts flyout. Fixed a bug that prevented selecting query-level monitor alerts 1 by 1. Consolidates bug fixes from PR 121 and 122 ([#123](https://github.com/opensearch-project/alerting-dashboards-plugin/pull/123)) \ No newline at end of file