Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Aug 11, 2021
1 parent 6e76b94 commit ac72493
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/ci-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ jobs:
matrix:
version:
- major: 5.x
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.16
image: 5.6.16
distribution: elasticsearch
- major: 6.x
image: docker.elastic.co/elasticsearch/elasticsearch:6.8.18
image: 6.8.18
distribution: elasticsearch
- major: 7.x
image: docker.elastic.co/elasticsearch/elasticsearch:7.14.0
image: 7.14.0
distribution: elasticsearch
- major: OpenSearch 1.x
image: opensearchproject/opensearch:1.0.0
image: 1.0.0
distribution: opensearch
name: elasticsearch ${{ matrix.version.major }}
steps:
- uses: actions/checkout@v2.3.4
Expand All @@ -38,4 +42,4 @@ jobs:
run: make install-ci

- name: Run elasticsearch integration tests
run: bash scripts/es-integration-test.sh ${{ matrix.version.image }}
run: bash scripts/es-integration-test.sh ${{ matrix.version. }} ${{ matrix.version.image }}
4 changes: 2 additions & 2 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac
return nil, err
}
// OpenSearch is based on ES 7.x
if strings.ContainsAny(pingResult.TagLine, "OpenSearch") {
if pingResult.Version.Number[0] == 1 {
if strings.Contains(pingResult.TagLine, "OpenSearch") {
if pingResult.Version.Number[0] == '1' {
logger.Info("OpenSearch 1.x detected, using ES 7.x index mappings")
esVersion = 7
}
Expand Down
7 changes: 7 additions & 0 deletions plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"net/http"
"os"
"strconv"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -68,6 +69,12 @@ func (s *ESStorageIntegration) getVersion() (uint, error) {
if err != nil {
return 0, err
}
// OpenSearch is based on ES 7.x
if strings.Contains(pingResult.TagLine, "OpenSearch") {
if pingResult.Version.Number[0] == '1' {
esVersion = 7
}
}
return uint(esVersion), nil
}

Expand Down
42 changes: 33 additions & 9 deletions scripts/es-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@
set -euxf -o pipefail

usage() {
echo $"Usage: $0 <es_image>"
echo $"Usage: $0 <elasticsearch|opensearch> <version>"
exit 1
}

check_arg() {
if [ ! $# -eq 1 ]; then
echo "ERROR: need exactly one argument"
if [ ! $# -eq 2 ]; then
echo "ERROR: need exactly two arguments, <elasticsearch|opensearch> <image>"
usage
fi
}

setup_es() {
local image=$1
local tag=$1
local image=docker.elastic.co/elasticsearch/elasticsearch
local params=(
--rm
--detach
Expand All @@ -24,9 +25,23 @@ setup_es() {
--env "transport.host=127.0.0.1"
--env "xpack.security.enabled=false"
--env "xpack.monitoring.enabled=false"
)
local cid=$(docker run ${params[@]} ${image}:${tag})
echo ${cid}
}

setup_opensearch() {
local image=opensearchproject/opensearch
local tag=$1
local params=(
--rm
--detach
--publish 9200:9200
--env "http.host=0.0.0.0"
--env "transport.host=127.0.0.1"
--env "plugins.security.disabled=true"
)
local cid=$(docker run ${params[@]} ${image})
local cid=$(docker run ${params[@]} ${image}:${tag})
echo ${cid}
}

Expand Down Expand Up @@ -57,8 +72,17 @@ build_query() {
}

run_integration_test() {
local es_version=$1
local cid=$(setup_es ${es_version})
local distro=$1
local version=$2
local cid
if [ ${distro} = "elasticsearch" ]; then
cid=$(setup_es ${version})
elif [ ${distro} == "opensearch" ]; then
cid=$(setup_opensearch ${version})
else
echo "Unknown distribution $distro. Valid options are opensearch or elasticsearch"
usage
fi
STORAGE=elasticsearch make storage-integration-test
make index-cleaner-integration-test
make index-rollover-integration-test
Expand All @@ -77,8 +101,8 @@ run_token_propagation_test() {
main() {
check_arg "$@"

echo "Executing integration test for elasticsearch $1"
run_integration_test "$1"
echo "Executing integration test for $1 $2"
run_integration_test "$1" "$2"
echo "Executing token propagation test"
run_token_propagation_test
}
Expand Down

0 comments on commit ac72493

Please sign in to comment.