Skip to content

Commit 6f80c0b

Browse files
committed
Fix error logs/message for loki-op 6
We're seeing a lot of errors with "no message found". This is because with Loki operator 6, the json of the error has changed. We need now to look at the "error" field. Also add more debug logs
1 parent eaddfc2 commit 6f80c0b

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

pkg/handler/loki.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,13 @@ func getLokiError(resp []byte, code int) (int, string) {
101101
hlog.WithError(err).Errorf("cannot unmarshal, response was: %v", string(resp))
102102
return http.StatusBadRequest, fmt.Sprintf("Unknown error from Loki\ncannot unmarshal\n%s", resp)
103103
}
104-
message, ok := f["message"]
104+
message, ok := f["error"]
105105
if !ok {
106-
return http.StatusBadRequest, "Unknown error from Loki\nno message found"
106+
message, ok = f["message"]
107+
if !ok {
108+
hlog.WithError(err).Errorf("unknown Loki error: %v", f)
109+
return http.StatusBadRequest, "Unknown error from Loki"
110+
}
107111
}
108112
return http.StatusBadRequest, fmt.Sprintf("Loki message: %s", message)
109113
}
@@ -135,6 +139,7 @@ func executeLokiQuery(flowsURL string, lokiClient httpclient.Caller) ([]byte, in
135139
}
136140
if code != http.StatusOK {
137141
newCode, msg := getLokiError(resp, code)
142+
hlog.Debugf("executeLokiQuery error: [%d] %s", code, msg)
138143
return nil, newCode, fmt.Errorf("Error from Loki query: [%d] %s", code, msg)
139144
}
140145
return resp, http.StatusOK, nil
@@ -151,6 +156,7 @@ func getLokiLabelValues(baseURL string, lokiClient httpclient.Caller, label stri
151156
}
152157
if code != http.StatusOK {
153158
newCode, msg := getLokiError(resp, code)
159+
hlog.Debugf("getLokiLabelValues error: [%d] %s", code, msg)
154160
return nil, newCode, errors.New(msg)
155161
}
156162
hlog.Tracef("getLokiLabelValues raw response: %s", resp)

0 commit comments

Comments
 (0)