-
Notifications
You must be signed in to change notification settings - Fork 178
in_rdkafka_group: support regexp pattern in topics #541
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
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1107138
in_rdkafka_group: support regexp pattern in topics
Watson1978 f275bb4
in_rdkafka_group: fix regexp pattern support in topics
Watson1978 d3159bf
test_in_rdkafka_group: add test for unmatched topic
Watson1978 81b2186
Drop garbage tag from explanation
kenhys File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| require 'helper' | ||
| require 'fluent/test/driver/input' | ||
| require 'securerandom' | ||
|
|
||
| class RdkafkaGroupInputTest < Test::Unit::TestCase | ||
|
|
||
| def have_rdkafka | ||
| begin | ||
| require 'fluent/plugin/in_rdkafka_group' | ||
| true | ||
| rescue LoadError | ||
| false | ||
| end | ||
| end | ||
|
|
||
| def setup | ||
| omit_unless(have_rdkafka, "rdkafka isn't installed") | ||
| Fluent::Test.setup | ||
| end | ||
|
|
||
| TOPIC_NAME = "kafka-input-#{SecureRandom.uuid}" | ||
|
|
||
| CONFIG = %[ | ||
| topics #{TOPIC_NAME} | ||
| kafka_configs {"bootstrap.servers": "localhost:9092", "group.id": "test_group"} | ||
| <parse> | ||
| @type none | ||
| </parse> | ||
| ] | ||
|
|
||
| def create_driver(conf = CONFIG) | ||
| Fluent::Test::Driver::Input.new(Fluent::Plugin::RdKafkaGroupInput).configure(conf) | ||
| end | ||
|
|
||
|
|
||
| def test_configure | ||
| d = create_driver | ||
| assert_equal [TOPIC_NAME], d.instance.topics | ||
| assert_equal 'localhost:9092', d.instance.kafka_configs['bootstrap.servers'] | ||
| end | ||
|
|
||
| def test_multi_worker_support | ||
| d = create_driver | ||
| assert_true d.instance.multi_workers_ready? | ||
| end | ||
|
|
||
| class ConsumeTest < self | ||
| TOPIC_NAME = "kafka-input-#{SecureRandom.uuid}" | ||
|
|
||
| def setup | ||
| @kafka = Kafka.new(["localhost:9092"], client_id: 'kafka') | ||
| @producer = @kafka.producer | ||
| @kafka.create_topic(TOPIC_NAME) | ||
| end | ||
|
|
||
| def teardown | ||
| @kafka.delete_topic(TOPIC_NAME) | ||
| @kafka.close | ||
| end | ||
|
|
||
| def test_consume | ||
| conf = %[ | ||
| topics #{TOPIC_NAME} | ||
| kafka_configs {"bootstrap.servers": "localhost:9092", "group.id": "test_group"} | ||
| <parse> | ||
| @type none | ||
| </parse> | ||
| ] | ||
|
|
||
| d = create_driver(conf) | ||
|
|
||
| d.run(expect_records: 1, timeout: 10) do | ||
| sleep 0.1 | ||
| @producer.produce("Hello, fluent-plugin-kafka!", topic: TOPIC_NAME) | ||
| @producer.deliver_messages | ||
| end | ||
|
|
||
| expected = {'message' => 'Hello, fluent-plugin-kafka!'} | ||
| assert_equal expected, d.events[0][2] | ||
| end | ||
| end | ||
|
|
||
| class ConsumeTopicWithRegexpTest < self | ||
| TOPIC_NAME1 = "kafka-input-1-#{SecureRandom.uuid}" | ||
| TOPIC_NAME2 = "kafka-input-22-#{SecureRandom.uuid}" | ||
| UNMATCHED_TOPIC = "kafka-input-333-#{SecureRandom.uuid}" | ||
|
|
||
| TOPIC_NAME_REGEXP = "/kafka-input-[0-9]{1,2}-.*/" | ||
|
|
||
| def setup | ||
| @kafka = Kafka.new(["localhost:9092"], client_id: 'kafka') | ||
| @producer = @kafka.producer | ||
| @kafka.create_topic(TOPIC_NAME1) | ||
| @kafka.create_topic(TOPIC_NAME2) | ||
| @kafka.create_topic(UNMATCHED_TOPIC) | ||
| end | ||
|
|
||
| def teardown | ||
| @kafka.delete_topic(TOPIC_NAME1) | ||
| @kafka.delete_topic(TOPIC_NAME2) | ||
| @kafka.delete_topic(UNMATCHED_TOPIC) | ||
| @kafka.close | ||
| end | ||
|
|
||
| def test_consume_with_regexp | ||
| conf = %[ | ||
| topics #{TOPIC_NAME_REGEXP} | ||
| kafka_configs {"bootstrap.servers": "localhost:9092", "group.id": "test_group"} | ||
| <parse> | ||
| @type none | ||
| </parse> | ||
| ] | ||
| d = create_driver(conf) | ||
|
|
||
| d.run(expect_records: 2, timeout: 10) do | ||
| sleep 0.1 | ||
| @producer.produce("Hello, fluent-plugin-kafka! in topic 1", topic: TOPIC_NAME1) | ||
| @producer.produce("Hello, fluent-plugin-kafka! in topic 2", topic: TOPIC_NAME2) | ||
| @producer.produce("Should be ignored", topic: UNMATCHED_TOPIC) | ||
| @producer.deliver_messages | ||
| end | ||
| expected_message_pattern = /Hello, fluent-plugin-kafka! in topic [12]/ | ||
| assert_equal 2, d.events.size | ||
| assert_match(expected_message_pattern, d.events[0][2]['message']) | ||
| assert_match(expected_message_pattern, d.events[1][2]['message']) | ||
| end | ||
| end | ||
| end | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.