Skip to content

Commit ca91c14

Browse files
committed
chore: fix rdkafka options tests
Signed-off-by: Peter Wilcsinszky <peter.wilcsinszky@axoflow.com>
1 parent 766970f commit ca91c14

File tree

4 files changed

+36
-6
lines changed

4 files changed

+36
-6
lines changed

docs/configuration/plugins/outputs/kafka.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ Password when using PLAIN/SCRAM SASL authentication
184184
### principal (string, optional) {#kafka-principal}
185185
186186
187-
### rdkafka_options (RdkafkaOptions, optional) {#kafka-rdkafka_options}
187+
### rdkafka_options (*RdkafkaOptions, optional) {#kafka-rdkafka_options}
188+
189+
RdkafkaOptions represents the global configuration properties for librdkafka.
188190
189191
190192
### required_acks (int, optional) {#kafka-required_acks}

pkg/sdk/logging/model/output/kafka.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ type _metaKafka interface{} //nolint:deadcode,unused
6565
// -[more info](https://github.com/fluent/fluent-plugin-kafka#output-plugin)
6666
type KafkaOutputConfig struct {
6767
// Use rdkafka2 instead of the legacy kafka2 output plugin. This plugin requires fluentd image version v1.16-4.9-full or higher.
68-
UseRdkafka bool `json:"use_rdkafka,omitempty"`
69-
RdkafkaOptions RdkafkaOptions `json:"rdkafka_options,omitempty"`
68+
UseRdkafka bool `json:"use_rdkafka,omitempty"`
69+
// RdkafkaOptions represents the global configuration properties for librdkafka.
70+
RdkafkaOptions *RdkafkaOptions `json:"rdkafka_options,omitempty"`
7071
// The list of all seed brokers, with their host and port information.
7172
Brokers string `json:"brokers"`
7273
// Topic Key (default: "topic")
@@ -362,6 +363,13 @@ func (e *KafkaOutputConfig) ToDirective(secretLoader secret.SecretLoader, id str
362363
} else {
363364
kafka.SubDirectives = append(kafka.SubDirectives, buffer)
364365
}
366+
if e.RdkafkaOptions != nil {
367+
if rdkafkaOptions, err := e.RdkafkaOptions.ToDirective(secretLoader, id); err != nil {
368+
return nil, err
369+
} else {
370+
kafka.SubDirectives = append(kafka.SubDirectives, rdkafkaOptions)
371+
}
372+
}
365373

366374
if e.Format != nil {
367375
if format, err := e.Format.ToDirective(secretLoader, ""); err != nil {
@@ -375,3 +383,9 @@ func (e *KafkaOutputConfig) ToDirective(secretLoader secret.SecretLoader, id str
375383
delete(kafka.Params, "use_rdkafka")
376384
return kafka, nil
377385
}
386+
387+
func (o *RdkafkaOptions) ToDirective(secretLoader secret.SecretLoader, id string) (types.Directive, error) {
388+
return types.NewFlatDirective(types.PluginMeta{
389+
Directive: "rdkafka_options",
390+
}, o, secretLoader)
391+
}

pkg/sdk/logging/model/output/kafka_test.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ package output_test
1717
import (
1818
"testing"
1919

20-
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/output"
21-
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/render"
2220
"github.com/stretchr/testify/require"
2321
"sigs.k8s.io/yaml"
22+
23+
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/output"
24+
"github.com/kube-logging/logging-operator/pkg/sdk/logging/model/render"
2425
)
2526

2627
func TestKafka(t *testing.T) {
@@ -99,6 +100,15 @@ buffer:
99100
timekey_use_utc true
100101
timekey_wait 30s
101102
</buffer>
103+
<rdkafka_options>
104+
sasl.mechanisms PLAIN
105+
sasl.username user
106+
security.protocol SASL_SSL
107+
ssl.ca.location /etc/ssl/certs/ca-certificates.crt
108+
ssl.certificate.location /etc/ssl/certs/tls.crt
109+
ssl.key.location /etc/ssl/certs/tls.key
110+
ssl.key.password password
111+
</rdkafka_options>
102112
<format>
103113
@type json
104114
</format>

pkg/sdk/logging/model/output/zz_generated.deepcopy.go

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)