Skip to content

Commit

Permalink
set MaxMessageBytes for sarama producer (#588)
Browse files Browse the repository at this point in the history
* set MaxMessageBytes for sarama producer

* fix lint emptyStringTest

* small fix in kafka params doc
  • Loading branch information
DmitryRomanov committed Feb 29, 2024
1 parent 5a3d4d1 commit 8f3cbe4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
9 changes: 5 additions & 4 deletions e2e/kafka_auth/kafka_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,11 @@ func (c *Config) Configure(t *testing.T, _ *cfg.Config, _ string) {
testFns := []func(){
func() {
config := &kafka_out.Config{
Brokers: c.Brokers,
DefaultTopic: outTopic,
ClientID: "test-auth-out",
BatchSize_: 10,
Brokers: c.Brokers,
DefaultTopic: outTopic,
ClientID: "test-auth-out",
BatchSize_: 10,
MaxMessageBytes_: 1000000,
}
if tt.sasl.Enabled {
config.SaslEnabled = true
Expand Down
2 changes: 1 addition & 1 deletion fd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func extractConditions(condJSON *simplejson.Json) (pipeline.MatchConditions, err
}

if value, ok := obj.(string); ok {
if len(value) > 0 && value[0] == '/' {
if value != "" && value[0] == '/' {
r, err := cfg.CompileRegex(value)
if err != nil {
return nil, fmt.Errorf("can't compile regexp %s: %w", value, err)
Expand Down
2 changes: 1 addition & 1 deletion plugin/action/convert_utf8_bytes/convert_utf8_bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func (p *Plugin) convert(node *insaneJSON.Node) {
p.buf = append(p.buf, nodeStr[:idx]...)
nodeStr = nodeStr[idx+1:]

for len(nodeStr) > 0 {
for nodeStr != "" {
ch := nodeStr[0]
switch ch {
case '\\':
Expand Down
7 changes: 7 additions & 0 deletions plugin/output/kafka/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ After this timeout the batch will be sent even if batch isn't full.

<br>

**`max_message_bytes`** *`cfg.Expression`* *`default=1000000`*

The maximum permitted size of a message.
Should be set equal to or smaller than the broker's `message.max.bytes`.

<br>

**`retry`** *`int`* *`default=10`*

Retries of insertion. If File.d cannot insert for this number of attempts,
Expand Down
8 changes: 8 additions & 0 deletions plugin/output/kafka/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ type Config struct {
BatchFlushTimeout cfg.Duration `json:"batch_flush_timeout" default:"200ms" parse:"duration"` // *
BatchFlushTimeout_ time.Duration

// > @3@4@5@6
// >
// > The maximum permitted size of a message.
// > Should be set equal to or smaller than the broker's `message.max.bytes`.
MaxMessageBytes cfg.Expression `json:"max_message_bytes" default:"1000000" parse:"expression"` // *
MaxMessageBytes_ int

// > @3@4@5@6
// >
// > Retries of insertion. If File.d cannot insert for this number of attempts,
Expand Down Expand Up @@ -321,6 +328,7 @@ func NewProducer(c *Config, l *zap.SugaredLogger) sarama.SyncProducer {
config.Net.TLS.Config = tlsCfg.Build()
}

config.Producer.MaxMessageBytes = c.MaxMessageBytes_
config.Producer.Partitioner = sarama.NewRoundRobinPartitioner
config.Producer.Flush.Messages = c.BatchSize_
// kafka plugin itself cares for flush frequency, but we are using batcher so disable it.
Expand Down

0 comments on commit 8f3cbe4

Please sign in to comment.