Skip to content

Commit

Permalink
[coordinator] Add support for Graphite Grafana plugin /find POST requ…
Browse files Browse the repository at this point in the history
…ests (#2153)
  • Loading branch information
tejasbhosale009 authored Mar 16, 2020
1 parent 548b247 commit fb46ae7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/query/api/v1/handler/graphite/find_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 18 additions & 5 deletions src/query/api/v1/handler/graphite/find_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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)
Expand Down Expand Up @@ -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)
}
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit fb46ae7

Please sign in to comment.