Skip to content

Commit

Permalink
Try to fix journal rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
errm committed Feb 8, 2017
1 parent a85dedd commit dac0582
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/fluent/plugin/in_systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class SystemdInput < Input
def configure(conf)
super
@pos_writer = PosWriter.new(@pos_file)
@journal = Systemd::Journal.new(path: @path)
@journal.filter(*@filters)
seek
end

def start
Expand All @@ -37,6 +34,12 @@ def shutdown

private

def init_journal
@journal = Systemd::Journal.new(path: @path)
@journal.filter(*@filters)
seek
end

def seek
seek_to(@pos_writer.cursor || read_from)
rescue Systemd::JournalError
Expand All @@ -59,6 +62,7 @@ def read_from
end

def run
init_journal
Thread.current.abort_on_exception = true
watch do |entry|
begin
Expand All @@ -67,6 +71,7 @@ def run
log.error("Exception emitting record: #{e}")
end
end
@pos_writer.sync
end

def formatted(entry)
Expand Down
4 changes: 4 additions & 0 deletions lib/fluent/plugin/systemd/pos_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ def shutdown
write_pos
end

def sync
write_pos
end

def update(c)
return unless @path
@lock.synchronize { @cursor = c }
Expand Down
11 changes: 11 additions & 0 deletions test/plugin/systemd/test_pos_writer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ def test_writing_the_cursor_when_file_does_not_exist_yet
FileUtils.rm_rf dir
end

def test_syncing_the_cursor_when_file_does_not_exist_yet
dir = Dir.mktmpdir("posdir")
path = "#{dir}/foo.pos"
pos_writer = Fluent::Plugin::SystemdInput::PosWriter.new(path)
pos_writer.start
pos_writer.update("this is the cursor")
pos_writer.sync
assert_equal File.read(path), "this is the cursor"
FileUtils.rm_rf dir
end

def test_file_permission_when_file_does_not_exist_yet
dir = Dir.mktmpdir("posdir")
path = "#{dir}/foo.pos"
Expand Down

0 comments on commit dac0582

Please sign in to comment.