Add Horrible Hacks for Group By Queries endpoint

This perpetuates the hacks that we added for :dashboardTime: so that
they will also work for :interval:. We should really find a better way
to do this.
pull/1609/head
Tim Raymond 2017-06-15 17:18:57 -04:00
parent 95862a9bbc
commit 4e7ec0b2a8
1 changed files with 15 additions and 1 deletions

View File

@ -11,6 +11,12 @@ import (
// Convert changes an InfluxQL query to a QueryConfig // Convert changes an InfluxQL query to a QueryConfig
func Convert(influxQL string) (chronograf.QueryConfig, error) { func Convert(influxQL string) (chronograf.QueryConfig, error) {
itsDashboardTime := false itsDashboardTime := false
intervalTime := false
if strings.Contains(influxQL, ":interval:") {
influxQL = strings.Replace(influxQL, ":interval:", "time(1234s)", 1)
intervalTime = true
}
if strings.Contains(influxQL, ":dashboardTime:") { if strings.Contains(influxQL, ":dashboardTime:") {
influxQL = strings.Replace(influxQL, ":dashboardTime:", "now() - 15m", 1) influxQL = strings.Replace(influxQL, ":dashboardTime:", "now() - 15m", 1)
itsDashboardTime = true itsDashboardTime = true
@ -25,6 +31,10 @@ func Convert(influxQL string) (chronograf.QueryConfig, error) {
influxQL = strings.Replace(influxQL, "now() - 15m", ":dashboardTime:", 1) influxQL = strings.Replace(influxQL, "now() - 15m", ":dashboardTime:", 1)
} }
if intervalTime {
influxQL = strings.Replace(influxQL, "time(1234s)", ":interval:", 1)
}
raw := chronograf.QueryConfig{ raw := chronograf.QueryConfig{
RawText: &influxQL, RawText: &influxQL,
Fields: []chronograf.Field{}, Fields: []chronograf.Field{},
@ -104,7 +114,11 @@ func Convert(influxQL string) (chronograf.QueryConfig, error) {
if !ok { if !ok {
return raw, nil return raw, nil
} }
qc.GroupBy.Time = lit.String() if intervalTime {
qc.GroupBy.Time = "auto"
} else {
qc.GroupBy.Time = lit.String()
}
case *influxql.VarRef: case *influxql.VarRef:
qc.GroupBy.Tags = append(qc.GroupBy.Tags, v.Val) qc.GroupBy.Tags = append(qc.GroupBy.Tags, v.Val)
} }