-
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
Add support for kafka 2.0.0 #8399
Changes from 6 commits
cc0e4f6
02bc9f6
094568e
fd424ec
3795248
b170ab5
1af7fc2
12b8051
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 |
---|---|---|
|
@@ -17,7 +17,16 @@ | |
|
||
package kafka | ||
|
||
import "github.com/Shopify/sarama" | ||
import ( | ||
"fmt" | ||
|
||
"github.com/Shopify/sarama" | ||
) | ||
|
||
// Version is a kafka version | ||
type Version struct { | ||
String 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. We could have the same features of the validation by using 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. Agree, changed |
||
|
||
// TODO: remove me. | ||
// Compat version overwrite for missing versions in sarama | ||
|
@@ -31,8 +40,6 @@ var ( | |
v1_1_1 = parseKafkaVersion("1.1.1") | ||
|
||
kafkaVersions = map[string]sarama.KafkaVersion{ | ||
"": sarama.V1_0_0_0, | ||
|
||
"0.8.2.0": sarama.V0_8_2_0, | ||
"0.8.2.1": sarama.V0_8_2_1, | ||
"0.8.2.2": sarama.V0_8_2_2, | ||
|
@@ -68,6 +75,10 @@ var ( | |
"1.1.1": v1_1_1, | ||
"1.1": v1_1_1, | ||
"1": v1_1_1, | ||
|
||
"2.0.0": sarama.V2_0_0_0, | ||
"2.0": sarama.V2_0_0_0, | ||
"2": sarama.V2_0_0_0, | ||
} | ||
) | ||
|
||
|
@@ -78,3 +89,29 @@ func parseKafkaVersion(s string) sarama.KafkaVersion { | |
} | ||
return v | ||
} | ||
|
||
// Validate that a kafka version is among the possible options | ||
func (v *Version) Validate() error { | ||
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. exported method Version.Validate should have comment or be unexported |
||
if _, ok := kafkaVersions[v.String]; !ok { | ||
return fmt.Errorf("unknown/unsupported kafka vesion '%v'", v.String) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// Unpack a kafka version | ||
func (v *Version) Unpack(s string) error { | ||
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. exported method Version.Unpack should have comment or be unexported |
||
tmp := Version{s} | ||
if err := tmp.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
*v = tmp | ||
return nil | ||
} | ||
|
||
// Get a sarama kafka version | ||
func (v *Version) Get() (sarama.KafkaVersion, bool) { | ||
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. exported method Version.Get should have comment or be unexported |
||
kv, ok := kafkaVersions[v.String] | ||
return kv, ok | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ import ( | |
|
||
"github.com/elastic/beats/libbeat/common" | ||
"github.com/elastic/beats/libbeat/common/fmtstr" | ||
"github.com/elastic/beats/libbeat/common/kafka" | ||
"github.com/elastic/beats/libbeat/common/transport/tlscommon" | ||
"github.com/elastic/beats/libbeat/logp" | ||
"github.com/elastic/beats/libbeat/monitoring" | ||
|
@@ -48,7 +49,7 @@ type kafkaConfig struct { | |
BrokerTimeout time.Duration `config:"broker_timeout" validate:"min=1"` | ||
Compression string `config:"compression"` | ||
CompressionLevel int `config:"compression_level"` | ||
Version string `config:"version"` | ||
Version kafka.Version `config:"version"` | ||
BulkMaxSize int `config:"bulk_max_size"` | ||
MaxRetries int `config:"max_retries" validate:"min=-1,nonzero"` | ||
ClientID string `config:"client_id"` | ||
|
@@ -96,7 +97,7 @@ func defaultConfig() kafkaConfig { | |
BrokerTimeout: 10 * time.Second, | ||
Compression: "gzip", | ||
CompressionLevel: 4, | ||
Version: "1.0.0", | ||
Version: kafka.Version{String: "1.0.0"}, | ||
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. +1 to have the default previous behavior, I was looking into that. |
||
MaxRetries: 3, | ||
ClientID: "beats", | ||
ChanBufferSize: 256, | ||
|
@@ -114,8 +115,8 @@ func (c *kafkaConfig) Validate() error { | |
return fmt.Errorf("compression mode '%v' unknown", c.Compression) | ||
} | ||
|
||
if _, ok := kafkaVersions[c.Version]; !ok { | ||
return fmt.Errorf("unknown/unsupported kafka version '%v'", c.Version) | ||
if err := c.Version.Validate(); err != nil { | ||
return err | ||
} | ||
|
||
if c.Username != "" && c.Password == "" { | ||
|
@@ -200,7 +201,7 @@ func newSaramaConfig(config *kafkaConfig) (*sarama.Config, error) { | |
// configure client ID | ||
k.ClientID = config.ClientID | ||
|
||
version, ok := kafkaVersions[config.Version] | ||
version, ok := config.Version.Get() | ||
if !ok { | ||
return nil, fmt.Errorf("Unknown/unsupported kafka version: %v", config.Version) | ||
} | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ ENV KAFKA_HOME /kafka | |
# The advertised host is kafka. This means it will not work if container is started locally and connected from localhost to it | ||
ENV KAFKA_ADVERTISED_HOST kafka | ||
ENV KAFKA_LOGS_DIR="/kafka-logs" | ||
ENV KAFKA_VERSION 1.1.1 | ||
ENV KAFKA_VERSION 2.0.0 | ||
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. thanks for updating this! 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. It would be still pending to test the output with multiple versions, but I leave this for a future change, maybe related with #7957 |
||
ENV _JAVA_OPTIONS "-Djava.net.preferIPv4Stack=true" | ||
ENV TERM=linux | ||
|
||
|
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.
exported type Version should have comment or be unexported