From f9a84c8e2dfe6296cc5ec909fe6d218dc15b42fd Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Tue, 14 Dec 2021 13:40:32 -0800 Subject: [PATCH 1/3] fix: [alert] add tooltip message for alert threshold value --- superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index 99deaa8cc1fd..dc4a54f3304d 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -54,6 +54,7 @@ import { Operator, Recipient, } from 'src/views/CRUD/alert/types'; +import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls'; import { AlertReportCronScheduler } from './components/AlertReportCronScheduler'; import { NotificationMethod } from './components/NotificationMethod'; @@ -1183,7 +1184,10 @@ const AlertReportModal: FunctionComponent = ({
- {t('Value')} + {t('Value')}{' '} + *
From 7da50df74b67148c5f95aebf0d7c2ca1b53526f3 Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Wed, 15 Dec 2021 15:12:19 -0800 Subject: [PATCH 2/3] support decimal value for alert condition threshold --- superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx | 4 +++- superset/reports/schemas.py | 2 +- tests/integration_tests/alerts_tests.py | 3 +++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index dc4a54f3304d..5dfeeecfafc9 100644 --- a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx +++ b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx @@ -1186,7 +1186,9 @@ const AlertReportModal: FunctionComponent = ({
{t('Value')}{' '} *
diff --git a/superset/reports/schemas.py b/superset/reports/schemas.py index c8486b8e3d27..3f2fb4416dbe 100644 --- a/superset/reports/schemas.py +++ b/superset/reports/schemas.py @@ -103,7 +103,7 @@ class ValidatorConfigJSONSchema(Schema): description=validator_config_json_op_description, validate=validate.OneOf(choices=["<", "<=", ">", ">=", "==", "!="]), ) - threshold = fields.Integer() + threshold = fields.Float() class ReportRecipientConfigJSONSchema(Schema): diff --git a/tests/integration_tests/alerts_tests.py b/tests/integration_tests/alerts_tests.py index 5f8f36fe749d..6a373093d524 100644 --- a/tests/integration_tests/alerts_tests.py +++ b/tests/integration_tests/alerts_tests.py @@ -266,6 +266,9 @@ def test_operator_validator(setup_database): # Test passing with result that equals threshold assert operator_validator(alert2, '{"op": "==", "threshold": 55}') is True + # Test passing with result that equals decimal threshold + assert operator_validator(alert2, '{"op": ">", "threshold": 54.999}') is True + @pytest.mark.parametrize( "description, query, validator_type, config", From 72b9cd1b38eba29680d805303fe9f521b8afcb6f Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Thu, 16 Dec 2021 14:37:41 -0800 Subject: [PATCH 3/3] add integration test --- .../integration_tests/reports/commands_tests.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index 1ed3f35a1651..72c43c8bbf04 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -409,7 +409,16 @@ def create_alert_slack_chart_grace(request): @pytest.fixture( - params=["alert1", "alert2", "alert3", "alert4", "alert5", "alert6", "alert7",] + params=[ + "alert1", + "alert2", + "alert3", + "alert4", + "alert5", + "alert6", + "alert7", + "alert8", + ] ) def create_alert_email_chart(request): param_config = { @@ -448,6 +457,11 @@ def create_alert_email_chart(request): "validator_type": ReportScheduleValidatorType.OPERATOR, "validator_config_json": '{"op": "!=", "threshold": 11}', }, + "alert8": { + "sql": "SELECT 55 as metric", + "validator_type": ReportScheduleValidatorType.OPERATOR, + "validator_config_json": '{"op": ">", "threshold": 54.999}', + }, } with app.app_context(): chart = db.session.query(Slice).first()