Alerting: Fix saving evaluation group. (#83188)

fix saving evaluation group
This commit is contained in:
Sonia Aguilar 2024-02-22 14:29:57 +01:00 committed by GitHub
parent 3ba33fe278
commit 2a1873f038
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -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';

View File

@ -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,