Skip to content

Commit debe752

Browse files
authored
Merge pull request #41 from jtwile2/continue-on-bad-msg
Continue Reading on Bad Messages
2 parents c5fa4ea + 98cf097 commit debe752

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

lib/fluent/plugin/in_systemd.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,12 @@ def formatted(entry)
128128

129129
def watch
130130
while @journal.move_next
131-
yield @journal.current_entry
131+
begin
132+
yield @journal.current_entry
133+
rescue Systemd::JournalError => e
134+
log.warn("Error Parsing Journal: #{e.class}: #{e.message}")
135+
next
136+
end
132137
@pos_storage.put(:journal, @journal.cursor)
133138
end
134139
end
3.82 MB
Binary file not shown.

test/plugin/test_in_systemd.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ def setup
5858
path test/fixture
5959
)
6060

61+
@badmsg_config = %(
62+
tag test
63+
path test/fixture/corrupt
64+
read_from_head true
65+
)
66+
6167
# deprecated
6268
@strip_config = base_config + %(
6369
strip_underscores true
@@ -92,7 +98,8 @@ def setup
9298
end
9399

94100
attr_reader :journal, :base_config, :pos_path, :pos_config, :head_config,
95-
:filter_config, :strip_config, :tail_config, :not_present_config, :storage_path
101+
:filter_config, :strip_config, :tail_config, :not_present_config,
102+
:badmsg_config, :storage_path
96103

97104
def create_driver(config)
98105
Fluent::Test::Driver::Input.new(Fluent::Plugin::SystemdInput).configure(config)
@@ -250,4 +257,11 @@ def test_journal_not_present
250257
d.run(timeout: 5)
251258
assert_match "Systemd::JournalError: No such file or directory retrying in 1s", d.logs.last
252259
end
260+
261+
def test_continue_on_bad_message
262+
d = create_driver(badmsg_config)
263+
d.run(expect_emits: 460)
264+
assert_equal 460, d.events.size
265+
assert_equal 0, d.error_events.size
266+
end
253267
end

0 commit comments

Comments
 (0)