Skip to content

Commit 01ceb73

Browse files
authored
in_systemd: pass storage conf to storage_create to support named storage (#140)
Previously, `storage_create` was called without the `conf` argument, which prevented it from properly parsing named storage sections . This commit extracts the storage configuration and explicitly passes it to `storage_create` along with `default_type`. This ensures that named storage settings are correctly applied and accurately reflected in the storage paths.
1 parent 6ab544e commit 01ceb73

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

lib/fluent/plugin/in_systemd.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ class SystemdInput < Input # rubocop:disable Metrics/ClassLength
5050
def configure(conf)
5151
super
5252
@journal = nil
53-
@pos_storage = storage_create(usage: 'positions')
53+
config = conf.elements.find { |e| e.name == 'storage' }
54+
@pos_storage = storage_create(usage: 'positions', conf: config, default_type: DEFAULT_STORAGE_TYPE)
5455
@mutator = SystemdEntryMutator.new(**@entry_opts.to_h)
5556
@mutator.warnings.each { |warning| log.warn(warning) }
5657
end

test/plugin/test_in_systemd.rb

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,58 @@ def test_reading_from_a_journal_with_corrupted_entries
268268
# Since libsystemd v250, it can read this corrupted record.
269269
assert { d.events.size == 460 or d.events.size == 461 }
270270
end
271+
272+
def test_configure_storage_with_conf_arg_does_not_raise
273+
config = base_config + %(
274+
@id in_systemd
275+
<storage system_cursor>
276+
@type local
277+
persistent true
278+
</storage>
279+
)
280+
Dir.mktmpdir('root_dir') do |root_dir|
281+
Fluent::SystemConfig.overwrite_system_config('root_dir' => root_dir) do
282+
assert_nothing_raised do
283+
create_driver(config)
284+
end
285+
end
286+
end
287+
end
288+
289+
def test_storage_path_reflects_conf_arg
290+
config = base_config + %(
291+
@id in_systemd
292+
<storage system_cursor>
293+
@type local
294+
persistent true
295+
</storage>
296+
)
297+
Dir.mktmpdir('root_dir') do |root_dir|
298+
expected = File.join(root_dir, 'worker0', 'in_systemd', 'storage.system_cursor.json')
299+
Fluent::SystemConfig.overwrite_system_config('root_dir' => root_dir) do
300+
d = create_driver(config)
301+
d.run(expect_emits: 1)
302+
assert_path_exist expected
303+
end
304+
end
305+
end
306+
307+
def test_storage_path_without_conf_arg
308+
config = base_config + %(
309+
read_from_head true
310+
@id in_systemd
311+
<storage>
312+
@type local
313+
persistent true
314+
</storage>
315+
)
316+
Dir.mktmpdir('root_dir') do |root_dir|
317+
expected = File.join(root_dir, 'worker0', 'in_systemd', 'storage.json')
318+
Fluent::SystemConfig.overwrite_system_config('root_dir' => root_dir) do
319+
d = create_driver(config)
320+
d.run(expect_emits: 1)
321+
assert_path_exist expected
322+
end
323+
end
324+
end
271325
end

0 commit comments

Comments
 (0)