Skip to content

Commit

Permalink
Remove olivere elastic client from OTEL (jaegertracing#2448)
Browse files Browse the repository at this point in the history
* Remove olivere elastic client from OTEL

Signed-off-by: Pavol Loffay <ploffay@redhat.com>

* Do not initialize after cleanup, use 1shard 0rep

Signed-off-by: Pavol Loffay <ploffay@redhat.com>
Signed-off-by: albertteoh <albert.teoh@logz.io>
  • Loading branch information
pavolloffay authored and albertteoh committed Sep 3, 2020
1 parent 6733d49 commit 43168f0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ package elasticsearchexporter
import (
"context"
"errors"
"fmt"
"net/http"
"strconv"
"strings"
"testing"
"time"

"github.com/olivere/elastic"
"github.com/stretchr/testify/require"
"go.uber.org/zap"

Expand All @@ -43,9 +43,9 @@ import (

const (
host = "0.0.0.0"
queryPort = "9200"
queryHostPort = host + ":" + queryPort
queryURL = "http://" + queryHostPort
esPort = "9200"
esHostPort = host + ":" + esPort
esURL = "http://" + esHostPort
indexPrefix = "integration-test"
tagKeyDeDotChar = "@"
maxSpanAge = time.Hour * 72
Expand All @@ -54,7 +54,6 @@ const (
type IntegrationTest struct {
integration.StorageIntegration

client *elastic.Client
logger *zap.Logger
}

Expand All @@ -74,56 +73,35 @@ func (s storageWrapper) WriteSpan(ctx context.Context, span *model.Span) error {
return err
}

func (s *IntegrationTest) getVersion() (uint, error) {
pingResult, _, err := s.client.Ping(queryURL).Do(context.Background())
if err != nil {
return 0, err
}
esVersion, err := strconv.Atoi(string(pingResult.Version.Number[0]))
if err != nil {
return 0, err
}
return uint(esVersion), nil
}

func (s *IntegrationTest) initializeES(allTagsAsFields bool) error {
rawClient, err := elastic.NewClient(
elastic.SetURL(queryURL),
elastic.SetSniff(false))
if err != nil {
return err
}
s.logger, _ = testutils.NewLogger()

s.client = rawClient
s.initSpanstore(allTagsAsFields)
s.CleanUp = func() error {
return s.esCleanUp(allTagsAsFields)
return s.esCleanUp()
}
s.Refresh = s.esRefresh
s.esCleanUp(allTagsAsFields)
s.esCleanUp()
// TODO: remove this flag after ES support returning spanKind when get operations
s.NotSupportSpanKindWithOperation = true
return nil
}

func (s *IntegrationTest) esCleanUp(allTagsAsFields bool) error {
_, err := s.client.DeleteIndex("*").Do(context.Background())
func (s *IntegrationTest) esCleanUp() error {
request, err := http.NewRequest(http.MethodDelete, fmt.Sprintf("%s/*", esURL), strings.NewReader(""))
if err != nil {
return err
}
return s.initSpanstore(allTagsAsFields)
}

func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
esVersion, err := s.getVersion()
response, err := http.DefaultClient.Do(request)
if err != nil {
return err
}
spanMapping, serviceMapping := es.GetSpanServiceMappings(5, 1, esVersion)
return response.Body.Close()
}

func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
cfg := config.Configuration{
Servers: []string{queryURL},
Servers: []string{esURL},
IndexPrefix: indexPrefix,
Tags: config.TagsAsFields{
AllAsFields: allTagsAsFields,
Expand All @@ -133,6 +111,8 @@ func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
if err != nil {
return err
}
esVersion := uint(w.esClientVersion())
spanMapping, serviceMapping := es.GetSpanServiceMappings(5, 1, esVersion)
err = w.CreateTemplates(context.Background(), spanMapping, serviceMapping)
if err != nil {
return err
Expand All @@ -153,7 +133,7 @@ func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
})
s.SpanReader = reader

depMapping := es.GetDependenciesMappings(5, 1, esVersion)
depMapping := es.GetDependenciesMappings(1, 0, esVersion)
depStore := esdependencyreader.NewDependencyStore(elasticsearchClient, s.logger, indexPrefix)
if err := depStore.CreateTemplates(depMapping); err != nil {
return nil
Expand All @@ -164,13 +144,16 @@ func (s *IntegrationTest) initSpanstore(allTagsAsFields bool) error {
}

func (s *IntegrationTest) esRefresh() error {
_, err := s.client.Refresh().Do(context.Background())
return err
response, err := http.Post(fmt.Sprintf("%s/_refresh", esURL), "application/json", strings.NewReader(""))
if err != nil {
return err
}
return response.Body.Close()
}

func healthCheck() error {
for i := 0; i < 200; i++ {
if _, err := http.Get(queryURL); err == nil {
if _, err := http.Get(esURL); err == nil {
return nil
}
time.Sleep(100 * time.Millisecond)
Expand Down
3 changes: 1 addition & 2 deletions cmd/opentelemetry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ require (
github.com/elastic/go-elasticsearch/v7 v7.0.0
github.com/imdario/mergo v0.3.9
github.com/jaegertracing/jaeger v1.18.2-0.20200707061226-97d2319ff2be
github.com/olivere/elastic v6.2.27+incompatible
github.com/opentracing/opentracing-go v1.1.1-0.20190913142402-a7454ce5950e
github.com/shirou/gopsutil v2.20.4+incompatible // indirect
github.com/spf13/pflag v1.0.5
Expand All @@ -19,5 +18,5 @@ require (
github.com/uber/jaeger-client-go v2.23.1+incompatible
github.com/uber/jaeger-lib v2.2.0+incompatible
go.opentelemetry.io/collector v0.8.1-0.20200820012544-1e65674799c8
go.uber.org/zap v1.15.0
go.uber.org/zap v1.16.0
)
3 changes: 2 additions & 1 deletion cmd/opentelemetry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1122,7 +1122,6 @@ go.uber.org/atomic v1.6.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=
go.uber.org/automaxprocs v1.3.0/go.mod h1:9CWT6lKIep8U41DDaPiH6eFscnTyjfTANNQNx6LrIcA=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.4.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+4=
go.uber.org/multierr v1.5.0 h1:KCa4XfM8CWFCpxXRGok+Q0SS/0XBhMDbHHGABQLvD2A=
go.uber.org/multierr v1.5.0/go.mod h1:FeouvMocqHpRaaGuG9EjoKcStLC43Zu/fmqdUMPcKYU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee h1:0mgffUl7nfd+FpvXMVz4IDEaUSmT1ysygQC7qYo7sG4=
Expand All @@ -1132,6 +1131,8 @@ go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.15.0 h1:ZZCA22JRF2gQE5FoNmhmrf7jeJJ2uhqDUNRYKm8dvmM=
go.uber.org/zap v1.15.0/go.mod h1:Mb2vm2krFEG5DV0W9qcHBYFtp/Wku1cvYaqPsS/WYfc=
go.uber.org/zap v1.16.0 h1:uFRZXykJGK9lLY4HtgSw44DnIcAM+kRBP7x5m+NpAOM=
go.uber.org/zap v1.16.0/go.mod h1:MA8QOfq0BHJwdXa996Y4dYkAqRKB8/1K1QMMZVaNZjQ=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190211182817-74369b46fc67/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
Expand Down

0 comments on commit 43168f0

Please sign in to comment.