mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(influxdb): add conditions property to tag
This commit is contained in:
parent
c7abd3ba4e
commit
8588bb386c
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user