test(alerting): add tests for multi serie checks

This commit is contained in:
bergquist
2016-05-30 14:58:32 +02:00
parent 411568351d
commit 3d5c27df91
2 changed files with 83 additions and 57 deletions

View File

@@ -48,12 +48,10 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
var aggValue = aggregator[rule.Aggregator](serie)
//if operators[rule.CritOperator](float64(rule.CritLevel), aggValue) {
if operators[rule.CritOperator](aggValue, float64(rule.CritLevel)) {
return &AlertResult{State: m.AlertStateCritical, Id: rule.Id, ActualValue: aggValue}
}
//if operators[rule.WarnOperator](float64(rule.WarnLevel), aggValue) {
if operators[rule.WarnOperator](aggValue, float64(rule.WarnLevel)) {
return &AlertResult{State: m.AlertStateWarn, Id: rule.Id, ActualValue: aggValue}
}

View File

@@ -10,70 +10,98 @@ func TestAlertingExecutor(t *testing.T) {
Convey("Test alert execution", t, func() {
executor := &ExecutorImpl{}
Convey("Show return ok since avg is above 2", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
Convey("single time serie", func() {
Convey("Show return ok since avg is above 2", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
})
Convey("Show return critical since below 2", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
})
Convey("Show return critical since sum is above 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{9, 0}, {9, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
})
Convey("Show return ok since avg is below 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "avg"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{9, 0}, {9, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
})
Convey("Show return ok since min is below 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "min"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{11, 0}, {9, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
})
Convey("Show return ok since max is above 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "max"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{1, 0}, {11, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
})
})
Convey("Show return critical since below 2", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "sum"}
Convey("muliple time series", func() {
Convey("both are ok", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
})
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
})
Convey("Show return critical since sum is above 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
Convey("first serie is good, second is critical", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{9, 0}, {9, 0}}),
}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
m.NewTimeSeries("test1", [][2]float64{{11, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
})
Convey("Show return ok since avg is below 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "avg"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{9, 0}, {9, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
})
Convey("Show return ok since min is below 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "min"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{11, 0}, {9, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateOk)
})
Convey("Show return ok since max is above 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "max"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{1, 0}, {11, 0}}),
}
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
result := executor.ValidateRule(rule, timeSeries)
So(result.State, ShouldEqual, m.AlertStateCritical)
})
})
})
}