Skip to content

Commit

Permalink
Merge pull request #19 from vyzigold/master
Browse files Browse the repository at this point in the history
Enhance error message returned from Loki
  • Loading branch information
paramite committed Aug 5, 2021
2 parents 9960b6c + ab1236e commit 7b12c5e
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions connector/loki/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import (
"bytes"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strconv"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -301,9 +303,17 @@ func (client *LokiConnector) send() (*http.Response, error) {
}
defer response.Body.Close()
if response.StatusCode != 204 {
buffer := new(strings.Builder)
body := ""
_, errCopy := io.Copy(buffer, response.Body)
if errCopy == nil {
body = buffer.String()
}

client.logger.Metadata(map[string]interface{}{
"error": err,
"response": response,
"error": err,
"response headers": response,
"response body": body,
})
client.logger.Error("Recieved unexpected statuscode when trying to send logs")
return nil, fmt.Errorf("Got %d http status code after pushing to loki instead of expected 204", response.StatusCode)
Expand Down

0 comments on commit 7b12c5e

Please sign in to comment.