Commit a948dfe5 by bergquist

fix(influxdb): fixes broken raw query usage

parent 9f7d0862
...@@ -12,6 +12,7 @@ type InfluxdbQueryParser struct{} ...@@ -12,6 +12,7 @@ type InfluxdbQueryParser struct{}
func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSourceInfo) (*Query, error) { func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSourceInfo) (*Query, error) {
policy := model.Get("policy").MustString("default") policy := model.Get("policy").MustString("default")
rawQuery := model.Get("query").MustString("") rawQuery := model.Get("query").MustString("")
useRawQuery := model.Get("rawQuery").MustBool(false)
alias := model.Get("alias").MustString("") alias := model.Get("alias").MustString("")
measurement := model.Get("measurement").MustString("") measurement := model.Get("measurement").MustString("")
...@@ -54,6 +55,7 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSo ...@@ -54,6 +55,7 @@ func (qp *InfluxdbQueryParser) Parse(model *simplejson.Json, dsInfo *tsdb.DataSo
RawQuery: rawQuery, RawQuery: rawQuery,
Interval: interval, Interval: interval,
Alias: alias, Alias: alias,
UseRawQuery: useRawQuery,
}, nil }, nil
} }
......
...@@ -8,6 +8,7 @@ type Query struct { ...@@ -8,6 +8,7 @@ type Query struct {
GroupBy []*QueryPart GroupBy []*QueryPart
Selects []*Select Selects []*Select
RawQuery string RawQuery string
UseRawQuery bool
Alias string Alias string
Interval string Interval string
......
...@@ -17,7 +17,7 @@ var ( ...@@ -17,7 +17,7 @@ var (
type QueryBuilder struct{} type QueryBuilder struct{}
func (qb *QueryBuilder) Build(query *Query, queryContext *tsdb.QueryContext) (string, error) { func (qb *QueryBuilder) Build(query *Query, queryContext *tsdb.QueryContext) (string, error) {
if query.RawQuery != "" { if query.UseRawQuery && query.RawQuery != "" {
q := query.RawQuery q := query.RawQuery
q = strings.Replace(q, "$timeFilter", qb.renderTimeFilter(query, queryContext), 1) q = strings.Replace(q, "$timeFilter", qb.renderTimeFilter(query, queryContext), 1)
......
...@@ -79,6 +79,7 @@ func TestInfluxdbQueryBuilder(t *testing.T) { ...@@ -79,6 +79,7 @@ func TestInfluxdbQueryBuilder(t *testing.T) {
GroupBy: []*QueryPart{groupBy1, groupBy3}, GroupBy: []*QueryPart{groupBy1, groupBy3},
Interval: "10s", Interval: "10s",
RawQuery: "Raw query", RawQuery: "Raw query",
UseRawQuery: true,
} }
rawQuery, err := builder.Build(query, queryContext) rawQuery, err := builder.Build(query, queryContext)
......
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