Skip to content

4.19: OLS-1188: Add the ability to attach Alert Rules and Silences to the prompt#1955

Merged
openshift-merge-bot[bot] merged 1 commit into
openshift:release-4.19from
kyoto:4.19-attach-alert-rule-silence
May 19, 2026
Merged

4.19: OLS-1188: Add the ability to attach Alert Rules and Silences to the prompt#1955
openshift-merge-bot[bot] merged 1 commit into
openshift:release-4.19from
kyoto:4.19-attach-alert-rule-silence

Conversation

@kyoto
Copy link
Copy Markdown
Member

@kyoto kyoto commented May 19, 2026

Manual cherry pick of #1941

Summary by CodeRabbit

Release Notes

  • New Features
    • Added support for Silence and Alerting rule resources with the ability to view and attach their YAML configurations from the prompt interface.
    • Enhanced error handling with informative messages for silence retrieval failures and missing alerting rule definitions.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kyoto kyoto added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label May 19, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

📝 Walkthrough

Walkthrough

This PR extends the Lightspeed Console plugin to support attaching generated YAML for Silence and AlertingRule monitoring resources. It adds validation utilities for rule ID generation and silence ID validation, detects resource detail pages via URL patterns, and implements fetch-and-attach flows in the Prompt component with corresponding UI labels.

Changes

Silence and AlertingRule YAML Attachment

Layer / File(s) Summary
Validation and ID generation foundation
src/validation.ts, package.json, unit-tests/validation.test.ts
Added alertingRuleID to deterministically hash rule identifiers using murmur3 hashing, added isValidSilenceID as a UUID v4-style regex validator, and covered both with comprehensive unit tests. New murmurhash-js dependency supports the hashing logic.
URL detection for resource detail pages
src/hooks/useLocationContext.ts
Extended URL pattern matching to recognize Silence detail pages at /monitoring/silences/{id} and AlertingRule pages at /monitoring/alertrules/{numeric}, validating IDs and populating context kind and name for downstream components.
Prompt component constants and K8s setup
src/components/Prompt.tsx
Added SILENCE_ENDPOINT and NON_K8S_KINDS constants, refactored Kubernetes watch resource configuration to treat non-K8s resources appropriately, and imported alertingRuleID for rule matching during attachment.
Prompt attachment UI and async fetch logic
src/components/Prompt.tsx
Extended attach dropdown menu with Silence and AlertingRule YAML options. Implemented async flows to fetch resources (silence by name, alerting rules by matched ID), convert to YAML, and dispatch attachment events on success or capture error messages on failure.
UI localization strings
locales/en/plugin__lightspeed-console-plugin.json
Added localized labels for "Alerting rule" and "Silence" resources, error message for failed silence fetch, and error message for missing alerting rule YAML definition.

Sequence Diagram

sequenceDiagram
  participant User
  participant Prompt
  participant LocationContext
  participant SilenceAPI
  participant AlertingRuleAPI
  participant YAMLConverter
  User->>LocationContext: Navigate to detail page
  LocationContext->>Prompt: Set kind and name in context
  Prompt->>User: Display attach menu
  User->>Prompt: Select Silence or AlertingRule
  alt Silence resource
    Prompt->>SilenceAPI: Fetch silence by name
    SilenceAPI-->>Prompt: Silence object
  else AlertingRule resource
    Prompt->>AlertingRuleAPI: Fetch rule definitions
    AlertingRuleAPI-->>Prompt: Rule object
  end
  Prompt->>YAMLConverter: Convert to YAML
  YAMLConverter-->>Prompt: YAML string
  Prompt->>User: Dispatch attachment
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A silence falls, a rule awakens bright,
With hashing salts and UUIDs in sight,
The Prompt now fetches what the URLs declare,
Converting rules to YAML with proper care!
— Your friendly rabbit, hopping through the code

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding functionality to attach Alert Rules and Silences to the prompt, which is reflected across multiple files including Prompt.tsx, validation.ts, and useLocationContext.ts.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

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

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

@openshift-ci openshift-ci Bot requested review from joshuawilson and syedriko May 19, 2026 00:06
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

1 similar comment
@openshift-ci
Copy link
Copy Markdown

openshift-ci Bot commented May 19, 2026

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by:

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copy link
Copy Markdown

@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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/hooks/useLocationContext.ts`:
- Around line 193-199: The route matcher in useLocationContext currently uses
path.match(new RegExp('/monitoring/alertrules/([0-9]+)')) which will match
nested routes; update the regex used when computing alertRuleMatch (inside
useLocationContext) to anchor it to the detail-page URL (e.g. require start and
end or allow only an optional trailing slash) so only exact detail pages
setKind('AlertingRule'), setName(alertRuleMatch[1]) and setNamespace(undefined);
keep the same variables (alertRuleMatch, setKind, setName, setNamespace) but
tighten the RegExp to avoid false positives.
🪄 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: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: eb0a33ec-2c4f-48c1-8cbd-e5af8e8903a6

📥 Commits

Reviewing files that changed from the base of the PR and between 16e82d2 and c4a911b.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (6)
  • locales/en/plugin__lightspeed-console-plugin.json
  • package.json
  • src/components/Prompt.tsx
  • src/hooks/useLocationContext.ts
  • src/validation.ts
  • unit-tests/validation.test.ts

Comment on lines +193 to +199
const alertRuleMatch = path.match(new RegExp('/monitoring/alertrules/([0-9]+)'));
if (alertRuleMatch) {
setKind('AlertingRule');
setName(alertRuleMatch[1]);
setNamespace(undefined);
return;
}
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 | ⚡ Quick win

Tighten AlertingRule route matching to detail-page URLs only.

Line 193 matches any path containing /monitoring/alertrules/<digits>, so nested paths can be misclassified as a detail page context. Anchor the regex to avoid false positives.

Proposed fix
-      const alertRuleMatch = path.match(new RegExp('/monitoring/alertrules/([0-9]+)'));
+      const alertRuleMatch = path.match(new RegExp('/monitoring/alertrules/([0-9]+)/?$'));
📝 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
const alertRuleMatch = path.match(new RegExp('/monitoring/alertrules/([0-9]+)'));
if (alertRuleMatch) {
setKind('AlertingRule');
setName(alertRuleMatch[1]);
setNamespace(undefined);
return;
}
const alertRuleMatch = path.match(new RegExp('/monitoring/alertrules/([0-9]+)/?$'));
if (alertRuleMatch) {
setKind('AlertingRule');
setName(alertRuleMatch[1]);
setNamespace(undefined);
return;
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/hooks/useLocationContext.ts` around lines 193 - 199, The route matcher in
useLocationContext currently uses path.match(new
RegExp('/monitoring/alertrules/([0-9]+)')) which will match nested routes;
update the regex used when computing alertRuleMatch (inside useLocationContext)
to anchor it to the detail-page URL (e.g. require start and end or allow only an
optional trailing slash) so only exact detail pages setKind('AlertingRule'),
setName(alertRuleMatch[1]) and setNamespace(undefined); keep the same variables
(alertRuleMatch, setKind, setName, setNamespace) but tighten the RegExp to avoid
false positives.

@kyoto kyoto added the lgtm Indicates that a PR is ready to be merged. label May 19, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit 5f62a48 into openshift:release-4.19 May 19, 2026
5 checks passed
@kyoto kyoto deleted the 4.19-attach-alert-rule-silence branch May 19, 2026 00:46
@kyoto kyoto changed the title 4.19: Add the ability to attach Alert Rules and Silences to the prompt 4.19: OLS-1188: Add the ability to attach Alert Rules and Silences to the prompt May 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant