From a3b0fbcaba3c233253a21890ea5077e66a846274 Mon Sep 17 00:00:00 2001 From: bergquist Date: Thu, 17 Nov 2016 15:47:15 +0100 Subject: [PATCH] fix(influxdb): fixes broken tag rendering for influxdb alerting closes #6626 ref #6523 --- pkg/tsdb/influxdb/query.go | 6 ++---- pkg/tsdb/influxdb/query_test.go | 14 ++++++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pkg/tsdb/influxdb/query.go b/pkg/tsdb/influxdb/query.go index e95b54b0a18..094f98cbe53 100644 --- a/pkg/tsdb/influxdb/query.go +++ b/pkg/tsdb/influxdb/query.go @@ -2,7 +2,6 @@ package influxdb import ( "fmt" - "strconv" "strings" "regexp" @@ -58,13 +57,12 @@ func (query *Query) renderTags() []string { } textValue := "" - numericValue, err := strconv.ParseFloat(tag.Value, 64) // quote value unless regex or number if tag.Operator == "=~" || tag.Operator == "!~" { textValue = tag.Value - } else if err == nil { - textValue = fmt.Sprintf("%v", numericValue) + } else if tag.Operator == "<" || tag.Operator == ">" { + textValue = tag.Value } else { textValue = fmt.Sprintf("'%s'", tag.Value) } diff --git a/pkg/tsdb/influxdb/query_test.go b/pkg/tsdb/influxdb/query_test.go index ee045444c9b..b6af67e5e42 100644 --- a/pkg/tsdb/influxdb/query_test.go +++ b/pkg/tsdb/influxdb/query_test.go @@ -106,13 +106,19 @@ func TestInfluxdbQueryBuilder(t *testing.T) { Convey("can render number tags", func() { query := &Query{Tags: []*Tag{&Tag{Operator: "=", Value: "10001", Key: "key"}}} - So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = 10001`) + So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = '10001'`) }) - Convey("can render number tags with decimals", func() { - query := &Query{Tags: []*Tag{&Tag{Operator: "=", Value: "10001.1", Key: "key"}}} + Convey("can render numbers less then condition tags", func() { + query := &Query{Tags: []*Tag{&Tag{Operator: "<", Value: "10001", Key: "key"}}} - So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" = 10001.1`) + So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" < 10001`) + }) + + Convey("can render number greather then condition tags", func() { + query := &Query{Tags: []*Tag{&Tag{Operator: ">", Value: "10001", Key: "key"}}} + + So(strings.Join(query.renderTags(), ""), ShouldEqual, `"key" > 10001`) }) Convey("can render string tags", func() {