fix: alerts work when "equals to" or "not equals to" used with "all the times" or "at least once" (#3244)

This commit is contained in:
Srikanth Chekuri 2023-08-13 21:26:55 +05:30 committed by GitHub
parent 03220fcf11
commit ec7c99dd26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 2 deletions

View File

@ -34,8 +34,9 @@ func (s Sample) MarshalJSON() ([]byte, error) {
} }
type Point struct { type Point struct {
T int64 T int64
V float64 V float64
Vs []float64
} }
func (p Point) String() string { func (p Point) String() string {

View File

@ -550,7 +550,40 @@ func (r *ThresholdRule) runChQuery(ctx context.Context, db clickhouse.Conn, quer
} }
} }
if s, ok := resultMap[labelHash]; ok {
s.Point.Vs = append(s.Point.Vs, s.Point.V)
}
} }
for _, s := range resultMap {
if r.matchType() == AllTheTimes && r.compareOp() == ValueIsEq {
for _, v := range s.Point.Vs {
if v != r.targetVal() { // if any of the values is not equal to target, alert shouldn't be sent
s.Point.V = v
}
}
} else if r.matchType() == AllTheTimes && r.compareOp() == ValueIsNotEq {
for _, v := range s.Point.Vs {
if v == r.targetVal() { // if any of the values is equal to target, alert shouldn't be sent
s.Point.V = v
}
}
} else if r.matchType() == AtleastOnce && r.compareOp() == ValueIsEq {
for _, v := range s.Point.Vs {
if v == r.targetVal() { // if any of the values is equal to target, alert should be sent
s.Point.V = v
}
}
} else if r.matchType() == AtleastOnce && r.compareOp() == ValueIsNotEq {
for _, v := range s.Point.Vs {
if v != r.targetVal() { // if any of the values is not equal to target, alert should be sent
s.Point.V = v
}
}
}
}
zap.S().Debugf("ruleid:", r.ID(), "\t resultmap(potential alerts):", len(resultMap)) zap.S().Debugf("ruleid:", r.ID(), "\t resultmap(potential alerts):", len(resultMap))
for _, sample := range resultMap { for _, sample := range resultMap {