Skip to content

Commit

Permalink
added filtration by from and to time ranges for raw query mode (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
futuarmo authored Dec 5, 2020
1 parent 3a1663d commit 1b70c39
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion backend/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (ds *CassandraDatasource) MetricQuery(tsdbReq *datasource.DatasourceRequest
var preparedQuery string

if queryData.Get("rawQuery").MustBool() {
preparedQuery = queryData.Get("target").MustString()
preparedQuery = ds.builder.RawMetricQuery(queryData, tsdbReq.TimeRange.FromRaw, tsdbReq.TimeRange.ToRaw)
} else {
preparedQuery = ds.builder.MetricQuery(queryData, tsdbReq.TimeRange.FromRaw, tsdbReq.TimeRange.ToRaw)
}
Expand Down
13 changes: 13 additions & 0 deletions backend/query_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"strings"

simplejson "github.com/bitly/go-simplejson"
)
Expand Down Expand Up @@ -31,3 +32,15 @@ func (qb *QueryBuilder) MetricQuery(queryData *simplejson.Json, timeRangeFrom st

return preparedQuery
}

func (qb *QueryBuilder) RawMetricQuery(queryData *simplejson.Json, timeRangeFrom string, timeRangeTo string) string {
if !queryData.Get("rawQuery").MustBool() {
return qb.MetricQuery(queryData, timeRangeFrom, timeRangeTo)
}

timeRangeReplacer := strings.NewReplacer("$__timeFrom", timeRangeFrom, "$__timeTo", timeRangeTo)

preparedQuery := queryData.Get("target").MustString()

return timeRangeReplacer.Replace(preparedQuery)
}

0 comments on commit 1b70c39

Please sign in to comment.