mirror of
https://github.com/grafana/grafana.git
synced 2024-11-30 12:44:10 -06:00
feat(alerting): more aggressive requirements for parsing alertrules
This commit is contained in:
parent
8b05af2f90
commit
6121d15ba7
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/grafana/grafana/pkg/components/simplejson"
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
||||||
"github.com/grafana/grafana/pkg/services/alerting/transformers"
|
"github.com/grafana/grafana/pkg/services/alerting/transformers"
|
||||||
@ -63,7 +64,16 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
|||||||
model.State = ruleDef.State
|
model.State = ruleDef.State
|
||||||
model.Frequency = ruleDef.Frequency
|
model.Frequency = ruleDef.Frequency
|
||||||
|
|
||||||
model.NotificationGroups = []int64{1, 2}
|
ngs := ruleDef.Settings.Get("notificationGroups").MustString()
|
||||||
|
var ids []int64
|
||||||
|
for _, v := range strings.Split(ngs, ",") {
|
||||||
|
id, err := strconv.Atoi(v)
|
||||||
|
if err == nil {
|
||||||
|
ids = append(ids, int64(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
model.NotificationGroups = ids
|
||||||
|
|
||||||
critical := ruleDef.Settings.Get("crit")
|
critical := ruleDef.Settings.Get("crit")
|
||||||
model.Critical = Level{
|
model.Critical = Level{
|
||||||
@ -78,6 +88,10 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
model.Transform = ruleDef.Settings.Get("transform").Get("type").MustString()
|
model.Transform = ruleDef.Settings.Get("transform").Get("type").MustString()
|
||||||
|
if model.Transform == "" {
|
||||||
|
return nil, fmt.Errorf("missing transform")
|
||||||
|
}
|
||||||
|
|
||||||
model.TransformParams = *ruleDef.Settings.Get("transform")
|
model.TransformParams = *ruleDef.Settings.Get("transform")
|
||||||
|
|
||||||
if model.Transform == "aggregation" {
|
if model.Transform == "aggregation" {
|
||||||
@ -91,7 +105,6 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
|||||||
DatasourceId: query.Get("datasourceId").MustInt64(),
|
DatasourceId: query.Get("datasourceId").MustInt64(),
|
||||||
From: query.Get("from").MustString(),
|
From: query.Get("from").MustString(),
|
||||||
To: query.Get("to").MustString(),
|
To: query.Get("to").MustString(),
|
||||||
Aggregator: query.Get("agg").MustString(),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if model.Query.Query == "" {
|
if model.Query.Query == "" {
|
||||||
|
@ -55,7 +55,7 @@ func TestAlertRuleModel(t *testing.T) {
|
|||||||
"datasourceId": 1
|
"datasourceId": 1
|
||||||
},
|
},
|
||||||
"transform": {
|
"transform": {
|
||||||
"method": "avg",
|
"type": "avg",
|
||||||
"name": "aggregation"
|
"name": "aggregation"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -132,12 +132,10 @@ func (e *Engine) resultHandler() {
|
|||||||
|
|
||||||
result.State = alertstates.Critical
|
result.State = alertstates.Critical
|
||||||
result.Description = fmt.Sprintf("Failed to run check after %d retires, Error: %v", maxAlertExecutionRetries, result.Error)
|
result.Description = fmt.Sprintf("Failed to run check after %d retires, Error: %v", maxAlertExecutionRetries, result.Error)
|
||||||
//e.reactToState(result)
|
|
||||||
e.responseHandler.Handle(result)
|
e.responseHandler.Handle(result)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result.AlertJob.ResetRetry()
|
result.AlertJob.ResetRetry()
|
||||||
//e.reactToState(result)
|
|
||||||
e.responseHandler.Handle(result)
|
e.responseHandler.Handle(result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -52,8 +52,8 @@ func TestAlertRuleExtraction(t *testing.T) {
|
|||||||
"to": "now"
|
"to": "now"
|
||||||
},
|
},
|
||||||
"transform": {
|
"transform": {
|
||||||
"method": "avg",
|
"type": "avg",
|
||||||
"type": "aggregation"
|
"name": "aggregation"
|
||||||
},
|
},
|
||||||
"warn": {
|
"warn": {
|
||||||
"value": 10,
|
"value": 10,
|
||||||
@ -87,7 +87,7 @@ func TestAlertRuleExtraction(t *testing.T) {
|
|||||||
"to": "now"
|
"to": "now"
|
||||||
},
|
},
|
||||||
"transform": {
|
"transform": {
|
||||||
"method": "avg",
|
"type": "avg",
|
||||||
"name": "aggregation"
|
"name": "aggregation"
|
||||||
},
|
},
|
||||||
"warn": {
|
"warn": {
|
||||||
|
@ -47,7 +47,6 @@ type Level struct {
|
|||||||
type AlertQuery struct {
|
type AlertQuery struct {
|
||||||
Query string
|
Query string
|
||||||
DatasourceId int64
|
DatasourceId int64
|
||||||
Aggregator string
|
|
||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user