fix: update alert-rule trait attachment instructions for components#542
fix: update alert-rule trait attachment instructions for components#542LakshanSS merged 1 commit intoopenchoreo:mainfrom
Conversation
Signed-off-by: Akila-I <akila.99g@gmail.com>
📝 WalkthroughSummary by CodeRabbit
WalkthroughUpdated kubectl patch instructions in a component alerts tutorial to be idempotent when attaching observability alert rule traits. Commands now conditionally check for existing trait instances before patching to prevent duplicates. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~15 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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.
🧹 Nitpick comments (1)
docs/tutorials/component-alerts-and-incidents.mdx (1)
412-533: Consider reducing repetition with a small shell helper for patching traits.The same patch pattern appears three times. A tiny helper (component + payload args) would lower copy/paste drift risk for future edits.
Optional refactor sketch
+# helper: add trait if missing, create spec.traits when absent +attach_alert_trait() { + local component="$1" + local instance="$2" + local value_json="$3" + + if kubectl get component "${component}" -n default \ + -o jsonpath='{.spec.traits[*].instanceName}' 2>/dev/null \ + | tr ' ' '\n' | grep -qx "${instance}"; then + echo "Trait '${instance}' already exists on component '${component}', skipping." + return 0 + fi + + kubectl patch component "${component}" -n default --type=json -p="[ + {\"op\":\"add\",\"path\":\"/spec/traits/-\",\"value\":${value_json}} + ]" 2>/dev/null || kubectl patch component "${component}" -n default --type=json -p="[ + {\"op\":\"add\",\"path\":\"/spec/traits\",\"value\":[${value_json}]} + ]" +}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@docs/tutorials/component-alerts-and-incidents.mdx` around lines 412 - 533, Create a small shell helper (e.g., add_component_trait) that accepts component name and a JSON payload or instanceName and parameters, encapsulates the kubectl get check and the two kubectl patch calls (the "/spec/traits/-" add with fallback to "/spec/traits"), and then call it three times for the existing alerts (instanceName values: frontend-rpc-unavailable-error-log-alert, recommendation-high-cpu-alert, cartservice-high-memory-alert) instead of repeating the patch block; update the script to build the trait object once per alert and pass it to add_component_trait to reduce duplication and ensure identical behavior to the current kubectl patch logic.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@docs/tutorials/component-alerts-and-incidents.mdx`:
- Around line 412-533: Create a small shell helper (e.g., add_component_trait)
that accepts component name and a JSON payload or instanceName and parameters,
encapsulates the kubectl get check and the two kubectl patch calls (the
"/spec/traits/-" add with fallback to "/spec/traits"), and then call it three
times for the existing alerts (instanceName values:
frontend-rpc-unavailable-error-log-alert, recommendation-high-cpu-alert,
cartservice-high-memory-alert) instead of repeating the patch block; update the
script to build the trait object once per alert and pass it to
add_component_trait to reduce duplication and ensure identical behavior to the
current kubectl patch logic.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: a0575f73-3b02-4414-b807-53c4aca92674
⛔ Files ignored due to path filters (1)
versioned_docs/version-v1.0.x/tutorials/component-alerts-and-incidents.mdxis excluded by!versioned_docs/**
📒 Files selected for processing (1)
docs/tutorials/component-alerts-and-incidents.mdx
Purpose
This pull request updates the alert-rule trait attachment instructions in both the main and versioned documentation for component alerts and incidents. The new approach ensures that alert-rule traits are not duplicated by first checking if the trait already exists before attempting to add it. If the
spec.traitsfield does not exist, it is created. This improves the robustness and idempotency of the setup process.Improvements to alert-rule trait application logic:
spec.traitsarray if it does not exist, ensuring compatibility with components that do not yet have traits defined. [1] [2]Documentation updates:
frontend,recommendation, andcartcomponents, making the process more robust and user-friendly. [1] [2] [3] [4] [5] [6]Related Issues
Checklist
sidebars.tsif adding a new documentation pagenpm run startto preview the changes locallynpm run buildto ensure the build passes without errors