Skip to content

Commit 4df1af5

Browse files
tedyagetian.zhiqiang3
andauthored
Add Headers into the ElasticsearchConfig. (#131)
Co-authored-by: tian.zhiqiang3 <[email protected]>
1 parent 428f35b commit 4df1af5

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ receivers:
158158
password: # optional
159159
cloudID: # optional
160160
apiKey: # optional
161+
headers: # optional,Can be used to append the additional key/value pairs into the request headers
161162
# If set to true, it allows updating the same document in ES (might be useful handling count)
162163
useEventID: true|false
163164
# Type should be only used for clusters Version 6 and lower.

pkg/sinks/elasticsearch.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,12 @@ import (
1919

2020
type ElasticsearchConfig struct {
2121
// Connection specific
22-
Hosts []string `yaml:"hosts"`
23-
Username string `yaml:"username"`
24-
Password string `yaml:"password"`
25-
CloudID string `yaml:"cloudID"`
26-
APIKey string `yaml:"apiKey"`
22+
Hosts []string `yaml:"hosts"`
23+
Username string `yaml:"username"`
24+
Password string `yaml:"password"`
25+
CloudID string `yaml:"cloudID"`
26+
APIKey string `yaml:"apiKey"`
27+
Headers map[string]string `yaml:"headers"` // Can be used to append additional key value pairs into the request headers
2728
// Indexing preferences
2829
UseEventID bool `yaml:"useEventID"`
2930
// DeDot all labels and annotations in the event. For both the event and the involvedObject
@@ -42,10 +43,18 @@ func NewElasticsearch(cfg *ElasticsearchConfig) (*Elasticsearch, error) {
4243
return nil, fmt.Errorf("failed to setup TLS: %w", err)
4344
}
4445

46+
var header = http.Header{}
47+
if len(cfg.Headers) > 0 {
48+
for k, v := range cfg.Headers {
49+
header.Add(k, v)
50+
}
51+
}
52+
4553
client, err := elasticsearch.NewClient(elasticsearch.Config{
4654
Addresses: cfg.Hosts,
4755
Username: cfg.Username,
4856
Password: cfg.Password,
57+
Header: header,
4958
CloudID: cfg.CloudID,
5059
APIKey: cfg.APIKey,
5160
Transport: &http.Transport{

0 commit comments

Comments
 (0)