Commit 41156835 by bergquist

feat(alerting): revert operand positions

parent 077be210
package alerting
import (
"github.com/grafana/grafana/pkg/bus"
m "github.com/grafana/grafana/pkg/models"
)
......@@ -11,25 +12,35 @@ type RuleReader interface {
type AlertRuleReader struct{}
func (this AlertRuleReader) Fetch() []m.AlertRule {
return []m.AlertRule{
//{Id: 1, Title: "alert rule 1", Interval: "10s", Frequency: 10},
//{Id: 2, Title: "alert rule 2", Interval: "10s", Frequency: 10},
//{Id: 3, Title: "alert rule 3", Interval: "10s", Frequency: 10},
//{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5},
//{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5},
{
Id: 1,
OrgId: 1,
Title: "alert rule 1",
Frequency: 3,
DatasourceId: 1,
WarnOperator: "<",
WarnLevel: 3,
CritOperator: "<",
CritLevel: 4,
Aggregator: "avg",
Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`,
QueryRange: 3600,
},
/*
return []m.AlertRule{
//{Id: 1, Title: "alert rule 1", Interval: "10s", Frequency: 10},
//{Id: 2, Title: "alert rule 2", Interval: "10s", Frequency: 10},
//{Id: 3, Title: "alert rule 3", Interval: "10s", Frequency: 10},
//{Id: 4, Title: "alert rule 4", Interval: "10s", Frequency: 5},
//{Id: 5, Title: "alert rule 5", Interval: "10s", Frequency: 5},
{
Id: 1,
OrgId: 1,
Title: "alert rule 1",
Frequency: 3,
DatasourceId: 1,
WarnOperator: "<",
WarnLevel: 3,
CritOperator: "<",
CritLevel: 4,
Aggregator: "avg",
Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`,
QueryRange: 3600,
},
}
*/
cmd := &m.GetAlertsQuery{
OrgId: 1,
}
bus.Dispatch(cmd)
return cmd.Result
}
......@@ -48,11 +48,13 @@ 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](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](float64(rule.WarnLevel), aggValue) {
if operators[rule.WarnOperator](aggValue, float64(rule.WarnLevel)) {
return &AlertResult{State: m.AlertStateWarn, Id: rule.Id, ActualValue: aggValue}
}
}
......
......@@ -11,7 +11,7 @@ func TestAlertingExecutor(t *testing.T) {
executor := &ExecutorImpl{}
Convey("Show return ok since avg is above 2", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "sum"}
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
......@@ -22,7 +22,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey("Show return critical since below 2", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{2, 0}}),
......@@ -33,7 +33,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey("Show return critical since sum is above 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "sum"}
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "sum"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{9, 0}, {9, 0}}),
......@@ -44,7 +44,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey("Show return ok since avg is below 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "avg"}
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "avg"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{9, 0}, {9, 0}}),
......@@ -55,7 +55,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey("Show return ok since min is below 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "min"}
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "min"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{11, 0}, {9, 0}}),
......@@ -66,7 +66,7 @@ func TestAlertingExecutor(t *testing.T) {
})
Convey("Show return ok since max is above 10", func() {
rule := m.AlertRule{CritLevel: 10, CritOperator: "<", Aggregator: "max"}
rule := m.AlertRule{CritLevel: 10, CritOperator: ">", Aggregator: "max"}
timeSeries := []*m.TimeSeries{
m.NewTimeSeries("test1", [][2]float64{{1, 0}, {11, 0}}),
......
......@@ -45,15 +45,15 @@
</div>
<div class="gf-form">
<span class="gf-form-label width-10">Query range</span>
<input class="gf-form-input max-width-10" type="text"
ng-model="ctrl.panel.alerting.queryRange" placeholder="10m"></input>
<span class="gf-form-label width-10">Query range (seconds)</span>
<input class="gf-form-input max-width-10" type="number"
ng-model="ctrl.panel.alerting.queryRange" placeholder="3600"></input>
</div>
<div class="gf-form">
<span class="gf-form-label width-10">Interval</span>
<input class="gf-form-input max-width-10" type="text"
ng-model="ctrl.panel.alerting.interval" placeholder="10s"></input>
<span class="gf-form-label width-10">Frequency (seconds)</span>
<input class="gf-form-input max-width-10" type="number"
ng-model="ctrl.panel.alerting.interval" placeholder="60"></input>
</div>
</div>
<div class="gf-form-group section">
......
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