logstash-integration-kafka 10.0.1-java → 10.1.0-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c46d0081cceeb47ad2a3718ab295b38350edbedce2448d6423257b9696d5f4ff
4
- data.tar.gz: 258b4f5bd38c5e4acfa848a23292dd54db45b0bc77dbf473821eb4caa228294c
3
+ metadata.gz: 254abccf066d63d45cf0660dafa06b603c97fb5557c1f978ecc41b41078c6ead
4
+ data.tar.gz: a6bcb799f703db46d80a4412f35809b7a7d13bcdf8eaf91e12ef06befc700a93
5
5
  SHA512:
6
- metadata.gz: a8ee6bb607a1636544679a647f1ed20d0ed5d022dcad5af08297b016cd19dc5a01251b2a00e9c5fe984df6bb5c4d9ec831113e94ce3a6c84503caaf966d12491
7
- data.tar.gz: 8d315bdf003dbb5b4c9bd0af488426c3f8a84d5aebf9084728fda9f62ac2f8a269c563750f4be5cf4ab51befb372c80f4d91717396c9a8e9a3682e2c314ecbee
6
+ metadata.gz: 9551a410f21e1015e56ebd2d2881d75c1eb3d13e5a3aff609e98ac4111376764bcc1978612bb9b239b2335757e129897a94be69bac02d996dfbf31d50ffc9614
7
+ data.tar.gz: 106b3fa2816631035f132a4771f4b5776fd9a79811305200d37a1b539a3ba1600079e8b9d9c1ec718ff9a2cecdea9115fb31b2ccd425edfe9097114da7ca752f
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
+ ## 10.1.0
2
+ - updated kafka client (and its dependencies) to version 2.4.1 ([#16](https://github.com/logstash-plugins/logstash-integration-kafka/pull/16))
3
+ - added the input `client_rack` parameter to enable support for follower fetching
4
+ - added the output `partitioner` parameter for tuning partitioning strategy
5
+ - Refactor: normalized error logging a bit - make sure exception type is logged
6
+ - Fix: properly handle empty ssl_endpoint_identification_algorithm [#8](https://github.com/logstash-plugins/logstash-integration-kafka/pull/8)
7
+ - Refactor : made `partition_assignment_strategy` option easier to configure by accepting simple values from an enumerated set instead of requiring lengthy class paths ([#25](https://github.com/logstash-plugins/logstash-integration-kafka/pull/25))
8
+
1
9
  ## 10.0.1
2
10
  - Fix links in changelog pointing to stand-alone plugin changelogs.
3
11
  - Refactor: scope java_import to plugin class
4
12
 
13
+
5
14
  ## 10.0.0
6
15
  - Initial release of the Kafka Integration Plugin, which combines
7
16
  previously-separate Kafka plugins and shared dependencies into a single
data/CONTRIBUTORS CHANGED
@@ -11,6 +11,7 @@ Contributors:
11
11
  * João Duarte (jsvd)
12
12
  * Kurt Hurtado (kurtado)
13
13
  * Ry Biesemeyer (yaauie)
14
+ * Rob Cowart (robcowart)
14
15
 
15
16
  Note: If you've sent us patches, bug reports, or otherwise contributed to
16
17
  Logstash, and you aren't on the list above and want to be, please let us know
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -71,8 +71,7 @@ inserted into your original event, you'll have to use the `mutate` filter to man
71
71
 
72
72
  This plugin supports these configuration options plus the <<plugins-{type}s-{plugin}-common-options>> described later.
73
73
 
74
- NOTE: Some of these options map to a Kafka option. See the
75
- https://kafka.apache.org/documentation for more details.
74
+ NOTE: Some of these options map to a Kafka option. See the https://kafka.apache.org/documentation for more details.
76
75
 
77
76
  [cols="<,<,<",options="header",]
78
77
  |=======================================================================
@@ -122,6 +121,7 @@ https://kafka.apache.org/documentation for more details.
122
121
  | <<plugins-{type}s-{plugin}-topics>> |<<array,array>>|No
123
122
  | <<plugins-{type}s-{plugin}-topics_pattern>> |<<string,string>>|No
124
123
  | <<plugins-{type}s-{plugin}-value_deserializer_class>> |<<string,string>>|No
124
+ | <<plugins-{type}s-{plugin}-client_rack>> |<<string,string>>|No
125
125
  |=======================================================================
126
126
 
127
127
  Also see <<plugins-{type}s-{plugin}-common-options>> for a list of options supported by all
@@ -374,10 +374,16 @@ we haven't seen any partition leadership changes to proactively discover any new
374
374
  * Value type is <<string,string>>
375
375
  * There is no default value for this setting.
376
376
 
377
- The class name of the partition assignment strategy that the client uses to
378
- distribute partition ownership amongst consumer instances. Maps to
379
- the Kafka `partition.assignment.strategy` setting, which defaults to
380
- `org.apache.kafka.clients.consumer.RangeAssignor`.
377
+ The name of the partition assignment strategy that the client uses to distribute
378
+ partition ownership amongst consumer instances, supported options are:
379
+
380
+ * `range`
381
+ * `round_robin`
382
+ * `sticky`
383
+ * `cooperative_sticky`
384
+
385
+ These map to Kafka's corresponding https://kafka.apache.org/24/javadoc/org/apache/kafka/clients/consumer/ConsumerPartitionAssignor.html[`ConsumerPartitionAssignor`]
386
+ implementations.
381
387
 
382
388
  [id="plugins-{type}s-{plugin}-poll_timeout_ms"]
383
389
  ===== `poll_timeout_ms`
@@ -578,6 +584,17 @@ The topics configuration will be ignored when using this configuration.
578
584
  Java Class used to deserialize the record's value
579
585
 
580
586
 
587
+ [id="plugins-{type}s-{plugin}-client_rack"]
588
+ ===== `client_rack`
589
+
590
+ * Value type is <<string,string>>
591
+ * There is no default value for this setting.
592
+
593
+ A rack identifier for the Kafka consumer.
594
+ Used to select the physically closest rack for the consumer to read from.
595
+ The setting corresponds with Kafka's `broker.rack` configuration.
596
+
597
+ NOTE: Only available for Kafka 2.4.0 and higher; see https://cwiki.apache.org/confluence/display/KAFKA/KIP-392%3A+Allow+consumers+to+fetch+from+closest+replica[KIP-392].
581
598
 
582
599
  [id="plugins-{type}s-{plugin}-common-options"]
583
600
  include::{include_path}/{type}.asciidoc[]
@@ -73,6 +73,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
73
73
  | <<plugins-{type}s-{plugin}-message_key>> |<<string,string>>|No
74
74
  | <<plugins-{type}s-{plugin}-metadata_fetch_timeout_ms>> |<<number,number>>|No
75
75
  | <<plugins-{type}s-{plugin}-metadata_max_age_ms>> |<<number,number>>|No
76
+ | <<plugins-{type}s-{plugin}-partitioner>> |<<string,string>>|No
76
77
  | <<plugins-{type}s-{plugin}-receive_buffer_bytes>> |<<number,number>>|No
77
78
  | <<plugins-{type}s-{plugin}-reconnect_backoff_ms>> |<<number,number>>|No
78
79
  | <<plugins-{type}s-{plugin}-request_timeout_ms>> |<<string,string>>|No
@@ -248,6 +249,21 @@ the timeout setting for initial metadata request to fetch topic metadata.
248
249
 
249
250
  the max time in milliseconds before a metadata refresh is forced.
250
251
 
252
+ [id="plugins-{type}s-{plugin}-partitioner"]
253
+ ===== `partitioner`
254
+
255
+ * Value type is <<string,string>>
256
+ * There is no default value for this setting.
257
+
258
+ The default behavior is to hash the `message_key` of an event to get the partition.
259
+ When no message key is present, the plugin picks a partition in a round-robin fashion.
260
+
261
+ Available options for choosing a partitioning strategy are as follows:
262
+
263
+ * `default` use the default partitioner as described above
264
+ * `round_robin` distributes writes to all partitions equally, regardless of `message_key`
265
+ * `uniform_sticky` sticks to a partition for the duration of a batch than randomly picks a new one
266
+
251
267
  [id="plugins-{type}s-{plugin}-receive_buffer_bytes"]
252
268
  ===== `receive_buffer_bytes`
253
269
 
@@ -1,8 +1,8 @@
1
1
  # AUTOGENERATED BY THE GRADLE SCRIPT. DO NOT EDIT.
2
2
 
3
3
  require 'jar_dependencies'
4
- require_jar('org.apache.kafka', 'kafka-clients', '2.3.0')
5
- require_jar('com.github.luben', 'zstd-jni', '1.4.2-1')
6
- require_jar('org.slf4j', 'slf4j-api', '1.7.26')
4
+ require_jar('org.apache.kafka', 'kafka-clients', '2.4.1')
5
+ require_jar('com.github.luben', 'zstd-jni', '1.4.3-1')
6
+ require_jar('org.slf4j', 'slf4j-api', '1.7.28')
7
7
  require_jar('org.lz4', 'lz4-java', '1.6.0')
8
8
  require_jar('org.xerial.snappy', 'snappy-java', '1.1.7.3')
@@ -128,8 +128,10 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
128
128
  # The period of time in milliseconds after which we force a refresh of metadata even if
129
129
  # we haven't seen any partition leadership changes to proactively discover any new brokers or partitions
130
130
  config :metadata_max_age_ms, :validate => :string
131
- # The class name of the partition assignment strategy that the client will use to distribute
132
- # partition ownership amongst consumer instances
131
+ # The name of the partition assignment strategy that the client uses to distribute
132
+ # partition ownership amongst consumer instances, supported options are `range`,
133
+ # `round_robin`, `sticky` and `cooperative_sticky`
134
+ # (for backwards compatibility setting the class name directly is supported).
133
135
  config :partition_assignment_strategy, :validate => :string
134
136
  # The size of the TCP receive buffer (SO_RCVBUF) to use when reading data.
135
137
  config :receive_buffer_bytes, :validate => :string
@@ -159,6 +161,11 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
159
161
  config :topics_pattern, :validate => :string
160
162
  # Time kafka consumer will wait to receive new messages from topics
161
163
  config :poll_timeout_ms, :validate => :number, :default => 100
164
+ # The rack id string to pass to the server when making requests. This is used
165
+ # as a selector for a rack, region, or datacenter. Corresponds to the broker.rack parameter
166
+ # in the broker configuration.
167
+ # Only has an effect in combination with brokers with Kafka 2.4+ with the broker.rack setting. Ignored otherwise.
168
+ config :client_rack, :validate => :string
162
169
  # The truststore type.
163
170
  config :ssl_truststore_type, :validate => :string
164
171
  # The JKS truststore path to validate the Kafka broker's certificate.
@@ -305,7 +312,7 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
305
312
  props.put(kafka::MAX_POLL_RECORDS_CONFIG, max_poll_records) unless max_poll_records.nil?
306
313
  props.put(kafka::MAX_POLL_INTERVAL_MS_CONFIG, max_poll_interval_ms) unless max_poll_interval_ms.nil?
307
314
  props.put(kafka::METADATA_MAX_AGE_CONFIG, metadata_max_age_ms) unless metadata_max_age_ms.nil?
308
- props.put(kafka::PARTITION_ASSIGNMENT_STRATEGY_CONFIG, partition_assignment_strategy) unless partition_assignment_strategy.nil?
315
+ props.put(kafka::PARTITION_ASSIGNMENT_STRATEGY_CONFIG, partition_assignment_strategy_class) unless partition_assignment_strategy.nil?
309
316
  props.put(kafka::RECEIVE_BUFFER_CONFIG, receive_buffer_bytes) unless receive_buffer_bytes.nil?
310
317
  props.put(kafka::RECONNECT_BACKOFF_MS_CONFIG, reconnect_backoff_ms) unless reconnect_backoff_ms.nil?
311
318
  props.put(kafka::REQUEST_TIMEOUT_MS_CONFIG, request_timeout_ms) unless request_timeout_ms.nil?
@@ -313,6 +320,7 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
313
320
  props.put(kafka::SEND_BUFFER_CONFIG, send_buffer_bytes) unless send_buffer_bytes.nil?
314
321
  props.put(kafka::SESSION_TIMEOUT_MS_CONFIG, session_timeout_ms) unless session_timeout_ms.nil?
315
322
  props.put(kafka::VALUE_DESERIALIZER_CLASS_CONFIG, value_deserializer_class)
323
+ props.put(kafka::CLIENT_RACK_CONFIG, client_rack) unless client_rack.nil?
316
324
 
317
325
  props.put("security.protocol", security_protocol) unless security_protocol.nil?
318
326
 
@@ -334,6 +342,24 @@ class LogStash::Inputs::Kafka < LogStash::Inputs::Base
334
342
  end
335
343
  end
336
344
 
345
+ def partition_assignment_strategy_class
346
+ case partition_assignment_strategy
347
+ when 'range'
348
+ 'org.apache.kafka.clients.consumer.RangeAssignor'
349
+ when 'round_robin'
350
+ 'org.apache.kafka.clients.consumer.RoundRobinAssignor'
351
+ when 'sticky'
352
+ 'org.apache.kafka.clients.consumer.StickyAssignor'
353
+ when 'cooperative_sticky'
354
+ 'org.apache.kafka.clients.consumer.CooperativeStickyAssignor'
355
+ else
356
+ unless partition_assignment_strategy.index('.')
357
+ raise LogStash::ConfigurationError, "unsupported partition_assignment_strategy: #{partition_assignment_strategy.inspect}"
358
+ end
359
+ partition_assignment_strategy # assume a fully qualified class-name
360
+ end
361
+ end
362
+
337
363
  def set_trustore_keystore_config(props)
338
364
  props.put("ssl.truststore.type", ssl_truststore_type) unless ssl_truststore_type.nil?
339
365
  props.put("ssl.truststore.location", ssl_truststore_location) unless ssl_truststore_location.nil?
@@ -101,6 +101,8 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
101
101
  config :metadata_fetch_timeout_ms, :validate => :number, :default => 60000
102
102
  # the max time in milliseconds before a metadata refresh is forced.
103
103
  config :metadata_max_age_ms, :validate => :number, :default => 300000
104
+ # Partitioner to use - can be `default`, `uniform_sticky`, `round_robin` or a fully qualified class name of a custom partitioner.
105
+ config :partitioner, :validate => :string
104
106
  # The size of the TCP receive buffer to use when reading data
105
107
  config :receive_buffer_bytes, :validate => :number, :default => 32768
106
108
  # The amount of time to wait before attempting to reconnect to a given host when a connection fails.
@@ -184,7 +186,7 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
184
186
  raise ConfigurationError, "A negative retry count (#{@retries}) is not valid. Must be a value >= 0"
185
187
  end
186
188
 
187
- @logger.warn("Kafka output is configured with finite retry. This instructs Logstash to LOSE DATA after a set number of send attempts fails. If you do not want to lose data if Kafka is down, then you must remove the retry setting.", :retries => @retries)
189
+ logger.warn("Kafka output is configured with finite retry. This instructs Logstash to LOSE DATA after a set number of send attempts fails. If you do not want to lose data if Kafka is down, then you must remove the retry setting.", :retries => @retries)
188
190
  end
189
191
 
190
192
 
@@ -202,8 +204,6 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
202
204
  end
203
205
  end
204
206
 
205
- # def register
206
-
207
207
  def prepare(record)
208
208
  # This output is threadsafe, so we need to keep a batch per thread.
209
209
  @thread_batch_map[Thread.current].add(record)
@@ -269,7 +269,7 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
269
269
  result = future.get()
270
270
  rescue => e
271
271
  # TODO(sissel): Add metric to count failures, possibly by exception type.
272
- logger.warn("KafkaProducer.send() failed: #{e}", :exception => e)
272
+ logger.warn("producer send failed", :exception => e.class, :message => e.message)
273
273
  failures << batch[i]
274
274
  end
275
275
  end
@@ -303,10 +303,9 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
303
303
  end
304
304
  prepare(record)
305
305
  rescue LogStash::ShutdownSignal
306
- @logger.debug('Kafka producer got shutdown signal')
306
+ logger.debug('producer received shutdown signal')
307
307
  rescue => e
308
- @logger.warn('kafka producer threw exception, restarting',
309
- :exception => e)
308
+ logger.warn('producer threw exception, restarting', :exception => e.class, :message => e.message)
310
309
  end
311
310
 
312
311
  def create_producer
@@ -324,6 +323,10 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
324
323
  props.put(kafka::LINGER_MS_CONFIG, linger_ms.to_s)
325
324
  props.put(kafka::MAX_REQUEST_SIZE_CONFIG, max_request_size.to_s)
326
325
  props.put(kafka::METADATA_MAX_AGE_CONFIG, metadata_max_age_ms) unless metadata_max_age_ms.nil?
326
+ unless partitioner.nil?
327
+ props.put(kafka::PARTITIONER_CLASS_CONFIG, partitioner = partitioner_class)
328
+ logger.debug('producer configured using partitioner', :partitioner_class => partitioner)
329
+ end
327
330
  props.put(kafka::RECEIVE_BUFFER_CONFIG, receive_buffer_bytes.to_s) unless receive_buffer_bytes.nil?
328
331
  props.put(kafka::RECONNECT_BACKOFF_MS_CONFIG, reconnect_backoff_ms) unless reconnect_backoff_ms.nil?
329
332
  props.put(kafka::REQUEST_TIMEOUT_MS_CONFIG, request_timeout_ms) unless request_timeout_ms.nil?
@@ -353,13 +356,31 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
353
356
  end
354
357
  end
355
358
 
359
+ def partitioner_class
360
+ case partitioner
361
+ when 'round_robin'
362
+ 'org.apache.kafka.clients.producer.RoundRobinPartitioner'
363
+ when 'uniform_sticky'
364
+ 'org.apache.kafka.clients.producer.UniformStickyPartitioner'
365
+ when 'default'
366
+ 'org.apache.kafka.clients.producer.internals.DefaultPartitioner'
367
+ else
368
+ unless partitioner.index('.')
369
+ raise LogStash::ConfigurationError, "unsupported partitioner: #{partitioner.inspect}"
370
+ end
371
+ partitioner # assume a fully qualified class-name
372
+ end
373
+ end
374
+
356
375
  def set_trustore_keystore_config(props)
357
- if ssl_truststore_location.nil?
358
- raise LogStash::ConfigurationError, "ssl_truststore_location must be set when SSL is enabled"
376
+ unless ssl_endpoint_identification_algorithm.to_s.strip.empty?
377
+ if ssl_truststore_location.nil?
378
+ raise LogStash::ConfigurationError, "ssl_truststore_location must be set when SSL is enabled"
379
+ end
380
+ props.put("ssl.truststore.type", ssl_truststore_type) unless ssl_truststore_type.nil?
381
+ props.put("ssl.truststore.location", ssl_truststore_location)
382
+ props.put("ssl.truststore.password", ssl_truststore_password.value) unless ssl_truststore_password.nil?
359
383
  end
360
- props.put("ssl.truststore.type", ssl_truststore_type) unless ssl_truststore_type.nil?
361
- props.put("ssl.truststore.location", ssl_truststore_location)
362
- props.put("ssl.truststore.password", ssl_truststore_password.value) unless ssl_truststore_password.nil?
363
384
 
364
385
  # Client auth stuff
365
386
  props.put("ssl.keystore.type", ssl_keystore_type) unless ssl_keystore_type.nil?
@@ -370,15 +391,15 @@ class LogStash::Outputs::Kafka < LogStash::Outputs::Base
370
391
  end
371
392
 
372
393
  def set_sasl_config(props)
373
- java.lang.System.setProperty("java.security.auth.login.config",jaas_path) unless jaas_path.nil?
374
- java.lang.System.setProperty("java.security.krb5.conf",kerberos_config) unless kerberos_config.nil?
394
+ java.lang.System.setProperty("java.security.auth.login.config", jaas_path) unless jaas_path.nil?
395
+ java.lang.System.setProperty("java.security.krb5.conf", kerberos_config) unless kerberos_config.nil?
375
396
 
376
397
  props.put("sasl.mechanism",sasl_mechanism)
377
398
  if sasl_mechanism == "GSSAPI" && sasl_kerberos_service_name.nil?
378
399
  raise LogStash::ConfigurationError, "sasl_kerberos_service_name must be specified when SASL mechanism is GSSAPI"
379
400
  end
380
401
 
381
- props.put("sasl.kerberos.service.name",sasl_kerberos_service_name) unless sasl_kerberos_service_name.nil?
402
+ props.put("sasl.kerberos.service.name", sasl_kerberos_service_name) unless sasl_kerberos_service_name.nil?
382
403
  props.put("sasl.jaas.config", sasl_jaas_config) unless sasl_jaas_config.nil?
383
404
  end
384
405
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-integration-kafka'
3
- s.version = '10.0.1'
3
+ s.version = '10.1.0'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = "Integration with Kafka - input and output plugins"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline "+
@@ -49,6 +49,6 @@ Gem::Specification.new do |s|
49
49
 
50
50
  s.add_development_dependency 'logstash-devutils'
51
51
  s.add_development_dependency 'rspec-wait'
52
- s.add_development_dependency 'poseidon'
52
+ s.add_development_dependency 'ruby-kafka'
53
53
  s.add_development_dependency 'snappy'
54
54
  end
@@ -1,7 +1,6 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/devutils/rspec/spec_helper"
3
3
  require "logstash/inputs/kafka"
4
- require "digest"
5
4
  require "rspec/wait"
6
5
 
7
6
  # Please run kafka_test_setup.sh prior to executing this integration test.
@@ -12,159 +11,129 @@ describe "inputs/kafka", :integration => true do
12
11
  let(:group_id_3) {rand(36**8).to_s(36)}
13
12
  let(:group_id_4) {rand(36**8).to_s(36)}
14
13
  let(:group_id_5) {rand(36**8).to_s(36)}
15
- let(:plain_config) { { 'topics' => ['logstash_integration_topic_plain'], 'codec' => 'plain', 'group_id' => group_id_1, 'auto_offset_reset' => 'earliest'} }
16
- let(:multi_consumer_config) { plain_config.merge({"group_id" => group_id_4, "client_id" => "spec", "consumer_threads" => 3}) }
17
- let(:snappy_config) { { 'topics' => ['logstash_integration_topic_snappy'], 'codec' => 'plain', 'group_id' => group_id_1, 'auto_offset_reset' => 'earliest'} }
18
- let(:lz4_config) { { 'topics' => ['logstash_integration_topic_lz4'], 'codec' => 'plain', 'group_id' => group_id_1, 'auto_offset_reset' => 'earliest'} }
19
- let(:pattern_config) { { 'topics_pattern' => 'logstash_integration_topic_.*', 'group_id' => group_id_2, 'codec' => 'plain', 'auto_offset_reset' => 'earliest'} }
20
- let(:decorate_config) { { 'topics' => ['logstash_integration_topic_plain'], 'codec' => 'plain', 'group_id' => group_id_3, 'auto_offset_reset' => 'earliest', 'decorate_events' => true} }
21
- let(:manual_commit_config) { { 'topics' => ['logstash_integration_topic_plain'], 'codec' => 'plain', 'group_id' => group_id_5, 'auto_offset_reset' => 'earliest', 'enable_auto_commit' => 'false'} }
14
+ let(:group_id_6) {rand(36**8).to_s(36)}
15
+ let(:plain_config) do
16
+ { 'topics' => ['logstash_integration_topic_plain'], 'codec' => 'plain', 'group_id' => group_id_1,
17
+ 'auto_offset_reset' => 'earliest' }
18
+ end
19
+ let(:multi_consumer_config) do
20
+ plain_config.merge({"group_id" => group_id_4, "client_id" => "spec", "consumer_threads" => 3})
21
+ end
22
+ let(:snappy_config) do
23
+ { 'topics' => ['logstash_integration_topic_snappy'], 'codec' => 'plain', 'group_id' => group_id_1,
24
+ 'auto_offset_reset' => 'earliest' }
25
+ end
26
+ let(:lz4_config) do
27
+ { 'topics' => ['logstash_integration_topic_lz4'], 'codec' => 'plain', 'group_id' => group_id_1,
28
+ 'auto_offset_reset' => 'earliest' }
29
+ end
30
+ let(:pattern_config) do
31
+ { 'topics_pattern' => 'logstash_integration_topic_.*', 'group_id' => group_id_2, 'codec' => 'plain',
32
+ 'auto_offset_reset' => 'earliest' }
33
+ end
34
+ let(:decorate_config) do
35
+ { 'topics' => ['logstash_integration_topic_plain'], 'codec' => 'plain', 'group_id' => group_id_3,
36
+ 'auto_offset_reset' => 'earliest', 'decorate_events' => true }
37
+ end
38
+ let(:manual_commit_config) do
39
+ { 'topics' => ['logstash_integration_topic_plain'], 'codec' => 'plain', 'group_id' => group_id_5,
40
+ 'auto_offset_reset' => 'earliest', 'enable_auto_commit' => 'false' }
41
+ end
22
42
  let(:timeout_seconds) { 30 }
23
43
  let(:num_events) { 103 }
24
44
 
25
45
  describe "#kafka-topics" do
26
- def thread_it(kafka_input, queue)
27
- Thread.new do
28
- begin
29
- kafka_input.run(queue)
30
- end
31
- end
32
- end
33
46
 
34
47
  it "should consume all messages from plain 3-partition topic" do
35
- kafka_input = LogStash::Inputs::Kafka.new(plain_config)
36
- queue = Queue.new
37
- t = thread_it(kafka_input, queue)
38
- begin
39
- t.run
40
- wait(timeout_seconds).for {queue.length}.to eq(num_events)
41
- expect(queue.length).to eq(num_events)
42
- ensure
43
- t.kill
44
- t.join(30_000)
45
- end
48
+ queue = consume_messages(plain_config, timeout: timeout_seconds, event_count: num_events)
49
+ expect(queue.length).to eq(num_events)
46
50
  end
47
51
 
48
52
  it "should consume all messages from snappy 3-partition topic" do
49
- kafka_input = LogStash::Inputs::Kafka.new(snappy_config)
50
- queue = Queue.new
51
- t = thread_it(kafka_input, queue)
52
- begin
53
- t.run
54
- wait(timeout_seconds).for {queue.length}.to eq(num_events)
55
- expect(queue.length).to eq(num_events)
56
- ensure
57
- t.kill
58
- t.join(30_000)
59
- end
53
+ queue = consume_messages(snappy_config, timeout: timeout_seconds, event_count: num_events)
54
+ expect(queue.length).to eq(num_events)
60
55
  end
61
56
 
62
57
  it "should consume all messages from lz4 3-partition topic" do
63
- kafka_input = LogStash::Inputs::Kafka.new(lz4_config)
64
- queue = Queue.new
65
- t = thread_it(kafka_input, queue)
66
- begin
67
- t.run
68
- wait(timeout_seconds).for {queue.length}.to eq(num_events)
69
- expect(queue.length).to eq(num_events)
70
- ensure
71
- t.kill
72
- t.join(30_000)
73
- end
58
+ queue = consume_messages(lz4_config, timeout: timeout_seconds, event_count: num_events)
59
+ expect(queue.length).to eq(num_events)
74
60
  end
75
61
 
76
62
  it "should consumer all messages with multiple consumers" do
77
- kafka_input = LogStash::Inputs::Kafka.new(multi_consumer_config)
78
- queue = Queue.new
79
- t = thread_it(kafka_input, queue)
80
- begin
81
- t.run
82
- wait(timeout_seconds).for {queue.length}.to eq(num_events)
63
+ consume_messages(multi_consumer_config, timeout: timeout_seconds, event_count: num_events) do |queue, kafka_input|
83
64
  expect(queue.length).to eq(num_events)
84
65
  kafka_input.kafka_consumers.each_with_index do |consumer, i|
85
66
  expect(consumer.metrics.keys.first.tags["client-id"]).to eq("spec-#{i}")
86
67
  end
87
- ensure
88
- t.kill
89
- t.join(30_000)
90
68
  end
91
69
  end
92
70
  end
93
71
 
94
- describe "#kafka-topics-pattern" do
95
- def thread_it(kafka_input, queue)
96
- Thread.new do
97
- begin
98
- kafka_input.run(queue)
99
- end
100
- end
101
- end
102
-
72
+ context "#kafka-topics-pattern" do
103
73
  it "should consume all messages from all 3 topics" do
104
- kafka_input = LogStash::Inputs::Kafka.new(pattern_config)
105
- queue = Queue.new
106
- t = thread_it(kafka_input, queue)
107
- begin
108
- t.run
109
- wait(timeout_seconds).for {queue.length}.to eq(3*num_events)
110
- expect(queue.length).to eq(3*num_events)
111
- ensure
112
- t.kill
113
- t.join(30_000)
114
- end
74
+ total_events = num_events * 3
75
+ queue = consume_messages(pattern_config, timeout: timeout_seconds, event_count: total_events)
76
+ expect(queue.length).to eq(total_events)
115
77
  end
116
78
  end
117
79
 
118
- describe "#kafka-decorate" do
119
- def thread_it(kafka_input, queue)
120
- Thread.new do
121
- begin
122
- kafka_input.run(queue)
123
- end
124
- end
125
- end
126
-
80
+ context "#kafka-decorate" do
127
81
  it "should show the right topic and group name in decorated kafka section" do
128
82
  start = LogStash::Timestamp.now.time.to_i
129
- kafka_input = LogStash::Inputs::Kafka.new(decorate_config)
130
- queue = Queue.new
131
- t = thread_it(kafka_input, queue)
132
- begin
133
- t.run
134
- wait(timeout_seconds).for {queue.length}.to eq(num_events)
83
+ consume_messages(decorate_config, timeout: timeout_seconds, event_count: num_events) do |queue, _|
135
84
  expect(queue.length).to eq(num_events)
136
85
  event = queue.shift
137
86
  expect(event.get("[@metadata][kafka][topic]")).to eq("logstash_integration_topic_plain")
138
87
  expect(event.get("[@metadata][kafka][consumer_group]")).to eq(group_id_3)
139
88
  expect(event.get("[@metadata][kafka][timestamp]")).to be >= start
140
- ensure
141
- t.kill
142
- t.join(30_000)
143
89
  end
144
90
  end
145
91
  end
146
92
 
147
- describe "#kafka-offset-commit" do
148
- def thread_it(kafka_input, queue)
149
- Thread.new do
150
- begin
151
- kafka_input.run(queue)
93
+ context "#kafka-offset-commit" do
94
+ it "should manually commit offsets" do
95
+ queue = consume_messages(manual_commit_config, timeout: timeout_seconds, event_count: num_events)
96
+ expect(queue.length).to eq(num_events)
97
+ end
98
+ end
99
+
100
+ context 'setting partition_assignment_strategy' do
101
+ let(:test_topic) { 'logstash_integration_partitioner_topic' }
102
+ let(:consumer_config) do
103
+ plain_config.merge(
104
+ "topics" => [test_topic],
105
+ 'group_id' => group_id_6,
106
+ "client_id" => "partition_assignment_strategy-spec",
107
+ "consumer_threads" => 2,
108
+ "partition_assignment_strategy" => partition_assignment_strategy
109
+ )
110
+ end
111
+ let(:partition_assignment_strategy) { nil }
112
+
113
+ # NOTE: just verify setting works, as its a bit cumbersome to do in a unit spec
114
+ [ 'range', 'round_robin', 'sticky', 'org.apache.kafka.clients.consumer.CooperativeStickyAssignor' ].each do |partition_assignment_strategy|
115
+ describe partition_assignment_strategy do
116
+ let(:partition_assignment_strategy) { partition_assignment_strategy }
117
+ it 'consumes data' do
118
+ consume_messages(consumer_config, timeout: false, event_count: 0)
152
119
  end
153
120
  end
154
121
  end
122
+ end
155
123
 
156
- it "should manually commit offsets" do
157
- kafka_input = LogStash::Inputs::Kafka.new(manual_commit_config)
158
- queue = Queue.new
159
- t = thread_it(kafka_input, queue)
160
- begin
161
- t.run
162
- wait(timeout_seconds).for {queue.length}.to eq(num_events)
163
- expect(queue.length).to eq(num_events)
164
- ensure
165
- t.kill
166
- t.join(30_000)
167
- end
124
+ private
125
+
126
+ def consume_messages(config, queue: Queue.new, timeout:, event_count:)
127
+ kafka_input = LogStash::Inputs::Kafka.new(config)
128
+ t = Thread.new { kafka_input.run(queue) }
129
+ begin
130
+ t.run
131
+ wait(timeout).for { queue.length }.to eq(event_count) unless timeout.eql?(false)
132
+ block_given? ? yield(queue, kafka_input) : queue
133
+ ensure
134
+ t.kill
135
+ t.join(30_000)
168
136
  end
169
137
  end
138
+
170
139
  end
@@ -3,26 +3,29 @@
3
3
  require "logstash/devutils/rspec/spec_helper"
4
4
  require 'logstash/outputs/kafka'
5
5
  require 'json'
6
- require 'poseidon'
6
+ require 'kafka'
7
7
 
8
8
  describe "outputs/kafka", :integration => true do
9
9
  let(:kafka_host) { 'localhost' }
10
10
  let(:kafka_port) { 9092 }
11
11
  let(:num_events) { 10 }
12
+
12
13
  let(:base_config) { {'client_id' => 'kafkaoutputspec'} }
13
- let(:event) { LogStash::Event.new({'message' => '183.60.215.50 - - [11/Sep/2014:22:00:00 +0000] "GET /scripts/netcat-webserver HTTP/1.1" 200 182 "-" "Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)"', '@timestamp' => LogStash::Timestamp.at(0) }) }
14
+ let(:message_content) do
15
+ '"GET /scripts/netcat-webserver HTTP/1.1" 200 182 "-" "Mozilla/5.0 (compatible; EasouSpider; +http://www.easou.com/search/spider.html)"'
16
+ end
17
+ let(:event) do
18
+ LogStash::Event.new({ 'message' =>
19
+ '183.60.215.50 - - [11/Sep/2014:22:00:00 +0000] ' + message_content,
20
+ '@timestamp' => LogStash::Timestamp.at(0)
21
+ })
22
+ end
14
23
 
24
+ let(:kafka_client) { Kafka.new ["#{kafka_host}:#{kafka_port}"] }
15
25
 
16
26
  context 'when outputting messages serialized as String' do
17
27
  let(:test_topic) { 'logstash_integration_topic1' }
18
28
  let(:num_events) { 3 }
19
- let(:consumer) do
20
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
21
- test_topic, 0, :earliest_offset)
22
- end
23
- subject do
24
- consumer.fetch
25
- end
26
29
 
27
30
  before :each do
28
31
  config = base_config.merge({"topic_id" => test_topic})
@@ -30,8 +33,10 @@ describe "outputs/kafka", :integration => true do
30
33
  end
31
34
 
32
35
  it 'should have data integrity' do
33
- expect(subject.size).to eq(num_events)
34
- subject.each do |m|
36
+ messages = fetch_messages(test_topic)
37
+
38
+ expect(messages.size).to eq(num_events)
39
+ messages.each do |m|
35
40
  expect(m.value).to eq(event.to_s)
36
41
  end
37
42
  end
@@ -41,13 +46,6 @@ describe "outputs/kafka", :integration => true do
41
46
  context 'when outputting messages serialized as Byte Array' do
42
47
  let(:test_topic) { 'topic1b' }
43
48
  let(:num_events) { 3 }
44
- let(:consumer) do
45
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
46
- test_topic, 0, :earliest_offset)
47
- end
48
- subject do
49
- consumer.fetch
50
- end
51
49
 
52
50
  before :each do
53
51
  config = base_config.merge(
@@ -60,8 +58,10 @@ describe "outputs/kafka", :integration => true do
60
58
  end
61
59
 
62
60
  it 'should have data integrity' do
63
- expect(subject.size).to eq(num_events)
64
- subject.each do |m|
61
+ messages = fetch_messages(test_topic)
62
+
63
+ expect(messages.size).to eq(num_events)
64
+ messages.each do |m|
65
65
  expect(m.value).to eq(event.to_s)
66
66
  end
67
67
  end
@@ -71,14 +71,6 @@ describe "outputs/kafka", :integration => true do
71
71
  context 'when setting message_key' do
72
72
  let(:num_events) { 10 }
73
73
  let(:test_topic) { 'logstash_integration_topic2' }
74
- let!(:consumer0) do
75
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
76
- test_topic, 0, :earliest_offset)
77
- end
78
- let!(:consumer1) do
79
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
80
- test_topic, 1, :earliest_offset)
81
- end
82
74
 
83
75
  before :each do
84
76
  config = base_config.merge({"topic_id" => test_topic, "message_key" => "static_key"})
@@ -86,19 +78,14 @@ describe "outputs/kafka", :integration => true do
86
78
  end
87
79
 
88
80
  it 'should send all events to one partition' do
89
- expect(consumer0.fetch.size == num_events || consumer1.fetch.size == num_events).to be true
81
+ data0 = fetch_messages(test_topic, partition: 0)
82
+ data1 = fetch_messages(test_topic, partition: 1)
83
+ expect(data0.size == num_events || data1.size == num_events).to be true
90
84
  end
91
85
  end
92
86
 
93
87
  context 'when using gzip compression' do
94
88
  let(:test_topic) { 'logstash_integration_gzip_topic' }
95
- let!(:consumer) do
96
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
97
- test_topic, 0, :earliest_offset)
98
- end
99
- subject do
100
- consumer.fetch
101
- end
102
89
 
103
90
  before :each do
104
91
  config = base_config.merge({"topic_id" => test_topic, "compression_type" => "gzip"})
@@ -106,8 +93,10 @@ describe "outputs/kafka", :integration => true do
106
93
  end
107
94
 
108
95
  it 'should have data integrity' do
109
- expect(subject.size).to eq(num_events)
110
- subject.each do |m|
96
+ messages = fetch_messages(test_topic)
97
+
98
+ expect(messages.size).to eq(num_events)
99
+ messages.each do |m|
111
100
  expect(m.value).to eq(event.to_s)
112
101
  end
113
102
  end
@@ -115,13 +104,6 @@ describe "outputs/kafka", :integration => true do
115
104
 
116
105
  context 'when using snappy compression' do
117
106
  let(:test_topic) { 'logstash_integration_snappy_topic' }
118
- let!(:consumer) do
119
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
120
- test_topic, 0, :earliest_offset)
121
- end
122
- subject do
123
- consumer.fetch
124
- end
125
107
 
126
108
  before :each do
127
109
  config = base_config.merge({"topic_id" => test_topic, "compression_type" => "snappy"})
@@ -129,8 +111,10 @@ describe "outputs/kafka", :integration => true do
129
111
  end
130
112
 
131
113
  it 'should have data integrity' do
132
- expect(subject.size).to eq(num_events)
133
- subject.each do |m|
114
+ messages = fetch_messages(test_topic)
115
+
116
+ expect(messages.size).to eq(num_events)
117
+ messages.each do |m|
134
118
  expect(m.value).to eq(event.to_s)
135
119
  end
136
120
  end
@@ -143,52 +127,85 @@ describe "outputs/kafka", :integration => true do
143
127
  config = base_config.merge({"topic_id" => test_topic, "compression_type" => "lz4"})
144
128
  load_kafka_data(config)
145
129
  end
130
+
131
+ # NOTE: depends on extlz4 gem which is using a C-extension
132
+ # it 'should have data integrity' do
133
+ # messages = fetch_messages(test_topic)
134
+ #
135
+ # expect(messages.size).to eq(num_events)
136
+ # messages.each do |m|
137
+ # expect(m.value).to eq(event.to_s)
138
+ # end
139
+ # end
146
140
  end
147
141
 
148
142
  context 'when using multi partition topic' do
149
- let(:num_events) { 10 }
143
+ let(:num_events) { 100 } # ~ more than (batch.size) 16,384 bytes
150
144
  let(:test_topic) { 'logstash_integration_topic3' }
151
- let!(:consumer0) do
152
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
153
- test_topic, 0, :earliest_offset)
154
- end
155
- let!(:consumer1) do
156
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
157
- test_topic, 1, :earliest_offset)
145
+
146
+ before :each do
147
+ config = base_config.merge("topic_id" => test_topic, "partitioner" => 'org.apache.kafka.clients.producer.UniformStickyPartitioner')
148
+ load_kafka_data(config) do # let's have a bit more (diverse) dataset
149
+ num_events.times.collect do
150
+ LogStash::Event.new.tap do |e|
151
+ e.set('message', event.get('message').sub('183.60.215.50') { "#{rand(126)+1}.#{rand(126)+1}.#{rand(126)+1}.#{rand(126)+1}" })
152
+ end
153
+ end
154
+ end
158
155
  end
159
156
 
160
- let!(:consumer2) do
161
- Poseidon::PartitionConsumer.new("my_test_consumer", kafka_host, kafka_port,
162
- test_topic, 2, :earliest_offset)
157
+ it 'should distribute events to all partitions' do
158
+ consumer0_records = fetch_messages(test_topic, partition: 0)
159
+ consumer1_records = fetch_messages(test_topic, partition: 1)
160
+ consumer2_records = fetch_messages(test_topic, partition: 2)
161
+
162
+ all_records = consumer0_records + consumer1_records + consumer2_records
163
+ expect(all_records.size).to eq(num_events * 2)
164
+ all_records.each do |m|
165
+ expect(m.value).to include message_content
166
+ end
167
+
168
+ expect(consumer0_records.size).to be > 1
169
+ expect(consumer1_records.size).to be > 1
170
+ expect(consumer2_records.size).to be > 1
163
171
  end
172
+ end
173
+
174
+ context 'setting partitioner' do
175
+ let(:test_topic) { 'logstash_integration_partitioner_topic' }
176
+ let(:partitioner) { nil }
164
177
 
165
178
  before :each do
166
- config = base_config.merge({"topic_id" => test_topic})
179
+ @messages_offset = fetch_messages_from_all_partitions
180
+
181
+ config = base_config.merge("topic_id" => test_topic, 'partitioner' => partitioner)
167
182
  load_kafka_data(config)
168
183
  end
169
184
 
170
- it 'should distribute events to all partition' do
171
- consumer0_records = consumer0.fetch
172
- consumer1_records = consumer1.fetch
173
- consumer2_records = consumer2.fetch
174
-
175
- expect(consumer0_records.size > 1 &&
176
- consumer1_records.size > 1 &&
177
- consumer2_records.size > 1).to be true
178
-
179
- all_records = consumer0_records + consumer1_records + consumer2_records
180
- expect(all_records.size).to eq(num_events)
181
- all_records.each do |m|
182
- expect(m.value).to eq(event.to_s)
185
+ [ 'default', 'round_robin', 'uniform_sticky' ].each do |partitioner|
186
+ describe partitioner do
187
+ let(:partitioner) { partitioner }
188
+ it 'loads data' do
189
+ expect(fetch_messages_from_all_partitions - @messages_offset).to eql num_events
190
+ end
183
191
  end
184
192
  end
193
+
194
+ def fetch_messages_from_all_partitions
195
+ 3.times.map { |i| fetch_messages(test_topic, partition: i).size }.sum
196
+ end
185
197
  end
186
198
 
187
199
  def load_kafka_data(config)
188
200
  kafka = LogStash::Outputs::Kafka.new(config)
189
201
  kafka.register
190
202
  kafka.multi_receive(num_events.times.collect { event })
203
+ kafka.multi_receive(Array(yield)) if block_given?
191
204
  kafka.close
192
205
  end
193
206
 
207
+ def fetch_messages(topic, partition: 0, offset: :earliest)
208
+ kafka_client.fetch_messages(topic: topic, partition: partition, offset: offset)
209
+ end
210
+
194
211
  end
@@ -34,6 +34,18 @@ describe LogStash::Inputs::Kafka do
34
34
  subject { LogStash::Inputs::Kafka.new(config) }
35
35
 
36
36
  it "should register" do
37
- expect {subject.register}.to_not raise_error
37
+ expect { subject.register }.to_not raise_error
38
+ end
39
+
40
+ context 'with client_rack' do
41
+ let(:config) { super.merge('client_rack' => 'EU-R1') }
42
+
43
+ it "sets broker rack parameter" do
44
+ expect(org.apache.kafka.clients.consumer.KafkaConsumer).
45
+ to receive(:new).with(hash_including('client.rack' => 'EU-R1')).
46
+ and_return kafka_client = double('kafka-consumer')
47
+
48
+ expect( subject.send(:create_consumer, 'sample_client-0') ).to be kafka_client
49
+ end
38
50
  end
39
51
  end
@@ -97,7 +97,7 @@ describe "outputs/kafka" do
97
97
  let(:sendcount) { failcount + 1 }
98
98
 
99
99
  it "should retry until successful" do
100
- count = 0;
100
+ count = 0
101
101
 
102
102
  expect_any_instance_of(org.apache.kafka.clients.producer.KafkaProducer).to receive(:send)
103
103
  .exactly(sendcount).times
@@ -189,4 +189,25 @@ describe "outputs/kafka" do
189
189
  end
190
190
  end
191
191
  end
192
+
193
+ context 'when ssl endpoint identification disabled' do
194
+
195
+ let(:config) do
196
+ simple_kafka_config.merge('ssl_endpoint_identification_algorithm' => '', 'security_protocol' => 'SSL')
197
+ end
198
+
199
+ subject { LogStash::Outputs::Kafka.new(config) }
200
+
201
+ it 'does not configure truststore' do
202
+ expect(org.apache.kafka.clients.producer.KafkaProducer).
203
+ to receive(:new).with(hash_excluding('ssl.truststore.location' => anything))
204
+ subject.register
205
+ end
206
+
207
+ it 'sets empty ssl.endpoint.identification.algorithm' do
208
+ expect(org.apache.kafka.clients.producer.KafkaProducer).
209
+ to receive(:new).with(hash_including('ssl.endpoint.identification.algorithm' => ''))
210
+ subject.register
211
+ end
212
+ end
192
213
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-integration-kafka
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.1
4
+ version: 10.1.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-12 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -140,7 +140,7 @@ dependencies:
140
140
  - - ">="
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
- name: poseidon
143
+ name: ruby-kafka
144
144
  prerelease: false
145
145
  type: :development
146
146
  version_requirements: !ruby/object:Gem::Requirement
@@ -188,10 +188,10 @@ files:
188
188
  - spec/integration/outputs/kafka_spec.rb
189
189
  - spec/unit/inputs/kafka_spec.rb
190
190
  - spec/unit/outputs/kafka_spec.rb
191
- - vendor/jar-dependencies/com/github/luben/zstd-jni/1.4.2-1/zstd-jni-1.4.2-1.jar
192
- - vendor/jar-dependencies/org/apache/kafka/kafka-clients/2.3.0/kafka-clients-2.3.0.jar
191
+ - vendor/jar-dependencies/com/github/luben/zstd-jni/1.4.3-1/zstd-jni-1.4.3-1.jar
192
+ - vendor/jar-dependencies/org/apache/kafka/kafka-clients/2.4.1/kafka-clients-2.4.1.jar
193
193
  - vendor/jar-dependencies/org/lz4/lz4-java/1.6.0/lz4-java-1.6.0.jar
194
- - vendor/jar-dependencies/org/slf4j/slf4j-api/1.7.26/slf4j-api-1.7.26.jar
194
+ - vendor/jar-dependencies/org/slf4j/slf4j-api/1.7.28/slf4j-api-1.7.28.jar
195
195
  - vendor/jar-dependencies/org/xerial/snappy/snappy-java/1.1.7.3/snappy-java-1.1.7.3.jar
196
196
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
197
197
  licenses: