mirror of
https://github.com/elastic/logstash.git
synced 2025-04-25 07:07:54 -04:00
Adds a test and fix for JIRA issue LOGSTASH-501: The file input adds an extra forward slash to the front of @source_path
This commit is contained in:
parent
794b43e380
commit
ae8d17caa8
2 changed files with 46 additions and 1 deletions
|
@ -1,6 +1,7 @@
|
||||||
require "logstash/inputs/base"
|
require "logstash/inputs/base"
|
||||||
require "logstash/namespace"
|
require "logstash/namespace"
|
||||||
require "socket" # for Socket.gethostname
|
require "socket" # for Socket.gethostname
|
||||||
|
require "uri"
|
||||||
|
|
||||||
# Stream events from files.
|
# Stream events from files.
|
||||||
#
|
#
|
||||||
|
@ -67,7 +68,7 @@ class LogStash::Inputs::File < LogStash::Inputs::Base
|
||||||
hostname = Socket.gethostname
|
hostname = Socket.gethostname
|
||||||
|
|
||||||
tail.subscribe do |path, line|
|
tail.subscribe do |path, line|
|
||||||
source = "file://#{hostname}/#{path}"
|
source = URI::Generic.new("file", nil, hostname, nil, nil, path, nil, nil, nil).to_s
|
||||||
@logger.debug("Received line", :path => path, :line => line)
|
@logger.debug("Received line", :path => path, :line => line)
|
||||||
e = to_event(line, source)
|
e = to_event(line, source)
|
||||||
if e
|
if e
|
||||||
|
|
44
test/logstash/inputs/test_file.rb
Normal file
44
test/logstash/inputs/test_file.rb
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
require "rubygems"
|
||||||
|
require File.join(File.dirname(__FILE__), "..", "minitest")
|
||||||
|
|
||||||
|
require "logstash/loadlibs"
|
||||||
|
require "logstash/testcase"
|
||||||
|
require "logstash/agent"
|
||||||
|
require "logstash/logging"
|
||||||
|
require "logstash/inputs/file"
|
||||||
|
|
||||||
|
require "tempfile"
|
||||||
|
|
||||||
|
describe LogStash::Inputs::File do
|
||||||
|
test "file input sets source_path properly for events" do
|
||||||
|
logfile = Tempfile.new("logstash")
|
||||||
|
begin
|
||||||
|
@input = LogStash::Inputs::File.new("type" => ["testing"], "path" => [logfile.path])
|
||||||
|
@input.register
|
||||||
|
|
||||||
|
queue = Queue.new
|
||||||
|
|
||||||
|
Thread.new { @input.run(queue) }
|
||||||
|
|
||||||
|
event = nil
|
||||||
|
while event.nil?
|
||||||
|
logfile.write("This is my log message.\n")
|
||||||
|
logfile.flush
|
||||||
|
|
||||||
|
begin
|
||||||
|
event = queue.pop(true)
|
||||||
|
rescue ThreadError => error
|
||||||
|
raise error unless error.to_s == "queue empty"
|
||||||
|
sleep(0.05)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
@input.teardown
|
||||||
|
|
||||||
|
assert_equal(logfile.path, event["@source_path"])
|
||||||
|
ensure
|
||||||
|
logfile.close
|
||||||
|
logfile.unlink
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end # testing for LogStash::Inputs::File
|
Loading…
Add table
Add a link
Reference in a new issue