Skip to content

Commit

Permalink
Merge pull request #49 from chancez/0.8_handle_corrupted_logs
Browse files Browse the repository at this point in the history
Gracefully handle corrupted journal log entries
  • Loading branch information
errm authored Nov 30, 2017
2 parents 8428e85 + 9eb8473 commit e22fefd
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ language: ruby
sudo: required
services:
- docker
rvm:
- 2.3
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ task build: "docker:test"
task default: :reevoocop

namespace :docker do
distros = [:ubuntu, :"tdagent-ubuntu", :"tdagent-centos"]
distros = %i[ubuntu tdagent-ubuntu tdagent-centos]
task test: distros

distros.each do |distro|
Expand Down
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.
18 changes: 15 additions & 3 deletions 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,8 @@ 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 @@ -112,7 +119,6 @@ def test_reading_from_the_journal_tail_with_strip_underscores
d.run
end


def test_pos_file_is_written
d = create_driver(pos_config)
d.run
Expand Down Expand Up @@ -140,7 +146,7 @@ def test_reading_from_a_pos
assert_equal 143, d.emits.size
end

def test_reading_from_an_invalid_pos # rubocop:disable Metrics/AbcSize
def test_reading_from_an_invalid_pos
file = File.open(pos_path, "w+")
file.print "thisisinvalid"
file.close
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 e22fefd

Please sign in to comment.