-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enhance kafka topic selection #2188
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,8 +14,6 @@ type kafkaConfig struct { | |
TLS *outputs.TLSConfig `config:"tls"` | ||
Timeout time.Duration `config:"timeout" validate:"min=1"` | ||
Worker int `config:"worker" validate:"min=1"` | ||
UseType bool `config:"use_type"` | ||
Topic string `config:"topic"` | ||
KeepAlive time.Duration `config:"keep_alive" validate:"min=0"` | ||
MaxMessageBytes *int `config:"max_message_bytes" validate:"min=1"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Topic still exist, don't we need it here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, Topic still exists, but not required here. |
||
RequiredACKs *int `config:"required_acks" validate:"min=-1"` | ||
|
@@ -32,8 +30,6 @@ var ( | |
TLS: nil, | ||
Timeout: 30 * time.Second, | ||
Worker: 1, | ||
UseType: false, | ||
Topic: "", | ||
KeepAlive: 0, | ||
MaxMessageBytes: nil, // use library default | ||
RequiredACKs: nil, // use library default | ||
|
@@ -50,10 +46,6 @@ func (c *kafkaConfig) Validate() error { | |
return errors.New("no hosts configured") | ||
} | ||
|
||
if c.UseType == false && c.Topic == "" { | ||
return errors.New("use_type must be true or topic must be set") | ||
} | ||
|
||
if _, ok := compressionModes[strings.ToLower(c.Compression)]; !ok { | ||
return fmt.Errorf("compression mode '%v' unknown", c.Compression) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ import ( | |
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/outputs" | ||
"github.com/elastic/beats/libbeat/outputs/outil" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
|
@@ -47,7 +48,8 @@ func newTestKafkaClient(t *testing.T, topic string) *client { | |
hosts := []string{getTestKafkaHost()} | ||
t.Logf("host: %v", hosts) | ||
|
||
client, err := newKafkaClient(hosts, topic, false, nil) | ||
sel := outil.MakeSelector(outil.ConstSelectorExpr(topic)) | ||
client, err := newKafkaClient(hosts, sel, nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
@@ -57,11 +59,13 @@ func newTestKafkaClient(t *testing.T, topic string) *client { | |
|
||
func newTestKafkaOutput(t *testing.T, topic string, useType bool) outputs.Outputer { | ||
|
||
if useType { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this to test BC compatibility? I assume it is just a simplification to keep the tests the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use_type has been removed from config. This is in order to keep the tests working without much change, as some tests use the event |
||
topic = "%{[type]}" | ||
} | ||
config := map[string]interface{}{ | ||
"hosts": []string{getTestKafkaHost()}, | ||
"timeout": "1s", | ||
"topic": topic, | ||
"use_type": useType, | ||
"hosts": []string{getTestKafkaHost()}, | ||
"timeout": "1s", | ||
"topic": topic, | ||
} | ||
|
||
cfg, err := common.NewConfigFrom(config) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -405,14 +405,10 @@ output.elasticsearch: | |
# to. | ||
#hosts: ["localhost:9092"] | ||
|
||
# The Kafka topic used for produced events. If use_type is set to true, the | ||
# topic will not be used. | ||
# The Kafka topic used for produced events. The setting can be a format string | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we already have some docs about how to use format string? If not, we should definitively create an issue for it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. see #2132 |
||
# using any event field. To set the topic from document type use `%{[type]}`. | ||
#topic: beats | ||
|
||
# Set Kafka topic by event type. If use_type is false, the topic option must | ||
# be configured. The default is false. | ||
#use_type: false | ||
|
||
# The number of concurrent load-balanced Kafka output workers. | ||
#worker: 1 | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should type be our default recommendation? Bringing up as we had recently some discussion around type. Perhaps better use beat.name by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Default recommendation should be a static string (we do not set any default and require user to set the topic name). type is commonly used with filebeat + multiple prospectors setting document_type.