From 9fdfcf4ae1e43ee9aef2df131b1efebeb4f12e9d Mon Sep 17 00:00:00 2001 From: gjohar Date: Wed, 12 Oct 2022 09:20:57 +0530 Subject: [PATCH 1/3] Add support for OpenSearch 2.x Signed-off-by: gjohar --- .github/workflows/ci-opensearch.yml | 3 +++ pkg/es/client/cluster_client.go | 2 +- pkg/es/config/config.go | 4 ++++ plugin/storage/integration/elasticsearch_test.go | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci-opensearch.yml b/.github/workflows/ci-opensearch.yml index 7a685571e69..43e9713b946 100644 --- a/.github/workflows/ci-opensearch.yml +++ b/.github/workflows/ci-opensearch.yml @@ -16,6 +16,9 @@ jobs: - major: 1.x image: 1.0.0 distribution: opensearch + - major: 2.x + image: 2.3.0 + distribution: opensearch name: ${{ matrix.version.distribution }} ${{ matrix.version.major }} steps: - uses: actions/checkout@v3 diff --git a/pkg/es/client/cluster_client.go b/pkg/es/client/cluster_client.go index 461f5ccdc2c..7d05e29497c 100644 --- a/pkg/es/client/cluster_client.go +++ b/pkg/es/client/cluster_client.go @@ -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 diff --git a/pkg/es/config/config.go b/pkg/es/config/config.go index e6f7909d3e3..fc47c357f24 100644 --- a/pkg/es/config/config.go +++ b/pkg/es/config/config.go @@ -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) diff --git a/plugin/storage/integration/elasticsearch_test.go b/plugin/storage/integration/elasticsearch_test.go index 0258a18cf65..9d2ec031b1f 100644 --- a/plugin/storage/integration/elasticsearch_test.go +++ b/plugin/storage/integration/elasticsearch_test.go @@ -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 } } From 4a75569aa308b13061f9341462b310eb133899a5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 10 Oct 2022 00:40:13 -0400 Subject: [PATCH 2/3] Bump github.com/kr/pretty from 0.3.0 to 0.3.1 (#3961) Bumps [github.com/kr/pretty](https://github.com/kr/pretty) from 0.3.0 to 0.3.1. - [Release notes](https://github.com/kr/pretty/releases) - [Commits](https://github.com/kr/pretty/compare/v0.3.0...v0.3.1) --- updated-dependencies: - dependency-name: github.com/kr/pretty dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: gjohar --- go.mod | 4 ++-- go.sum | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 6e497ef9283..d890af8f34d 100644 --- a/go.mod +++ b/go.mod @@ -29,7 +29,7 @@ require ( github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 github.com/hashicorp/go-hclog v1.3.1 github.com/hashicorp/go-plugin v1.4.5 - github.com/kr/pretty v0.3.0 + github.com/kr/pretty v0.3.1 github.com/olivere/elastic v6.2.37+incompatible github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger v0.61.0 github.com/opentracing-contrib/go-grpc v0.0.0-20191001143057-db30781987df @@ -125,7 +125,7 @@ require ( github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/procfs v0.8.0 // indirect github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect - github.com/rogpeppe/go-internal v1.6.2 // indirect + github.com/rogpeppe/go-internal v1.9.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spf13/afero v1.8.2 // indirect github.com/spf13/cast v1.5.0 // indirect diff --git a/go.sum b/go.sum index 9b9cca0e7ef..69614b8c5c8 100644 --- a/go.sum +++ b/go.sum @@ -444,8 +444,9 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.0/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= -github.com/kr/pretty v0.3.0 h1:WgNl7dwNpEZ6jJ9k1snq4pZsg7DOEN8hP9Xw0Tsjwk0= github.com/kr/pretty v0.3.0/go.mod h1:640gp4NfQd8pI5XOwp5fnNeVWj67G7CFk/SaSQn7NBk= +github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= +github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= @@ -554,6 +555,7 @@ github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= +github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= @@ -598,8 +600,8 @@ github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= -github.com/rogpeppe/go-internal v1.6.2 h1:aIihoIOHCiLZHxyoNQ+ABL4NKhFTgKLBdMLyEAh98m0= -github.com/rogpeppe/go-internal v1.6.2/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTEfhy4qGm1nDQc= +github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= +github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rs/cors v1.8.2 h1:KCooALfAYGs415Cwu5ABvv9n9509fSiG5SQJn/AQo4U= github.com/rs/cors v1.8.2/go.mod h1:XyqrcTp5zjWr1wsJ8PIRZssZ8b/WMcMf71DJnit4EMU= github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g= From 7763f356fcdd330627c6d2a762a8c60245992425 Mon Sep 17 00:00:00 2001 From: gjohar Date: Wed, 12 Oct 2022 17:46:18 +0530 Subject: [PATCH 3/3] Added unit test for OpenSearch version 2.x check Signed-off-by: gjohar --- pkg/es/client/cluster_client_test.go | 32 +++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/pkg/es/client/cluster_client_test.go b/pkg/es/client/cluster_client_test.go index 67a8ebe3511..c0ff770a427 100644 --- a/pkg/es/client/cluster_client_test.go +++ b/pkg/es/client/cluster_client_test.go @@ -63,7 +63,7 @@ const badVersionNoNumber = ` } ` -const opensearchInfo = ` +const opensearch1 = ` { "name" : "opensearch-node1", "cluster_name" : "opensearch-cluster", @@ -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 = ` { @@ -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, }, {