Skip to content

Commit 1851dc8

Browse files
authored
Merge pull request #2190 from urso/upd/sarama-v1.10.0
Update to sarama v1.10.0
2 parents 6c2e3c9 + 44da82f commit 1851dc8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1414
-325
lines changed

CHANGELOG.asciidoc

+6-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ https://github.com/elastic/beats/compare/v5.0.0-alpha5...master[Check the HEAD d
5353
- Configurable redis `keys` using filters and format strings. {pull}2169[2169]
5454
- Add format string support to `output.kafka.topic`. {pull}2188[2188]
5555
- Add `output.kafka.topics` for more advanced kafka topic selection per event. {pull}2188[2188]
56-
56+
- Add support for kafka 0.10.
57+
- Add support for kafka 0.10. {pull}2190[2190]
58+
- Add SASL/PLAIN authentication support to kafka output. {pull}2190[2190]
59+
- Make Kafka metadata update configurable. {pull}2190[2190]
60+
- Add kafka version setting (optional) enabling kafka broker version support. {pull}2190[2190]
61+
- Add kafka message timestamp if at least version 0.10 is configured. {pull}2190[2190]
5762

5863
*Metricbeat*
5964

filebeat/filebeat.full.yml

+21
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,27 @@ output.elasticsearch:
487487
# using any event field. To set the topic from document type use `%{[type]}`.
488488
#topic: beats
489489

490+
# Authentication details. Password is required if username is set.
491+
#username: ''
492+
#password: ''
493+
494+
# Kafka version filebeat is assumed to run against. Defaults to the oldest
495+
# supported stable version (currently version 0.8.2.0)
496+
#version: 0.8.2
497+
498+
# Metadata update configuration. Metadata do contain leader information
499+
# deciding which broker to use when publishing.
500+
#metadata:
501+
# Max metadata request retry attempts when cluster is in middle of leader
502+
# election. Defaults to 3 retries.
503+
#retry.max: 3
504+
505+
# Waiting time between retries during leader elections. Default is 250ms.
506+
#retry.backoff: 250ms
507+
508+
# Refresh metadata interval. Defaults to every 10 minutes.
509+
#refresh_frequency: 10m
510+
490511
# The number of concurrent load-balanced Kafka output workers.
491512
#worker: 1
492513

glide.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ import:
5959
- package: github.com/miekg/dns
6060
version: 5d001d020961ae1c184f9f8152fdc73810481677
6161
- package: github.com/Shopify/sarama
62-
version: v1.9.0
62+
version: v1.10.0
6363
- package: github.com/klauspost/crc32
6464
version: v1.0
6565
- package: github.com/golang/snappy
6666
version: d9eb7a3d35ec988b8585d4a0068e462c27d28380
67+
- package: github.com/eapache/go-xerial-snappy
68+
version: bb955e01b9346ac19dc29eb16586c90ded99a98c
6769
- package: github.com/eapache/queue
6870
version: ded5959c0d4e360646dc9e9908cff48666781367
6971
- package: github.com/eapache/go-resiliency

libbeat/_meta/config.full.yml

+21
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,27 @@ output.elasticsearch:
261261
# using any event field. To set the topic from document type use `%{[type]}`.
262262
#topic: beats
263263

264+
# Authentication details. Password is required if username is set.
265+
#username: ''
266+
#password: ''
267+
268+
# Kafka version beatname is assumed to run against. Defaults to the oldest
269+
# supported stable version (currently version 0.8.2.0)
270+
#version: 0.8.2
271+
272+
# Metadata update configuration. Metadata do contain leader information
273+
# deciding which broker to use when publishing.
274+
#metadata:
275+
# Max metadata request retry attempts when cluster is in middle of leader
276+
# election. Defaults to 3 retries.
277+
#retry.max: 3
278+
279+
# Waiting time between retries during leader elections. Default is 250ms.
280+
#retry.backoff: 250ms
281+
282+
# Refresh metadata interval. Defaults to every 10 minutes.
283+
#refresh_frequency: 10m
284+
264285
# The number of concurrent load-balanced Kafka output workers.
265286
#worker: 1
266287

libbeat/docs/outputconfig.asciidoc

+29
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,24 @@ The default value is true.
541541
The list of Kafka broker addresses from where to fetch the cluster metadata.
542542
The cluster metadata contain the actual Kafka brokers events are published to.
543543

544+
===== version
545+
546+
Kafka version ${beatname_lc} is assumed to run against. Defaults to oldest
547+
supported stable version (currently version 0.8.2.0).
548+
549+
Event timestamps will be added, if version 0.10.0.0+ is enabled.
550+
551+
Valid values are `0.8.2.0`, `0.8.2.1`, `0.8.2.2`, `0.8.2`, `0.8`, `0.9.0.0`,
552+
`0.9.0.1`, `0.9.0`, `0.9`, `0.10.0.0`, `0.10.0`, and `0.10`.
553+
554+
===== username
555+
556+
The username for connecting to Kafka. If username is configured, the passowrd must be configured as well. Only SASL/PLAIN is supported.
557+
558+
===== password
559+
560+
The password for connecting to Kafka.
561+
544562
===== topic
545563

546564
The Kafka topic used for produced events. The setting can be a format string
@@ -554,6 +572,17 @@ The configurable ClientID used for logging, debugging, and auditing purposes. Th
554572

555573
The number of concurrent load-balanced Kafka output workers.
556574

575+
===== metadata
576+
577+
Kafka metadata update settings. The metadata do contain information about
578+
brokers, topics, partition, and active leaders to use for publishing.
579+
580+
*`refresh_frequency`*:: Metadata refreash interval. Defaults to 10 minutes.
581+
582+
*`retry.max`*:: Total number of metadata update retries when cluster is in middle of leader election. The default is 3.
583+
584+
*`retry.backoff`*:: Waiting time between retries during leader elections. Default is 250ms.
585+
557586
===== max_retries
558587

559588
The number of times to retry publishing an event after a publishing failure.

libbeat/outputs/kafka/client.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -108,16 +108,30 @@ func (c *client) AsyncPublishEvents(
108108
for _, event := range events {
109109
topic, err := c.topic.Select(event)
110110

111+
var ts time.Time
112+
113+
// message timestamps have been added to kafka with version 0.10.0.0
114+
if c.config.Version.IsAtLeast(sarama.V0_10_0_0) {
115+
if tsRaw, ok := event["@timestamp"]; ok {
116+
if tmp, ok := tsRaw.(common.Time); ok {
117+
ts = time.Time(tmp)
118+
} else if tmp, ok := tsRaw.(time.Time); ok {
119+
ts = tmp
120+
}
121+
}
122+
}
123+
111124
jsonEvent, err := json.Marshal(event)
112125
if err != nil {
113126
ref.done()
114127
continue
115128
}
116129

117130
msg := &sarama.ProducerMessage{
118-
Metadata: ref,
119-
Topic: topic,
120-
Value: sarama.ByteEncoder(jsonEvent),
131+
Metadata: ref,
132+
Topic: topic,
133+
Value: sarama.ByteEncoder(jsonEvent),
134+
Timestamp: ts,
121135
}
122136

123137
ch <- msg

libbeat/outputs/kafka/config.go

+36-4
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,54 @@ type kafkaConfig struct {
1414
TLS *outputs.TLSConfig `config:"tls"`
1515
Timeout time.Duration `config:"timeout" validate:"min=1"`
1616
Worker int `config:"worker" validate:"min=1"`
17+
Metadata metaConfig `config:"metadata"`
1718
KeepAlive time.Duration `config:"keep_alive" validate:"min=0"`
1819
MaxMessageBytes *int `config:"max_message_bytes" validate:"min=1"`
1920
RequiredACKs *int `config:"required_acks" validate:"min=-1"`
2021
BrokerTimeout time.Duration `config:"broker_timeout" validate:"min=1"`
2122
Compression string `config:"compression"`
23+
Version string `config:"version"`
2224
MaxRetries int `config:"max_retries" validate:"min=-1,nonzero"`
2325
ClientID string `config:"client_id"`
2426
ChanBufferSize int `config:"channel_buffer_size" validate:"min=1"`
27+
Username string `config:"username"`
28+
Password string `config:"password"`
29+
}
30+
31+
type metaConfig struct {
32+
Retry metaRetryConfig `config:"retry"`
33+
RefreshFreq time.Duration `config:"refresh_frequency" validate:"min=0"`
34+
}
35+
36+
type metaRetryConfig struct {
37+
Max int `config:"max" validate:"min=0"`
38+
Backoff time.Duration `config:"backoff" validate:"min=0"`
2539
}
2640

2741
var (
2842
defaultConfig = kafkaConfig{
29-
Hosts: nil,
30-
TLS: nil,
31-
Timeout: 30 * time.Second,
32-
Worker: 1,
43+
Hosts: nil,
44+
TLS: nil,
45+
Timeout: 30 * time.Second,
46+
Worker: 1,
47+
Metadata: metaConfig{
48+
Retry: metaRetryConfig{
49+
Max: 3,
50+
Backoff: 250 * time.Millisecond,
51+
},
52+
RefreshFreq: 10 * time.Minute,
53+
},
3354
KeepAlive: 0,
3455
MaxMessageBytes: nil, // use library default
3556
RequiredACKs: nil, // use library default
3657
BrokerTimeout: 10 * time.Second,
3758
Compression: "gzip",
59+
Version: "",
3860
MaxRetries: 3,
3961
ClientID: "beats",
4062
ChanBufferSize: 256,
63+
Username: "",
64+
Password: "",
4165
}
4266
)
4367

@@ -50,5 +74,13 @@ func (c *kafkaConfig) Validate() error {
5074
return fmt.Errorf("compression mode '%v' unknown", c.Compression)
5175
}
5276

77+
if _, ok := kafkaVersions[c.Version]; !ok {
78+
return fmt.Errorf("unknown/unsupported kafka version '%v'", c.Version)
79+
}
80+
81+
if c.Username != "" && c.Password == "" {
82+
return fmt.Errorf("password must be set when username is configured")
83+
}
84+
5385
return nil
5486
}

libbeat/outputs/kafka/kafka.go

+37-2
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,25 @@ var (
5353
"gzip": sarama.CompressionGZIP,
5454
"snappy": sarama.CompressionSnappy,
5555
}
56+
57+
kafkaVersions = map[string]sarama.KafkaVersion{
58+
"": sarama.V0_8_2_0,
59+
60+
"0.8.2.0": sarama.V0_8_2_0,
61+
"0.8.2.1": sarama.V0_8_2_1,
62+
"0.8.2.2": sarama.V0_8_2_2,
63+
"0.8.2": sarama.V0_8_2_2,
64+
"0.8": sarama.V0_8_2_2,
65+
66+
"0.9.0.0": sarama.V0_9_0_0,
67+
"0.9.0.1": sarama.V0_9_0_1,
68+
"0.9.0": sarama.V0_9_0_1,
69+
"0.9": sarama.V0_9_0_1,
70+
71+
"0.10.0.0": sarama.V0_10_0_0,
72+
"0.10.0": sarama.V0_10_0_0,
73+
"0.10": sarama.V0_10_0_0,
74+
}
5675
)
5776

5877
// New instantiates a new kafka output instance.
@@ -211,8 +230,16 @@ func newKafkaConfig(config *kafkaConfig) (*sarama.Config, error) {
211230
k.Net.TLS.Enable = tls != nil
212231
k.Net.TLS.Config = tls
213232

214-
// TODO: configure metadata level properties
215-
// use lib defaults
233+
if config.Username != "" {
234+
k.Net.SASL.Enable = true
235+
k.Net.SASL.User = config.Username
236+
k.Net.SASL.Password = config.Password
237+
}
238+
239+
// configure metadata update properties
240+
k.Metadata.Retry.Max = config.Metadata.Retry.Max
241+
k.Metadata.Retry.Backoff = config.Metadata.Retry.Backoff
242+
k.Metadata.RefreshFrequency = config.Metadata.RefreshFreq
216243

217244
// configure producer API properties
218245
if config.MaxMessageBytes != nil {
@@ -237,6 +264,7 @@ func newKafkaConfig(config *kafkaConfig) (*sarama.Config, error) {
237264
retryMax = 1000
238265
}
239266
k.Producer.Retry.Max = retryMax
267+
// TODO: k.Producer.Retry.Backoff = ?
240268

241269
// configure per broker go channel buffering
242270
k.ChannelBufferSize = config.ChanBufferSize
@@ -247,5 +275,12 @@ func newKafkaConfig(config *kafkaConfig) (*sarama.Config, error) {
247275
logp.Err("Invalid kafka configuration: %v", err)
248276
return nil, err
249277
}
278+
279+
version, ok := kafkaVersions[config.Version]
280+
if !ok {
281+
return nil, fmt.Errorf("Unknown/unsupported kafka version: %v", config.Version)
282+
}
283+
k.Version = version
284+
250285
return k, nil
251286
}

metricbeat/metricbeat.full.yml

+21
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,27 @@ output.elasticsearch:
409409
# using any event field. To set the topic from document type use `%{[type]}`.
410410
#topic: beats
411411

412+
# Authentication details. Password is required if username is set.
413+
#username: ''
414+
#password: ''
415+
416+
# Kafka version metricbeat is assumed to run against. Defaults to the oldest
417+
# supported stable version (currently version 0.8.2.0)
418+
#version: 0.8.2
419+
420+
# Metadata update configuration. Metadata do contain leader information
421+
# deciding which broker to use when publishing.
422+
#metadata:
423+
# Max metadata request retry attempts when cluster is in middle of leader
424+
# election. Defaults to 3 retries.
425+
#retry.max: 3
426+
427+
# Waiting time between retries during leader elections. Default is 250ms.
428+
#retry.backoff: 250ms
429+
430+
# Refresh metadata interval. Defaults to every 10 minutes.
431+
#refresh_frequency: 10m
432+
412433
# The number of concurrent load-balanced Kafka output workers.
413434
#worker: 1
414435

packetbeat/packetbeat.full.yml

+21
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,27 @@ output.elasticsearch:
679679
# using any event field. To set the topic from document type use `%{[type]}`.
680680
#topic: beats
681681

682+
# Authentication details. Password is required if username is set.
683+
#username: ''
684+
#password: ''
685+
686+
# Kafka version packetbeat is assumed to run against. Defaults to the oldest
687+
# supported stable version (currently version 0.8.2.0)
688+
#version: 0.8.2
689+
690+
# Metadata update configuration. Metadata do contain leader information
691+
# deciding which broker to use when publishing.
692+
#metadata:
693+
# Max metadata request retry attempts when cluster is in middle of leader
694+
# election. Defaults to 3 retries.
695+
#retry.max: 3
696+
697+
# Waiting time between retries during leader elections. Default is 250ms.
698+
#retry.backoff: 250ms
699+
700+
# Refresh metadata interval. Defaults to every 10 minutes.
701+
#refresh_frequency: 10m
702+
682703
# The number of concurrent load-balanced Kafka output workers.
683704
#worker: 1
684705

vendor/github.com/Shopify/sarama/.github/ISSUE_TEMPLATE.md

+19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)