Notification Rule Processing Engine#6
Conversation
* 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>
|
@CodeAnt-AI: review |
|
CodeAnt AI is running the review. |
Nitpicks 🔍
|
| key={key} | ||
| ruleIdentifier={{ ruleSourceName: 'grafana', uid: rule.uid }} | ||
| <GrafanaRuleListItem | ||
| rule={rule} |
There was a problem hiding this comment.
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.| 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.| // 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); |
There was a problem hiding this comment.
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.| // 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 finished running the review. |
|
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! |
|
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! |
User description
Test 5nn
Summary by CodeRabbit
New Features
Bug Fixes
Refactor
✏️ 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
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:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
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:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
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.