From 7224ea522989b5f70a7a4e15e0f198ddcb787d39 Mon Sep 17 00:00:00 2001 From: bergquist Date: Tue, 31 May 2016 13:55:16 +0200 Subject: [PATCH] chore(alerting): convert alert levels to float --- pkg/api/dtos/alerting.go | 30 ++++++++-------- pkg/models/alerts.go | 34 +++++++++---------- pkg/services/alerting/dashboard_parser.go | 4 +-- pkg/services/alerting/executor.go | 4 +-- pkg/services/sqlstore/migrations/alert_mig.go | 4 +-- 5 files changed, 38 insertions(+), 38 deletions(-) diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go index 9441efaf2ba..5fc2dbc371b 100644 --- a/pkg/api/dtos/alerting.go +++ b/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"` } diff --git a/pkg/models/alerts.go b/pkg/models/alerts.go index 4e94dd4a206..fd3540a8b62 100644 --- a/pkg/models/alerts.go +++ b/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"` diff --git a/pkg/services/alerting/dashboard_parser.go b/pkg/services/alerting/dashboard_parser.go index 24a49a51957..74f193d2134 100644 --- a/pkg/services/alerting/dashboard_parser.go +++ b/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(), diff --git a/pkg/services/alerting/executor.go b/pkg/services/alerting/executor.go index 42dbdfbe308..93a4b2bee02 100644 --- a/pkg/services/alerting/executor.go +++ b/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} } } diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index 038a343b6b8..ebe55f0c252 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/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},