Skip to content

Commit

Permalink
IG-16745: grafana: in case query request is empty ignore it and retur…
Browse files Browse the repository at this point in the history
…n empty array (#582)
  • Loading branch information
katyakats authored Jan 6, 2021
1 parent 0db3396 commit b82eaac
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
8 changes: 4 additions & 4 deletions http/grafana.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (

const querySeparator = ";"
const fieldsItemsSeperator = ","
const defaultBackend = "tsdb"

type outputType int

Expand Down Expand Up @@ -108,14 +107,15 @@ func simpleJSONRequestFactory(method string, request []byte) ([]simpleJSONReques
switch method {
case "query":
for _, target := range reqBase.Targets {
currRequest := &simpleJSONQueryRequest{Backend: defaultBackend, requestSimpleJSONBase: reqBase}
currRequest := &simpleJSONQueryRequest{requestSimpleJSONBase: reqBase}
currRequest.Type = target["type"].(string)
fieldInput := target["target"].(string)
if err := currRequest.parseQueryLine(fieldInput); err != nil {
return nil, errors.Wrap(err, "Failed to parse target")
}

requests = append(requests, currRequest)
if currRequest.Backend != "" {
requests = append(requests, currRequest)
}
}
case "search":
currRequest :=
Expand Down
20 changes: 11 additions & 9 deletions http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,20 @@ func (s *Server) handleSimpleJSON(ctx *fasthttp.RequestCtx, method string) {
ctx.Error(fmt.Sprintf("bad request - %s", err), http.StatusBadRequest)
return
}

var results interface{}
for _, req := range requests {
result, err := s.executeSimpleJSONSubRequest(req, ctx)
if err != nil {
ctx.Error(fmt.Sprintf("Error querying: %s", err.Error()), http.StatusInternalServerError)
return
if len(requests) > 0 {
for _, req := range requests {
result, err := s.executeSimpleJSONSubRequest(req, ctx)
if err != nil {
ctx.Error(fmt.Sprintf("Error querying: %s", err.Error()), http.StatusInternalServerError)
return
}
results = appendSimpleJSONResults(results, result)
}

results = appendSimpleJSONResults(results, result)
} else {
a := make([]string, 0)
results = a
}

_ = s.replyJSON(ctx, results)
}

Expand Down

0 comments on commit b82eaac

Please sign in to comment.