diff --git a/.ci/Dockerfile b/.ci/Dockerfile new file mode 100644 index 0000000..9ccbde9 --- /dev/null +++ b/.ci/Dockerfile @@ -0,0 +1,27 @@ +ARG ELASTIC_STACK_VERSION +ARG DISTRIBUTION_SUFFIX +FROM docker.elastic.co/logstash/logstash${DISTRIBUTION_SUFFIX}:${ELASTIC_STACK_VERSION} +USER root +RUN localedef -i en_US -f UTF-8 en_US.UTF-8 +RUN locale -a +USER logstash + +COPY --chown=logstash:logstash Gemfile /usr/share/plugins/plugin/Gemfile +COPY --chown=logstash:logstash *.gemspec VERSION* version* /usr/share/plugins/plugin/ +RUN cp /usr/share/logstash/logstash-core/versions-gem-copy.yml /usr/share/logstash/versions.yml +# NOTE: since 8.0 JDK is bundled as part of the LS distribution under $LS_HOME/jdk +ENV PATH="${PATH}:/usr/share/logstash/vendor/jruby/bin:/usr/share/logstash/jdk/bin" +ENV LOGSTASH_SOURCE="1" +ENV ELASTIC_STACK_VERSION=$ELASTIC_STACK_VERSION +# DISTRIBUTION="default" (by default) or "oss" +ARG DISTRIBUTION +ENV DISTRIBUTION=$DISTRIBUTION +# INTEGRATION="true" while integration testing (false-y by default) +ARG INTEGRATION +ENV INTEGRATION=$INTEGRATION +RUN gem install bundler -v '< 2' +WORKDIR /usr/share/plugins/plugin +RUN bundle install --with test ci +COPY --chown=logstash:logstash . /usr/share/plugins/plugin +RUN bundle exec rake vendor +RUN .ci/setup.sh diff --git a/.travis.yml b/.travis.yml index a50fc73..9d01d1c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,19 @@ import: -- logstash-plugins/.ci:travis/travis.yml@1.x \ No newline at end of file +- logstash-plugins/.ci:travis/travis.yml@1.x + +before_install: + - sudo apt-get install jq + - sudo apt-get install libseccomp-dev + - sudo locale-gen en_US.UTF-8 + - sudo dpkg-reconfigure locales +arch: + - arm64 + - amd64 + +virt: vm + +env: + jobs: + - ELASTIC_STACK_VERSION=7.x + - SNAPSHOT=true ELASTIC_STACK_VERSION=8.0.0-SNAPSHOT + - SNAPSHOT=true ELASTIC_STACK_VERSION=7.11.0-SNAPSHOT diff --git a/lib/filewatch/helper.rb b/lib/filewatch/helper.rb index 5da8c0f..66fa844 100644 --- a/lib/filewatch/helper.rb +++ b/lib/filewatch/helper.rb @@ -3,8 +3,10 @@ # https://raw.githubusercontent.com/rails/rails/v4.2.1/activesupport/lib/active_support/core_ext/file/atomic.rb # change method name to avoid borking active_support and vice versa require 'fileutils' +require "logstash/util/loggable" module FileHelper + include LogStash::Util::Loggable extend self # Write to a file atomically. Useful for situations where you don't # want other processes or threads to see half-written files. @@ -38,8 +40,13 @@ def write_atomically(file_name) return return_val if old_stat.nil? # Set correct uid/gid on new file - File.chown(old_stat.uid, old_stat.gid, file_name) if old_stat - + if old_stat + begin + File.chown(old_stat.uid, old_stat.gid, file_name) + rescue Errno::EPERM => e + logger.error("sincedb_write: #{file_name} error:", :old_stat => old_stat, :exception => e.class, :message => e.message) + end + end return_val end diff --git a/spec/inputs/file_read_spec.rb b/spec/inputs/file_read_spec.rb index d1533bd..5c21030 100644 --- a/spec/inputs/file_read_spec.rb +++ b/spec/inputs/file_read_spec.rb @@ -338,10 +338,11 @@ sincedb_content = File.read(sincedb_path).strip expect( sincedb_content ).to_not be_empty - Stud.try(3.times) do + Stud.try(10.times, RSpec::Expectations::ExpectationNotMetError) do sleep(1.5) # > sincedb_clean_after sincedb_content = File.read(sincedb_path).strip + puts "sincedb content is #{sincedb_content}" expect( sincedb_content ).to be_empty end end diff --git a/spec/inputs/file_tail_spec.rb b/spec/inputs/file_tail_spec.rb index 7aefc69..4af7cd2 100644 --- a/spec/inputs/file_tail_spec.rb +++ b/spec/inputs/file_tail_spec.rb @@ -201,7 +201,10 @@ let(:conf) { Hash.new } let(:mlconf) { Hash.new } let(:events) { Array.new } - let(:mlcodec) { LogStash::Codecs::Multiline.new(mlconf) } + let(:mlcodec) { + puts " The value of mlconf is #{mlconf}" + LogStash::Codecs::Multiline.new(mlconf) + } let(:tracer_codec) { FileInput::CodecTracer.new } let(:tmpdir_path) { Stud::Temporary.directory } let(:tmpfile_path) { ::File.join(tmpdir_path, "#{suffix}.txt") } @@ -222,7 +225,7 @@ fd.puts("ignore me 2") fd.fsync end - mlconf.update("pattern" => "^\s", "what" => "previous") + mlconf.update("pattern" => "^\\s", "what" => "previous") conf.update("type" => "blah", "path" => path_path, "sincedb_path" => sincedb_path, @@ -341,7 +344,7 @@ let(:suffix) { "J" } let(:tmpfile_path2) { ::File.join(tmpdir_path, "K.txt") } before do - mlconf.update("pattern" => "^\s", "what" => "previous") + mlconf.update("pattern" => "^\\s", "what" => "previous") conf.update( "type" => "blah", "path" => path_path,