Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Refactor: unify event updates to happen in one place #297

Merged
merged 4 commits into from
Jun 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions lib/logstash/inputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lib/logstash/inputs/file_listener.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions spec/inputs/file_read_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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