Commit cc0a39f8 by utkarshcmu

Added downsampling params to alerting

parent 5e0fa0f0
......@@ -14,7 +14,7 @@ import (
"io/ioutil"
"net/http"
"net/url"
//"net/http/httputil"
"net/http/httputil"
"encoding/json"
"gopkg.in/guregu/null.v3"
......@@ -58,16 +58,31 @@ func (e *OpenTsdbExecutor) Execute(ctx context.Context, queries tsdb.QuerySlice,
tsdbQuery.Start = queryContext.TimeRange.GetFromAsMsEpoch()
tsdbQuery.End = queryContext.TimeRange.GetToAsMsEpoch()
tsdbQuery.Queries = make([]map[string]interface{}, len(queries))
for _, query := range queries {
tsdbQuery.Queries = []OpenTsdbMetric{
OpenTsdbMetric{
Metric: query.Model.Get("metric").MustString(),
Aggregator: query.Model.Get("aggregator").MustString(),
},
for i := 0; i < len(queries); i++ {
metric := make(map[string]interface{})
metric["metric"] = queries[i].Model.Get("metric").MustString()
metric["aggregator"] = queries[i].Model.Get("aggregator").MustString()
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()
}
}
tsdbQuery.Queries[i] = metric
}
if setting.Env == setting.DEV {
plog.Debug("OpenTsdb request", "params", tsdbQuery)
}
......@@ -110,13 +125,13 @@ func (e *OpenTsdbExecutor) createRequest(data OpenTsdbQuery) (*http.Request, err
req.SetBasicAuth(e.BasicAuthUser, e.BasicAuthPassword)
}
/*
requestDump, err := httputil.DumpRequest(req, true)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(requestDump))
*/
return req, err
}
......
......@@ -3,12 +3,7 @@ package opentsdb
type OpenTsdbQuery struct {
Start int64 `json:"start"`
End int64 `json:"end"`
Queries []OpenTsdbMetric `json:"queries"`
}
type OpenTsdbMetric struct {
Metric string `json:"metric"`
Aggregator string `json:"aggregator"`
Queries []map[string]interface{} `json:"queries"`
}
type OpenTsdbResponse struct {
......
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