Skip to content

Commit

Permalink
[7.x](backport #25743) Don't include full ES index template in errors (
Browse files Browse the repository at this point in the history
…#26318)

* Don't include full ES index template in errors (#25743)

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 #25540

* Update expected log messages in tests

(cherry picked from commit 766e303)

Co-authored-by: Andrew Kroh <andrew.kroh@elastic.co>
  • Loading branch information
mergify[bot] and andrewkroh authored Jun 30, 2021
1 parent 1dfcb20 commit 19bb27c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Fix role_arn to work with access keys for AWS. {pull}25446[25446]
- Fix `community_id` processor so that ports greater than 65535 aren't valid. {pull}25409[25409]
- Fix ILM alias creation when write alias exists and initial index does not exist {pull}26143[26143]
- Omit full index template from errors that occur while loading the template. {pull}25743[25743]
- In the script processor, the `decode_xml` and `decode_xml_wineventlog` processors are now available as `DecodeXML` and `DecodeXMLWineventlog` respectively.
- Fix encoding errors when using the disk queue on nested data with multi-byte characters {pull}26484[26484]

Expand Down
17 changes: 9 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 @@ -82,15 +82,15 @@ func NewFileLoader(c FileClient) *FileLoader {
return &FileLoader{client: c}
}

// 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 := template(config, info, l.client.GetVersion(), migration)
if err != nil || tmpl == nil {
return err
Expand All @@ -108,19 +108,20 @@ func (l *ESLoader) Load(config TemplateConfig, info beat.Info, fields []byte, mi
}

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

//loading template to ES
// loading template to ES
body, err := 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)
}
logp.Info("template with name '%s' loaded.", templateName)

logp.Info("Template with name %q loaded.", templateName)
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions libbeat/tests/system/test_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_json_template(self):
proc = self.start_beat()
self.wait_until(lambda: self.log_contains("mockbeat start running."))
self.wait_until(lambda: self.log_contains("Loading json template from file"))
self.wait_until(lambda: self.log_contains("template with name 'bla' loaded"))
self.wait_until(lambda: self.log_contains('Template with name "bla" loaded.'))
proc.check_kill_and_wait()

result = es.transport.perform_request('GET', '/_template/' + template_name)
Expand Down Expand Up @@ -149,7 +149,7 @@ def test_template_default(self):
self.render_config()
proc = self.start_beat()
self.wait_until(lambda: self.log_contains("mockbeat start running."))
self.wait_until(lambda: self.log_contains("template with name 'mockbeat-9.9.9' loaded"))
self.wait_until(lambda: self.log_contains('Template with name "mockbeat-9.9.9" loaded.'))
self.wait_until(lambda: self.log_contains("PublishEvents: 1 events have been published"))
proc.check_kill_and_wait()

Expand Down

0 comments on commit 19bb27c

Please sign in to comment.