Skip to content

Commit

Permalink
Don't include full ES index template in errors
Browse files Browse the repository at this point in the history
Index templates in some beats can be very large (~1MB) and including the data in errors can use a lot of memory and also makes for very large log lines. If the error is recurring then this makes the effects worse. So this change removes the index template body from the error. Users that need to see the index template for debugging can use `<beatname> export template --es.version=1.2.3`.

Fixes elastic#25540
  • Loading branch information
andrewkroh committed Jun 14, 2021
1 parent 81e5cc0 commit d3871e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix handling of `file_selectors` in aws-s3 input. {pull}25792[25792]
- Fix ILM alias creation when write alias exists and initial index does not exist {pull}26143[26143]
- Include date separator in the filename prefix of `dateRotator` to make sure nothing gets purged accidentally {pull}26176[26176]
- Omit full index template from errors that occur while loading the template. {pull}25743[25743]

*Auditbeat*

Expand Down
16 changes: 8 additions & 8 deletions libbeat/template/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ var (
}
)

//Loader interface for loading templates
// Loader interface for loading templates.
type Loader interface {
Load(config TemplateConfig, info beat.Info, fields []byte, migration bool) error
}
Expand Down Expand Up @@ -94,15 +94,15 @@ func newTemplateBuilder() *templateBuilder {
return &templateBuilder{log: logp.NewLogger("template")}
}

// Load checks if the index mapping template should be loaded
// Load checks if the index mapping template should be loaded.
// In case the template is not already loaded or overwriting is enabled, the
// template is built and written to index
// template is built and written to index.
func (l *ESLoader) Load(config TemplateConfig, info beat.Info, fields []byte, migration bool) error {
if l.client == nil {
return errors.New("can not load template without active Elasticsearch client")
}

//build template from config
// build template from config
tmpl, err := l.builder.template(config, info, l.client.GetVersion(), migration)
if err != nil || tmpl == nil {
return err
Expand All @@ -120,19 +120,19 @@ func (l *ESLoader) Load(config TemplateConfig, info beat.Info, fields []byte, mi
}

if exists && !config.Overwrite {
l.log.Infof("Template %s already exists and will not be overwritten.", templateName)
l.log.Infof("Template %q already exists and will not be overwritten.", templateName)
return nil
}

//loading template to ES
// loading template to ES
body, err := l.builder.buildBody(tmpl, config, fields)
if err != nil {
return err
}
if err := l.loadTemplate(templateName, config.Type, body); err != nil {
return fmt.Errorf("could not load template. Elasticsearch returned: %v. Template is: %s", err, body.StringToPrint())
return fmt.Errorf("failed to load template: %w", err)
}
l.log.Infof("template with name '%s' loaded.", templateName)
l.log.Infof("Template with name %q loaded.", templateName)
return nil
}

Expand Down

0 comments on commit d3871e2

Please sign in to comment.