fix: correct HighMemoryUsage alert self-dividing expression - #32
Open
FUstomato wants to merge 1 commit into
Open
fix: correct HighMemoryUsage alert self-dividing expression#32FUstomato wants to merge 1 commit into
FUstomato wants to merge 1 commit into
Conversation
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.
Summary
Fix the HighMemoryUsage alert rule expression in
tools/monitoring_setup.pywhich contained a self-dividing PromQL expression (process_resident_memory_bytes / process_resident_memory_bytes) that always evaluates to 1, making the alert completely ineffective. Also add a newvalidate_self_dividing_expressions()function with--validateCLI integration to prevent similar issues in the future.Changes
1. Fix HighMemoryUsage alert expression (
tools/monitoring_setup.py)Before (buggy):
After (fixed):
The original expression divides
process_resident_memory_bytesby itself, always yielding ~1.0, which means the alert would never fire regardless of actual memory usage. The fix usesnode_memory_MemTotal_bytes(standard node_exporter metric) as the denominator to compute the actual ratio of process memory to total system memory.2. Add
validate_self_dividing_expressions()functionNew validation function that detects PromQL self-dividing patterns (e.g.,
X / X) in both alert rules and recording rules. It correctly:{...}and time range selectors[...]by (...)/without (...)grouping clauses (label names are not metrics)/operators (respects parentheses and braces)3. Enhanced
--validateCLI flagThe existing
--validateflag now runs the self-dividing expression check before connectivity checks. If issues are found, exits with code 1 to integrate with CI/CD pipelines.Testing
python3 tools/monitoring_setup.py --validatereports "PASS: No self-dividing expressions found."Checklist