feat(alerting): separate operator and level

This commit is contained in:
bergquist
2016-05-03 17:31:04 +02:00
parent 27c34745a6
commit 1624dc9dfd
11 changed files with 143 additions and 122 deletions

View File

@@ -75,6 +75,8 @@ func alertIsDifferent(rule1, rule2 m.AlertRule) bool {
result = result || rule1.Aggregator != rule2.Aggregator
result = result || rule1.CritLevel != rule2.CritLevel
result = result || rule1.WarnLevel != rule2.WarnLevel
result = result || rule1.WarnOperator != rule2.WarnOperator
result = result || rule1.CritOperator != rule2.CritOperator
result = result || rule1.Query != rule2.Query
result = result || rule1.QueryRefId != rule2.QueryRefId
result = result || rule1.Interval != rule2.Interval

View File

@@ -22,18 +22,20 @@ func TestAlertRuleChangesDataAccess(t *testing.T) {
Convey("When dashboard is removed", func() {
items := []m.AlertRule{
{
PanelId: 1,
DashboardId: testDash.Id,
Query: "Query",
QueryRefId: "A",
WarnLevel: "> 30",
CritLevel: "> 50",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
OrgId: FakeOrgId,
PanelId: 1,
DashboardId: testDash.Id,
Query: "Query",
QueryRefId: "A",
WarnLevel: 30,
CritLevel: 50,
WarnOperator: ">",
CritOperator: ">",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
OrgId: FakeOrgId,
},
}

View File

@@ -16,19 +16,21 @@ func TestAlertingDataAccess(t *testing.T) {
items := []m.AlertRule{
{
PanelId: 1,
DashboardId: testDash.Id,
OrgId: testDash.OrgId,
Query: "Query",
QueryRefId: "A",
WarnLevel: "> 30",
CritLevel: "> 50",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
State: "OK",
PanelId: 1,
DashboardId: testDash.Id,
OrgId: testDash.OrgId,
Query: "Query",
QueryRefId: "A",
WarnLevel: 30,
CritLevel: 50,
WarnOperator: ">",
CritOperator: ">",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
State: "OK",
},
}
@@ -59,8 +61,10 @@ func TestAlertingDataAccess(t *testing.T) {
So(err2, ShouldBeNil)
So(query.Result.Interval, ShouldEqual, "10")
So(query.Result.WarnLevel, ShouldEqual, "> 30")
So(query.Result.CritLevel, ShouldEqual, "> 50")
So(query.Result.WarnLevel, ShouldEqual, 30)
So(query.Result.CritLevel, ShouldEqual, 50)
So(query.Result.WarnOperator, ShouldEqual, ">")
So(query.Result.CritOperator, ShouldEqual, ">")
So(query.Result.Query, ShouldEqual, "Query")
So(query.Result.QueryRefId, ShouldEqual, "A")
So(query.Result.Title, ShouldEqual, "Alerting title")
@@ -177,17 +181,19 @@ func TestAlertingDataAccess(t *testing.T) {
Convey("When dashboard is removed", func() {
items := []m.AlertRule{
{
PanelId: 1,
DashboardId: testDash.Id,
Query: "Query",
QueryRefId: "A",
WarnLevel: "> 30",
CritLevel: "> 50",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
PanelId: 1,
DashboardId: testDash.Id,
Query: "Query",
QueryRefId: "A",
WarnLevel: 30,
CritLevel: 50,
WarnOperator: ">",
CritOperator: ">",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
},
}

View File

@@ -15,18 +15,20 @@ func TestAlertingStateAccess(t *testing.T) {
items := []m.AlertRule{
{
PanelId: 1,
DashboardId: testDash.Id,
OrgId: testDash.OrgId,
Query: "Query",
QueryRefId: "A",
WarnLevel: "> 30",
CritLevel: "> 50",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
PanelId: 1,
DashboardId: testDash.Id,
OrgId: testDash.OrgId,
Query: "Query",
QueryRefId: "A",
WarnLevel: 30,
CritLevel: 50,
WarnOperator: ">",
CritOperator: ">",
Interval: "10",
Title: "Alerting title",
Description: "Alerting description",
QueryRange: "5m",
Aggregator: "avg",
},
}

View File

@@ -12,8 +12,10 @@ func addAlertMigrations(mg *Migrator) {
{Name: "org_id", Type: DB_BigInt, Nullable: false},
{Name: "query", Type: DB_Text, Nullable: false},
{Name: "query_ref_id", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "warn_level", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "crit_level", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "warn_level", Type: DB_BigInt, Nullable: false},
{Name: "warn_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
{Name: "crit_level", Type: DB_BigInt, Nullable: false},
{Name: "crit_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
{Name: "interval", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},
{Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false},