Skip to content

Commit

Permalink
improve sincedb_path argument handling and documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
jsvd authored and jordansissel committed Jul 8, 2015
1 parent 11ed55f commit c4cf3b9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/logstash/inputs/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ class LogStash::Inputs::File < LogStash::Inputs::Base
# How often (in seconds) we expand globs to discover new files to watch.
config :discover_interval, :validate => :number, :default => 15

# Where to write the sincedb database (keeps track of the current
# position of monitored log files). The default will write
# sincedb files to some path matching `$HOME/.sincedb*`
# Path of the sincedb database file (keeps track of the current
# position of monitored log files) that will be written to disk.
# The default will write sincedb files to some path matching `$HOME/.sincedb*`
# NOTE: it must be a file path and not a directory path
config :sincedb_path, :validate => :string

# How often (in seconds) to write a since database with the current position of
Expand Down Expand Up @@ -120,6 +121,10 @@ def register
:sincedb_path => @sincedb_path, :path => @path)
end

if File.directory?(@sincedb_path)
raise ArgumentError.new("sincedb_path must be a file path, not a directory. Received: \"#{@sincedb_path}\"")
end

@tail_config[:sincedb_path] = @sincedb_path

if @start_position == "beginning"
Expand Down
11 changes: 11 additions & 0 deletions spec/inputs/file_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "logstash/devutils/rspec/spec_helper"
require "tempfile"
require "stud/temporary"
require "logstash/inputs/file"

describe "inputs/file" do

Expand Down Expand Up @@ -165,4 +166,14 @@
insist { events[1]["path"] } == "#{tmpfile_path}"
insist { events[1]["host"] } == "#{Socket.gethostname.force_encoding(Encoding::UTF_8)}"
end

context "sincedb_path is an existing directory" do
it "should raise exception" do
tmpfile_path = Stud::Temporary.pathname
Stud::Temporary.directory do |sincedb_path|
plugin = LogStash::Inputs::File.new("path" => tmpfile_path, "sincedb_path" => sincedb_path)
expect { plugin.register }.to raise_error(ArgumentError)
end
end
end
end

0 comments on commit c4cf3b9

Please sign in to comment.