Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(conditions): compare percentage thresholds numerically - #6603

Merged
shahargl merged 1 commit into
keephq:mainfrom
aditya-786:fix/threshold-percentage-numeric
Jun 27, 2026
Merged

shahargl merged 1 commit into
keephq:mainfrom
aditya-786:fix/threshold-percentage-numeric

Conversation

@aditya-786

@aditya-786 aditya-786 commented Jun 27, 2026 •

Copy link
Copy Markdown
Contributor

Linked Issue

Fixes #6604

Description

ThresholdCondition._validate returns percentage values (e.g. "90%", "100%") unchanged as strings, so _apply_threshold then 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% (see examples/workflows/db_disk_space_monitor.yml) fails to fire when the actual value is 100% — a silently missed alert in a monitoring tool.

_validate already deliberately accepts two percentage strings (via _is_percentage), so the fix is: when both values are percentages, strip the % and convert to float before returning, so the gt/lt comparison 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_numerically to tests/test_conditions.py:

  • apply("90%", "100%") is True (was False)
  • apply("50%", "9%") is False (was True)

Both assertions fail before this change and pass after. ruff check and ruff format pass locally.

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.
@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. Bug Something isn't working labels Jun 27, 2026
@CLAassistant

CLAassistant commented Jun 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@shahargl shahargl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jun 27, 2026
@shahargl
shahargl merged commit 425f7a0 into keephq:main Jun 27, 2026
4 of 5 checks passed
@github-actions

Copy link
Copy Markdown
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. 🙌
If you're feeling adventurous, why not dive into another issue and keep contributing? The community would love to see more from you! 🚀

For any support, feel free to reach out on the community: https://slack.keephq.dev. Happy coding! 👩‍💻👨‍💻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ThresholdCondition compares percentage values lexicographically instead of numerically

3 participants