@@ -33,12 +33,13 @@ var linesRead = prometheus.NewCounterVec(
33
33
[]string {"topic" })
34
34
35
35
type KafkaConfiguration struct {
36
- Brokers []string `yaml:"brokers"`
37
- Topic string `yaml:"topic"`
38
- GroupID string `yaml:"group_id"`
39
- Partition int `yaml:"partition"`
40
- Timeout string `yaml:"timeout"`
41
- TLS * TLSConfig `yaml:"tls"`
36
+ Brokers []string `yaml:"brokers"`
37
+ Topic string `yaml:"topic"`
38
+ GroupID string `yaml:"group_id"`
39
+ Partition int `yaml:"partition"`
40
+ Timeout string `yaml:"timeout"`
41
+ TLS * TLSConfig `yaml:"tls"`
42
+ BatchConfiguration KafkaBatchConfiguration `yaml:"batch"`
42
43
configuration.DataSourceCommonCfg `yaml:",inline"`
43
44
}
44
45
@@ -49,6 +50,14 @@ type TLSConfig struct {
49
50
CaCert string `yaml:"ca_cert"`
50
51
}
51
52
53
+ type KafkaBatchConfiguration struct {
54
+ BatchMinBytes int `yaml:"min_bytes"`
55
+ BatchMaxBytes int `yaml:"max_bytes"`
56
+ BatchMaxWait time.Duration `yaml:"max_wait"`
57
+ BatchQueueSize int `yaml:"queue_size"`
58
+ CommitInterval time.Duration `yaml:"commit_interval"`
59
+ }
60
+
52
61
type KafkaSource struct {
53
62
metricsLevel int
54
63
Config KafkaConfiguration
@@ -294,6 +303,22 @@ func (kc *KafkaConfiguration) NewReader(dialer *kafka.Dialer, logger *log.Entry)
294
303
logger .Warnf ("no group_id specified, crowdsec will only read from the 1st partition of the topic" )
295
304
}
296
305
306
+ if kc .BatchConfiguration .BatchMinBytes != 0 {
307
+ rConf .MinBytes = kc .BatchConfiguration .BatchMinBytes
308
+ }
309
+ if kc .BatchConfiguration .BatchMaxBytes != 0 {
310
+ rConf .MaxBytes = kc .BatchConfiguration .BatchMaxBytes
311
+ }
312
+ if kc .BatchConfiguration .BatchMaxWait != 0 {
313
+ rConf .MaxWait = kc .BatchConfiguration .BatchMaxWait
314
+ }
315
+ if kc .BatchConfiguration .BatchQueueSize != 0 {
316
+ rConf .QueueCapacity = kc .BatchConfiguration .BatchQueueSize
317
+ }
318
+ if kc .BatchConfiguration .CommitInterval != 0 {
319
+ rConf .CommitInterval = kc .BatchConfiguration .CommitInterval
320
+ }
321
+
297
322
if err := rConf .Validate (); err != nil {
298
323
return & kafka.Reader {}, fmt .Errorf ("while validating reader configuration: %w" , err )
299
324
}
0 commit comments