Skip to content

Commit 0d1d174

Browse files
authored
Make ci compatible with os2.x (#153)
* Fix the integration test to work with OpenSearch 2.x Don't run the parent_spec for opensearch >= 2.x Update index_spec.rb and compressed_indexing_spec.rb to not expect the _type field in the doc for Opensearch >= 2.0.0 * Update the OpenSearch versions in the .github/workflows/CI test matrix * Replace the python command in scripts/logstash-run.sh to extract the version field with grep For some logstash version e.g. 7.17.1, 8.3.2 the images are missing python leading to the following command to fail echo $(curl -s $SERVICE_URL | python -c "import sys, json; print(json.load(sys.stdin)['version']['number'])") That is causing some integration test to fail which depends on the OpenSearch version number. installing python in the container failed as GitHub action is complaining about missing apt-get Signed-off-by: Deep Datta <[email protected]>
1 parent 9f08019 commit 0d1d174

File tree

7 files changed

+28
-6
lines changed

7 files changed

+28
-6
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ jobs:
3434
strategy:
3535
matrix:
3636
logstash: [ "7.16.3", "7.17.1", "8.3.2" ]
37-
opensearch: [ "1.2.1" ]
37+
opensearch: [ "1.3.4", "2.1.0" ]
3838
secure: [ true, false ]
3939

4040
name: Integration Test logstash-output-opensearch against OpenSearch

scripts/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ RUN gem install bundler -v '< 2'
1010
WORKDIR /usr/share/plugins/plugin
1111
RUN bundle install --with test ci
1212
COPY --chown=logstash:logstash . /usr/share/plugins/plugin
13-
RUN bundle exec rake vendor
13+
RUN bundle exec rake vendor

scripts/logstash-run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ wait_for_es() {
1616
[[ $count -eq 0 ]] && exit 1
1717
sleep 20
1818
done
19-
echo $(curl -s $SERVICE_URL | python -c "import sys, json; print(json.load(sys.stdin)['version']['number'])")
19+
echo $(curl -s $SERVICE_URL | grep -oP '"number"[^"]+"\K[^"]+')
2020
}
2121

2222
if [[ "$SECURE_INTEGRATION" == "true" ]]; then

spec/integration/outputs/compressed_indexing_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,13 @@
5959
response = http_client.get("#{index_url}/_search?q=*&size=1000")
6060
result = LogStash::Json.load(response.body)
6161
result["hits"]["hits"].each do |doc|
62-
expect(doc["_type"]).to eq(type)
62+
# FIXME This checks for OpenSearch 1.x or OpenDistro which has version 7.10.x
63+
# need a cleaner way to check this.
64+
if OpenSearchHelper.check_version?("< 2") || OpenSearchHelper.check_version?("> 7")
65+
expect(doc["_type"]).to eq(type)
66+
else
67+
expect(doc).not_to include("_type")
68+
end
6369
expect(doc["_index"]).to eq(index)
6470
end
6571
end

spec/integration/outputs/index_spec.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,13 @@
8888
response = http_client.get("#{index_url}/_search?q=*&size=1000")
8989
result = LogStash::Json.load(response.body)
9090
result["hits"]["hits"].each do |doc|
91-
expect(doc["_type"]).to eq(type)
91+
# FIXME This checks for OpenSearch 1.x or OpenDistro which has version 7.10.x
92+
# need a cleaner way to check this.
93+
if OpenSearchHelper.check_version?("< 2") || OpenSearchHelper.check_version?("> 7")
94+
expect(doc["_type"]).to eq(type)
95+
else
96+
expect(doc).not_to include("_type")
97+
end
9298
expect(doc["_index"]).to eq(index)
9399
end
94100
end

spec/integration/outputs/parent_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
require_relative "../../../spec/opensearch_spec_helper"
1111
require "logstash/outputs/opensearch"
1212

13-
context "join field tests", :integration => true do
13+
context "join field tests", :integration => true && OpenSearchHelper.check_version?("<2") do
1414

1515
shared_examples "a join field based parent indexer" do
1616
let(:index) { 10.times.collect { rand(10).to_s }.join("") }

spec/opensearch_spec_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def self.version
4949
RSpec.configuration.filter[:version]
5050
end
5151

52+
def self.check_version?(*requirement)
53+
version = self.version
54+
if version.nil? || version.empty?
55+
puts "version tag isn't set. Returning false from 'check_version?`."
56+
return false
57+
end
58+
release_version = Gem::Version.new(version).release
59+
Gem::Requirement.new(requirement).satisfied_by?(release_version)
60+
end
61+
5262
RSpec::Matchers.define :have_hits do |expected|
5363
match do |actual|
5464
expected == actual['hits']['total']['value']

0 commit comments

Comments
 (0)