Skip to content

Commit 06af687

Browse files
dinalkatyakats
andauthored
IG-16745: grafana: in case query request is empty ignore it and return empty array (#582) (#583)
Co-authored-by: Katya Katsenelenbogen <katyak@iguazio.com>
1 parent 26bd756 commit 06af687

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

http/grafana.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ import (
3737

3838
const querySeparator = ";"
3939
const fieldsItemsSeperator = ","
40-
const defaultBackend = "tsdb"
4140

4241
type outputType int
4342

@@ -108,14 +107,15 @@ func simpleJSONRequestFactory(method string, request []byte) ([]simpleJSONReques
108107
switch method {
109108
case "query":
110109
for _, target := range reqBase.Targets {
111-
currRequest := &simpleJSONQueryRequest{Backend: defaultBackend, requestSimpleJSONBase: reqBase}
110+
currRequest := &simpleJSONQueryRequest{requestSimpleJSONBase: reqBase}
112111
currRequest.Type = target["type"].(string)
113112
fieldInput := target["target"].(string)
114113
if err := currRequest.parseQueryLine(fieldInput); err != nil {
115114
return nil, errors.Wrap(err, "Failed to parse target")
116115
}
117-
118-
requests = append(requests, currRequest)
116+
if currRequest.Backend != "" {
117+
requests = append(requests, currRequest)
118+
}
119119
}
120120
case "search":
121121
currRequest :=

http/server.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,18 +470,20 @@ func (s *Server) handleSimpleJSON(ctx *fasthttp.RequestCtx, method string) {
470470
ctx.Error(fmt.Sprintf("bad request - %s", err), http.StatusBadRequest)
471471
return
472472
}
473-
474473
var results interface{}
475-
for _, req := range requests {
476-
result, err := s.executeSimpleJSONSubRequest(req, ctx)
477-
if err != nil {
478-
ctx.Error(fmt.Sprintf("Error querying: %s", err.Error()), http.StatusInternalServerError)
479-
return
474+
if len(requests) > 0 {
475+
for _, req := range requests {
476+
result, err := s.executeSimpleJSONSubRequest(req, ctx)
477+
if err != nil {
478+
ctx.Error(fmt.Sprintf("Error querying: %s", err.Error()), http.StatusInternalServerError)
479+
return
480+
}
481+
results = appendSimpleJSONResults(results, result)
480482
}
481-
482-
results = appendSimpleJSONResults(results, result)
483+
} else {
484+
a := make([]string, 0)
485+
results = a
483486
}
484-
485487
_ = s.replyJSON(ctx, results)
486488
}
487489

0 commit comments

Comments
 (0)