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

Create ES index templates instead of indices #1627

Merged
merged 4 commits into from
Aug 2, 2019
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
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Changes by Version

##### Breaking Changes

* Create ES index templates instead of indices ([#1627](https://github.com/jaegertracing/jaeger/pull/1627), [@pavolloffay](https://github.com/pavolloffay))

This can break existing Elasticsearch deployments if security policies are applied.
For instance Jaeger `X-Pack` configuration now requires permission to create index templates - `manage_index_templates`.

##### New Features

##### Bug fixes, Minor Improvements
Expand All @@ -25,7 +30,7 @@ Changes by Version

##### Bug fixes, Minor Improvements

Change default for bearer-token-propagation to false ([#1642](https://github.com/jaegertracing/jaeger/pull/1642), [@wsoula](https://github.com/wsoula))
* Change default for bearer-token-propagation to false ([#1642](https://github.com/jaegertracing/jaeger/pull/1642), [@wsoula](https://github.com/wsoula))

#### UI Changes

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ generate-zipkin-swagger: idl-submodule

.PHONY: install-mockery
install-mockery:
go get -u github.com/vektra/mockery
go get -u github.com/vektra/mockery/.../

.PHONY: generate-mocks
generate-mocks: install-mockery
Expand Down
7 changes: 7 additions & 0 deletions pkg/es/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
type Client interface {
IndexExists(index string) IndicesExistsService
CreateIndex(index string) IndicesCreateService
CreateTemplate(id string) TemplateCreateService
Index() IndexService
Search(indices ...string) SearchService
MultiSearch() MultiSearchService
Expand All @@ -42,6 +43,12 @@ type IndicesCreateService interface {
Do(ctx context.Context) (*elastic.IndicesCreateResult, error)
}

// TemplateCreateService is an abstraction for creating a mapping
type TemplateCreateService interface {
Body(mapping string) TemplateCreateService
Do(ctx context.Context) (*elastic.IndicesPutTemplateResponse, error)
}

// IndexService is an abstraction for elastic BulkService
type IndexService interface {
Index(index string) IndexService
Expand Down
7 changes: 7 additions & 0 deletions pkg/es/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ type Configuration struct {
Enabled bool
TLS TLSConfig
UseReadWriteAliases bool
CreateIndexTemplates bool
}

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

// NewClient creates a new ElasticSearch client
Expand Down Expand Up @@ -248,6 +250,11 @@ func (c *Configuration) IsEnabled() bool {
return c.Enabled
}

// IsCreateIndexTemplates determines whether index templates should be created or not
func (c *Configuration) IsCreateIndexTemplates() bool {
return c.CreateIndexTemplates
}

// getConfigOptions wraps the configs to feed to the ElasticSearch client init
func (c *Configuration) getConfigOptions(logger *zap.Logger) ([]elastic.ClientOptionFunc, error) {

Expand Down
21 changes: 19 additions & 2 deletions pkg/es/mocks/Client.go

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

5 changes: 3 additions & 2 deletions pkg/es/mocks/IndexService.go

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

5 changes: 3 additions & 2 deletions pkg/es/mocks/IndicesCreateService.go

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

5 changes: 3 additions & 2 deletions pkg/es/mocks/IndicesExistsService.go

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

5 changes: 3 additions & 2 deletions pkg/es/mocks/MultiSearchService.go

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

5 changes: 3 additions & 2 deletions pkg/es/mocks/SearchService.go

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

67 changes: 67 additions & 0 deletions pkg/es/mocks/TemplateCreateService.go

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

25 changes: 25 additions & 0 deletions pkg/es/wrapper/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ func (c ClientWrapper) CreateIndex(index string) es.IndicesCreateService {
return WrapESIndicesCreateService(c.client.CreateIndex(index))
}

// CreateTemplate calls this function to internal client.
func (c ClientWrapper) CreateTemplate(ttype string) es.TemplateCreateService {
return WrapESTemplateCreateService(c.client.IndexPutTemplate(ttype))
}

// Index calls this function to internal client.
func (c ClientWrapper) Index() es.IndexService {
r := elastic.NewBulkIndexRequest()
Expand Down Expand Up @@ -105,6 +110,26 @@ func (c IndicesCreateServiceWrapper) Do(ctx context.Context) (*elastic.IndicesCr
return c.indicesCreateService.Do(ctx)
}

// TemplateCreateServiceWrapper is a wrapper around elastic.IndicesPutTemplateService.
type TemplateCreateServiceWrapper struct {
mappingCreateService *elastic.IndicesPutTemplateService
}

// WrapESTemplateCreateService creates an TemplateCreateService out of *elastic.IndicesPutTemplateService.
func WrapESTemplateCreateService(mappingCreateService *elastic.IndicesPutTemplateService) TemplateCreateServiceWrapper {
return TemplateCreateServiceWrapper{mappingCreateService: mappingCreateService}
}

// Body calls this function to internal service.
func (c TemplateCreateServiceWrapper) Body(mapping string) es.TemplateCreateService {
return WrapESTemplateCreateService(c.mappingCreateService.BodyString(mapping))
}

// Do calls this function to internal service.
func (c TemplateCreateServiceWrapper) Do(ctx context.Context) (*elastic.IndicesPutTemplateResponse, error) {
return c.mappingCreateService.Do(ctx)
}

// ---

// IndexServiceWrapper is a wrapper around elastic.ESIndexService.
Expand Down
23 changes: 13 additions & 10 deletions plugin/storage/es/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,18 @@ func loadTagsFromFile(filePath string) ([]string, error) {

// CreateArchiveSpanReader implements storage.ArchiveFactory
func (f *Factory) CreateArchiveSpanReader() (spanstore.Reader, error) {
cfg := f.Options.Get(archiveNamespace)
if !cfg.Enabled {
if !f.archiveConfig.IsEnabled() {
return nil, nil
}
return createSpanReader(f.metricsFactory, f.logger, f.archiveClient, cfg, true)
return createSpanReader(f.metricsFactory, f.logger, f.archiveClient, f.archiveConfig, true)
}

// CreateArchiveSpanWriter implements storage.ArchiveFactory
func (f *Factory) CreateArchiveSpanWriter() (spanstore.Writer, error) {
cfg := f.Options.Get(archiveNamespace)
if !cfg.Enabled {
if !f.archiveConfig.IsEnabled() {
return nil, nil
}
return createSpanWriter(f.metricsFactory, f.logger, f.archiveClient, cfg, true)
return createSpanWriter(f.metricsFactory, f.logger, f.archiveClient, f.archiveConfig, true)
}

func createSpanReader(
Expand Down Expand Up @@ -179,7 +177,7 @@ func createSpanWriter(
}

spanMapping, serviceMapping := GetMappings(cfg.GetNumShards(), cfg.GetNumReplicas())
return esSpanStore.NewSpanWriter(esSpanStore.SpanWriterParams{
writer := esSpanStore.NewSpanWriter(esSpanStore.SpanWriterParams{
Client: client,
Logger: logger,
MetricsFactory: mFactory,
Expand All @@ -189,9 +187,14 @@ func createSpanWriter(
TagDotReplacement: cfg.GetTagDotReplacement(),
Archive: archive,
UseReadWriteAliases: cfg.GetUseReadWriteAliases(),
SpanMapping: spanMapping,
ServiceMapping: serviceMapping,
}), nil
})
if cfg.IsCreateIndexTemplates() {
err := writer.CreateTemplates(spanMapping, serviceMapping)
if err != nil {
return nil, err
}
}
return writer, nil
}

// GetMappings returns span and service mappings
Expand Down
Loading