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
Getting stuck on Journal Rotation #70
Comments
Hi! That's a good question. It seems like you can tell when an "invalidate" event occurs if you are using wait, which the
So it should be sufficient to just call
Should have solved it as well, although a little heavy-handed. |
Let me see if I can reproduce in testing and come up with anything concrete. |
I was able to reproduce the issue like so: #!/usr/bin/env ruby
require 'systemd/journal'
j = Systemd::Journal.new
j.seek(:end)
j.move_previous
loop do
j.wait
while j.move_next
puts j.current_entry.inspect
end
end
My initial attempt to solve this was the following: #!/usr/bin/env ruby
require 'systemd/journal'
j = Systemd::Journal.new
j.seek(:end)
j.move_previous
cursor = j.cursor
loop do
if j.wait == :invalidate
puts 'received invalidate'
j = Systemd::Journal.new
puts "seek: #{j.seek(cursor)}"
puts "move next: #{j.move_next}"
end
while j.move_next
puts j.current_entry.inspect
cursor = j.cursor
end
end However, it seems the very first time you call This eventually worked for me: #!/usr/bin/env ruby
require 'systemd/journal'
j = Systemd::Journal.new
j.seek(:end)
j.move_previous
j.wait(0) # why do we need a wait here?
cursor = j.cursor
loop do
if j.wait == :invalidate
puts 'received invalidate'
j = Systemd::Journal.new
puts "fake wait returned #{j.wait(0)} " # why do we need a wait here?
puts "seek: #{j.seek(cursor)}"
puts "move next: #{j.move_next}"
end
while j.move_next
puts j.current_entry.inspect
cursor = j.cursor
end
end After forcing a rotation with So, this is a long winded way of saying, I'm not sure what the fix is here :) It might be worthwhile trying to get some information about why |
Thanks for your help... digging into the documentation but it is not entirely clear about when invalidate I guess I am not that bothered, so long as the behaviour is something I know about... I will do some more testing, but it is still strange that my heavy handed approach did not work... |
I browsed through the source a bit and found that it's expected that the very first call to You can mimic this either by calling FWIW I asked on IRC about the right behaviour when the journal is rotated, but didn't ever get an answer. I would be inclined to try something like this and see if it solves for you:
I will look into adding functionality to handle this automatically since it seems like a useful usecase. If we're going to be creating new journal instances frequently, I'll probably also need to update the cleanup code to run immediately instead of relying on a finalizer. |
Based on suggestions from @ledbettj in ledbettj/systemd-journal#70 thanks :)
@ledbettj, the above code does not seem right, given systemd/systemd#7998 (comment). It seems that as long as If we instead, expose |
This ensures that inotify properly tracks journal rotation fixing ledbettj#70 and should also guard against the issues in systemd/systemd#7998 and rsyslog/rsyslog#2437
So in We do however still need to reload on So it seems that this:
Is unfortunately not the case (unless I am missing something) |
Why do we still need to reload on invalidate? The C code in systemd/systemd#7998 (comment) seems to show that it is not needed, right? |
Hi I am trying to debug some issues with my fluentd plugin: fluent-plugins-nursery/fluent-plugin-systemd#27
Essentially when the journal is rotated we stop receiving events... my first go at trying to fix this was to new up a
Systemd::Journal
every time#move_next
returned false... this does not seem to work however.I am not sure if this is something that should be handled by my plugin or Systemd::Journal, but I hoped you might have some insight that would help fix this?
The text was updated successfully, but these errors were encountered: