From 2a1873f03815f5ea26da31be7e5157a2c3f171a4 Mon Sep 17 00:00:00 2001 From: Sonia Aguilar <33540275+soniaAguilarPeiron@users.noreply.github.com> Date: Thu, 22 Feb 2024 14:29:57 +0100 Subject: [PATCH] Alerting: Fix saving evaluation group. (#83188) fix saving evaluation group --- .../rule-editor/GrafanaEvaluationBehavior.tsx | 2 +- .../app/features/alerting/unified/state/actions.ts | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx b/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx index d0f6672c41c..22953dbb920 100644 --- a/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx @@ -18,7 +18,7 @@ import { } from '@grafana/ui'; import { CombinedRuleGroup, CombinedRuleNamespace } from '../../../../../types/unified-alerting'; -import { logInfo, LogMessages } from '../../Analytics'; +import { LogMessages, logInfo } from '../../Analytics'; import { useCombinedRuleNamespaces } from '../../hooks/useCombinedRuleNamespaces'; import { useUnifiedAlertingSelector } from '../../hooks/useUnifiedAlertingSelector'; import { RuleFormValues } from '../../types/rule-form'; diff --git a/public/app/features/alerting/unified/state/actions.ts b/public/app/features/alerting/unified/state/actions.ts index a609c09e06e..0035acdcecf 100644 --- a/public/app/features/alerting/unified/state/actions.ts +++ b/public/app/features/alerting/unified/state/actions.ts @@ -65,6 +65,7 @@ import { FetchRulerRulesFilter, setRulerRuleGroup, } from '../api/ruler'; +import { encodeGrafanaNamespace } from '../components/expressions/util'; import { RuleFormType, RuleFormValues } from '../types/rule-form'; import { addDefaultsToAlertmanagerConfig, removeMuteTimingFromRoute } from '../utils/alertmanager'; import { @@ -803,11 +804,14 @@ export const updateLotexNamespaceAndGroupAction: AsyncThunk< } const newNamespaceAlreadyExists = Boolean(rulesResult[newNamespaceName]); - if (newNamespaceName !== namespaceName && newNamespaceAlreadyExists) { + const isGrafanaManagedGroup = rulesSourceName === GRAFANA_RULES_SOURCE_NAME; + const originalNamespace = isGrafanaManagedGroup ? encodeGrafanaNamespace(namespaceName) : namespaceName; + + if (newNamespaceName !== originalNamespace && newNamespaceAlreadyExists) { throw new Error(`Namespace "${newNamespaceName}" already exists.`); } if ( - newNamespaceName === namespaceName && + newNamespaceName === originalNamespace && groupName === newGroupName && groupInterval === existingGroup.interval ) { @@ -829,8 +833,8 @@ export const updateLotexNamespaceAndGroupAction: AsyncThunk< } } // if renaming namespace - make new copies of all groups, then delete old namespace - - if (newNamespaceName !== namespaceName) { + // this is only possible for cloud rules + if (newNamespaceName !== originalNamespace) { for (const group of rulesResult[namespaceName]) { await setRulerRuleGroup( rulerConfig,