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

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

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
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]
- In the script processor, the `decode_xml` and `decode_xml_wineventlog` processors are now available as `DecodeXML` and `DecodeXMLWineventlog` respectively.

*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
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