Skip to content

Commit

Permalink
Only attempt loading the ES template if ES output is enabled
Browse files Browse the repository at this point in the history
It used to raise an error if any template setting was set but
the ES output wasn't enabled. This caused problems with the new
Metricbeat config, which sets template settings in the configuration.

Also removes the code that enables the template loading on `-setup`,
because template loading is by default enabled anyway.

Fixes elastic#4435.
  • Loading branch information
Tudor Golubenco committed Jun 1, 2017
1 parent 08c2542 commit 78bc5f0
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions libbeat/beat/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,17 +459,6 @@ func (b *Beat) loadDashboards() error {
// the elasticsearch output. It is important the the registration happens before
// the publisher is created.
func (b *Beat) registerTemplateLoading() error {
if *setup {
// -setup implies template.enabled=true
if b.Config.Template == nil {
b.Config.Template = common.NewConfig()
}
err := b.Config.Template.SetBool("enabled", -1, true)
if err != nil {
return fmt.Errorf("Error setting template.enabled=true: %v", err)
}
}

// Check if outputting to file is enabled, and output to file if it is
if b.Config.Template != nil && b.Config.Template.Enabled() {
var cfg template.TemplateConfig
Expand All @@ -495,33 +484,31 @@ func (b *Beat) registerTemplateLoading() error {

esConfig := b.Config.Output["elasticsearch"]
// Loads template by default if esOutput is enabled
if (b.Config.Template == nil && esConfig.Enabled()) || (b.Config.Template != nil && b.Config.Template.Enabled()) {
if esConfig == nil || !esConfig.Enabled() {
return fmt.Errorf("Template loading requested but the Elasticsearch output is not configured/enabled")
}

// load template through callback to make sure it is also loaded
// on reconnecting
callback := func(esClient *elasticsearch.Client) error {

if b.Config.Template == nil {
b.Config.Template = common.NewConfig()
if esConfig != nil && esConfig.Enabled() {
if b.Config.Template == nil || (b.Config.Template != nil && b.Config.Template.Enabled()) {
// load template through callback to make sure it is also loaded
// on reconnecting
callback := func(esClient *elasticsearch.Client) error {

if b.Config.Template == nil {
b.Config.Template = common.NewConfig()
}

loader, err := template.NewLoader(b.Config.Template, esClient, b.Info)
if err != nil {
return fmt.Errorf("Error creating Elasticsearch template loader: %v", err)
}

err = loader.Load()
if err != nil {
return fmt.Errorf("Error loading Elasticsearch template: %v", err)
}

return nil
}

loader, err := template.NewLoader(b.Config.Template, esClient, b.Info)
if err != nil {
return fmt.Errorf("Error creating Elasticsearch template loader: %v", err)
}

err = loader.Load()
if err != nil {
return fmt.Errorf("Error loading Elasticsearch template: %v", err)
}

return nil
elasticsearch.RegisterConnectCallback(callback)
}

elasticsearch.RegisterConnectCallback(callback)
}

return nil
Expand Down

0 comments on commit 78bc5f0

Please sign in to comment.