mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Alerting: Fix non-applicable error checks for cloud and recording rules (#75233)
This commit is contained in:
parent
14f4ed0180
commit
3b2dcecbda
@ -82,8 +82,14 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
|
|||||||
const rulesSourcesWithRuler = useRulesSourcesWithRuler();
|
const rulesSourcesWithRuler = useRulesSourcesWithRuler();
|
||||||
|
|
||||||
const runQueriesPreview = useCallback(() => {
|
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('queries'));
|
||||||
}, [runQueries, getValues]);
|
}, [isCloudAlertRuleType, runQueries, getValues]);
|
||||||
|
|
||||||
// whenever we update the queries we have to update the form too
|
// whenever we update the queries we have to update the form too
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@ -104,18 +110,27 @@ export const QueryAndExpressionsStep = ({ editingExistingRule, onDataChange }: P
|
|||||||
|
|
||||||
const emptyQueries = queries.length === 0;
|
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(() => {
|
useEffect(() => {
|
||||||
const currentCondition = getValues('condition');
|
if (!isGrafanaManagedType) {
|
||||||
|
|
||||||
if (!currentCondition || !queryPreviewData[currentCondition]) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const error =
|
const currentCondition = getValues('condition');
|
||||||
errorFromPreviewData(queryPreviewData[currentCondition]) ??
|
if (!currentCondition) {
|
||||||
errorFromCurrentCondition(queryPreviewData[currentCondition]);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const previewData = queryPreviewData[currentCondition];
|
||||||
|
if (!previewData) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const error = errorFromPreviewData(previewData) ?? errorFromCurrentCondition(previewData);
|
||||||
|
|
||||||
onDataChange(error?.message || '');
|
onDataChange(error?.message || '');
|
||||||
}, [queryPreviewData, getValues, onDataChange]);
|
}, [queryPreviewData, getValues, onDataChange, isGrafanaManagedType]);
|
||||||
|
|
||||||
const handleSetCondition = useCallback(
|
const handleSetCondition = useCallback(
|
||||||
(refId: string | null) => {
|
(refId: string | null) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user