Notification Rule Processing Engine - #766
malinosqui wants to merge 15 commits into
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>
Code Review Completed! 🔥The code review was successfully completed based on your current configurations. Kody Guide: Usage and ConfigurationInteracting with Kody
Current Kody ConfigurationReview OptionsThe following review options are enabled or disabled:
|
| const isProvisioned = rule ? isProvisionedRule(rule) : false; | ||
| // TODO: Add support for federated rules | ||
| // const isFederated = isFederatedRuleGroup(); | ||
| const isFederated = false; | ||
| const isGrafanaManagedAlertRule = rulerRuleType.grafana.rule(rule); | ||
| const isPluginProvided = isPluginProvidedRule(rule); | ||
|
|
||
| // if a rule is either provisioned, federated or provided by a plugin rule, we don't allow it to be removed or edited | ||
| const immutableRule = isProvisioned || isFederated || isPluginProvided; |
There was a problem hiding this comment.
Immutability bypass occurs in useAllRulerRuleAbilities because hardcoding isFederated to false surfaces mutation actions for Mimir and Loki federated rules. Restore the isFederatedRuleGroup() evaluation to ensure these rules remain strictly immutable.
const isProvisioned = rule ? isProvisionedRule(rule) : false;
const isFederated = isFederatedRuleGroup(groupIdentifier); // or pass down group/fetch it
const isGrafanaManagedAlertRule = rulerRuleType.grafana.rule(rule);
const isPluginProvided = isPluginProvidedRule(rule);
// if a rule is either provisioned, federated or provided by a plugin rule, we don't allow it to be removed or edited
const immutableRule = isProvisioned || isFederated || isPluginProvided;Prompt for LLM
File public/app/features/alerting/unified/hooks/useAbilities.ts:
Line 242 to 250:
WHAT: The `isFederated` check was removed and hardcoded to `false` in `useAllRulerRuleAbilities`, dropping immutability guarantees for federated rules. WHY: Mimir/Loki federated rules rely on this check to disable mutation actions; hardcoding it to false surfaces Edit/Delete buttons in the UI for rules that must remain strictly immutable. HOW: Restore the federated evaluation (e.g. `isFederatedRuleGroup()`) by passing the group or fetching the group context, rather than hardcoding it to false.
Suggested Code:
const isProvisioned = rule ? isProvisionedRule(rule) : false;
const isFederated = isFederatedRuleGroup(groupIdentifier); // or pass down group/fetch it
const isGrafanaManagedAlertRule = rulerRuleType.grafana.rule(rule);
const isPluginProvided = isPluginProvidedRule(rule);
// if a rule is either provisioned, federated or provided by a plugin rule, we don't allow it to be removed or edited
const immutableRule = isProvisioned || isFederated || isPluginProvided;
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
| @@ -93,3 +114,38 @@ export function RuleActionsButtons({ compact, rule, promRule, groupIdentifier }: | |||
| </Stack> | |||
There was a problem hiding this comment.
Silence drawer rendering failure occurs because rulerRuleType.grafana.alertingRule(rule) evaluates to false when rule is undefined following the removal of Ruler API calls. Expand the rendering condition to include prometheusRuleType.grafana.alertingRule(promRule) and update SilenceGrafanaRuleDrawer to support the promRule context.
{(rulerRuleType.grafana.alertingRule(rule) || prometheusRuleType.grafana.alertingRule(promRule)) && showSilenceDrawer && (
<SilenceGrafanaRuleDrawer rulerRule={rule} promRule={promRule} onClose={() => setShowSilenceDrawer(false)} />
)}Prompt for LLM
File public/app/features/alerting/unified/rule-list/components/RuleActionsButtons.V2.tsx:
Line 114:
WHAT: The Silence drawer silently fails to open when clicking 'Silence' in the list view because it strictly requires the `rule` (RulerRuleDTO) object which is no longer passed. WHY: The PR removed Ruler API calls in the list view, meaning `rule` is undefined; the condition `rulerRuleType.grafana.alertingRule(rule)` evaluates to false, so the drawer is never mounted even though the state opens it. HOW: Expand the rendering condition to also check `promRule` (e.g., `prometheusRuleType.grafana.alertingRule(promRule)`) and update the drawer to support `promRule` or fetch the Ruler rule internally.
Suggested Code:
{(rulerRuleType.grafana.alertingRule(rule) || prometheusRuleType.grafana.alertingRule(promRule)) && showSilenceDrawer && (
<SilenceGrafanaRuleDrawer rulerRule={rule} promRule={promRule} onClose={() => setShowSilenceDrawer(false)} />
)}
Talk to Kody by mentioning @kody
Was this suggestion helpful? React with 👍 or 👎 to help Kody learn from this interaction.
This pull request refactors the Alerting Rule List view to eliminate dependencies on the Ruler API for Grafana-managed rules. By relying exclusively on the Prometheus API, it simplifies data loading and improves performance when rendering the rule list.
Key Changes:
useGetGrafanaRulerGroupQuery) and related prefetching logic from the rule list view. The list now populates directly from Prometheus rule data (GrafanaPromRuleDTO).GrafanaRuleListItemcomponent to render rule items directly from Prometheus rules, replacing the previousGrafanaRuleLoader.matchRuleslogic inGrafanaGroupLoaderthat previously synchronized Ruler rules with Prometheus rules.AlertRuleMenuandRuleActionsButtons.V2to support rendering action buttons and dropdown menus using either Ruler or Prometheus rule data.useGrafanaPromRuleAbilities,useIsGrafanaPromRuleEditable) to evaluate user permissions (edit, delete, duplicate, silence, etc.) using Prometheus rule data and folder UIDs, bypassing the need for Ruler rules.provenancefield toGrafanaPromRuleDTOBaseand introduced anisProvisionedPromRuleutility to allow the UI to identify provisioned rules directly from the Prometheus API response.