mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
tech(alerting): expression -> settings
This commit is contained in:
parent
bb6888885e
commit
7f22b9eb6e
@ -20,7 +20,7 @@ type Alert struct {
|
|||||||
Created time.Time
|
Created time.Time
|
||||||
Updated time.Time
|
Updated time.Time
|
||||||
|
|
||||||
Expression *simplejson.Json
|
Settings *simplejson.Json
|
||||||
}
|
}
|
||||||
|
|
||||||
func (alert *Alert) ValidToSave() bool {
|
func (alert *Alert) ValidToSave() bool {
|
||||||
@ -32,9 +32,9 @@ func (this *Alert) ContainsUpdates(other *Alert) bool {
|
|||||||
result = result || this.Name != other.Name
|
result = result || this.Name != other.Name
|
||||||
result = result || this.Description != other.Description
|
result = result || this.Description != other.Description
|
||||||
|
|
||||||
if this.Expression != nil && other.Expression != nil {
|
if this.Settings != nil && other.Settings != nil {
|
||||||
json1, err1 := this.Expression.Encode()
|
json1, err1 := this.Settings.Encode()
|
||||||
json2, err2 := other.Expression.Encode()
|
json2, err2 := other.Settings.Encode()
|
||||||
|
|
||||||
if err1 != nil || err2 != nil {
|
if err1 != nil || err2 != nil {
|
||||||
return false
|
return false
|
||||||
|
@ -14,13 +14,13 @@ func TestAlertingModelTest(t *testing.T) {
|
|||||||
json2, _ := simplejson.NewJson([]byte(`{ "field": "value" }`))
|
json2, _ := simplejson.NewJson([]byte(`{ "field": "value" }`))
|
||||||
|
|
||||||
rule1 := &Alert{
|
rule1 := &Alert{
|
||||||
Expression: json1,
|
Settings: json1,
|
||||||
Name: "Namn",
|
Name: "Namn",
|
||||||
Description: "Description",
|
Description: "Description",
|
||||||
}
|
}
|
||||||
|
|
||||||
rule2 := &Alert{
|
rule2 := &Alert{
|
||||||
Expression: json2,
|
Settings: json2,
|
||||||
Name: "Namn",
|
Name: "Namn",
|
||||||
Description: "Description",
|
Description: "Description",
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ func TestAlertingModelTest(t *testing.T) {
|
|||||||
|
|
||||||
Convey("Changing the expression should contain update", func() {
|
Convey("Changing the expression should contain update", func() {
|
||||||
json2, _ := simplejson.NewJson([]byte(`{ "field": "newValue" }`))
|
json2, _ := simplejson.NewJson([]byte(`{ "field": "newValue" }`))
|
||||||
rule1.Expression = json2
|
rule1.Settings = json2
|
||||||
So(rule1.ContainsUpdates(rule2), ShouldBeTrue)
|
So(rule1.ContainsUpdates(rule2), ShouldBeTrue)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -60,28 +60,28 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
|
|||||||
model.Description = ruleDef.Description
|
model.Description = ruleDef.Description
|
||||||
model.State = ruleDef.State
|
model.State = ruleDef.State
|
||||||
|
|
||||||
critical := ruleDef.Expression.Get("critical")
|
critical := ruleDef.Settings.Get("critical")
|
||||||
model.Critical = Level{
|
model.Critical = Level{
|
||||||
Operator: critical.Get("op").MustString(),
|
Operator: critical.Get("op").MustString(),
|
||||||
Level: critical.Get("level").MustFloat64(),
|
Level: critical.Get("level").MustFloat64(),
|
||||||
}
|
}
|
||||||
|
|
||||||
warning := ruleDef.Expression.Get("warn")
|
warning := ruleDef.Settings.Get("warn")
|
||||||
model.Warning = Level{
|
model.Warning = Level{
|
||||||
Operator: warning.Get("op").MustString(),
|
Operator: warning.Get("op").MustString(),
|
||||||
Level: warning.Get("level").MustFloat64(),
|
Level: warning.Get("level").MustFloat64(),
|
||||||
}
|
}
|
||||||
|
|
||||||
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Expression.Get("frequency").MustString())
|
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Settings.Get("frequency").MustString())
|
||||||
model.Transform = ruleDef.Expression.Get("transform").Get("type").MustString()
|
model.Transform = ruleDef.Settings.Get("transform").Get("type").MustString()
|
||||||
model.TransformParams = *ruleDef.Expression.Get("transform")
|
model.TransformParams = *ruleDef.Settings.Get("transform")
|
||||||
|
|
||||||
if model.Transform == "aggregation" {
|
if model.Transform == "aggregation" {
|
||||||
method := ruleDef.Expression.Get("transform").Get("method").MustString()
|
method := ruleDef.Settings.Get("transform").Get("method").MustString()
|
||||||
model.Transformer = transformers.NewAggregationTransformer(method)
|
model.Transformer = transformers.NewAggregationTransformer(method)
|
||||||
}
|
}
|
||||||
|
|
||||||
query := ruleDef.Expression.Get("query")
|
query := ruleDef.Settings.Get("query")
|
||||||
model.Query = AlertQuery{
|
model.Query = AlertQuery{
|
||||||
Query: query.Get("query").MustString(),
|
Query: query.Get("query").MustString(),
|
||||||
DatasourceId: query.Get("datasourceId").MustInt64(),
|
DatasourceId: query.Get("datasourceId").MustInt64(),
|
||||||
|
@ -100,7 +100,7 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
alert.Expression = jsonAlert
|
alert.Settings = jsonAlert
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
_, err := NewAlertRuleFromDBModel(alert)
|
_, err := NewAlertRuleFromDBModel(alert)
|
||||||
|
@ -21,7 +21,7 @@ func TestAlertingDataAccess(t *testing.T) {
|
|||||||
OrgId: testDash.OrgId,
|
OrgId: testDash.OrgId,
|
||||||
Name: "Alerting title",
|
Name: "Alerting title",
|
||||||
Description: "Alerting description",
|
Description: "Alerting description",
|
||||||
Expression: simplejson.New(),
|
Settings: simplejson.New(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,21 +102,21 @@ func TestAlertingDataAccess(t *testing.T) {
|
|||||||
PanelId: 1,
|
PanelId: 1,
|
||||||
Name: "1",
|
Name: "1",
|
||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
Expression: simplejson.New(),
|
Settings: simplejson.New(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DashboardId: testDash.Id,
|
DashboardId: testDash.Id,
|
||||||
PanelId: 2,
|
PanelId: 2,
|
||||||
Name: "2",
|
Name: "2",
|
||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
Expression: simplejson.New(),
|
Settings: simplejson.New(),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
DashboardId: testDash.Id,
|
DashboardId: testDash.Id,
|
||||||
PanelId: 3,
|
PanelId: 3,
|
||||||
Name: "3",
|
Name: "3",
|
||||||
OrgId: 1,
|
OrgId: 1,
|
||||||
Expression: simplejson.New(),
|
Settings: simplejson.New(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ func addAlertMigrations(mg *Migrator) {
|
|||||||
{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
|
{Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false},
|
||||||
{Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},
|
{Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},
|
||||||
{Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
|
{Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false},
|
||||||
{Name: "expression", Type: DB_Text, Nullable: false},
|
{Name: "settings", Type: DB_Text, Nullable: false},
|
||||||
{Name: "scheduler", Type: DB_BigInt, Nullable: false},
|
{Name: "scheduler", Type: DB_BigInt, Nullable: false},
|
||||||
{Name: "enabled", Type: DB_Bool, Nullable: false},
|
{Name: "enabled", Type: DB_Bool, Nullable: false},
|
||||||
{Name: "created", Type: DB_DateTime, Nullable: false},
|
{Name: "created", Type: DB_DateTime, Nullable: false},
|
||||||
|
Loading…
Reference in New Issue
Block a user