diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index bbb843b..109b0d5 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -34,7 +34,7 @@ jobs: strategy: matrix: logstash: [ "7.16.3", "7.17.1", "8.3.2" ] - opensearch: [ "1.2.1" ] + opensearch: [ "1.3.4", "2.1.0" ] secure: [ true, false ] name: Integration Test logstash-output-opensearch against OpenSearch diff --git a/scripts/Dockerfile b/scripts/Dockerfile index 34857fd..5f726da 100644 --- a/scripts/Dockerfile +++ b/scripts/Dockerfile @@ -10,4 +10,4 @@ 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 \ No newline at end of file +RUN bundle exec rake vendor diff --git a/scripts/logstash-run.sh b/scripts/logstash-run.sh index c6916a0..4b823f3 100755 --- a/scripts/logstash-run.sh +++ b/scripts/logstash-run.sh @@ -16,7 +16,7 @@ wait_for_es() { [[ $count -eq 0 ]] && exit 1 sleep 20 done - echo $(curl -s $SERVICE_URL | python -c "import sys, json; print(json.load(sys.stdin)['version']['number'])") + echo $(curl -s $SERVICE_URL | grep -oP '"number"[^"]+"\K[^"]+') } if [[ "$SECURE_INTEGRATION" == "true" ]]; then diff --git a/spec/integration/outputs/compressed_indexing_spec.rb b/spec/integration/outputs/compressed_indexing_spec.rb index faf48cc..cc9703a 100644 --- a/spec/integration/outputs/compressed_indexing_spec.rb +++ b/spec/integration/outputs/compressed_indexing_spec.rb @@ -59,7 +59,13 @@ response = http_client.get("#{index_url}/_search?q=*&size=1000") result = LogStash::Json.load(response.body) result["hits"]["hits"].each do |doc| - expect(doc["_type"]).to eq(type) + # FIXME This checks for OpenSearch 1.x or OpenDistro which has version 7.10.x + # need a cleaner way to check this. + if OpenSearchHelper.check_version?("< 2") || OpenSearchHelper.check_version?("> 7") + expect(doc["_type"]).to eq(type) + else + expect(doc).not_to include("_type") + end expect(doc["_index"]).to eq(index) end end diff --git a/spec/integration/outputs/index_spec.rb b/spec/integration/outputs/index_spec.rb index 83ed12f..5b8e025 100644 --- a/spec/integration/outputs/index_spec.rb +++ b/spec/integration/outputs/index_spec.rb @@ -88,7 +88,13 @@ response = http_client.get("#{index_url}/_search?q=*&size=1000") result = LogStash::Json.load(response.body) result["hits"]["hits"].each do |doc| - expect(doc["_type"]).to eq(type) + # FIXME This checks for OpenSearch 1.x or OpenDistro which has version 7.10.x + # need a cleaner way to check this. + if OpenSearchHelper.check_version?("< 2") || OpenSearchHelper.check_version?("> 7") + expect(doc["_type"]).to eq(type) + else + expect(doc).not_to include("_type") + end expect(doc["_index"]).to eq(index) end end diff --git a/spec/integration/outputs/parent_spec.rb b/spec/integration/outputs/parent_spec.rb index f8c957d..4edd256 100644 --- a/spec/integration/outputs/parent_spec.rb +++ b/spec/integration/outputs/parent_spec.rb @@ -10,7 +10,7 @@ require_relative "../../../spec/opensearch_spec_helper" require "logstash/outputs/opensearch" -context "join field tests", :integration => true do +context "join field tests", :integration => true && OpenSearchHelper.check_version?("<2") do shared_examples "a join field based parent indexer" do let(:index) { 10.times.collect { rand(10).to_s }.join("") } diff --git a/spec/opensearch_spec_helper.rb b/spec/opensearch_spec_helper.rb index 6eb447d..6bcdb16 100644 --- a/spec/opensearch_spec_helper.rb +++ b/spec/opensearch_spec_helper.rb @@ -49,6 +49,16 @@ def self.version RSpec.configuration.filter[:version] end + def self.check_version?(*requirement) + version = self.version + if version.nil? || version.empty? + puts "version tag isn't set. Returning false from 'check_version?`." + return false + end + release_version = Gem::Version.new(version).release + Gem::Requirement.new(requirement).satisfied_by?(release_version) + end + RSpec::Matchers.define :have_hits do |expected| match do |actual| expected == actual['hits']['total']['value']