feat(outputs.http): Include body sample in non-retryable error logs (#16597)

This commit is contained in:
David Grant 2025-03-26 10:25:11 -07:00 committed by GitHub
parent 52244af2b6
commit c17467b8cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 7 additions and 7 deletions

View File

@ -230,19 +230,19 @@ func (h *HTTP) writeMetric(reqBody []byte) error {
defer resp.Body.Close()
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 := ""
scanner := bufio.NewScanner(io.LimitReader(resp.Body, maxErrMsgLen))
if scanner.Scan() {
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)
}