Commit cc0a39f8 by utkarshcmu

Added downsampling params to alerting

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