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

Add support for OpenSearch 2.x #3966

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .github/workflows/ci-opensearch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ jobs:
- major: 1.x
image: 1.0.0
distribution: opensearch
- major: 2.x
yurishkuro marked this conversation as resolved.
Show resolved Hide resolved
image: 2.3.0
distribution: opensearch
name: ${{ matrix.version.distribution }} ${{ matrix.version.major }}
steps:
- uses: actions/checkout@v3
Expand Down
2 changes: 1 addition & 1 deletion pkg/es/client/cluster_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *ClusterClient) Version() (uint, error) {
if err != nil {
return 0, fmt.Errorf("invalid version format: %s", version[0])
}
if strings.Contains(info.TagLine, "OpenSearch") && major == 1 {
if strings.Contains(info.TagLine, "OpenSearch") && (major == 1 || major == 2) {
return 7, nil
}
return uint(major), nil
Expand Down
32 changes: 29 additions & 3 deletions pkg/es/client/cluster_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const badVersionNoNumber = `
}
`

const opensearchInfo = `
const opensearch1 = `
{
"name" : "opensearch-node1",
"cluster_name" : "opensearch-cluster",
Expand All @@ -83,6 +83,26 @@ const opensearchInfo = `
}
`

const opensearch2 = `
{
"name" : "opensearch-node1",
"cluster_name" : "opensearch-cluster",
"cluster_uuid" : "1StaUGrGSx61r41d-1nDiw",
"version" : {
"distribution" : "opensearch",
"number" : "2.3.0",
"build_type" : "tar",
"build_hash" : "34550c5b17124ddc59458ef774f6b43a086522e3",
"build_date" : "2021-07-02T23:22:21.383695Z",
"build_snapshot" : false,
"lucene_version" : "8.8.2",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "The OpenSearch Project: https://opensearch.org/"
}
`

const elasticsearch7 = `

{
Expand Down Expand Up @@ -146,9 +166,15 @@ func TestVersion(t *testing.T) {
expectedResult: 7,
},
{
name: "success with opensearch",
name: "success with opensearch 1",
responseCode: http.StatusOK,
response: opensearch1,
expectedResult: 7,
},
{
name: "success with opensearch 2",
responseCode: http.StatusOK,
response: opensearchInfo,
response: opensearch2,
expectedResult: 7,
},
{
Expand Down
4 changes: 4 additions & 0 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac
logger.Info("OpenSearch 1.x detected, using ES 7.x index mappings")
esVersion = 7
}
if pingResult.Version.Number[0] == '2' {
logger.Info("OpenSearch 2.x detected, using ES 7.x index mappings")
esVersion = 7
}
}
logger.Info("Elasticsearch detected", zap.Int("version", esVersion))
c.Version = uint(esVersion)
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/integration/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (s *ESStorageIntegration) getVersion() (uint, error) {
}
// OpenSearch is based on ES 7.x
if strings.Contains(pingResult.TagLine, "OpenSearch") {
if pingResult.Version.Number[0] == '1' {
if pingResult.Version.Number[0] == '1' || pingResult.Version.Number[0] == '2' {
esVersion = 7
}
}
Expand Down