Skip to content

fix: update alert-rule trait attachment instructions for components#542

Merged
LakshanSS merged 1 commit intoopenchoreo:mainfrom
akila-i:obs-alerts-docs-fix
Apr 2, 2026
Merged

fix: update alert-rule trait attachment instructions for components#542
LakshanSS merged 1 commit intoopenchoreo:mainfrom
akila-i:obs-alerts-docs-fix

Conversation

@akila-i
Copy link
Copy Markdown
Contributor

@akila-i akila-i commented Apr 2, 2026

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.traits field does not exist, it is created. This improves the robustness and idempotency of the setup process.

Improvements to alert-rule trait application logic:

  • Added checks to prevent duplicate alert-rule trait instances by verifying if the trait already exists on a component before attempting to add it. [1] [2]
  • Updated the patching logic to create the spec.traits array if it does not exist, ensuring compatibility with components that do not yet have traits defined. [1] [2]

Documentation updates:

  • Updated the instructions and example shell scripts for attaching alert-rule traits to the frontend, recommendation, and cart components, making the process more robust and user-friendly. [1] [2] [3] [4] [5] [6]

Related Issues

Include any related issues that are resolved by this PR.

Checklist

  • Updated sidebars.ts if adding a new documentation page
  • Run npm run start to preview the changes locally
  • Run npm run build to ensure the build passes without errors
  • Verified all links are working (no broken links)

Signed-off-by: Akila-I <akila.99g@gmail.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

📝 Walkthrough

Summary by CodeRabbit

  • Documentation
    • Updated kubectl patch tutorial instructions to ensure commands can run multiple times without errors when attaching trait instances.

Walkthrough

Updated 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

Cohort / File(s) Summary
Documentation Update
docs/tutorials/component-alerts-and-incidents.mdx
Modified kubectl patch commands to add idempotency checks. Instead of always appending trait instances, commands now verify whether a trait with the target instanceName already exists and conditionally patch only when absent. Error output is suppressed with fallback logic to handle missing fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change—updating alert-rule trait attachment instructions for components to be more robust and idempotent.
Description check ✅ Passed The description covers the Purpose and Checklist sections with good detail about the improvements and documentation updates, though the Related Issues section is incomplete.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 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

📥 Commits

Reviewing files that changed from the base of the PR and between 3819932 and f788c57.

⛔ Files ignored due to path filters (1)
  • versioned_docs/version-v1.0.x/tutorials/component-alerts-and-incidents.mdx is excluded by !versioned_docs/**
📒 Files selected for processing (1)
  • docs/tutorials/component-alerts-and-incidents.mdx

@LakshanSS LakshanSS merged commit bde9015 into openchoreo:main Apr 2, 2026
3 checks passed
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.

3 participants