tech(alerting): expression -> settings

This commit is contained in:
bergquist 2016-06-13 15:18:19 +02:00
parent bb6888885e
commit 7f22b9eb6e
6 changed files with 20 additions and 20 deletions

View File

@ -20,7 +20,7 @@ type Alert struct {
Created time.Time
Updated time.Time
Expression *simplejson.Json
Settings *simplejson.Json
}
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.Description != other.Description
if this.Expression != nil && other.Expression != nil {
json1, err1 := this.Expression.Encode()
json2, err2 := other.Expression.Encode()
if this.Settings != nil && other.Settings != nil {
json1, err1 := this.Settings.Encode()
json2, err2 := other.Settings.Encode()
if err1 != nil || err2 != nil {
return false

View File

@ -14,13 +14,13 @@ func TestAlertingModelTest(t *testing.T) {
json2, _ := simplejson.NewJson([]byte(`{ "field": "value" }`))
rule1 := &Alert{
Expression: json1,
Settings: json1,
Name: "Namn",
Description: "Description",
}
rule2 := &Alert{
Expression: json2,
Settings: json2,
Name: "Namn",
Description: "Description",
}
@ -32,7 +32,7 @@ func TestAlertingModelTest(t *testing.T) {
Convey("Changing the expression should contain update", func() {
json2, _ := simplejson.NewJson([]byte(`{ "field": "newValue" }`))
rule1.Expression = json2
rule1.Settings = json2
So(rule1.ContainsUpdates(rule2), ShouldBeTrue)
})
})

View File

@ -60,28 +60,28 @@ func NewAlertRuleFromDBModel(ruleDef *m.Alert) (*AlertRule, error) {
model.Description = ruleDef.Description
model.State = ruleDef.State
critical := ruleDef.Expression.Get("critical")
critical := ruleDef.Settings.Get("critical")
model.Critical = Level{
Operator: critical.Get("op").MustString(),
Level: critical.Get("level").MustFloat64(),
}
warning := ruleDef.Expression.Get("warn")
warning := ruleDef.Settings.Get("warn")
model.Warning = Level{
Operator: warning.Get("op").MustString(),
Level: warning.Get("level").MustFloat64(),
}
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Expression.Get("frequency").MustString())
model.Transform = ruleDef.Expression.Get("transform").Get("type").MustString()
model.TransformParams = *ruleDef.Expression.Get("transform")
model.Frequency = getTimeDurationStringToSeconds(ruleDef.Settings.Get("frequency").MustString())
model.Transform = ruleDef.Settings.Get("transform").Get("type").MustString()
model.TransformParams = *ruleDef.Settings.Get("transform")
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)
}
query := ruleDef.Expression.Get("query")
query := ruleDef.Settings.Get("query")
model.Query = AlertQuery{
Query: query.Get("query").MustString(),
DatasourceId: query.Get("datasourceId").MustInt64(),

View File

@ -100,7 +100,7 @@ func (e *DashAlertExtractor) GetAlerts() ([]*m.Alert, error) {
}
}
alert.Expression = jsonAlert
alert.Settings = jsonAlert
// validate
_, err := NewAlertRuleFromDBModel(alert)

View File

@ -21,7 +21,7 @@ func TestAlertingDataAccess(t *testing.T) {
OrgId: testDash.OrgId,
Name: "Alerting title",
Description: "Alerting description",
Expression: simplejson.New(),
Settings: simplejson.New(),
},
}
@ -102,21 +102,21 @@ func TestAlertingDataAccess(t *testing.T) {
PanelId: 1,
Name: "1",
OrgId: 1,
Expression: simplejson.New(),
Settings: simplejson.New(),
},
{
DashboardId: testDash.Id,
PanelId: 2,
Name: "2",
OrgId: 1,
Expression: simplejson.New(),
Settings: simplejson.New(),
},
{
DashboardId: testDash.Id,
PanelId: 3,
Name: "3",
OrgId: 1,
Expression: simplejson.New(),
Settings: simplejson.New(),
},
}

View File

@ -16,7 +16,7 @@ func addAlertMigrations(mg *Migrator) {
{Name: "name", 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: "expression", Type: DB_Text, Nullable: false},
{Name: "settings", Type: DB_Text, Nullable: false},
{Name: "scheduler", Type: DB_BigInt, Nullable: false},
{Name: "enabled", Type: DB_Bool, Nullable: false},
{Name: "created", Type: DB_DateTime, Nullable: false},