From bdfb773a987048bac6d3c7c26896948fb04799e0 Mon Sep 17 00:00:00 2001 From: bergquist Date: Sun, 27 Nov 2016 16:53:29 +0100 Subject: [PATCH] fix(alerting): fixes broken no_value evaluator closes #6701 --- pkg/services/alerting/conditions/evaluator.go | 8 ++++---- .../alerting/conditions/evaluator_test.go | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/services/alerting/conditions/evaluator.go b/pkg/services/alerting/conditions/evaluator.go index 19c268f2671..57abb2edd25 100644 --- a/pkg/services/alerting/conditions/evaluator.go +++ b/pkg/services/alerting/conditions/evaluator.go @@ -17,9 +17,9 @@ type AlertEvaluator interface { Eval(reducedValue null.Float) bool } -type NoDataEvaluator struct{} +type NoValueEvaluator struct{} -func (e *NoDataEvaluator) Eval(reducedValue null.Float) bool { +func (e *NoValueEvaluator) Eval(reducedValue null.Float) bool { return reducedValue.Valid == false } @@ -118,8 +118,8 @@ func NewAlertEvaluator(model *simplejson.Json) (AlertEvaluator, error) { return newRangedEvaluator(typ, model) } - if typ == "no_data" { - return &NoDataEvaluator{}, nil + if typ == "no_value" { + return &NoValueEvaluator{}, nil } return nil, alerting.ValidationError{Reason: "Evaluator invalid evaluator type: " + typ} diff --git a/pkg/services/alerting/conditions/evaluator_test.go b/pkg/services/alerting/conditions/evaluator_test.go index 24c5cfacea4..e2a3cb48396 100644 --- a/pkg/services/alerting/conditions/evaluator_test.go +++ b/pkg/services/alerting/conditions/evaluator_test.go @@ -44,15 +44,20 @@ func TestEvalutors(t *testing.T) { So(evalutorScenario(`{"type": "outside_range", "params": [100, 1] }`, 50), ShouldBeFalse) }) - Convey("no_data", t, func() { - So(evalutorScenario(`{"type": "no_data", "params": [] }`, 50), ShouldBeFalse) + Convey("no_value", t, func() { + Convey("should be false if serie have values", func() { + So(evalutorScenario(`{"type": "no_value", "params": [] }`, 50), ShouldBeFalse) + }) - jsonModel, err := simplejson.NewJson([]byte(`{"type": "no_data", "params": [] }`)) - So(err, ShouldBeNil) + Convey("should be true when the serie have no value", func() { + jsonModel, err := simplejson.NewJson([]byte(`{"type": "no_value", "params": [] }`)) + So(err, ShouldBeNil) - evaluator, err := NewAlertEvaluator(jsonModel) - So(err, ShouldBeNil) + evaluator, err := NewAlertEvaluator(jsonModel) + So(err, ShouldBeNil) - So(evaluator.Eval(null.FloatFromPtr(nil)), ShouldBeTrue) + So(evaluator.Eval(null.FloatFromPtr(nil)), ShouldBeTrue) + + }) }) }