-
Notifications
You must be signed in to change notification settings - Fork 299
🚀 Feature: Create dmesg enricher action #2037
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| from robusta.api import * | ||
|
|
||
|
|
||
| class DmesgParams(ActionParams): | ||
| """ | ||
| :var tail_lines: Number of lines to show from the end of the dmesg output. | ||
| """ | ||
|
|
||
| tail_lines: int = 100 | ||
|
|
||
|
|
||
| @action | ||
| def dmesg_enricher(event: NodeEvent, params: DmesgParams): | ||
| """ | ||
| Run dmesg on the node and display the output. | ||
| """ | ||
| node = event.get_node() | ||
| if not node: | ||
| logging.error("dmesg_enricher was called on event without node") | ||
| return | ||
|
|
||
| node_name = node.metadata.name | ||
| exec_result = RobustaPod.exec_in_debugger_pod( | ||
| "dmesg", | ||
| node_name, | ||
| override_container_name="debug", | ||
| command_timeout=60, | ||
| ) | ||
|
|
||
| if exec_result.return_code != 0: | ||
| logging.error(f"dmesg failed on node {node_name}: {exec_result.stderr}") | ||
| return | ||
|
|
||
| output = exec_result.stdout | ||
| if params.tail_lines: | ||
| output = "\n".join(output.splitlines()[-params.tail_lines:]) | ||
|
|
||
| event.add_enrichment([ | ||
| FileBlock("dmesg.txt", output.encode()), | ||
| ]) | ||
|
|
||
|
|
||
| @action | ||
| def dmesg_enricher_on_pod(event: PodEvent, params: DmesgParams): | ||
| """ | ||
| Run dmesg on the node where the pod is running. | ||
| """ | ||
| pod = event.get_pod() | ||
| if not pod: | ||
| logging.error("dmesg_enricher_on_pod was called on event without pod") | ||
| return | ||
|
|
||
| if not pod.spec.nodeName: | ||
| logging.error(f"pod {pod.metadata.name} has no nodeName") | ||
| return | ||
|
|
||
| node_event = NodeEvent( | ||
| metadata=pod.metadata, | ||
| involvedObject=pod, | ||
| nodeName=pod.spec.nodeName, | ||
| ) | ||
| dmesg_enricher(node_event, params) | ||
|
Comment on lines
+57
to
+62
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify NodeEvent constructor and check how other playbooks create NodeEvent from pods
echo "=== NodeEvent class definition ==="
ast-grep --pattern $'class NodeEvent($$$):
def __init__($$$):
$$$
'
echo ""
echo "=== How other playbooks handle similar pod-to-node scenarios ==="
rg -n "NodeEvent\(" --type py -C 5 playbooks/Repository: robusta-dev/robusta Length of output: 3569 🏁 Script executed: #!/bin/bash
# Check PodEvent class and verify named_sinks attribute
echo "=== PodEvent class definition ==="
rg -n "class PodEvent" --type py -A 10 src/robusta/integrations/kubernetes/autogenerated/events.py | head -20
echo ""
echo "=== Check if PodEvent inherits named_sinks ==="
rg -n "class KubernetesResourceEvent" --type py -A 5 src/robusta/integrations/kubernetes/
echo ""
echo "=== Verify named_sinks usage in PodEvent context ==="
rg -n "named_sinks" --type py src/robusta/integrations/kubernetes/autogenerated/events.py | head -10Repository: robusta-dev/robusta Length of output: 1818 Critical: The The current approach of synthesizing a Use Proposed fix node_event = NodeEvent(
- metadata=pod.metadata,
- involvedObject=pod,
- nodeName=pod.spec.nodeName,
+ obj=Node.readNode(pod.spec.nodeName).obj,
+ named_sinks=event.named_sinks,
)
dmesg_enricher(node_event, params)Add error handling to gracefully handle Node lookup failures. 🧰 Tools🪛 Flake8 (7.3.0)[error] 57-57: 'NodeEvent' may be undefined, or defined from star imports: robusta.api (F405) 🪛 Ruff (0.15.7)[error] 57-57: (F405) 🤖 Prompt for AI Agents |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: robusta-dev/robusta
Length of output: 6151
🏁 Script executed:
sed -n '318,345p' src/robusta/integrations/kubernetes/custom_models.pyRepository: robusta-dev/robusta
Length of output: 1014
Critical:
exec_in_debugger_podAPI mismatch causes runtime failure.The method signature
exec_in_debugger_pod(pod_name: str, node_name: str, cmd, ...) -> strconfirms three critical issues:"dmesg"is passed aspod_name(1st arg), but should be thecmd(3rd arg).override_container_nameandcommand_timeoutare not valid parameters; onlydebug_imageandcustom_annotationsare supported.str(command output), not an object with.return_code,.stderr,.stdoutattributes. Lines 30-34 will fail when accessing these attributes.🐛 Proposed fix aligning with the actual API
📝 Committable suggestion
🧰 Tools
🪛 Flake8 (7.3.0)
[error] 23-23: 'RobustaPod' may be undefined, or defined from star imports: robusta.api
(F405)
[error] 31-31: 'logging' may be undefined, or defined from star imports: robusta.api
(F405)
🪛 Ruff (0.15.7)
[error] 23-23:
RobustaPodmay be undefined, or defined from star imports(F405)
[error] 31-31:
loggingmay be undefined, or defined from star imports(F405)
🤖 Prompt for AI Agents