-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Change template loading configuration to be part of setup #4080
Conversation
31c0e65
to
c93d68c
Compare
libbeat/beat/beat.go
Outdated
@@ -252,6 +254,11 @@ func (b *Beat) launch(bt Creator) error { | |||
return err | |||
} | |||
|
|||
err = b.loadTemplate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, if I understand it correctly, this means that the template loading is only attempted once at startup not on every connection made to ES? If this is the case, then this is a regression for two reasons:
- If ES is not up when the Beat start, the Beat will fail with an error. It used to "wait" for ES to come up
- If for whatever reason ES is restarted without data, but the Beat is not restarted, the template is not loaded again, resulting in bad mapping.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. This just go a lot trickier to implement as it now uses its own client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TBH this is a deal breaker for me, especially the part where Beats don't start if ES is not up is going to really annoying to users.
Ideally we'd also have the pipelines loaded on each connection. It's currently done only on startup, but that can lead to errors similar to these. I think we need some sort of generic callback mechanism to do this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree
libbeat/beat/beat.go
Outdated
@@ -447,6 +454,48 @@ func (b *Beat) loadDashboards() error { | |||
return nil | |||
} | |||
|
|||
func (b *Beat) loadTemplate() error { | |||
if *setup { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The template should be always loaded, not only on -setup
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should be always loaded. The check on line 472 is different from the Dashboard one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, but then this check here is not needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you run -setup
but have setup.template.enabled: false
what is the expected behaviour?
libbeat/beat/beat.go
Outdated
esConfig := b.Config.Output["elasticsearch"] | ||
|
||
// Loads template by default if esOutput is enabled | ||
if (b.Config.Template == nil && esConfig.Enabled()) || (b.Config.Dashboards != nil && b.Config.Template.Enabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a reference to b.Config.Dasboards
there, by mistake?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed
6a14fab
to
27755db
Compare
@@ -71,6 +71,12 @@ type Connection struct { | |||
version string | |||
} | |||
|
|||
var connectCallbackRegister connectCallback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having this as global means it will also be applied to non-output ES clients (e.g. the one loading the dashboards, or the one loading the pipelines or the one for monitoring). That is perhaps OK, but mentioning it in case someone else thinks of something about that.
Of course, the global is kind of last resort solution. @urso any suggestions on how we can improve this? (Not necessarily in this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is also getting interesting in the case we would allow in the setup to define an elasticsearch host to load the template potentially with a different user. We already have something similar for the metrics.
Talking about metrics, this means also for the connection to the monitoring instance it would load the template? Not sure if this is intended.
* Change config option to setup.template.* from outputs.elasticsearch.template.* * Move loading logic into template package * Remove template loading logic from elasticsearch output * Changelog updated * Template tests were moved from output to template package * Documentation was updated. Will need some more work for which a follow up Github issue will be created. * Add `GetVersion()` to elasticsearch client. * Introduce callback registration for elasticsearch output. This should be generalised later. The template loading registers only with the output client factory which means, the template is not loaded when connecting for loading dashboards, pipeline or monitoring data which is intended. This is only migration the existing options. New options like outputting to a json file or load additional config options will be added in a follow up PR. Part of elastic#3654 and elastic#3921
27755db
to
5133bf6
Compare
@@ -0,0 +1,10 @@ | |||
package beat | |||
|
|||
type TemplateConfig struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
exported type TemplateConfig should have comment or be unexported
@@ -0,0 +1,17 @@ | |||
package template | |||
|
|||
type TemplateConfig struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
exported type TemplateConfig should have comment or be unexported
@@ -0,0 +1,17 @@ | |||
package template | |||
|
|||
type TemplateConfig struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
type name will be used as template.TemplateConfig by other packages, and that stutters; consider calling this Config
"github.com/elastic/beats/libbeat/paths" | ||
) | ||
|
||
// TemplateLoader is a subset of the Elasticsearch client API capable of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
comment on exported type ESClient should be of the form "ESClient ..." (with optional leading article)
GetVersion() string | ||
} | ||
|
||
type Loader struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
exported type Loader should have comment or be unexported
beatInfo common.BeatInfo | ||
} | ||
|
||
func NewLoader(cfg *common.Config, client ESClient, beatInfo common.BeatInfo) (*Loader, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
exported function NewLoader should have comment or be unexported
}, nil | ||
} | ||
|
||
// loadTemplate checks if the index mapping template should be loaded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[golint] reported by reviewdog 🐶
comment on exported method Loader.Load should be of the form "Load ..."
GetVersion()
to elasticsearch client.This is only migration the existing options. New options like outputting to a json file or load additional config options will be added in a follow up PR.
Part of elastic#3654 and elastic#3921