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
This commit is contained in:
Grace Guo 2021-12-16 22:51:23 -08:00 committed by GitHub
parent 4beaa81de3
commit c5af7a48df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 3 deletions

View File

@ -54,6 +54,7 @@ import {
Operator, Operator,
Recipient, Recipient,
} from 'src/views/CRUD/alert/types'; } from 'src/views/CRUD/alert/types';
import { InfoTooltipWithTrigger } from '@superset-ui/chart-controls';
import { AlertReportCronScheduler } from './components/AlertReportCronScheduler'; import { AlertReportCronScheduler } from './components/AlertReportCronScheduler';
import { NotificationMethod } from './components/NotificationMethod'; import { NotificationMethod } from './components/NotificationMethod';
@ -1183,7 +1184,12 @@ const AlertReportModal: FunctionComponent<AlertReportModalProps> = ({
</StyledInputContainer> </StyledInputContainer>
<StyledInputContainer> <StyledInputContainer>
<div className="control-label"> <div className="control-label">
{t('Value')} {t('Value')}{' '}
<InfoTooltipWithTrigger
tooltip={t(
'Threshold value should be double precision number',
)}
/>
<span className="required">*</span> <span className="required">*</span>
</div> </div>
<div className="input-container"> <div className="input-container">

View File

@ -103,7 +103,7 @@ class ValidatorConfigJSONSchema(Schema):
description=validator_config_json_op_description, description=validator_config_json_op_description,
validate=validate.OneOf(choices=["<", "<=", ">", ">=", "==", "!="]), validate=validate.OneOf(choices=["<", "<=", ">", ">=", "==", "!="]),
) )
threshold = fields.Integer() threshold = fields.Float()
class ReportRecipientConfigJSONSchema(Schema): class ReportRecipientConfigJSONSchema(Schema):

View File

@ -266,6 +266,9 @@ def test_operator_validator(setup_database):
# Test passing with result that equals threshold # Test passing with result that equals threshold
assert operator_validator(alert2, '{"op": "==", "threshold": 55}') is True 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( @pytest.mark.parametrize(
"description, query, validator_type, config", "description, query, validator_type, config",

View File

@ -411,7 +411,16 @@ def create_alert_slack_chart_grace(request):
@pytest.fixture( @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): def create_alert_email_chart(request):
param_config = { param_config = {
@ -450,6 +459,11 @@ def create_alert_email_chart(request):
"validator_type": ReportScheduleValidatorType.OPERATOR, "validator_type": ReportScheduleValidatorType.OPERATOR,
"validator_config_json": '{"op": "!=", "threshold": 11}', "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(): with app.app_context():
chart = db.session.query(Slice).first() chart = db.session.query(Slice).first()