Commit 2374d098 by utkarshcmu

Fixed query parsing bugs

parent ace81760
......@@ -60,61 +60,8 @@ func (e *OpenTsdbExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
tsdbQuery.Queries = make([]map[string]interface{}, len(queries))
for i := 0; i < len(queries); i++ {
metric := make(map[string]interface{})
// Setting metric and aggregator
metric["metric"] = queries[i].Model.Get("metric").MustString()
metric["aggregator"] = queries[i].Model.Get("aggregator").MustString()
// Setting downsampling options
disableDownsampling := queries[i].Model.Get("disableDownsampling").MustBool()
if !disableDownsampling {
downsampleInterval := queries[i].Model.Get("downsampleInterval").MustString()
if downsampleInterval == "" {
downsampleInterval = "1m" //default value for blank
}
downsample := downsampleInterval + "-" + queries[i].Model.Get("downsampleAggregator").MustString()
if queries[i].Model.Get("downsampleFillPolicy").MustString() != "none" {
metric["downsample"] = downsample + "-" + queries[i].Model.Get("downsampleFillPolicy").MustString()
}
}
// Setting rate options
if queries[i].Model.Get("shouldComputeRate").MustBool() {
metric["rate"] = true
rateOptions := make(map[string]interface{})
rateOptions["counter"] = queries[i].Model.Get("isCounter").MustBool()
counterMax, counterMaxCheck := queries[i].Model.CheckGet("counterMax")
if counterMaxCheck {
counterMaxVal, err := strconv.ParseFloat(counterMax.MustString(),64)
if err == nil {
rateOptions["counterMax"] = counterMaxVal
}
}
resetValue, resetValueCheck := queries[i].Model.CheckGet("counterResetValue")
if resetValueCheck {
resetValueVal, err := strconv.ParseFloat(resetValue.MustString(),64)
if err == nil {
rateOptions["resetValue"] = resetValueVal
}
}
metric["rateOptions"] = rateOptions
}
// Setting tags
tags, tagsCheck := queries[i].Model.CheckGet("tags")
if tagsCheck && len(tags.MustMap()) > 0 {
metric["tags"] = tags.MustMap()
}
// Setting filters
filters, filtersCheck := queries[i].Model.CheckGet("filters")
if filtersCheck && len(filters.MustArray()) > 0 {
metric["filters"] = filters.MustArray()
}
tsdbQuery.Queries[i] = metric
metric := e.buildMetric(queries[i])
tsdbQuery.Queries[i] = metric
}
if setting.Env == setting.DEV {
......@@ -205,3 +152,62 @@ func (e *OpenTsdbExecutor) parseResponse(query OpenTsdbQuery, res *http.Response
queryResults["A"] = queryRes
return queryResults, nil
}
func (e *OpenTsdbExecutor) buildMetric(query *tsdb.Query) (map[string]interface{}) {
metric := make(map[string]interface{})
// Setting metric and aggregator
metric["metric"] = query.Model.Get("metric").MustString()
metric["aggregator"] = query.Model.Get("aggregator").MustString()
// Setting downsampling options
disableDownsampling := query.Model.Get("disableDownsampling").MustBool()
if !disableDownsampling {
downsampleInterval := query.Model.Get("downsampleInterval").MustString()
if downsampleInterval == "" {
downsampleInterval = "1m" //default value for blank
}
downsample := downsampleInterval + "-" + query.Model.Get("downsampleAggregator").MustString()
if query.Model.Get("downsampleFillPolicy").MustString() != "none" {
metric["downsample"] = downsample + "-" + query.Model.Get("downsampleFillPolicy").MustString()
} else {
metric["downsample"] = downsample
}
}
// Setting rate options
if query.Model.Get("shouldComputeRate").MustBool() {
metric["rate"] = true
rateOptions := make(map[string]interface{})
rateOptions["counter"] = query.Model.Get("isCounter").MustBool()
counterMax, counterMaxCheck := query.Model.CheckGet("counterMax")
if counterMaxCheck {
rateOptions["counterMax"] = counterMax.MustFloat64()
}
resetValue, resetValueCheck := query.Model.CheckGet("counterResetValue")
if resetValueCheck {
rateOptions["resetValue"] = resetValue.MustFloat64()
}
metric["rateOptions"] = rateOptions
}
// Setting tags
tags, tagsCheck := query.Model.CheckGet("tags")
if tagsCheck && len(tags.MustMap()) > 0 {
metric["tags"] = tags.MustMap()
}
// Setting filters
filters, filtersCheck := query.Model.CheckGet("filters")
if filtersCheck && len(filters.MustArray()) > 0 {
metric["filters"] = filters.MustArray()
}
return metric
}
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