Skip to content

[$30 BOUNTY] Fix HighMemoryUsage alert ratio expression + add validation#25

Open
lee-muriithi-kingori wants to merge 1 commit into
weilixiong:mainfrom
lee-muriithi-kingori:fix-high-memory-alert
Open

[$30 BOUNTY] Fix HighMemoryUsage alert ratio expression + add validation#25
lee-muriithi-kingori wants to merge 1 commit into
weilixiong:mainfrom
lee-muriithi-kingori:fix-high-memory-alert

Conversation

@lee-muriithi-kingori

Copy link
Copy Markdown

Description

Fixed the HighMemoryUsage Prometheus alert that was using a self-dividing expression (process_resident_memory_bytes / process_resident_memory_bytes), which always evaluates to 1 for any non-zero value.

Changes

  1. Fixed the alert expression:

    • Before: process_resident_memory_bytes / process_resident_memory_bytes > 0.9 (always true)
    • After: process_resident_memory_bytes / machine_memory_bytes > 0.9 (meaningful ratio)
  2. Added alert expression validation:

    • validate_alert_expression() - catches self-dividing patterns using regex
    • validate_all_alert_rules() - bulk validation of all rules
    • --validate-alerts CLI flag for standalone validation
    • Validation runs before any rule upload, blocking on errors
  3. Validation catches:

    • Self-dividing expressions: metric / metric
    • Empty expressions
    • Expressions without valid PromQL identifiers

Validation

$ python3 tools/monitoring_setup.py --validate-alerts
Validating alert rules...
  [OK] HighErrorRate
  [OK] HighLatency
  [OK] ServiceDown
  [OK] HighCPUUsage
  [OK] HighMemoryUsage
  [OK] LowDiskSpace
  [OK] CertificateExpiring
  [OK] HighDBConnections
  [OK] QueueBacklog
  [OK] GoroutineLeak
  [OK] GCPauseTime
  [OK] RateLimitExceeded

Bounty Claim

/claim #1

- Fixed self-dividing expression: process_resident_memory_bytes / process_resident_memory_bytes
- Changed to: process_resident_memory_bytes / machine_memory_bytes
- Added validate_alert_expression() to catch self-dividing PromQL patterns
- Added validate_all_alert_rules() for bulk validation
- Added --validate-alerts CLI flag for standalone validation
- Validation now runs before any rule upload (blocks on errors)

Closes weilixiong#1
@SysCallVirtuoso

Copy link
Copy Markdown

"Really great work on implementing the validate_alert_expression() logic here. Catching the self-dividing patterns (metric / metric) via regex is a much more robust approach than simply manual review.

Have you considered also expanding the validation to catch cases where the denominator might be a constant that evaluates to zero? I’ve been playing with similar telemetry mitigation logic in my own projects, and adding a check for const == 0 edge cases could really harden the whole suite against false alerts.
Looking forward to seeing how this scales in the main branch!"

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants