mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
test(alerting): add tests for multi serie checks
This commit is contained in:
@@ -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}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user