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 Elasticsearch version flag #1753

Merged
merged 3 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add Elasticsearch version flag
Signed-off-by: Pavol Loffay <ploffay@redhat.com>
  • Loading branch information
pavolloffay committed Aug 22, 2019
commit 1c88b09d8ee4afa8ad098600dd274847aa84c14f
2 changes: 1 addition & 1 deletion pkg/es/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type Client interface {
Search(indices ...string) SearchService
MultiSearch() MultiSearchService
io.Closer
GetVersion() int
GetVersion() uint
}

// IndicesExistsService is an abstraction for elastic.IndicesExistsService
Expand Down
30 changes: 20 additions & 10 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type Configuration struct {
TLS TLSConfig
UseReadWriteAliases bool
CreateIndexTemplates bool
Version uint
}

// TLSConfig describes the configuration properties to connect tls enabled ElasticSearch cluster
Expand All @@ -89,6 +90,7 @@ type ClientBuilder interface {
GetTokenFilePath() string
IsEnabled() bool
IsCreateIndexTemplates() bool
GetVersion() uint
}

// NewClient creates a new ElasticSearch client
Expand Down Expand Up @@ -157,18 +159,21 @@ func (c *Configuration) NewClient(logger *zap.Logger, metricsFactory metrics.Fac
return nil, err
}

// Determine ElasticSearch Version
pingResult, _, err := rawClient.Ping(c.Servers[0]).Do(context.Background())
if err != nil {
return nil, err
}
esVersion, err := strconv.Atoi(string(pingResult.Version.Number[0]))
if err != nil {
return nil, err
if c.Version == 0 {
// Determine ElasticSearch Version
pingResult, _, err := rawClient.Ping(c.Servers[0]).Do(context.Background())
if err != nil {
return nil, err
}
esVersion, err := strconv.Atoi(string(pingResult.Version.Number[0]))
if err != nil {
return nil, err
}
logger.Info("Elasticsearch detected", zap.Int("version", esVersion))
c.Version = uint(esVersion)
}
logger.Info("Elasticsearch detected", zap.Int("version", esVersion))

return eswrapper.WrapESClient(rawClient, service, esVersion), nil
return eswrapper.WrapESClient(rawClient, service, c.Version), nil
}

// ApplyDefaults copies settings from source unless its own value is non-zero.
Expand Down Expand Up @@ -243,6 +248,11 @@ func (c *Configuration) GetAllTagsAsFields() bool {
return c.AllTagsAsFields
}

// GetVersion returns Elasticsearch version
func (c *Configuration) GetVersion() uint {
return c.Version
}

// GetTagDotReplacement returns character is used to replace dots in tag keys, when
// the tag is stored as object field.
func (c *Configuration) GetTagDotReplacement() string {
Expand Down
29 changes: 8 additions & 21 deletions pkg/es/mocks/Client.go

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

21 changes: 4 additions & 17 deletions pkg/es/mocks/IndexService.go

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

25 changes: 7 additions & 18 deletions pkg/es/mocks/IndicesCreateService.go

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

21 changes: 4 additions & 17 deletions pkg/es/mocks/IndicesExistsService.go

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

25 changes: 7 additions & 18 deletions pkg/es/mocks/MultiSearchService.go

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

25 changes: 7 additions & 18 deletions pkg/es/mocks/SearchService.go

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

25 changes: 7 additions & 18 deletions pkg/es/mocks/TemplateCreateService.go

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

10 changes: 5 additions & 5 deletions pkg/es/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,16 @@ import (
type ClientWrapper struct {
client *elastic.Client
bulkService *elastic.BulkProcessor
esVersion int
esVersion uint
}

// GetVersion returns the ElasticSearch Version
func (c ClientWrapper) GetVersion() int {
func (c ClientWrapper) GetVersion() uint {
return c.esVersion
}

// WrapESClient creates a ESClient out of *elastic.Client.
func WrapESClient(client *elastic.Client, s *elastic.BulkProcessor, esVersion int) ClientWrapper {
func WrapESClient(client *elastic.Client, s *elastic.BulkProcessor, esVersion uint) ClientWrapper {
return ClientWrapper{client: client, bulkService: s, esVersion: esVersion}
}

Expand Down Expand Up @@ -152,11 +152,11 @@ func (c TemplateCreateServiceWrapper) Do(ctx context.Context) (*elastic.IndicesP
type IndexServiceWrapper struct {
bulkIndexReq *elastic.BulkIndexRequest
bulkService *elastic.BulkProcessor
esVersion int
esVersion uint
}

// WrapESIndexService creates an ESIndexService out of *elastic.ESIndexService.
func WrapESIndexService(indexService *elastic.BulkIndexRequest, bulkService *elastic.BulkProcessor, esVersion int) IndexServiceWrapper {
func WrapESIndexService(indexService *elastic.BulkIndexRequest, bulkService *elastic.BulkProcessor, esVersion uint) IndexServiceWrapper {
return IndexServiceWrapper{bulkIndexReq: indexService, bulkService: bulkService, esVersion: esVersion}
}

Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/dependencystore/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const dependenciesMapping7 = `{
"mappings":{}
}`

func getMapping(version int) string {
func getMapping(version uint) string {
if version == 7 {
return dependenciesMapping7
}
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/dependencystore/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func TestWriteDependencies(t *testing.T) {
createIndexError error
writeError error
expectedError string
esVersion int
esVersion uint
}{
{
createIndexError: errors.New("index not created"),
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func createSpanWriter(
}

// GetMappings returns span and service mappings
func GetMappings(shards, replicas int64, esVersion int) (string, string) {
func GetMappings(shards, replicas int64, esVersion uint) (string, string) {
if esVersion == 7 {
return fixMapping(loadMapping("/jaeger-span-7.json"), shards, replicas),
fixMapping(loadMapping("/jaeger-service-7.json"), shards, replicas)
Expand Down
2 changes: 1 addition & 1 deletion plugin/storage/es/factory_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (m *mockClientBuilder) NewClient(logger *zap.Logger, metricsFactory metrics
tService.On("Body", mock.Anything).Return(tService)
tService.On("Do", context.Background()).Return(nil, m.createTemplateError)
c.On("CreateTemplate", mock.Anything).Return(tService)
c.On("GetVersion").Return(6)
c.On("GetVersion").Return(uint(6))
return c, nil
}
return nil, m.err
Expand Down
Loading