From fb46ae7fc9ef99c6f5695f9d2cca317931404de5 Mon Sep 17 00:00:00 2001 From: tejasbhosale009 <31762585+tejasbhosale009@users.noreply.github.com> Date: Mon, 16 Mar 2020 23:52:50 +0530 Subject: [PATCH] [coordinator] Add support for Graphite Grafana plugin /find POST requests (#2153) --- .../api/v1/handler/graphite/find_parser.go | 3 +-- .../api/v1/handler/graphite/find_test.go | 23 +++++++++++++++---- .../handleroptions/fetch_options.go | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/query/api/v1/handler/graphite/find_parser.go b/src/query/api/v1/handler/graphite/find_parser.go index 5533dac01e..f2ee0bc730 100644 --- a/src/query/api/v1/handler/graphite/find_parser.go +++ b/src/query/api/v1/handler/graphite/find_parser.go @@ -57,8 +57,7 @@ func parseFindParamsToQueries(r *http.Request) ( _rawQueryString string, _err *xhttp.ParseError, ) { - values := r.URL.Query() - query := values.Get("query") + query := r.FormValue("query") if query == "" { return nil, nil, "", xhttp.NewParseError(errors.ErrNoQueryFound, http.StatusBadRequest) diff --git a/src/query/api/v1/handler/graphite/find_test.go b/src/query/api/v1/handler/graphite/find_test.go index 2196d38ab8..0ad181bfa6 100644 --- a/src/query/api/v1/handler/graphite/find_test.go +++ b/src/query/api/v1/handler/graphite/find_test.go @@ -218,7 +218,7 @@ func (r results) Less(i, j int) bool { return strings.Compare(r[i].ID, r[j].ID) == -1 } -func testFind(t *testing.T, ex bool, ex2 bool, header string) { +func testFind(t *testing.T, httpMethod string, ex bool, ex2 bool, header string) { ctrl := gomock.NewController(t) defer ctrl.Finish() @@ -233,11 +233,22 @@ func testFind(t *testing.T, ex bool, ex2 bool, header string) { h := NewFindHandler(opts) // execute the query + params := make(url.Values) + params.Set("query", "foo.b*") + params.Set("from", from.s) + params.Set("until", until.s) + w := &writer{} req := &http.Request{ - URL: &url.URL{ - RawQuery: fmt.Sprintf("query=foo.b*&from=%s&until=%s", from.s, until.s), - }, + Method: httpMethod, + } + switch httpMethod { + case http.MethodGet: + req.URL = &url.URL{ + RawQuery: params.Encode(), + } + case http.MethodPost: + req.Form = params } h.ServeHTTP(w, req) @@ -289,7 +300,9 @@ var limitTests = []struct { func TestFind(t *testing.T) { for _, tt := range limitTests { t.Run(tt.name, func(t *testing.T) { - testFind(t, tt.ex, tt.ex2, tt.header) + for _, httpMethod := range FindHTTPMethods { + testFind(t, httpMethod, tt.ex, tt.ex2, tt.header) + } }) } } diff --git a/src/query/api/v1/handler/prometheus/handleroptions/fetch_options.go b/src/query/api/v1/handler/prometheus/handleroptions/fetch_options.go index 8b830936a4..a3d00c191f 100644 --- a/src/query/api/v1/handler/prometheus/handleroptions/fetch_options.go +++ b/src/query/api/v1/handler/prometheus/handleroptions/fetch_options.go @@ -81,7 +81,7 @@ func ParseLimit(req *http.Request, defaultLimit int) (int, error) { return n, nil } - if str := req.URL.Query().Get("limit"); str != "" { + if str := req.FormValue("limit"); str != "" { n, err := strconv.Atoi(str) if err != nil { err = fmt.Errorf(