From 16a9e56eca6fde23ee6d426ecd87d955d71b0a31 Mon Sep 17 00:00:00 2001 From: bergquist Date: Mon, 30 May 2016 09:18:22 +0200 Subject: [PATCH] tech(alerting): change queryrange to int from str --- pkg/api/dtos/alerting.go | 2 +- pkg/models/alerts.go | 2 +- pkg/services/alerting/alert_rule_reader.go | 2 +- pkg/services/alerting/dashboard_parser.go | 2 +- pkg/services/alerting/graphite/graphite.go | 3 ++- pkg/services/sqlstore/alert_rule_changes_test.go | 2 +- pkg/services/sqlstore/alert_rule_test.go | 6 +++--- pkg/services/sqlstore/alert_state_test.go | 2 +- pkg/services/sqlstore/migrations/alert_mig.go | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go index f1081217f79..0097a802d91 100644 --- a/pkg/api/dtos/alerting.go +++ b/pkg/api/dtos/alerting.go @@ -13,7 +13,7 @@ type AlertRuleDTO struct { Interval string `json:"interval"` Title string `json:"title"` Description string `json:"description"` - QueryRange string `json:"queryRange"` + QueryRange int `json:"queryRange"` Aggregator string `json:"aggregator"` State string `json:"state"` diff --git a/pkg/models/alerts.go b/pkg/models/alerts.go index abf003e9d7f..68d9dbf1053 100644 --- a/pkg/models/alerts.go +++ b/pkg/models/alerts.go @@ -20,7 +20,7 @@ type AlertRule struct { Frequency int64 `json:"frequency"` Title string `json:"title"` Description string `json:"description"` - QueryRange string `json:"queryRange"` + QueryRange int `json:"queryRange"` Aggregator string `json:"aggregator"` State string `json:"state"` diff --git a/pkg/services/alerting/alert_rule_reader.go b/pkg/services/alerting/alert_rule_reader.go index 9ed05623043..160877482ff 100644 --- a/pkg/services/alerting/alert_rule_reader.go +++ b/pkg/services/alerting/alert_rule_reader.go @@ -30,7 +30,7 @@ func (this AlertRuleReader) Fetch() []m.AlertRule { CritLevel: 4, Aggregator: "avg", Query: `{"refId":"A","target":"statsd.fakesite.counters.session_start.*.count","textEditor":true}"`, - QueryRange: "1h", + QueryRange: 3600, }, } } diff --git a/pkg/services/alerting/dashboard_parser.go b/pkg/services/alerting/dashboard_parser.go index d382d137694..fa49cb0e914 100644 --- a/pkg/services/alerting/dashboard_parser.go +++ b/pkg/services/alerting/dashboard_parser.go @@ -29,7 +29,7 @@ func ParseAlertsFromDashboard(cmd *m.SaveDashboardCommand) []m.AlertRule { Interval: alerting.Get("interval").MustString(), Title: alerting.Get("title").MustString(), Description: alerting.Get("description").MustString(), - QueryRange: alerting.Get("queryRange").MustString(), + QueryRange: alerting.Get("queryRange").MustInt(), Aggregator: alerting.Get("aggregator").MustString(), } diff --git a/pkg/services/alerting/graphite/graphite.go b/pkg/services/alerting/graphite/graphite.go index 78412600387..aa12c446132 100644 --- a/pkg/services/alerting/graphite/graphite.go +++ b/pkg/services/alerting/graphite/graphite.go @@ -8,6 +8,7 @@ import ( m "github.com/grafana/grafana/pkg/models" "net/http" "net/url" + "strconv" "time" ) @@ -30,7 +31,7 @@ func (this GraphiteClient) GetSeries(rule m.AlertRule) (m.TimeSeriesSlice, error "format": []string{"json"}, "target": []string{getTargetFromRule(rule)}, "until": []string{"now"}, - "from": []string{"-" + rule.QueryRange}, + "from": []string{"-" + strconv.Itoa(rule.QueryRange) + "s"}, } res, err := goreq.Request{ diff --git a/pkg/services/sqlstore/alert_rule_changes_test.go b/pkg/services/sqlstore/alert_rule_changes_test.go index d4c641fef2f..1636501fc23 100644 --- a/pkg/services/sqlstore/alert_rule_changes_test.go +++ b/pkg/services/sqlstore/alert_rule_changes_test.go @@ -33,7 +33,7 @@ func TestAlertRuleChangesDataAccess(t *testing.T) { Interval: "10", Title: "Alerting title", Description: "Alerting description", - QueryRange: "5m", + QueryRange: 3600, Aggregator: "avg", OrgId: FakeOrgId, }, diff --git a/pkg/services/sqlstore/alert_rule_test.go b/pkg/services/sqlstore/alert_rule_test.go index 2aa3d53971a..e56cd15c571 100644 --- a/pkg/services/sqlstore/alert_rule_test.go +++ b/pkg/services/sqlstore/alert_rule_test.go @@ -28,7 +28,7 @@ func TestAlertingDataAccess(t *testing.T) { Interval: "10", Title: "Alerting title", Description: "Alerting description", - QueryRange: "5m", + QueryRange: 3600, Aggregator: "avg", DatasourceId: 42, }, @@ -67,7 +67,7 @@ func TestAlertingDataAccess(t *testing.T) { So(alert.QueryRefId, ShouldEqual, "A") So(alert.Title, ShouldEqual, "Alerting title") So(alert.Description, ShouldEqual, "Alerting description") - So(alert.QueryRange, ShouldEqual, "5m") + So(alert.QueryRange, ShouldEqual, 3600) So(alert.Aggregator, ShouldEqual, "avg") So(alert.State, ShouldEqual, "OK") So(alert.DatasourceId, ShouldEqual, 42) @@ -191,7 +191,7 @@ func TestAlertingDataAccess(t *testing.T) { Interval: "10", Title: "Alerting title", Description: "Alerting description", - QueryRange: "5m", + QueryRange: 3600, Aggregator: "avg", }, } diff --git a/pkg/services/sqlstore/alert_state_test.go b/pkg/services/sqlstore/alert_state_test.go index a598169e15e..6c716fdc474 100644 --- a/pkg/services/sqlstore/alert_state_test.go +++ b/pkg/services/sqlstore/alert_state_test.go @@ -27,7 +27,7 @@ func TestAlertingStateAccess(t *testing.T) { Interval: "10", Title: "Alerting title", Description: "Alerting description", - QueryRange: "5m", + QueryRange: 3600, Aggregator: "avg", }, } diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index 1de01276622..26bd500fad1 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -24,7 +24,7 @@ func addAlertMigrations(mg *Migrator) { {Name: "frequency", Type: DB_BigInt, Nullable: false}, {Name: "title", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "description", Type: DB_NVarchar, Length: 255, Nullable: false}, - {Name: "query_range", Type: DB_NVarchar, Length: 255, Nullable: false}, + {Name: "query_range", Type: DB_Int, Nullable: false}, {Name: "aggregator", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "state", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "created", Type: DB_DateTime, Nullable: false},