Repository navigation
fix(conditions): compare percentage thresholds numerically - #6603
Merged
shahargl merged 1 commit intoJun 27, 2026
Merged
Conversation
ThresholdCondition._validate returned percentage values (e.g. "90%", "100%") unchanged as strings, so _apply_threshold compared them lexicographically: "100%" < "90%" and "9%" > "50%". A threshold like `compare_to: 90%` (see examples/workflows/db_disk_space_monitor.yml) therefore failed to fire for a 100%-full resource — a silent missed alert. When both values are percentages, strip "%" and convert to float so the gt/lt comparison is numeric.
Contributor
|
🌈 Fantastic work @aditya-786! Your very first PR to keep has been merged! 🎉🥳 You've just taken your first step into open-source, and we couldn't be happier to have you onboard. 🙌 For any support, feel free to reach out on the community: https://slack.keephq.dev. Happy coding! 👩💻👨💻 |
2 of 4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Linked Issue
Fixes #6604
Description
ThresholdCondition._validatereturns percentage values (e.g."90%","100%") unchanged as strings, so_apply_thresholdthen compares them lexicographically instead of numerically:"100%" > "90%"→False(because'1' < '9')"9%" > "50%"→True(because'9' > '5')So a workflow threshold like
compare_to: 90%(seeexamples/workflows/db_disk_space_monitor.yml) fails to fire when the actual value is 100% — a silently missed alert in a monitoring tool._validatealready deliberately accepts two percentage strings (via_is_percentage), so the fix is: when both values are percentages, strip the%and convert tofloatbefore returning, so thegt/ltcomparison is numeric. Numeric-vs-numeric and mixed numeric/percentage inputs are unaffected (the latter still raise as before).Test
Added
test_threshold_condition_percentage_values_compared_numericallytotests/test_conditions.py:apply("90%", "100%")isTrue(wasFalse)apply("50%", "9%")isFalse(wasTrue)Both assertions fail before this change and pass after.
ruff checkandruff formatpass locally.