Skip to content

Commit

Permalink
Continue Reading on Bad Messages
Browse files Browse the repository at this point in the history
Backport of #41 to
0.0.x branch
  • Loading branch information
Chance Zibolski committed Nov 21, 2017
1 parent 8428e85 commit 75d6834
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 6 additions & 1 deletion lib/fluent/plugin/in_systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,12 @@ def watch
while @running
init_journal if @journal.wait(0) == :invalidate
while @journal.move_next && @running
yield @journal.current_entry
begin
yield @journal.current_entry
rescue Systemd::JournalError => e
log.warn("Error Parsing Journal: #{e.class}: #{e.message}")
next
end
@pos_writer.update(@journal.cursor)
end
# prevent a loop of death
Expand Down
Binary file added test/fixture/corrupt/test.badmsg.journal
Binary file not shown.
14 changes: 13 additions & 1 deletion test/plugin/test_in_systemd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ def setup
path test/fixture
)

@badmsg_config = %(
tag test
path test/fixture/corrupt
read_from_head true
)

@strip_config = base_config + %(
strip_underscores true
)
Expand All @@ -37,7 +43,7 @@ def setup
)
end

attr_reader :journal, :base_config, :pos_path, :pos_config, :head_config, :filter_config, :strip_config, :tail_config
attr_reader :journal, :base_config, :pos_path, :pos_config, :head_config, :filter_config, :strip_config, :tail_config, :badmsg_config

def create_driver(config)
Fluent::Test::InputTestDriver.new(Fluent::SystemdInput).configure(config)
Expand Down Expand Up @@ -180,4 +186,10 @@ def test_reading_from_the_journal_tail_explicit_setting
d.run
end

def test_continue_on_bad_message
d = create_driver(badmsg_config)
d.run
assert_equal 460, d.events.size
end

end

0 comments on commit 75d6834

Please sign in to comment.