Skip to content

Commit

Permalink
Merge 2ceea68 into 9fb9b88
Browse files Browse the repository at this point in the history
  • Loading branch information
federicotdn committed Jul 25, 2023
2 parents 9fb9b88 + 2ceea68 commit ba783fd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
10 changes: 10 additions & 0 deletions log/loki.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
type lokiHook struct {
fallbackLogger logrus.FieldLogger
addr string
headers [][2]string
labels [][2]string
ch chan *logrus.Entry
limit int
Expand Down Expand Up @@ -124,6 +125,11 @@ func (h *lokiHook) parseArgs(line string) error {
labelKey := strings.TrimPrefix(key, "label.")
h.labels = append(h.labels, [2]string{labelKey, value})

continue
} else if strings.HasPrefix(key, "header.") {
headerKey := strings.TrimPrefix(key, "header.")
h.headers = append(h.headers, [2]string{headerKey, value})

continue
}

Expand Down Expand Up @@ -336,6 +342,10 @@ func (h *lokiHook) push(b bytes.Buffer) error {

req.Header.Set("Content-Type", "application/json")

for _, header := range h.headers {
req.Header.Set(header[0], header[1])
}

res, err := h.client.Do(req)

if res != nil {
Expand Down
3 changes: 2 additions & 1 deletion log/loki_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,10 @@ func TestSyslogFromConfigLine(t *testing.T) {
},
},
{
line: "loki=somewhere:1233,label.something=else,label.foo=bar,limit=32,level=info,allowedLabels=[something],pushPeriod=5m32s,msgMaxSize=1231",
line: "loki=somewhere:1233,label.something=else,label.foo=bar,limit=32,level=info,allowedLabels=[something],pushPeriod=5m32s,msgMaxSize=1231,header.x-test=123,header.authorization=token foobar",
res: lokiHook{
addr: "somewhere:1233",
headers: [][2]string{{"x-test", "123"}, {"authorization", "token foobar"}},
limit: 32,
pushPeriod: time.Minute*5 + time.Second*32,
levels: logrus.AllLevels[:5],
Expand Down

0 comments on commit ba783fd

Please sign in to comment.