Skip to content

Commit a01be99

Browse files
authored
Merge pull request #242 from jotak/log-unmarshal
[Trivial] Add error logs on unmarshal errors
2 parents 96f1243 + d077a85 commit a01be99

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

pkg/handler/loki.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ func getLokiError(resp []byte, code int) string {
7373
}
7474
err := json.Unmarshal(resp, &f)
7575
if err != nil {
76+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
7677
return fmt.Sprintf("Unknown error from Loki\ncannot unmarshal\n%s", resp)
7778
}
7879
message, ok := f["message"]
@@ -115,6 +116,7 @@ func fetchSingle(lokiClient httpclient.Caller, flowsURL string, merger loki.Merg
115116
}
116117
var qr model.QueryResponse
117118
if err := json.Unmarshal(resp, &qr); err != nil {
119+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
118120
return http.StatusInternalServerError, err
119121
}
120122
if _, err := merger.Add(qr.Data); err != nil {
@@ -146,6 +148,7 @@ func fetchParallel(lokiClient httpclient.Caller, queries []string, merger loki.M
146148
var qr model.QueryResponse
147149
err := json.Unmarshal(resp, &qr)
148150
if err != nil {
151+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
149152
errChan <- errorWithCode{err: err, code: http.StatusInternalServerError}
150153
} else {
151154
resChan <- qr
@@ -240,6 +243,7 @@ func LokiConfig(cfg *loki.Config, param string) func(w http.ResponseWriter, r *h
240243
cfg := make(map[string]interface{})
241244
err = yaml.Unmarshal(resp, &cfg)
242245
if err != nil {
246+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
243247
writeError(w, code, err.Error())
244248
return
245249
}

pkg/handler/resources.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ func getNamesForPrefix(cfg *loki.Config, lokiClient httpclient.Caller, prefix, k
137137
var qr model.QueryResponse
138138
err = json.Unmarshal(resp, &qr)
139139
if err != nil {
140+
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
140141
return nil, http.StatusInternalServerError, errors.New("Failed to unmarshal Loki response: " + err.Error())
141142
}
142143

0 commit comments

Comments
 (0)