diff --git a/ee/query-service/rules/anomaly.go b/ee/query-service/rules/anomaly.go index 462911ec18..a04bfc2840 100644 --- a/ee/query-service/rules/anomaly.go +++ b/ee/query-service/rules/anomaly.go @@ -70,13 +70,14 @@ func NewAnomalyRule( BaseRule: baseRule, } - if strings.ToLower(p.RuleCondition.Seasonality) == "hourly" { + switch strings.ToLower(p.RuleCondition.Seasonality) { + case "hourly": t.seasonality = anomaly.SeasonalityHourly - } else if strings.ToLower(p.RuleCondition.Seasonality) == "daily" { + case "daily": t.seasonality = anomaly.SeasonalityDaily - } else if strings.ToLower(p.RuleCondition.Seasonality) == "weekly" { + case "weekly": t.seasonality = anomaly.SeasonalityWeekly - } else { + default: t.seasonality = anomaly.SeasonalityDaily } diff --git a/pkg/query-service/rules/alerting.go b/pkg/query-service/rules/alerting.go index 2947a80450..ec2b0c8016 100644 --- a/pkg/query-service/rules/alerting.go +++ b/pkg/query-service/rules/alerting.go @@ -84,12 +84,14 @@ type NamedAlert struct { type CompareOp string const ( - CompareOpNone CompareOp = "0" - ValueIsAbove CompareOp = "1" - ValueIsBelow CompareOp = "2" - ValueIsEq CompareOp = "3" - ValueIsNotEq CompareOp = "4" - ValueIsAboveOrBelow CompareOp = "5" + CompareOpNone CompareOp = "0" + ValueIsAbove CompareOp = "1" + ValueIsBelow CompareOp = "2" + ValueIsEq CompareOp = "3" + ValueIsNotEq CompareOp = "4" + ValueAboveOrEq CompareOp = "5" + ValueBelowOrEq CompareOp = "6" + ValueOutsideBounds CompareOp = "7" ) type MatchType string diff --git a/pkg/query-service/rules/base_rule.go b/pkg/query-service/rules/base_rule.go index 9f76c5ae1f..181eaa3a28 100644 --- a/pkg/query-service/rules/base_rule.go +++ b/pkg/query-service/rules/base_rule.go @@ -388,9 +388,9 @@ func (r *BaseRule) ShouldAlert(series v3.Series) (Sample, bool) { break } } - } else if r.compareOp() == ValueIsAboveOrBelow { + } else if r.compareOp() == ValueOutsideBounds { for _, smpl := range series.Points { - if smpl.Value > r.targetVal() || smpl.Value < r.targetVal() { + if math.Abs(smpl.Value) >= r.targetVal() { alertSmpl = Sample{Point: Point{V: smpl.Value}, Metric: lblsNormalized, MetricOrig: lbls} shouldAlert = true break @@ -457,9 +457,9 @@ func (r *BaseRule) ShouldAlert(series v3.Series) (Sample, bool) { } } } - } else if r.compareOp() == ValueIsAboveOrBelow { + } else if r.compareOp() == ValueOutsideBounds { for _, smpl := range series.Points { - if smpl.Value > r.targetVal() || smpl.Value < r.targetVal() { + if math.Abs(smpl.Value) >= r.targetVal() { alertSmpl = Sample{Point: Point{V: smpl.Value}, Metric: lblsNormalized, MetricOrig: lbls} shouldAlert = true break @@ -494,8 +494,8 @@ func (r *BaseRule) ShouldAlert(series v3.Series) (Sample, bool) { if avg != r.targetVal() { shouldAlert = true } - } else if r.compareOp() == ValueIsAboveOrBelow { - if avg > r.targetVal() || avg < r.targetVal() { + } else if r.compareOp() == ValueOutsideBounds { + if math.Abs(avg) >= r.targetVal() { shouldAlert = true } } @@ -526,8 +526,8 @@ func (r *BaseRule) ShouldAlert(series v3.Series) (Sample, bool) { if sum != r.targetVal() { shouldAlert = true } - } else if r.compareOp() == ValueIsAboveOrBelow { - if sum > r.targetVal() || sum < r.targetVal() { + } else if r.compareOp() == ValueOutsideBounds { + if math.Abs(sum) >= r.targetVal() { shouldAlert = true } }