-
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
MessagePackEventStream returns only first event #2099
Comments
AFAIK, If you really want to use these methods, you first need to call require 'fluent/event'
time = Fluent::EventTime.now
array_stream = Fluent::ArrayEventStream.new([[time, {'a' => 1}], [time, {'a' => 2}]])
mp_stream = Fluent::MessagePackEventStream.new(array_stream.to_msgpack_stream)
mp_stream.ensure_unpacked!
puts mp_stream.any?
puts mp_stream.size # Prints 0
mp_stream.each do |time|
puts time # Executes only once
end The above code should work just as you expect. |
@fujimotos I understand that
From my issue it may seem like I'm "picking" on |
@osela OK, I've got your point.
I actully agree with you on that point. As long as plugin developers misuse these methods in the wild, I concur In this particular case, the problem is that Maybe we can implement |
@fujimotos It's not just Would you mind sharing some insight regarding the usage of |
I actually don't know any case. My basic stance here is that, since this class is intentionally designed to defer the unpack I'm not saying the current design is super convincing (for example, its child class |
@fujimotos I investigated the issue further and also checked the commit where the code was introduced and I'm fairly certain it's a bug rather than the intended behavior. The problem is in the def each(&block)
if @unpacked_times
@unpacked_times.each_with_index do |time, i|
block.call(time, @unpacked_records[i])
end
else
@unpacked_times = []
@unpacked_records = []
msgpack_unpacker.feed_each(@data) do |time, record|
@unpacked_times << time
@unpacked_records << record
block.call(time, record)
end
@size = @unpacked_times.size
end
nil
end
end The I guess the code was written this way to avoid looping over the data twice, once for unpacking and again for returning it from I'm going to create a pull request to make What do you think? @tagomoris, do you have some input by any chance? |
This issue has been automatically marked as stale because it has been open 90 days with no activity. Remove stale label or comment or this issue will be closed in 30 days |
This issue was automatically closed because of stale in 30 days |
After calling
any?
orfirst()
on an instance of MessagePackEventStream which contains multiple events, iterating over it usingeach
returns only the first event and the streamsize
is 0.Here is a minimal reproduction:
Commenting the call to
any?
makes it work as it should. Am I missing something here?I noticed it trying to debug a specific filter directly following a forward-input.
I'm using fluentd 1.2.4.
The text was updated successfully, but these errors were encountered: