Skip to content

Notification Rule Processing Engine#6

Closed
ShashankFC wants to merge 1 commit into
notification-rule-baselinefrom
notification-rule-enhancements
Closed

Notification Rule Processing Engine#6
ShashankFC wants to merge 1 commit into
notification-rule-baselinefrom
notification-rule-enhancements

Conversation

@ShashankFC

@ShashankFC ShashankFC commented Feb 13, 2026

Copy link
Copy Markdown

User description

Test 5nn

Summary by CodeRabbit

  • New Features

    • Added a More menu button to rule actions, providing access to silence, duplicate, copy link, export, and delete operations.
  • Bug Fixes

    • Improved permission evaluation for alert rule actions, now correctly handling both Grafana-managed and externally-sourced rules with separate capability checks.
  • Refactor

    • Streamlined rule list display logic for better performance and maintainability.

✏️ Tip: You can customize this high-level summary in your review settings.

nn---n*Replicated from [ai-code-review-evaluation/grafana-coderabbit#5](https://github.com/ai-code-review-evaluation/grafana-coderabbit/pull/5)*

CodeAnt-AI Description

Notification rule list and actions now use Prometheus rule data and show contextual action menus

What Changed

  • Rule list no longer waits for Ruler API responses; Grafana-managed rules are rendered directly from Prometheus responses so group lists load without Ruler calls and show consistent rule items.
  • Each Grafana-managed rule in the list shows its own action buttons and a "More" menu; that menu exposes Silence, Duplicate, Copy link, Export, and Delete when the user has the corresponding folder/alerting permissions.
  • Edit/delete availability respects folder-level Grafana permissions: Edit and Delete buttons are shown or hidden based on the user's granted access for the rule's folder.
  • Introduced a dedicated Grafana rule list item component so rule entries link to the correct Grafana rule view and preserve state (alerting vs recording) in the list.
  • Tests updated to cover permission-aware rendering of More menu items, multiple rules each having action buttons, and hiding Edit when edit permission is denied.

Impact

✅ Faster rule list load when Ruler is unavailable
✅ Clearer action availability in More menu for Grafana-managed rules
✅ Fewer incorrect Edit/Delete buttons shown for users without folder permissions

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

* wip

* Add working actions for GMA rules based on Prom-only API

* Remove Ruler-loader related code for Grafana rules

Co-authored-by: Sonia Augilar <sonia.aguilar@grafana.com>

* Remove outdated tests

* add some comments

* remove commented code

* remove showLocation property

* Add missing mocks in tests

* Add showLocation to GrafanaRuleListItem, improve useAbilities, address PR feedback

* Enhance GrafanaGroupLoader tests: Add permission checks and More button functionality

- Introduced user permission grants for alerting actions in tests.
- Added tests for rendering the More button with action menu options.
- Verified that each rule has its own action buttons and handles permissions correctly.
- Ensured the edit button is not rendered when user lacks edit permissions.
- Confirmed the correct menu actions are displayed when the More button is clicked.

* Update translations

---------

Co-authored-by: Sonia Aguilar <soniaaguilarpeiron@gmail.com>
Co-authored-by: Sonia Augilar <sonia.aguilar@grafana.com>
@ShashankFC

Copy link
Copy Markdown
Author

@CodeAnt-AI: review

@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

CodeAnt AI is running the review.

@codeant-ai codeant-ai Bot added the size:XL This PR changes 500-999 lines, ignoring generated files label Feb 13, 2026
@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Rendering inconsistency
    The menu rendering checks for canPause (which is true when either ruler or grafana prom abilities allow pause) but the Pause menu item is gated by rulerRuleType.grafana.rule(rulerRule) and groupIdentifier.groupOrigin === 'grafana'. This means a Grafana-managed prom-rule (with no rulerRule present) could have canPause === true but still not render the Pause menu because the extra rulerRule-based guard blocks it. Verify and align the capability computation and rendering conditions so they reflect the same source-of-truth (promRule vs rulerRule) in list and detail views.

  • Hook duplication / divergence risk
    New hooks split ability logic across useAllRulerRuleAbilities, useAllGrafanaPromRuleAbilities, and the deprecated useAllAlertRuleAbilities. Similar logic is duplicated (immutable rule checks, duplicateSupported, etc.). This increases maintenance risk and may accidentally drift the permission model between rulers and grafana-prom rules. Consider consolidating shared logic or centralizing common computations to avoid divergence and make tests easier to reason about.

  • Silent failure on missing identifier
    getEditableIdentifier logs a warning and returns undefined when an identifier cannot be constructed; the component returns null in that case. This will silently hide the action menu for those rules. Validate that callers expect this behavior and consider surfacing a fallback or a safe default action if appropriate.

  • Missing React key
    The Grafana rule items rendered in the FilterView list don't include a React key prop. React list rendering needs stable keys to avoid unexpected re-renders and visual/list inconsistencies. Use the existing key value already computed for each ruleWithOrigin.

  • Key string formatting bug
    The helper getGrafanaRuleKey returns a key string with an extra closing brace: grafana-${namespace.uid}-${groupName}-${rule.uid}}. That trailing brace will produce mismatched/incorrect keys. Remove the stray }.

key={key}
ruleIdentifier={{ ruleSourceName: 'grafana', uid: rule.uid }}
<GrafanaRuleListItem
rule={rule}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The Grafana-origin rule list items are rendered inside an array .map() without a key prop on GrafanaRuleListItem, which will trigger React's "missing key" warning and can lead to incorrect reconciliation if the list changes; use the computed key to uniquely identify these items. [possible bug]

Severity Level: Major ⚠️
- ⚠️ React logs missing key warnings in rule list view.
- ⚠️ Potentially unstable reconciliation when Grafana rules are added/removed.
- ⚠️ No automated tests catch this React key warning currently.
Suggested change
rule={rule}
key={key}
Steps of Reproduction ✅
1. Navigate in the UI to the alerting rule list page that renders `RuleListPage` from
`public/app/features/alerting/unified/rule-list/RuleList.v2.tsx:98-107` (e.g.
`/alerting/list` in Grafana).

2. Ensure list view is active so that `RuleList` renders `<FilterView
filterState={filterState} />` at `RuleList.v2.tsx:18-29` (for example, `view=list` URL
param as covered in `RuleList.v2.test.tsx:65-70`).

3. Use or configure alerting such that at least one rule in the results returned by
`useFilteredRulesIteratorProvider` (called in `FilterView.tsx:56-80`) has `origin ===
'grafana'` and is included in the `rules` state array (`FilterView.tsx:64-106`).

4. When `FilterViewResults` renders, it maps over `rules` at `FilterView.tsx:151-176`; for
a Grafana-origin rule it returns `<GrafanaRuleListItem ... />` without a `key` prop
(`FilterView.tsx:155-163`), while datasource and unknown items use `key={key}`
(`FilterView.tsx:165-173`), causing React to emit the "Each child in a list should have a
unique 'key' prop" warning in the browser console for the rule list `<ul>`.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** public/app/features/alerting/unified/rule-list/FilterView.tsx
**Line:** 158:158
**Comment:**
	*Possible Bug: The Grafana-origin rule list items are rendered inside an array `.map()` without a `key` prop on `GrafanaRuleListItem`, which will trigger React's "missing key" warning and can lead to incorrect reconciliation if the list changes; use the computed `key` to uniquely identify these items.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
👍 | 👎

Comment on lines +191 to +207
// With proper permissions, all 4 menu actions should be available:

it('should not include ruler rules in matches if they have no prometheus counterpart', () => {
const rulerRules = [
mockGrafanaRulerRule({ uid: '1' }),
mockGrafanaRulerRule({ uid: '2' }),
mockGrafanaRulerRule({ uid: '3' }),
];
// 1. Silence notifications - available for alerting rules (AlertingSilenceCreate permission)
expect(ui.menuItems.silence().get()).toBeInTheDocument();

// Only create prom rule for the second ruler rule
const promRules = [rulerRuleToPromRule(rulerRules[1])];
// 2. Copy link - always available
expect(ui.menuItems.copyLink().get()).toBeInTheDocument();

const { matches, promOnlyRules } = matchRules(promRules, rulerRules);
// 3. Duplicate - should be available with create permissions (AlertingRuleCreate permission)
expect(ui.menuItems.duplicate().get()).toBeInTheDocument();

expect(matches.size).toBe(1);
expect(promOnlyRules).toHaveLength(0);
// 4. Export - should be available for Grafana alerting rules (AlertingRuleRead permission)
expect(ui.menuItems.export().get()).toBeInTheDocument();

// Verify that only the second ruler rule is in matches
expect(matches.has(rulerRules[0])).toBe(false);
expect(matches.get(rulerRules[1])).toBe(promRules[0]);
expect(matches.has(rulerRules[2])).toBe(false);
// Verify that the menu contains all 4 expected menu items
const menuItems = byRole('menuitem').getAll();
expect(menuItems.length).toBe(4);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggestion: The test for the More menu assumes only four menu items and never asserts the presence of the Delete action, which contradicts the implemented behavior (and PR description) where the More menu exposes silence, duplicate, copy link, export, and delete actions; this will cause the test to fail or miss regressions in the delete action. [logic error]

Severity Level: Major ⚠️
- ⚠️ Delete action in More menu is completely untested.
- ⚠️ Test enforces four items, conflicting with five-action design.
- ⚠️ Future delete regressions may ship without test failures.
Suggested change
// With proper permissions, all 4 menu actions should be available:
it('should not include ruler rules in matches if they have no prometheus counterpart', () => {
const rulerRules = [
mockGrafanaRulerRule({ uid: '1' }),
mockGrafanaRulerRule({ uid: '2' }),
mockGrafanaRulerRule({ uid: '3' }),
];
// 1. Silence notifications - available for alerting rules (AlertingSilenceCreate permission)
expect(ui.menuItems.silence().get()).toBeInTheDocument();
// Only create prom rule for the second ruler rule
const promRules = [rulerRuleToPromRule(rulerRules[1])];
// 2. Copy link - always available
expect(ui.menuItems.copyLink().get()).toBeInTheDocument();
const { matches, promOnlyRules } = matchRules(promRules, rulerRules);
// 3. Duplicate - should be available with create permissions (AlertingRuleCreate permission)
expect(ui.menuItems.duplicate().get()).toBeInTheDocument();
expect(matches.size).toBe(1);
expect(promOnlyRules).toHaveLength(0);
// 4. Export - should be available for Grafana alerting rules (AlertingRuleRead permission)
expect(ui.menuItems.export().get()).toBeInTheDocument();
// Verify that only the second ruler rule is in matches
expect(matches.has(rulerRules[0])).toBe(false);
expect(matches.get(rulerRules[1])).toBe(promRules[0]);
expect(matches.has(rulerRules[2])).toBe(false);
// Verify that the menu contains all 4 expected menu items
const menuItems = byRole('menuitem').getAll();
expect(menuItems.length).toBe(4);
// With proper permissions, all 5 menu actions should be available:
// 1. Silence notifications - available for alerting rules (AlertingSilenceCreate permission)
expect(ui.menuItems.silence().get()).toBeInTheDocument();
// 2. Copy link - always available
expect(ui.menuItems.copyLink().get()).toBeInTheDocument();
// 3. Duplicate - should be available with create permissions (AlertingRuleCreate permission)
expect(ui.menuItems.duplicate().get()).toBeInTheDocument();
// 4. Export - should be available for Grafana alerting rules (AlertingRuleRead permission)
expect(ui.menuItems.export().get()).toBeInTheDocument();
// 5. Delete - should be available with delete permissions (AlertingRuleDelete permission)
expect(ui.menuItems.delete().get()).toBeInTheDocument();
// Verify that the menu contains all 5 expected menu items
const menuItems = byRole('menuitem').getAll();
expect(menuItems.length).toBe(5);
Steps of Reproduction ✅
1. Open `public/app/features/alerting/unified/rule-list/GrafanaGroupLoader.test.tsx` and
inspect the UI helpers at lines 30–43: `ui.menuItems` defines five selectors (`silence`,
`duplicate`, `copyLink`, `export`, `delete`) intended for menu items rendered when the
"More" button is clicked.

2. In the same file, inspect the `beforeEach` in the `describe('GrafanaGroupLoader')`
block at lines 47–62: it calls `grantUserPermissions` and `setFolderAccessControl` with
`AccessControlAction.AlertingRuleDelete` set to `true`, indicating the test environment is
configured for the Delete action to be available alongside the other actions.

3. Still in this file, locate the test `it('should render correct menu actions when More
button is clicked', async () => {` at lines 171–208: it opens the More menu and asserts
presence only of `silence`, `copyLink`, `duplicate`, and `export`, never calling
`ui.menuItems.delete()` and finally asserting `expect(menuItems.length).toBe(4);`.

4. Compare these tests to the declared helpers and permissions: despite having a `delete`
menu selector and explicit delete permissions configured, there is no assertion for the
Delete menu item and the test asserts there are only four menu items; as a result, any
regression where the Delete action is missing from the More menu would not be detected by
this test, and if the component renders all five actions as per the feature description,
this test will incorrectly fail by expecting `length === 4` instead of `5`.
Prompt for AI Agent 🤖
This is a comment left during a code review.

**Path:** public/app/features/alerting/unified/rule-list/GrafanaGroupLoader.test.tsx
**Line:** 191:207
**Comment:**
	*Logic Error: The test for the More menu assumes only four menu items and never asserts the presence of the Delete action, which contradicts the implemented behavior (and PR description) where the More menu exposes silence, duplicate, copy link, export, and delete actions; this will cause the test to fail or miss regressions in the delete action.

Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
👍 | 👎

@codeant-ai

codeant-ai Bot commented Feb 13, 2026

Copy link
Copy Markdown

CodeAnt AI finished running the review.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions!

@github-actions github-actions Bot added the stale label Mar 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it has not had any further activity in the last 2 weeks. Thank you for your contributions!

@github-actions github-actions Bot closed this Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XL This PR changes 500-999 lines, ignoring generated files stale

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants