feat(influxdb): add conditions property to tag

This commit is contained in:
bergquist 2016-10-05 16:57:32 +02:00
parent c7abd3ba4e
commit 8588bb386c
3 changed files with 25 additions and 11 deletions

View File

@ -10,9 +10,10 @@ type Query struct {
}
type Tag struct {
Key string
Operator string
Value string
Key string
Operator string
Value string
Condition string
}
type Select []QueryPart

View File

@ -69,23 +69,30 @@ func (*InfluxdbQueryParser) parseTags(model *simplejson.Json) ([]*Tag, error) {
var result []*Tag
for _, t := range model.Get("tags").MustArray() {
tagJson := simplejson.NewFromAny(t)
tag := &Tag{}
var err error
key, err := tagJson.Get("key").String()
tag.Key, err = tagJson.Get("key").String()
if err != nil {
return nil, err
}
tag.Value, err = tagJson.Get("value").String()
if err != nil {
return nil, err
}
operator, err := tagJson.Get("operator").String()
if err != nil {
return nil, err
if err == nil {
tag.Operator = operator
}
value, err := tagJson.Get("value").String()
if err != nil {
return nil, err
condition, err := tagJson.Get("condition").String()
if err == nil {
tag.Condition = condition
}
result = append(result, &Tag{Key: key, Operator: operator, Value: value})
result = append(result, tag)
}
return result, nil

View File

@ -89,6 +89,12 @@ func TestInfluxdbQueryParser(t *testing.T) {
"key": "datacenter",
"operator": "=",
"value": "America"
},
{
"condition": "OR",
"key": "hostname",
"operator": "=",
"value": "server1"
}
]
}
@ -101,7 +107,7 @@ func TestInfluxdbQueryParser(t *testing.T) {
So(err, ShouldBeNil)
So(len(res.GroupBy), ShouldEqual, 3)
So(len(res.Selects), ShouldEqual, 3)
So(len(res.Tags), ShouldEqual, 1)
So(len(res.Tags), ShouldEqual, 2)
})
})
}