Skip to content

Commit e22fefd

Browse files
authored
Merge pull request #49 from chancez/0.8_handle_corrupted_logs
Gracefully handle corrupted journal log entries
2 parents 8428e85 + 9eb8473 commit e22fefd

5 files changed

Lines changed: 24 additions & 5 deletions

File tree

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ language: ruby
22
sudo: required
33
services:
44
- docker
5+
rvm:
6+
- 2.3

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ task build: "docker:test"
1414
task default: :reevoocop
1515

1616
namespace :docker do
17-
distros = [:ubuntu, :"tdagent-ubuntu", :"tdagent-centos"]
17+
distros = %i[ubuntu tdagent-ubuntu tdagent-centos]
1818
task test: distros
1919

2020
distros.each do |distro|

lib/fluent/plugin/in_systemd.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,12 @@ def watch
8585
while @running
8686
init_journal if @journal.wait(0) == :invalidate
8787
while @journal.move_next && @running
88-
yield @journal.current_entry
88+
begin
89+
yield @journal.current_entry
90+
rescue Systemd::JournalError => e
91+
log.warn("Error Parsing Journal: #{e.class}: #{e.message}")
92+
next
93+
end
8994
@pos_writer.update(@journal.cursor)
9095
end
9196
# prevent a loop of death
3.82 MB
Binary file not shown.

test/plugin/test_in_systemd.rb

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ def setup
1212
path test/fixture
1313
)
1414

15+
@badmsg_config = %(
16+
tag test
17+
path test/fixture/corrupt
18+
read_from_head true
19+
)
20+
1521
@strip_config = base_config + %(
1622
strip_underscores true
1723
)
@@ -37,7 +43,8 @@ def setup
3743
)
3844
end
3945

40-
attr_reader :journal, :base_config, :pos_path, :pos_config, :head_config, :filter_config, :strip_config, :tail_config
46+
attr_reader :journal, :base_config, :pos_path, :pos_config, :head_config,
47+
:filter_config, :strip_config, :tail_config, :badmsg_config
4148

4249
def create_driver(config)
4350
Fluent::Test::InputTestDriver.new(Fluent::SystemdInput).configure(config)
@@ -112,7 +119,6 @@ def test_reading_from_the_journal_tail_with_strip_underscores
112119
d.run
113120
end
114121

115-
116122
def test_pos_file_is_written
117123
d = create_driver(pos_config)
118124
d.run
@@ -140,7 +146,7 @@ def test_reading_from_a_pos
140146
assert_equal 143, d.emits.size
141147
end
142148

143-
def test_reading_from_an_invalid_pos # rubocop:disable Metrics/AbcSize
149+
def test_reading_from_an_invalid_pos
144150
file = File.open(pos_path, "w+")
145151
file.print "thisisinvalid"
146152
file.close
@@ -180,4 +186,10 @@ def test_reading_from_the_journal_tail_explicit_setting
180186
d.run
181187
end
182188

189+
def test_continue_on_bad_message
190+
d = create_driver(badmsg_config)
191+
d.run
192+
assert_equal 460, d.events.size
193+
end
194+
183195
end

0 commit comments

Comments
 (0)