From 398d73ba2bc662b4fc18a05fa33dcd7f74dd70aa Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Thu, 16 Dec 2021 22:51:23 -0800 Subject: [PATCH] fix: [alert] allow decimal for alert threshold value (#17751) * fix: [alert] add tooltip message for alert threshold value * support decimal value for alert condition threshold * add integration test --- .../src/views/CRUD/alert/AlertReportModal.tsx | 8 +++++++- superset/reports/schemas.py | 2 +- tests/integration_tests/alerts_tests.py | 3 +++ .../integration_tests/reports/commands_tests.py | 16 +++++++++++++++- 4 files changed, 26 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx b/superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx index 99deaa8cc1fdb..5dfeeecfafc9f 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,12 @@ const AlertReportModal: FunctionComponent = ({
- {t('Value')} + {t('Value')}{' '} + *
diff --git a/superset/reports/schemas.py b/superset/reports/schemas.py index c8486b8e3d274..3f2fb4416dbe0 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 5f8f36fe749df..6a373093d5245 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", diff --git a/tests/integration_tests/reports/commands_tests.py b/tests/integration_tests/reports/commands_tests.py index 3a7cc873e3131..df584ec830d91 100644 --- a/tests/integration_tests/reports/commands_tests.py +++ b/tests/integration_tests/reports/commands_tests.py @@ -411,7 +411,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 = { @@ -450,6 +459,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()