Skip to content

Commit

Permalink
[exporter/elasticsearchexporter]: Rollback to client 7.17.7 due to in…
Browse files Browse the repository at this point in the history
…compatibility (#16353)

Elasticsearch version 7.10 is incompatibility due to newer version of elasticsearch client.
  • Loading branch information
leewoobin789 committed Mar 8, 2023
1 parent 03c7bc0 commit b51da37
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 69 deletions.
16 changes: 16 additions & 0 deletions .chloggen/elastic-exporter-version-rollback.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: elasticsearchexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: roll back elasticsearch client to v7.17.7 due to incompatibility with older elasticsearch versions

# One or more tracking issues related to the change
issues: [16310]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:
3 changes: 1 addition & 2 deletions cmd/configschema/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -337,8 +337,7 @@ require (
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.1.0 // indirect
github.com/elastic/go-elasticsearch/v8 v8.5.0 // indirect
github.com/elastic/go-elasticsearch/v7 v7.17.7 // indirect
github.com/elastic/go-structform v0.0.10 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/envoyproxy/go-control-plane v0.10.3 // indirect
Expand Down
7 changes: 2 additions & 5 deletions cmd/configschema/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions cmd/otelcontribcol/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,7 @@ require (
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.1.0 // indirect
github.com/elastic/go-elasticsearch/v8 v8.5.0 // indirect
github.com/elastic/go-elasticsearch/v7 v7.17.7 // indirect
github.com/elastic/go-structform v0.0.10 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/envoyproxy/go-control-plane v0.10.3 // indirect
Expand Down
7 changes: 2 additions & 5 deletions cmd/otelcontribcol/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 18 additions & 40 deletions exporter/elasticsearchexporter/elasticsearch_bulk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,25 @@ import (
"bytes"
"context"
"crypto/tls"
"errors"
"fmt"
"io"
"net"
"net/http"
"time"

"github.com/cenkalti/backoff/v4"
elasticsearch "github.com/elastic/go-elasticsearch/v8"
esutil "github.com/elastic/go-elasticsearch/v8/esutil"
elasticsearch7 "github.com/elastic/go-elasticsearch/v7"
esutil7 "github.com/elastic/go-elasticsearch/v7/esutil"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/sanitize"
)

type esClientCurrent = elasticsearch.Client
type esConfigCurrent = elasticsearch.Config
type esBulkIndexerCurrent = esutil.BulkIndexer
type esBulkIndexerItem = esutil.BulkIndexerItem
type esBulkIndexerResponseItem = esutil.BulkIndexerResponseItem
type esClientCurrent = elasticsearch7.Client
type esConfigCurrent = elasticsearch7.Config
type esBulkIndexerCurrent = esutil7.BulkIndexer

type esBulkIndexerItem = esutil7.BulkIndexerItem
type esBulkIndexerResponseItem = esutil7.BulkIndexerResponseItem

// clientLogger implements the estransport.Logger interface
// that is required by the Elasticsearch client for logging.
Expand Down Expand Up @@ -95,16 +94,15 @@ func newElasticsearchClient(logger *zap.Logger, config *Config) (*esClientCurren

// maxRetries configures the maximum number of event publishing attempts,
// including the first send and additional retries.

maxRetries := config.Retry.MaxRequests - 1
retryDisabled := !config.Retry.Enabled || maxRetries <= 0
retryOnError := newRetryOnErrorFunc(retryDisabled)

if retryDisabled {
maxRetries = 0
retryOnError = nil
}

return elasticsearch.NewClient(esConfigCurrent{
return elasticsearch7.NewClient(esConfigCurrent{
Transport: transport,

// configure connection setup
Expand All @@ -116,11 +114,12 @@ func newElasticsearchClient(logger *zap.Logger, config *Config) (*esClientCurren
Header: headers,

// configure retry behavior
RetryOnStatus: retryOnStatus,
DisableRetry: retryDisabled,
RetryOnError: retryOnError,
MaxRetries: maxRetries,
RetryBackoff: createElasticsearchBackoffFunc(&config.Retry),
RetryOnStatus: retryOnStatus,
DisableRetry: retryDisabled,
EnableRetryOnTimeout: config.Retry.Enabled,
//RetryOnError: retryOnError, // should be used from esclient version 8 onwards
MaxRetries: maxRetries,
RetryBackoff: createElasticsearchBackoffFunc(&config.Retry),

// configure sniffing
DiscoverNodesOnStart: config.Discovery.OnStart,
Expand All @@ -132,27 +131,6 @@ func newElasticsearchClient(logger *zap.Logger, config *Config) (*esClientCurren
Logger: (*clientLogger)(logger),
})
}
func newRetryOnErrorFunc(retryDisabled bool) func(_ *http.Request, err error) bool {
if retryDisabled {
return func(_ *http.Request, err error) bool {
return false
}
}

return func(_ *http.Request, err error) bool {
var netError net.Error
shouldRetry := false

if isNetError := errors.As(err, &netError); isNetError && netError != nil {
// on Timeout (Proposal: predefined configuratble rules)
if !netError.Timeout() {
shouldRetry = true
}
}

return shouldRetry
}
}

func newTransport(config *Config, tlsCfg *tls.Config) *http.Transport {
transport := http.DefaultTransport.(*http.Transport).Clone()
Expand All @@ -169,9 +147,9 @@ func newTransport(config *Config, tlsCfg *tls.Config) *http.Transport {
return transport
}

func newBulkIndexer(logger *zap.Logger, client *elasticsearch.Client, config *Config) (esBulkIndexerCurrent, error) {
func newBulkIndexer(logger *zap.Logger, client *elasticsearch7.Client, config *Config) (esBulkIndexerCurrent, error) {
// TODO: add debug logger
return esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
return esutil7.NewBulkIndexer(esutil7.BulkIndexerConfig{
NumWorkers: config.NumWorkers,
FlushBytes: config.Flush.Bytes,
FlushInterval: config.Flush.Interval,
Expand Down
3 changes: 1 addition & 2 deletions exporter/elasticsearchexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.19

require (
github.com/cenkalti/backoff/v4 v4.2.0
github.com/elastic/go-elasticsearch/v8 v8.5.0
github.com/elastic/go-elasticsearch/v7 v7.17.7
github.com/elastic/go-structform v0.0.10
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.73.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.73.0
Expand All @@ -21,7 +21,6 @@ require (
require (
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elastic/elastic-transport-go/v8 v8.1.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand Down
7 changes: 2 additions & 5 deletions exporter/elasticsearchexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion exporter/elasticsearchexporter/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type httpTestError struct {
cause error
}

const currentESVersion = "8.4.0"
const currentESVersion = "7.17.7"

func (e *httpTestError) Error() string {
return fmt.Sprintf("http request failed (status=%v): %v", e.Status(), e.Message())
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ require (
github.com/eapache/go-resiliency v1.3.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230111030713-bf00bc1b83b6 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.1.0 // indirect
github.com/elastic/go-elasticsearch/v8 v8.5.0 // indirect
github.com/elastic/go-elasticsearch/v7 v7.17.7 // indirect
github.com/elastic/go-structform v0.0.10 // indirect
github.com/emicklei/go-restful/v3 v3.9.0 // indirect
github.com/envoyproxy/go-control-plane v0.10.3 // indirect
Expand Down
7 changes: 2 additions & 5 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit b51da37

Please sign in to comment.