From 3b2dcecbda299c61b80d8bbe1afd24094c68c5bb Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Thu, 21 Sep 2023 16:01:34 +0200 Subject: [PATCH] Alerting: Fix non-applicable error checks for cloud and recording rules (#75233) --- .../QueryAndExpressionsStep.tsx | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 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 8d531b8b79a..6b2b2febf60 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 @@ -82,8 +82,14 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P const rulesSourcesWithRuler = useRulesSourcesWithRuler(); const runQueriesPreview = useCallback(() => { + if (isCloudAlertRuleType) { + // we will skip preview for cloud rules, these do not have any time series preview + // Grafana Managed rules and recording rules do + return; + } + runQueries(getValues('queries')); - }, [runQueries, getValues]); + }, [isCloudAlertRuleType, runQueries, getValues]); // whenever we update the queries we have to update the form too useEffect(() => { @@ -104,18 +110,27 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P const emptyQueries = queries.length === 0; + // apply some validations and asserts to the results of the evaluation when creating or editing + // Grafana-managed alert rules useEffect(() => { - const currentCondition = getValues('condition'); - - if (!currentCondition || !queryPreviewData[currentCondition]) { + if (!isGrafanaManagedType) { return; } - const error = - errorFromPreviewData(queryPreviewData[currentCondition]) ?? - errorFromCurrentCondition(queryPreviewData[currentCondition]); + const currentCondition = getValues('condition'); + if (!currentCondition) { + return; + } + + const previewData = queryPreviewData[currentCondition]; + if (!previewData) { + return; + } + + const error = errorFromPreviewData(previewData) ?? errorFromCurrentCondition(previewData); + onDataChange(error?.message || ''); - }, [queryPreviewData, getValues, onDataChange]); + }, [queryPreviewData, getValues, onDataChange, isGrafanaManagedType]); const handleSetCondition = useCallback( (refId: string | null) => {