From 45a8ca3111276db92a2a7d33a7c19265faf1f996 Mon Sep 17 00:00:00 2001 From: Konrad Lalik Date: Tue, 29 Aug 2023 14:05:03 +0200 Subject: [PATCH] Alerting: Fix labels suggestions Grafana-managed rules (#73983) --- .../QueryAndExpressionsStep.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx index cae1906c3be..d9616c3e7a9 100644 --- a/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/query-and-alert-condition/QueryAndExpressionsStep.tsx @@ -312,6 +312,13 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P prevCondition && setValue('condition', prevCondition); } else { setValue('type', RuleFormType.cloudAlerting); + // dataSourceName is used only by Mimir/Loki alerting and recording rules + // It should be empty for Grafana managed alert rules + const newDsName = getDataSourceSrv().getInstanceSettings(queries[0].datasourceUid)?.name; + if (newDsName) { + setValue('dataSourceName', newDsName); + } + updateExpressionAndDatasource(queries); const expressions = queries.filter((query) => query.datasourceUid === ExpressionDatasourceUID); @@ -549,11 +556,9 @@ const useSetExpressionAndDataSource = () => { if (!dataSourceSettings) { throw new Error('The Data source has not been defined.'); } - setValue('dataSourceName', dataSourceSettings.name); if (isPromOrLokiQuery(query.model)) { const expression = query.model.expr; - setValue('expression', expression); } };