Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions playbooks/robusta_playbooks/dns_alerts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import logging
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

from robusta.api import *


@action
def dns_target_down_enricher(alert: PrometheusKubernetesAlert):
"""
Enrich TargetDown alerts for DNS pods when kube-dns is used instead of CoreDNS.
"""
if not alert.job.startswith("kube-dns"):
return
Comment on lines +10 to +11
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

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.


alert.override_finding_attributes(
description=(
"TargetDown alert fired for kube-dns pods, but your cluster is configured "
"to use CoreDNS. This alert is likely a false positive.\n\n"
"To resolve this, either:\n"
"1. Disable the kube-dns scrape job in your Prometheus configuration, or\n"
"2. Update the alert rule to exclude kube-dns when CoreDNS is in use."
),
severity=FindingSeverity.INFO,
)