Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect OpenSearch version #3198

Merged
merged 6 commits into from
Aug 11, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/ci-elasticsearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,16 @@ jobs:
version:
- major: 5.x
image: 5.6.16
distribution: elasticsearch
- major: 6.x
image: 6.8.18
distribution: elasticsearch
- major: 7.x
image: 7.14.0
distribution: elasticsearch
- major: OpenSearch 1.x
image: 1.0.0
distribution: opensearch
name: elasticsearch ${{ matrix.version.major }}
steps:
- uses: actions/[email protected]
Expand All @@ -36,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 }}
7 changes: 7 additions & 0 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,13 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac
if err != nil {
return nil, err
}
// OpenSearch is based on ES 7.x
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
}
}
logger.Info("Elasticsearch detected", zap.Int("version", esVersion))
c.Version = uint(esVersion)
}
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") {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unfortunate we should refactor the test to use the pkg/es/config

if pingResult.Version.Number[0] == '1' {
esVersion = 7
}
}
return uint(esVersion), nil
}

Expand Down
38 changes: 31 additions & 7 deletions scripts/es-integration-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
set -euxf -o pipefail

usage() {
echo $"Usage: $0 <es_version>"
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
}
Expand All @@ -30,6 +30,21 @@ setup_es() {
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}:${tag})
echo ${cid}
}

setup_query() {
local arch=$(go env GOARCH)
local params=(
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