From cd1ec561b11d7e92e137a78391d23754b38fc5f9 Mon Sep 17 00:00:00 2001 From: Srikanth Chekuri Date: Sat, 16 Nov 2024 20:17:34 +0530 Subject: [PATCH] fix: compare op outside bounds for anomaly alert (#6458) --- ee/query-service/rules/anomaly.go | 5 +++++ frontend/src/container/FormAlertRules/RuleOptions.tsx | 4 ++-- pkg/query-service/rules/base_rule.go | 4 ++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ee/query-service/rules/anomaly.go b/ee/query-service/rules/anomaly.go index 08ff3afcda..ceec23747e 100644 --- a/ee/query-service/rules/anomaly.go +++ b/ee/query-service/rules/anomaly.go @@ -61,6 +61,11 @@ func NewAnomalyRule( zap.L().Info("creating new AnomalyRule", zap.String("id", id), zap.Any("opts", opts)) + if p.RuleCondition.CompareOp == baserules.ValueIsBelow { + target := -1 * *p.RuleCondition.Target + p.RuleCondition.Target = &target + } + baseRule, err := baserules.NewBaseRule(id, p, reader, opts...) if err != nil { return nil, err diff --git a/frontend/src/container/FormAlertRules/RuleOptions.tsx b/frontend/src/container/FormAlertRules/RuleOptions.tsx index e9aa8f860f..8eebb8268d 100644 --- a/frontend/src/container/FormAlertRules/RuleOptions.tsx +++ b/frontend/src/container/FormAlertRules/RuleOptions.tsx @@ -102,9 +102,9 @@ function RuleOptions({ {t('option_notequal')} )} - + {/* the value 5 and 6 are reserved for above or equal and below or equal */} {ruleType === 'anomaly_rule' && ( - {t('option_above_below')} + {t('option_above_below')} )} ); diff --git a/pkg/query-service/rules/base_rule.go b/pkg/query-service/rules/base_rule.go index b6d2db0a3c..466cba83fd 100644 --- a/pkg/query-service/rules/base_rule.go +++ b/pkg/query-service/rules/base_rule.go @@ -463,9 +463,9 @@ func (r *BaseRule) ShouldAlert(series v3.Series) (Sample, bool) { } } else if r.compareOp() == ValueOutsideBounds { for _, smpl := range series.Points { - if math.Abs(smpl.Value) >= r.targetVal() { + if math.Abs(smpl.Value) < r.targetVal() { alertSmpl = Sample{Point: Point{V: smpl.Value}, Metric: lbls} - shouldAlert = true + shouldAlert = false break } }