feat(tsdb): add missing content type and join url using path

This commit is contained in:
bergquist 2016-09-01 11:12:35 +02:00
parent 3d3365f242
commit d73547c0dc

View File

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"net/url" "net/url"
"path"
"strings" "strings"
"time" "time"
@ -44,18 +45,20 @@ func (e *GraphiteExecutor) Execute(queries tsdb.QuerySlice, context *tsdb.QueryC
for _, query := range queries { for _, query := range queries {
params["target"] = []string{query.Query} params["target"] = []string{query.Query}
glog.Debug("Graphite request", "query", query.Query)
} }
formData := params.Encode() u, _ := url.Parse(e.Url)
glog.Info("Graphite request body", "formdata", formData) u.Path = path.Join(u.Path, "render")
req, err := http.NewRequest(http.MethodPost, e.Url+"/render", strings.NewReader(formData)) glog.Info("Graphite request body", "formdata", params.Encode())
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(params.Encode()))
if err != nil { if err != nil {
glog.Info("Failed to create request", "error", err) glog.Info("Failed to create request", "error", err)
result.Error = fmt.Errorf("Failed to create request. error: %v", err) result.Error = fmt.Errorf("Failed to create request. error: %v", err)
return result return result
} }
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
if e.BasicAuth { if e.BasicAuth {
req.SetBasicAuth(e.BasicAuthUser, e.BasicAuthPassword) req.SetBasicAuth(e.BasicAuthUser, e.BasicAuthPassword)
} }