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,