diff --git a/lib/logstash/inputs/file.rb b/lib/logstash/inputs/file.rb index d305df6..f1e7405 100644 --- a/lib/logstash/inputs/file.rb +++ b/lib/logstash/inputs/file.rb @@ -373,12 +373,11 @@ def run(queue) @completely_stopped.make_true end # def run - def post_process_this(event) + def post_process_this(event, path) + event.set("[@metadata][path]", path) event.set("[@metadata][host]", @host) attempt_set(event, @source_host_field, @host) - - source_path = event.get('[@metadata][path]') and - attempt_set(event, @source_path_field, source_path) + attempt_set(event, @source_path_field, path) if path decorate(event) @queue.get << event diff --git a/lib/logstash/inputs/file_listener.rb b/lib/logstash/inputs/file_listener.rb index 5cf689d..5a264a6 100644 --- a/lib/logstash/inputs/file_listener.rb +++ b/lib/logstash/inputs/file_listener.rb @@ -40,8 +40,7 @@ def accept(data) end def process_event(event) - event.set("[@metadata][path]", path) - input.post_process_this(event) + input.post_process_this(event, path) end end diff --git a/spec/inputs/file_read_spec.rb b/spec/inputs/file_read_spec.rb index 54c3685..02bf83d 100644 --- a/spec/inputs/file_read_spec.rb +++ b/spec/inputs/file_read_spec.rb @@ -338,7 +338,7 @@ sincedb_content = File.read(sincedb_path).strip expect( sincedb_content ).to_not be_empty - Stud.try(3.times) do + try(3) do sleep(1.5) # > sincedb_clean_after sincedb_content = File.read(sincedb_path).strip @@ -363,7 +363,10 @@ def wait_for_start_processing(run_thread, timeout: 1.0) end end - def wait_for_file_removal(path, timeout: 3 * interval) - wait(timeout).for { File.exist?(path) }.to be_falsey + def wait_for_file_removal(path) + timeout = interval + try(5) do + wait(timeout).for { File.exist?(path) }.to be_falsey + end end end