Skip to content

Commit

Permalink
fix: compare op outside bounds for anomaly alert (#6458)
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv authored Nov 16, 2024
1 parent 0acf39a commit cd1ec56
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions ee/query-service/rules/anomaly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/container/FormAlertRules/RuleOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ function RuleOptions({
<Select.Option value="4">{t('option_notequal')}</Select.Option>
</>
)}

{/* the value 5 and 6 are reserved for above or equal and below or equal */}
{ruleType === 'anomaly_rule' && (
<Select.Option value="5">{t('option_above_below')}</Select.Option>
<Select.Option value="7">{t('option_above_below')}</Select.Option>
)}
</InlineSelect>
);
Expand Down
4 changes: 2 additions & 2 deletions pkg/query-service/rules/base_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit cd1ec56

Please sign in to comment.