Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 29 additions & 20 deletions apis/fluentbit/v1alpha2/clusterfluentbitconfig_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,14 @@ import (
. "github.com/onsi/gomega"
)

var expected = `[Service]
const (
authorization = "foo:bar"
xLogHeader0 = "testing"
xLogHeaderAppID = "9780495d9db3"
xLogHeaderAppName = "app_name"
)

var expected = fmt.Sprintf(`[Service]
Daemon false
Flush 1
Grace 30
Expand Down Expand Up @@ -72,10 +79,10 @@ var expected = `[Service]
port 433
uri /logs
format json_lines
header Authorization foo:bar
header X-Log-Header-0 testing
header X-Log-Header-App-ID 9780495d9db3
header X-Log-Header-App-Name app_name
header Authorization %s
header X-Log-Header-0 %s
header X-Log-Header-App-ID %s
header X-Log-Header-App-Name %s
json_date_key timestamp
json_date_format iso8601
tls On
Expand Down Expand Up @@ -110,8 +117,9 @@ var expected = `[Service]
syslog_message_key log
tls On
tls.verify true
`
var expectedYaml = `service:
`, authorization, xLogHeader0, xLogHeaderAppID, xLogHeaderAppName)

var expectedYaml = fmt.Sprintf(`service:
daemon: false
flush: 1
grace: 30
Expand Down Expand Up @@ -171,10 +179,10 @@ pipeline:
uri: /logs
format: json_lines
header:
- Authorization foo:bar
- X-Log-Header-0 testing
- X-Log-Header-App-ID 9780495d9db3
- X-Log-Header-App-Name app_name
- Authorization %s
- X-Log-Header-0 %s
- X-Log-Header-App-ID %s
- X-Log-Header-App-Name %s
json_date_key: timestamp
json_date_format: iso8601
tls: On
Expand Down Expand Up @@ -205,7 +213,8 @@ pipeline:
match: 098f6bcd4621d373cade4e832627b4f6.kube.namespace.*
brokers: 127.0.1.1:9092
topics: fluentbit-namespace
`
`, authorization, xLogHeader0, xLogHeaderAppID, xLogHeaderAppName)

var expectedK8s = `[Service]
Daemon false
Flush 1
Expand Down Expand Up @@ -510,10 +519,10 @@ func Test_FluentBitConfig_RenderMainConfig(t *testing.T) {

headers := map[string]string{}

headers["Authorization"] = "foo:bar"
headers["X-Log-Header-App-Name"] = "app_name"
headers["X-Log-Header-0"] = "testing"
headers["X-Log-Header-App-ID"] = "9780495d9db3"
headers["Authorization"] = authorization
headers["X-Log-Header-App-Name"] = xLogHeaderAppName
headers["X-Log-Header-0"] = xLogHeader0
headers["X-Log-Header-App-ID"] = xLogHeaderAppID

httpOutput := ClusterOutput{
TypeMeta: metav1.TypeMeta{
Expand Down Expand Up @@ -742,10 +751,10 @@ func Test_FluentBitConfig_RenderMainConfigYaml(t *testing.T) {

headers := map[string]string{}

headers["Authorization"] = "foo:bar"
headers["X-Log-Header-App-Name"] = "app_name"
headers["X-Log-Header-0"] = "testing"
headers["X-Log-Header-App-ID"] = "9780495d9db3"
headers["Authorization"] = authorization
headers["X-Log-Header-App-Name"] = xLogHeaderAppName
headers["X-Log-Header-0"] = xLogHeader0
headers["X-Log-Header-App-ID"] = xLogHeaderAppID

httpOutput := ClusterOutput{
TypeMeta: metav1.TypeMeta{
Expand Down
6 changes: 6 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/output/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package output

const (
header = "header"
addLabel = "add_label"
)
2 changes: 1 addition & 1 deletion apis/fluentbit/v1alpha2/plugins/output/http_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (h *HTTP) Params(sl plugins.SecretLoader) (*params.KVs, error) {
kvs.Insert("header_tag", h.HeaderTag)
}
kvs.InsertStringMap(h.Headers, func(k, v string) (string, string) {
return "header", fmt.Sprintf(" %s %s", k, v)
return header, fmt.Sprintf(" %s %s", k, v)
})
if h.JsonDateKey != "" {
kvs.Insert("json_date_key", h.JsonDateKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func (o *OpenTelemetry) Params(sl plugins.SecretLoader) (*params.KVs, error) {
kvs.Insert("traces_uri", o.TracesUri)
}
kvs.InsertStringMap(o.Header, func(k, v string) (string, string) {
return "header", fmt.Sprintf(" %s %s", k, v)
return header, fmt.Sprintf(" %s %s", k, v)
})
if o.LogResponsePayload != nil {
kvs.Insert("log_response_payload", fmt.Sprint(*o.LogResponsePayload))
}
kvs.InsertStringMap(o.AddLabel, func(k, v string) (string, string) {
return "add_label", fmt.Sprintf(" %s %s", k, v)
return addLabel, fmt.Sprintf(" %s %s", k, v)
})
if o.LogsBodyKeyAttributes != nil {
kvs.Insert("logs_body_key_attributes", fmt.Sprint(*o.LogsBodyKeyAttributes))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func TestOpenTelemetry_Params(t *testing.T) {
expected.Insert("metrics_uri", "expected_metrics_uri")
expected.Insert("logs_uri", "expected_logs_uri")
expected.Insert("traces_uri", "expected_traces_uri")
expected.Insert("header", " custom_header_key custom_header_val")
expected.Insert(header, " custom_header_key custom_header_val")
expected.Insert("log_response_payload", "true")
expected.Insert("add_label", " add_label_key add_label_val")
expected.Insert(addLabel, " add_label_key add_label_val")
expected.Insert("logs_body_key_attributes", "true")
expected.Insert("logs_body_key", "expected_logs_body_key")
expected.Insert("tls", "On")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (p *PrometheusExporter) Params(sl plugins.SecretLoader) (*params.KVs, error
kvs.Insert("port", fmt.Sprint(*p.Port))
}
kvs.InsertStringMap(p.AddLabels, func(k, v string) (string, string) {
return "add_label", fmt.Sprintf(" %s %s", k, v)
return addLabel, fmt.Sprintf(" %s %s", k, v)
})
return kvs, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,14 @@ func (p *PrometheusRemoteWrite) Params(sl plugins.SecretLoader) (*params.KVs, er
kvs.Insert("uri", p.URI)
}
kvs.InsertStringMap(p.Headers, func(k, v string) (string, string) {
return "header", fmt.Sprintf(" %s %s", k, v)
return header, fmt.Sprintf(" %s %s", k, v)
})

if p.LogResponsePayload != nil {
kvs.Insert("log_response_payload", fmt.Sprint(*p.LogResponsePayload))
}
kvs.InsertStringMap(p.AddLabels, func(k, v string) (string, string) {
return "add_label", fmt.Sprintf(" %s %s", k, v)
return addLabel, fmt.Sprintf(" %s %s", k, v)
})
if p.Workers != nil {
kvs.Insert("workers", fmt.Sprint(*p.Workers))
Expand Down