feat(outputs.http): Include body sample in non-retryable error logs (#16597)
This commit is contained in:
parent
52244af2b6
commit
c17467b8cb
|
|
@ -230,19 +230,19 @@ func (h *HTTP) writeMetric(reqBody []byte) error {
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
|
||||||
for _, nonRetryableStatusCode := range h.NonRetryableStatusCodes {
|
|
||||||
if resp.StatusCode == nonRetryableStatusCode {
|
|
||||||
h.Log.Errorf("Received non-retryable status %v. Metrics are lost.", resp.StatusCode)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
errorLine := ""
|
errorLine := ""
|
||||||
scanner := bufio.NewScanner(io.LimitReader(resp.Body, maxErrMsgLen))
|
scanner := bufio.NewScanner(io.LimitReader(resp.Body, maxErrMsgLen))
|
||||||
if scanner.Scan() {
|
if scanner.Scan() {
|
||||||
errorLine = scanner.Text()
|
errorLine = scanner.Text()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, nonRetryableStatusCode := range h.NonRetryableStatusCodes {
|
||||||
|
if resp.StatusCode == nonRetryableStatusCode {
|
||||||
|
h.Log.Errorf("Received non-retryable status %v. Metrics are lost. body: %s", resp.StatusCode, errorLine)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("when writing to [%s] received status code: %d. body: %s", h.URL, resp.StatusCode, errorLine)
|
return fmt.Errorf("when writing to [%s] received status code: %d. body: %s", h.URL, resp.StatusCode, errorLine)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue