Commit a3b0fbca by bergquist

fix(influxdb): fixes broken tag rendering for influxdb alerting

closes #6626
ref #6523
parent 7ce33c31
...@@ -2,7 +2,6 @@ package influxdb ...@@ -2,7 +2,6 @@ package influxdb
import ( import (
"fmt" "fmt"
"strconv"
"strings" "strings"
"regexp" "regexp"
...@@ -58,13 +57,12 @@ func (query *Query) renderTags() []string { ...@@ -58,13 +57,12 @@ func (query *Query) renderTags() []string {
} }
textValue := "" textValue := ""
numericValue, err := strconv.ParseFloat(tag.Value, 64)
// quote value unless regex or number // quote value unless regex or number
if tag.Operator == "=~" || tag.Operator == "!~" { if tag.Operator == "=~" || tag.Operator == "!~" {
textValue = tag.Value textValue = tag.Value
} else if err == nil { } else if tag.Operator == "<" || tag.Operator == ">" {
textValue = fmt.Sprintf("%v", numericValue) textValue = tag.Value
} else { } else {
textValue = fmt.Sprintf("'%s'", tag.Value) textValue = fmt.Sprintf("'%s'", tag.Value)
} }
......
...@@ -106,13 +106,19 @@ func TestInfluxdbQueryBuilder(t *testing.T) { ...@@ -106,13 +106,19 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
Convey("can render number tags", func() { Convey("can render number tags", func() {
query := &Query{Tags: []*Tag{&Tag{Operator: "=", Value: "10001", Key: "key"}}} 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() { Convey("can render numbers less then condition tags", func() {
query := &Query{Tags: []*Tag{&Tag{Operator: "=", Value: "10001.1", Key: "key"}}} 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() { Convey("can render string tags", func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment