Alerting: Fix non-applicable error checks for cloud and recording rules (#75233)

This commit is contained in:
Gilles De Mey 2023-09-21 16:01:34 +02:00 committed by GitHub
parent 14f4ed0180
commit 3b2dcecbda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) => {