-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
in_forward: Add source_hostname_key parameter. fix #804 #807
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 |
---|---|---|
|
@@ -29,6 +29,7 @@ def setup | |
port #{PORT} | ||
bind 127.0.0.1 | ||
] | ||
PEERADDR = ['?', '0000', '127.0.0.1', '127.0.0.1'] | ||
|
||
def create_driver(conf=CONFIG) | ||
Fluent::Test::InputTestDriver.new(Fluent::ForwardInput).configure(conf) | ||
|
@@ -260,7 +261,7 @@ def test_set_size_to_option | |
|
||
d.run do | ||
Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| | ||
option = d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") | ||
option = d.instance.send(:on_message, obj, chunk.size, PEERADDR) | ||
assert_equal option['size'], events.length | ||
end | ||
end | ||
|
@@ -282,7 +283,7 @@ def test_send_large_chunk_warning | |
|
||
d.run do | ||
Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| | ||
d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") | ||
d.instance.send(:on_message, obj, chunk.size, PEERADDR) | ||
end | ||
end | ||
|
||
|
@@ -311,7 +312,7 @@ def test_send_large_chunk_only_warning | |
|
||
d.run do | ||
Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| | ||
d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") | ||
d.instance.send(:on_message, obj, chunk.size, PEERADDR) | ||
end | ||
end | ||
|
||
|
@@ -338,7 +339,7 @@ def test_send_large_chunk_limit | |
# d.run => send_data | ||
d.run do | ||
Fluent::Engine.msgpack_factory.unpacker.feed_each(chunk) do |obj| | ||
d.instance.send(:on_message, obj, chunk.size, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") | ||
d.instance.send(:on_message, obj, chunk.size, PEERADDR) | ||
end | ||
end | ||
|
||
|
@@ -360,7 +361,7 @@ def test_send_broken_chunk(data) | |
|
||
# d.run => send_data | ||
d.run do | ||
d.instance.send(:on_message, data, 1000000000, "host: 127.0.0.1, addr: 127.0.0.1, port: 0000") | ||
d.instance.send(:on_message, data, 1000000000, PEERADDR) | ||
end | ||
|
||
# check emitted data | ||
|
@@ -476,7 +477,6 @@ def test_respond_to_message_json_requiring_ack | |
|
||
assert_equal events, d.emits | ||
assert_equal expected_acks, @responses.map { |res| JSON.parse(res)['ack'] } | ||
|
||
end | ||
|
||
def test_not_respond_to_message_not_requiring_ack | ||
|
@@ -583,5 +583,53 @@ def send_data(data, try_to_receive_response=false, response_timeout=1) | |
@responses << res if try_to_receive_response | ||
end | ||
|
||
# TODO: Use sub_test_case. Currently Errno::EADDRINUSE happens inside sub_test_case | ||
test 'message protocol with source_hostname_key' do | ||
execute_test { |events| | ||
events.each { |tag, time, record| | ||
send_data [tag, time, record].to_msgpack | ||
} | ||
} | ||
end | ||
|
||
test 'forward protocol with source_hostname_key' do | ||
execute_test { |events| | ||
entries = [] | ||
events.each {|tag,time,record| | ||
entries << [time, record] | ||
} | ||
send_data ['tag1', entries].to_msgpack | ||
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. I cannot understand why this code works well... 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. Correct way to do it is 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. EventTime is serialized to int via 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. Yeah, using Fluent::MessagePackFactory is better. "packed forward protocol with source_hostname_key" case does 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. It looks incorrect behavior to simulate |
||
} | ||
end | ||
|
||
test 'packed forward protocol with source_hostname_key' do | ||
execute_test { |events| | ||
entries = '' | ||
events.each { |tag, time, record| | ||
Fluent::Engine.msgpack_factory.packer(entries).write([time, record]).flush | ||
} | ||
send_data Fluent::Engine.msgpack_factory.packer.write(["tag1", entries]).to_s | ||
} | ||
end | ||
|
||
def execute_test(&block) | ||
d = create_driver(CONFIG + 'source_hostname_key source') | ||
|
||
time = Fluent::EventTime.parse("2011-01-02 13:14:15 UTC") | ||
events = [ | ||
["tag1", time, {"a"=>1}], | ||
["tag1", time, {"a"=>2}] | ||
] | ||
d.expected_emits_length = events.length | ||
|
||
d.run do | ||
block.call(events) | ||
end | ||
|
||
d.emits.each { |tag, _time, record| | ||
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. Does 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. Test calls |
||
assert_true record.has_key?('source') | ||
} | ||
end | ||
|
||
# TODO heartbeat | ||
end |
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.
IMO it's better to have a note for performance degradation.
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.
It seems document issue like this: https://github.com/fluent/fluentd-docs/pull/215/files