Skip to content

Commit

Permalink
fix: [alert] allow decimal for alert threshold value (#17751)
Browse files Browse the repository at this point in the history
* fix: [alert] add tooltip message for alert threshold value

* support decimal value for alert condition threshold

* add integration test
  • Loading branch information
Grace Guo authored Dec 17, 2021
1 parent 4beaa81 commit c5af7a4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
8 changes: 7 additions & 1 deletion superset-frontend/src/views/CRUD/alert/AlertReportModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -1183,7 +1184,12 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
</StyledInputContainer>
<StyledInputContainer>
<div className="control-label">
{t('Value')}
{t('Value')}{' '}
<InfoTooltipWithTrigger
tooltip={t(
'Threshold value should be double precision number',
)}
/>
<span className="required">*</span>
</div>
<div className="input-container">
Expand Down
2 changes: 1 addition & 1 deletion superset/reports/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 3 additions & 0 deletions tests/integration_tests/alerts_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 15 additions & 1 deletion tests/integration_tests/reports/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit c5af7a4

Please sign in to comment.