Commit dfb1b191 by utkarshcmu

Implemented operator based firiing in backend

parent b2db2b26
...@@ -23,6 +23,7 @@ type QueryCondition struct { ...@@ -23,6 +23,7 @@ type QueryCondition struct {
Query AlertQuery Query AlertQuery
Reducer QueryReducer Reducer QueryReducer
Evaluator AlertEvaluator Evaluator AlertEvaluator
Operator string
HandleRequest tsdb.HandleRequestFunc HandleRequest tsdb.HandleRequestFunc
} }
...@@ -72,6 +73,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.Conditio ...@@ -72,6 +73,7 @@ func (c *QueryCondition) Eval(context *alerting.EvalContext) (*alerting.Conditio
return &alerting.ConditionResult{ return &alerting.ConditionResult{
Firing: evalMatchCount > 0, Firing: evalMatchCount > 0,
NoDataFound: emptySerieCount == len(seriesList), NoDataFound: emptySerieCount == len(seriesList),
Operator: c.Operator,
EvalMatches: matches, EvalMatches: matches,
}, nil }, nil
} }
...@@ -168,8 +170,12 @@ func NewQueryCondition(model *simplejson.Json, index int) (*QueryCondition, erro ...@@ -168,8 +170,12 @@ func NewQueryCondition(model *simplejson.Json, index int) (*QueryCondition, erro
if err != nil { if err != nil {
return nil, err return nil, err
} }
condition.Evaluator = evaluator condition.Evaluator = evaluator
operatorJson := model.Get("operator")
operator := operatorJson.Get("type").MustString()
condition.Operator = operator
return &condition, nil return &condition, nil
} }
......
...@@ -32,10 +32,11 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) { ...@@ -32,10 +32,11 @@ func (e *DefaultEvalHandler) Eval(context *EvalContext) {
break break
} }
// break if result has not triggered yet // calculating Firing based on operator
if cr.Firing == false { if cr.Operator == "or" {
firing = false firing = firing || cr.Firing
break } else {
firing = firing && cr.Firing
} }
context.EvalMatches = append(context.EvalMatches, cr.EvalMatches...) context.EvalMatches = append(context.EvalMatches, cr.EvalMatches...)
......
...@@ -24,6 +24,7 @@ type Notifier interface { ...@@ -24,6 +24,7 @@ type Notifier interface {
type ConditionResult struct { type ConditionResult struct {
Firing bool Firing bool
NoDataFound bool NoDataFound bool
Operator string
EvalMatches []*EvalMatch EvalMatches []*EvalMatch
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment