Skip to content

Commit

Permalink
Merge pull request #242 from jotak/log-unmarshal
Browse files Browse the repository at this point in the history
[Trivial] Add error logs on unmarshal errors
  • Loading branch information
jotak authored Nov 25, 2022
2 parents 96f1243 + d077a85 commit a01be99
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pkg/handler/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func getLokiError(resp []byte, code int) string {
}
err := json.Unmarshal(resp, &f)
if err != nil {
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
return fmt.Sprintf("Unknown error from Loki\ncannot unmarshal\n%s", resp)
}
message, ok := f["message"]
Expand Down Expand Up @@ -115,6 +116,7 @@ func fetchSingle(lokiClient httpclient.Caller, flowsURL string, merger loki.Merg
}
var qr model.QueryResponse
if err := json.Unmarshal(resp, &qr); err != nil {
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
return http.StatusInternalServerError, err
}
if _, err := merger.Add(qr.Data); err != nil {
Expand Down Expand Up @@ -146,6 +148,7 @@ func fetchParallel(lokiClient httpclient.Caller, queries []string, merger loki.M
var qr model.QueryResponse
err := json.Unmarshal(resp, &qr)
if err != nil {
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
errChan <- errorWithCode{err: err, code: http.StatusInternalServerError}
} else {
resChan <- qr
Expand Down Expand Up @@ -240,6 +243,7 @@ func LokiConfig(cfg *loki.Config, param string) func(w http.ResponseWriter, r *h
cfg := make(map[string]interface{})
err = yaml.Unmarshal(resp, &cfg)
if err != nil {
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
writeError(w, code, err.Error())
return
}
Expand Down
1 change: 1 addition & 0 deletions pkg/handler/resources.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ func getNamesForPrefix(cfg *loki.Config, lokiClient httpclient.Caller, prefix, k
var qr model.QueryResponse
err = json.Unmarshal(resp, &qr)
if err != nil {
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
return nil, http.StatusInternalServerError, errors.New("Failed to unmarshal Loki response: " + err.Error())
}

Expand Down

0 comments on commit a01be99

Please sign in to comment.