diff --git a/public/app/features/alerting/unified/rule-editor/formDefaults.ts b/public/app/features/alerting/unified/rule-editor/formDefaults.ts index b7b9c8c48b0..1dab9a35fa6 100644 --- a/public/app/features/alerting/unified/rule-editor/formDefaults.ts +++ b/public/app/features/alerting/unified/rule-editor/formDefaults.ts @@ -34,9 +34,12 @@ const KEEP_FIRING_FOR_DEFAULT = '0s'; export const DEFAULT_GROUP_EVALUATION_INTERVAL = formatPrometheusDuration( clamp(GROUP_EVALUATION_MIN_INTERVAL_MS, GROUP_EVALUATION_INTERVAL_LOWER_BOUND, GROUP_EVALUATION_INTERVAL_UPPER_BOUND) ); -export const getDefaultFormValues = (): RuleFormValues => { +export const getDefaultFormValues = (ruleType?: RuleFormType): RuleFormValues => { const { canCreateGrafanaRules, canCreateCloudRules } = getRulesAccess(); const type = (() => { + if (ruleType === RuleFormType.grafanaRecording) { + return RuleFormType.grafanaRecording; + } if (canCreateGrafanaRules) { return RuleFormType.grafana; } @@ -70,7 +73,7 @@ export const getDefaultFormValues = (): RuleFormValues => { overrideGrouping: false, overrideTimings: false, muteTimeIntervals: [], - editorSettings: getDefaultEditorSettings(), + editorSettings: getDefaultEditorSettings(ruleType), targetDatasourceUid: config.unifiedAlerting?.defaultRecordingRulesTargetDatasourceUID, // cortex / loki @@ -88,7 +91,11 @@ export const getDefautManualRouting = () => { return manualRouting !== 'false'; }; -function getDefaultEditorSettings() { +function getDefaultEditorSettings(ruleType?: RuleFormType) { + if (ruleType === RuleFormType.grafanaRecording) { + return undefined; + } + const editorSettingsEnabled = config.featureToggles.alertingQueryAndExpressionsStepMode ?? false; if (!editorSettingsEnabled) { return undefined; @@ -109,7 +116,7 @@ export function formValuesFromQueryParams(ruleDefinition: string, type: RuleForm ruleFromQueryParams = JSON.parse(ruleDefinition); } catch (err) { return { - ...getDefaultFormValues(), + ...getDefaultFormValues(type), queries: getDefaultQueries(), }; } @@ -117,7 +124,7 @@ export function formValuesFromQueryParams(ruleDefinition: string, type: RuleForm return setQueryEditorSettings( setInstantOrRange( revealHiddenQueries({ - ...getDefaultFormValues(), + ...getDefaultFormValues(type), ...ruleFromQueryParams, annotations: normalizeDefaultAnnotations(ruleFromQueryParams.annotations ?? []), queries: ruleFromQueryParams.queries ?? getDefaultQueries(), @@ -130,7 +137,7 @@ export function formValuesFromQueryParams(ruleDefinition: string, type: RuleForm export function formValuesFromPrefill(rule: Partial): RuleFormValues { return revealHiddenQueries({ - ...getDefaultFormValues(), + ...getDefaultFormValues(rule.type), ...rule, }); } @@ -141,7 +148,7 @@ export function formValuesFromExistingRule(rule: RuleWithLocation) export function defaultFormValuesForRuleType(ruleType: RuleFormType): RuleFormValues { return { - ...getDefaultFormValues(), + ...getDefaultFormValues(ruleType), condition: 'C', queries: getDefaultQueries(isGrafanaRecordingRuleByType(ruleType)), type: ruleType, diff --git a/public/app/features/alerting/unified/utils/rule-form.ts b/public/app/features/alerting/unified/utils/rule-form.ts index c4208d61f52..42e2d235007 100644 --- a/public/app/features/alerting/unified/utils/rule-form.ts +++ b/public/app/features/alerting/unified/utils/rule-form.ts @@ -277,11 +277,12 @@ function getEditorSettingsFromDTO(ga: GrafanaRuleDefinition) { export function rulerRuleToFormValues(ruleWithLocation: RuleWithLocation): RuleFormValues { const { ruleSourceName, namespace, group, rule } = ruleWithLocation; + const isGrafanaRecordingRule = rulerRuleType.grafana.recordingRule(rule); - const defaultFormValues = getDefaultFormValues(); + const defaultFormValues = getDefaultFormValues(isGrafanaRecordingRule ? RuleFormType.grafanaRecording : undefined); if (isGrafanaRulesSource(ruleSourceName)) { // GRAFANA-MANAGED RULES - if (rulerRuleType.grafana.recordingRule(rule)) { + if (isGrafanaRecordingRule) { // grafana recording rule const ga = rule.grafana_alert; return { @@ -382,7 +383,8 @@ export function rulerRuleToFormValues(ruleWithLocation: RuleWithLocation): RuleF } export function grafanaRuleDtoToFormValues(rule: RulerGrafanaRuleDTO, namespace: string): RuleFormValues { - const defaultFormValues = getDefaultFormValues(); + const isGrafanaRecordingRule = rulerRuleType.grafana.recordingRule(rule); + const defaultFormValues = getDefaultFormValues(isGrafanaRecordingRule ? RuleFormType.grafanaRecording : undefined); const ga = rule.grafana_alert; const duration = rule.for;