-
Notifications
You must be signed in to change notification settings - Fork 14k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: [alert] allow decimal for alert threshold value #17751
fix: [alert] allow decimal for alert threshold value #17751
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any reason why not to adjust the onThresholdChange function as well to make inputting a non integer impossible?
server-side has value validation. I think add front-end validation is not necessary. |
I guess why let the user type in something invalid at all? We're adding the tooltip, but that would only be seen if you hover over it. You wouldn't let a user type letters into a credit card number input (for example), so why not filter out/disallow decimal points from the text here? |
Server-side has validation, front-end doesn't really need to do extra validation, no matter its decimal or letter.
|
Codecov Report
@@ Coverage Diff @@
## master #17751 +/- ##
==========================================
- Coverage 67.78% 67.78% -0.01%
==========================================
Files 1602 1605 +3
Lines 64146 64208 +62
Branches 6773 6790 +17
==========================================
+ Hits 43484 43525 +41
- Misses 18809 18827 +18
- Partials 1853 1856 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
Why do we have such a server side restriction in the first place? It feels like here at least floats should be allowed, too. It's very common to set up alerts on percent/ratio metrics, etc. Can we maybe just change the server side validation to cc @dpgaspar |
I'm also surprised we don't have inline form validation on the client side. It feels like we should at least introduce some common pattern of how to do form validation for forms outside of the Explore controls. It might be worth starting a front-end infra project to tackle things like this. |
to @etr2460: your suggestion is, user type in 3.5, Superset secretly truncate to 3 and save into backend without user notice? User still believe Superset accept decimal but actually not? 😳 I think this behavior is even worse than throw exception. to @ktmud: I think add front-end input validation just for this input field is very random and not necessary. For Superset, site-wide consistent front-end validation behavior is probably more desirable for chart controls, etc. If in the near future, Superset has plan for explore view, like consistent chart controls or similar features, this validation framework is a good candidate. |
nope, that handler sets the value in state and then renders it to the input (because it's a controlled component). The effect of this change would be that pressing the period key would put nothing in the input, and pasting a decimal string would truncate to everything before the decimal:
just like how making the input a |
Besides changes you added, to make your solution work, you also need to draft a UI to display the error message, right? And did your solution handle that's what i mean the simple front-end validation is not necessary. It's not completed, not well designed, not consistent with the rest of Superset input. So i think it's random and not necessary. |
I think running into the precision problem is probably less frustrating than not being able to type in float. It's unlikely users would need the alert threshold to be highly sensitive with many decimals. Also, with |
So far I think support decimal is a general acceptable solution. I will update this PR. |
Agree that supporting decimal values is the better solution, thanks for making that change! Can you also change the PR title to be accurate?
yup, because the input was already of type="number". unfortunately html inputs didn't have an "integer" type :/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stamping, but can you update the screenshots and the test plan to reflect the validation you did that decimals work? thanks!
{t('Value')}{' '} | ||
<InfoTooltipWithTrigger | ||
tooltip={t( | ||
'Threshold value should be double precision number', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it doesn't need to be a double right? an integer is still fine. do we even need the tooltip now? Or if you want to add it, you could make it "Threshold can be an integer or a float"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
double precision number could be integer or float right?
And, if you type in 3.14159265358979323846264338327950288419716939937510
it will be truncated to 3.141592653589793
by backend. I think it is necessary to let users know there is a limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, i got confused by the fact that the schema called it a float
, but python calls its doubles floats 🤦 carry on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, we need to make sure this is not a breaking change. left a comment regarding tests
@@ -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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is for the old alerts code base. This test can be added here: https://github.com/apache/superset/blob/master/tests/integration_tests/reports/commands_tests.py#L414
Optional (but would be great). Adding integration API tests to assert bad and good validator_config_json
7385ea4
to
3e45e15
Compare
3e45e15
to
bbdecea
Compare
bbdecea
to
72b9cd1
Compare
added integration test to commands_tests. |
* fix: [alert] add tooltip message for alert threshold value * support decimal value for alert condition threshold * add integration test
* fix: [alert] add tooltip message for alert threshold value * support decimal value for alert condition threshold * add integration test
SUMMARY
Our users typing in decimal value in alert condition threshold, and then Superset returns error message from server-side.
This PR is to allow backend accept decimal number, and add a simple tooltip for this input field.
cc @dpgaspar
TESTING INSTRUCTIONS
CI and manual test.
ADDITIONAL INFORMATION