From e1197641f34656c9c1ec8d1c20b208d36504a289 Mon Sep 17 00:00:00 2001 From: Gilles De Mey Date: Fri, 2 Feb 2024 12:58:04 +0100 Subject: [PATCH] Alerting: Fixes for pending period (#81718) --- .../rule-editor/GrafanaEvaluationBehavior.tsx | 2 +- .../unified/components/rules/EditRuleGroupModal.tsx | 2 +- .../alerting/unified/components/rules/RuleDetails.tsx | 11 +++++------ .../app/features/alerting/unified/utils/rule-form.ts | 4 +--- public/app/features/alerting/unified/utils/rules.ts | 4 ++-- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx b/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx index 5833c36bac4..d0f6672c41c 100644 --- a/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx +++ b/public/app/features/alerting/unified/components/rule-editor/GrafanaEvaluationBehavior.tsx @@ -57,7 +57,7 @@ const forValidationOptions = (evaluateEvery: string): RegisterOptions => ({ const millisEvery = parsePrometheusDuration(evaluateEvery); return millisFor >= millisEvery ? true - : 'For duration must be greater than or equal to the evaluation interval.'; + : 'Pending period must be greater than or equal to the evaluation interval.'; } catch (err) { // if we fail to parse "every", assume validation is successful, or the error messages // will overlap in the UI diff --git a/public/app/features/alerting/unified/components/rules/EditRuleGroupModal.tsx b/public/app/features/alerting/unified/components/rules/EditRuleGroupModal.tsx index feb3f46d748..bc24dd8be88 100644 --- a/public/app/features/alerting/unified/components/rules/EditRuleGroupModal.tsx +++ b/public/app/features/alerting/unified/components/rules/EditRuleGroupModal.tsx @@ -82,7 +82,7 @@ export const RulesForGroupTable = ({ rulesWithoutRecordingRules }: { rulesWithou }, { id: 'for', - label: 'For', + label: 'Pending period', renderCell: ({ data: { forDuration } }) => { return <>{forDuration}; }, diff --git a/public/app/features/alerting/unified/components/rules/RuleDetails.tsx b/public/app/features/alerting/unified/components/rules/RuleDetails.tsx index 070622f132c..cf6800f43d0 100644 --- a/public/app/features/alerting/unified/components/rules/RuleDetails.tsx +++ b/public/app/features/alerting/unified/components/rules/RuleDetails.tsx @@ -72,7 +72,7 @@ const EvaluationBehaviorSummary = ({ rule }: EvaluationBehaviorSummaryProps) => // recording rules don't have a for duration if (!isRecordingRulerRule(rule.rulerRule)) { - forDuration = rule.rulerRule?.for; + forDuration = rule.rulerRule?.for ?? '0s'; } return ( @@ -82,11 +82,10 @@ const EvaluationBehaviorSummary = ({ rule }: EvaluationBehaviorSummaryProps) => Every {every} )} - {forDuration && ( - - {forDuration} - - )} + + + {forDuration} + {lastEvaluation && !isNullDate(lastEvaluation) && ( diff --git a/public/app/features/alerting/unified/utils/rule-form.ts b/public/app/features/alerting/unified/utils/rule-form.ts index ac37e3c4402..71c4aff9861 100644 --- a/public/app/features/alerting/unified/utils/rule-form.ts +++ b/public/app/features/alerting/unified/utils/rule-form.ts @@ -330,9 +330,7 @@ export function alertingRulerRuleToRuleForm( > { const defaultFormValues = getDefaultFormValues(); - const [forTime, forTimeUnit] = rule.for - ? parseInterval(rule.for) - : [defaultFormValues.forTime, defaultFormValues.forTimeUnit]; + const [forTime, forTimeUnit] = rule.for ? parseInterval(rule.for) : [0, 's']; const [keepFiringForTime, keepFiringForTimeUnit] = rule.keep_firing_for ? parseInterval(rule.keep_firing_for) diff --git a/public/app/features/alerting/unified/utils/rules.ts b/public/app/features/alerting/unified/utils/rules.ts index 05759a8df69..3885db0d20d 100644 --- a/public/app/features/alerting/unified/utils/rules.ts +++ b/public/app/features/alerting/unified/utils/rules.ts @@ -229,8 +229,8 @@ export const getAlertInfo = (alert: RulerRuleDTO, currentEvaluation: string): Al if (isAlertingRulerRule(alert)) { return { alertName: alert.alert, - forDuration: alert.for ?? '1m', - evaluationsToFire: getNumberEvaluationsToStartAlerting(alert.for ?? '1m', currentEvaluation), + forDuration: alert.for ?? '0s', + evaluationsToFire: getNumberEvaluationsToStartAlerting(alert.for ?? '0s', currentEvaluation), }; } return emptyAlert;