mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(alerting): separate operator and level
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -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},
|
||||
|
||||
Reference in New Issue
Block a user