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

Remove olivere elastic client from OTEL #2448

Merged
merged 2 commits into from
Sep 2, 2020
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
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
Copy link
Member

Choose a reason for hiding this comment

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

Can you rebase? This change has been merged into master.

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 OK here, that PR should have changed the version also here.

)
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