Skip to content

Commit dfb1b19

Browse files
committed
Implemented operator based firiing in backend
1 parent b2db2b2 commit dfb1b19

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

pkg/services/alerting/conditions/query.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type QueryCondition struct {
2323
Query AlertQuery
2424
Reducer QueryReducer
2525
Evaluator AlertEvaluator
26+
Operator string
2627
HandleRequest tsdb.HandleRequestFunc
2728
}
2829

@@ -72,6 +73,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.Conditio
7273
return &alerting.ConditionResult{
7374
Firing: evalMatchCount > 0,
7475
NoDataFound: emptySerieCount == len(seriesList),
76+
Operator: c.Operator,
7577
EvalMatches: matches,
7678
}, nil
7779
}
@@ -168,8 +170,12 @@ func NewQueryCondition(model *simplejson.Json, index int) (*QueryCondition, erro
168170
if err != nil {
169171
return nil, err
170172
}
171-
172173
condition.Evaluator = evaluator
174+
175+
operatorJson := model.Get("operator")
176+
operator := operatorJson.Get("type").MustString()
177+
condition.Operator = operator
178+
173179
return &condition, nil
174180
}
175181

pkg/services/alerting/eval_handler.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
3232
break
3333
}
3434

35-
// break if result has not triggered yet
36-
if cr.Firing == false {
37-
firing = false
38-
break
35+
// calculating Firing based on operator
36+
if cr.Operator == "or" {
37+
firing = firing || cr.Firing
38+
} else {
39+
firing = firing && cr.Firing
3940
}
4041

4142
context.EvalMatches = append(context.EvalMatches, cr.EvalMatches...)

pkg/services/alerting/interfaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type Notifier interface {
2424
type ConditionResult struct {
2525
Firing bool
2626
NoDataFound bool
27+
Operator string
2728
EvalMatches []*EvalMatch
2829
}
2930

0 commit comments

Comments
 (0)