Ver Fonte

chore(alerting): convert alert levels to float

bergquist há 9 anos atrás
pai
commit
7224ea5229

+ 15 - 15
pkg/api/dtos/alerting.go

@@ -1,21 +1,21 @@
 package dtos
 
 type AlertRuleDTO struct {
-	Id           int64  `json:"id"`
-	DashboardId  int64  `json:"dashboardId"`
-	PanelId      int64  `json:"panelId"`
-	Query        string `json:"query"`
-	QueryRefId   string `json:"queryRefId"`
-	WarnLevel    int64  `json:"warnLevel"`
-	CritLevel    int64  `json:"critLevel"`
-	WarnOperator string `json:"warnOperator"`
-	CritOperator string `json:"critOperator"`
-	Frequency    int64  `json:"frequency"`
-	Title        string `json:"title"`
-	Description  string `json:"description"`
-	QueryRange   int    `json:"queryRange"`
-	Aggregator   string `json:"aggregator"`
-	State        string `json:"state"`
+	Id           int64   `json:"id"`
+	DashboardId  int64   `json:"dashboardId"`
+	PanelId      int64   `json:"panelId"`
+	Query        string  `json:"query"`
+	QueryRefId   string  `json:"queryRefId"`
+	WarnLevel    float64 `json:"warnLevel"`
+	CritLevel    float64 `json:"critLevel"`
+	WarnOperator string  `json:"warnOperator"`
+	CritOperator string  `json:"critOperator"`
+	Frequency    int64   `json:"frequency"`
+	Title        string  `json:"title"`
+	Description  string  `json:"description"`
+	QueryRange   int     `json:"queryRange"`
+	Aggregator   string  `json:"aggregator"`
+	State        string  `json:"state"`
 
 	DashbboardUri string `json:"dashboardUri"`
 }

+ 17 - 17
pkg/models/alerts.go

@@ -5,23 +5,23 @@ import (
 )
 
 type AlertRule struct {
-	Id           int64  `json:"id"`
-	OrgId        int64  `json:"-"`
-	DatasourceId int64  `json:"datasourceId"`
-	DashboardId  int64  `json:"dashboardId"`
-	PanelId      int64  `json:"panelId"`
-	Query        string `json:"query"`
-	QueryRefId   string `json:"queryRefId"`
-	WarnLevel    int64  `json:"warnLevel"`
-	CritLevel    int64  `json:"critLevel"`
-	WarnOperator string `json:"warnOperator"`
-	CritOperator string `json:"critOperator"`
-	Frequency    int64  `json:"frequency"`
-	Title        string `json:"title"`
-	Description  string `json:"description"`
-	QueryRange   int    `json:"queryRange"`
-	Aggregator   string `json:"aggregator"`
-	State        string `json:"state"`
+	Id           int64   `json:"id"`
+	OrgId        int64   `json:"-"`
+	DatasourceId int64   `json:"datasourceId"`
+	DashboardId  int64   `json:"dashboardId"`
+	PanelId      int64   `json:"panelId"`
+	Query        string  `json:"query"`
+	QueryRefId   string  `json:"queryRefId"`
+	WarnLevel    float64 `json:"warnLevel"`
+	CritLevel    float64 `json:"critLevel"`
+	WarnOperator string  `json:"warnOperator"`
+	CritOperator string  `json:"critOperator"`
+	Frequency    int64   `json:"frequency"`
+	Title        string  `json:"title"`
+	Description  string  `json:"description"`
+	QueryRange   int     `json:"queryRange"`
+	Aggregator   string  `json:"aggregator"`
+	State        string  `json:"state"`
 
 	Created time.Time `json:"created"`
 	Updated time.Time `json:"updated"`

+ 2 - 2
pkg/services/alerting/dashboard_parser.go

@@ -22,8 +22,8 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []m.AlertRule {
 				PanelId:      panel.Get("id").MustInt64(),
 				Id:           alerting.Get("id").MustInt64(),
 				QueryRefId:   alerting.Get("queryRef").MustString(),
-				WarnLevel:    alerting.Get("warnLevel").MustInt64(),
-				CritLevel:    alerting.Get("critLevel").MustInt64(),
+				WarnLevel:    alerting.Get("warnLevel").MustFloat64(),
+				CritLevel:    alerting.Get("critLevel").MustFloat64(),
 				WarnOperator: alerting.Get("warnOperator").MustString(),
 				CritOperator: alerting.Get("critOperator").MustString(),
 				Frequency:    alerting.Get("frequency").MustInt64(),

+ 2 - 2
pkg/services/alerting/executor.go

@@ -57,11 +57,11 @@ func (this *ExecutorImpl) ValidateRule(rule m.AlertRule, series m.TimeSeriesSlic
 
 		var aggValue = aggregator[rule.Aggregator](serie)
 
-		if operators[rule.CritOperator](aggValue, float64(rule.CritLevel)) {
+		if operators[rule.CritOperator](aggValue, rule.CritLevel) {
 			return &m.AlertResult{State: m.AlertStateCritical, Id: rule.Id, ActualValue: aggValue, Rule: rule}
 		}
 
-		if operators[rule.WarnOperator](aggValue, float64(rule.WarnLevel)) {
+		if operators[rule.WarnOperator](aggValue, rule.WarnLevel) {
 			return &m.AlertResult{State: m.AlertStateWarn, Id: rule.Id, ActualValue: aggValue, Rule: rule}
 		}
 	}

+ 2 - 2
pkg/services/sqlstore/migrations/alert_mig.go

@@ -16,9 +16,9 @@ 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_BigInt, Nullable: false},
+			{Name: "warn_level", Type: DB_Float, Nullable: false},
 			{Name: "warn_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
-			{Name: "crit_level", Type: DB_BigInt, Nullable: false},
+			{Name: "crit_level", Type: DB_Float, Nullable: false},
 			{Name: "crit_operator", Type: DB_NVarchar, Length: 10, Nullable: false},
 			{Name: "frequency", Type: DB_BigInt, Nullable: false},
 			{Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false},