Skip to content

Commit

Permalink
chore: address review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanthccv committed Sep 23, 2024
1 parent 7c4cf0d commit da3b790
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
9 changes: 5 additions & 4 deletions ee/query-service/rules/anomaly.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
14 changes: 8 additions & 6 deletions pkg/query-service/rules/alerting.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions pkg/query-service/rules/base_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
}
}
Expand Down

0 comments on commit da3b790

Please sign in to comment.