Skip to content

Commit ff7498c

Browse files
authored
feat(loki): add support for custom headers (#142)
add custom headers support in Loki sink, and documentation in README fix: #141
1 parent f48d5bf commit ff7498c

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,8 @@ receivers:
515515
receivers:
516516
- name: "loki"
517517
loki:
518+
headers: # optional
519+
X-Scope-OrgID: tennantID
518520
streamLabels:
519521
foo: bar
520522
url: http://127.0.0.1:3100/loki/api/v1/push

pkg/sinks/loki.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/http"
1212
"strconv"
1313
"time"
14+
"github.com/rs/zerolog/log"
1415
)
1516

1617
type promtailStream struct {
@@ -27,6 +28,7 @@ type LokiConfig struct {
2728
StreamLabels map[string]string `yaml:"streamLabels"`
2829
TLS TLS `yaml:"tls"`
2930
URL string `yaml:"url"`
31+
Headers map[string]string `yaml:"headers"`
3032
}
3133

3234
type Loki struct {
@@ -72,6 +74,17 @@ func (l *Loki) Send(ctx context.Context, ev *kube.EnhancedEvent) error {
7274

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

77+
for k, v := range l.cfg.Headers {
78+
realValue, err := GetString(ev, v)
79+
if err != nil {
80+
log.Debug().Err(err).Msgf("parse template failed: %s", v)
81+
req.Header.Add(k, v)
82+
} else {
83+
log.Debug().Msgf("request header: {%s: %s}", k, realValue)
84+
req.Header.Add(k, realValue)
85+
}
86+
}
87+
7588
client := http.DefaultClient
7689
resp, err := client.Do(req)
7790
if err != nil {

0 commit comments

Comments
 (0)