🚀 Feature: Create DNS alerts enricher for TargetDown alerts#2038
🚀 Feature: Create DNS alerts enricher for TargetDown alerts#2038letho1608 wants to merge 1 commit intorobusta-dev:masterfrom
Conversation
Create a new action that enriches TargetDown alerts when they're related to coreDns but kubeDns is being used instead. This will help users understand why they're getting irrelevant alerts and how to fix them. Affected files: dns_alerts.py Signed-off-by: Le Quang Tho <92069270+letho1608@users.noreply.github.com>
WalkthroughA new robusta enricher action Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~4 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@playbooks/robusta_playbooks/dns_alerts.py`:
- Line 1: Remove the unused import statement "import logging" from
playbooks/robusta_playbooks/dns_alerts.py so the file no longer imports the
logging module it doesn't use; locate the top-level import and delete that line
to eliminate the unused dependency.
- Around line 10-11: The current check uses alert.job.startswith("kube-dns") but
alert.job is Optional and may be None; update the guard to handle None first
(e.g., assign job = alert.job or "" or explicitly if not alert.job: return) and
then call startswith on that safe string; change the condition around the
existing alert.job.startswith usage in dns_alerts.py so it never calls
startswith on None.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: efa22d9d-055f-4c92-b910-6026985f3fee
📒 Files selected for processing (1)
playbooks/robusta_playbooks/dns_alerts.py
| @@ -0,0 +1,22 @@ | |||
| import logging | |||
There was a problem hiding this comment.
Remove unused logging import.
The logging module is imported but never used in this file.
Proposed fix
-import logging📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| import logging | |
| from robusta.api import * |
🧰 Tools
🪛 Flake8 (7.3.0)
[error] 1-1: 'logging' imported but unused
(F401)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@playbooks/robusta_playbooks/dns_alerts.py` at line 1, Remove the unused
import statement "import logging" from playbooks/robusta_playbooks/dns_alerts.py
so the file no longer imports the logging module it doesn't use; locate the
top-level import and delete that line to eliminate the unused dependency.
| if not alert.job.startswith("kube-dns"): | ||
| return |
There was a problem hiding this comment.
alert.job can be None, causing AttributeError.
According to src/robusta/integrations/prometheus/models.py, the job field is defined as Optional[RobustaJob] = None. Calling .startswith() on None will raise an AttributeError.
Proposed fix
- if not alert.job.startswith("kube-dns"):
+ if not alert.job or not alert.job.startswith("kube-dns"):
return🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@playbooks/robusta_playbooks/dns_alerts.py` around lines 10 - 11, The current
check uses alert.job.startswith("kube-dns") but alert.job is Optional and may be
None; update the guard to handle None first (e.g., assign job = alert.job or ""
or explicitly if not alert.job: return) and then call startswith on that safe
string; change the condition around the existing alert.job.startswith usage in
dns_alerts.py so it never calls startswith on None.
🚀 New Feature
Problem
Create a new action that enriches TargetDown alerts when they're related to coreDns but kubeDns is being used instead. This will help users understand why they're getting irrelevant alerts and how to fix them.
Severity:
highFile:
playbooks/robusta_playbooks/dns_alerts.pySolution
Create a new Python file with a function decorated with @action that:
Changes
playbooks/robusta_playbooks/dns_alerts.py(new)Testing
Closes #553