-
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
Allow template pattern to be overwritten #4769
Conversation
libbeat/_meta/config.reference.yml
Outdated
# The version of the beat will always be appended to the given name | ||
# so the final name is beatname-%{[beat.version]}. | ||
#setup.template.name: "beatname" | ||
# The f |
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.
Ignore this doc and below for the moment. Take a look at the PR description on the behaviour.
It would be nice if the template name would be based on the elasticsearch index name. the problem with that for the moment is that the index name includes the daily pattern: We could change this to:
This would allow the template loading to take by default the index name as the name for the template. Problem with this it's an additional break in case someone configured a different index-name. |
libbeat/_meta/config.reference.yml
Outdated
|
||
# Template patttern. By default the template patter is "-%{[beat.version]}-*" to apply to the default index settings. | ||
# The first part is the version of the beat and then -* is used to match all daily indicies. | ||
#setup.template.pattern: "beatname-%{[beat.version]}-*" |
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.
Do we even need the -*
for the pattern or could we just use *
so it would also apply do indices which are exactly like the index name?
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.
Not sure I understand this suggestion. You mean something lie beatname-%{[beat.version]}*
?
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.
Yes
|
||
pattern := config.Pattern | ||
if pattern == "" { | ||
pattern = name + "-*" |
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.
Should we remove here the -
and make this just *
?
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.
This is just the default, right? I'd say let's keep the -*
, so that it's less likely to apply accidentally to other indices.
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.
Yes 👍
libbeat/beat/beat.go
Outdated
} | ||
|
||
// Get ES Index name for comparison | ||
esCfg := 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.
@urso Should I also check for indicies
here and len==0
?
metricbeat/docs/fields.asciidoc
Outdated
@@ -2790,28 +2790,28 @@ Bytes in non-idle span. | |||
|
|||
|
|||
[[exported-fields-graphite]] | |||
== graphite Fields | |||
== graphite fields |
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.
@dedemorton Seems like some of your recent changes are revert? I wonder why the previous builds went green?
libbeat/template/template.go
Outdated
return t.name | ||
} | ||
|
||
// GetPattern returns the name of the template which is {index}-{version} |
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.
Comment seems out of date.
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.
updated
libbeat/beat/beat.go
Outdated
} | ||
|
||
if esCfg.Index != "" && (cfg.Name == "" || cfg.Pattern == "") { | ||
return fmt.Errorf("setup.template.name and setup.template.pattern have to be set if index name is modified.") |
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.
Does the name really have to be changed? I'm thinking we could only check on the setup.template.pattern
?
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 will be kind of strange if the name is not changed. Assuming someone changes the index to test-{daily}
and the pattern to test-*
he then sees beatname-{version}-{daily}
as the template name with test-*
as pattern. In case that template is already there, it would not be overwritten and he would still not have the expected template.
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.
Generally LGTM. Waiting for a review from @urso as well.
ab01baa
to
5bc30f9
Compare
50d71f4
to
882e29d
Compare
The version number of apm-server and the system tests have to be kept manually in sync until elastic/beats#4769 is merged.
882e29d
to
bb589c3
Compare
@ruflin I tested this branch, but when using a configuration like this (which is what's suggested in the docs):
I get this in the resulting template:
So it seems like the variables are not resolved as I was expecting. |
I don't see any use of format strings being applied. It's all strings only. When/how does |
Currently the default works when not set because it is set internal. But as @urso said there is currently no handling of the special strings. My suggestion is to support in this version everything under |
libbeat/template/template.go
Outdated
} | ||
|
||
logp.Debug("template", "Lookup key for pattern not available: %s", key) | ||
return nil, nil |
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.
should we handled this as error? Compiling a pattern with missing field might give you an invalid index name.
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.
yes, will return an error if there is a pattern but doesn't match either of the two.
libbeat/template/template.go
Outdated
|
||
if key == "[beat.version]" { | ||
return Formatter{s: bV.String()}, nil | ||
} |
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.
Date patterns start with +
character. See: https://github.com/elastic/beats/blob/master/libbeat/common/fmtstr/formatevents.go#L252
That is, we can replace %{+<pattern>}
with *
in here.
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.
Is there an easy way to reuse this pattern compiling?
libbeat/template/template.go
Outdated
@@ -167,3 +204,19 @@ func loadYaml(path string) (Fields, error) { | |||
} | |||
return fields, nil | |||
} | |||
|
|||
type Formatter 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.
don't leak/export this type if you don't need it. Also template.Formatter
is kind of a bad choice here.
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, need to come up with a better name
libbeat/template/template.go
Outdated
@@ -41,6 +45,39 @@ func New(beatVersion string, beatName string, esVersion string, config TemplateC | |||
pattern = name + "-*" | |||
} | |||
|
|||
compiler := func(key string, ops []fmtstr.VariableOp) (fmtstr.FormatEvaler, 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.
Any plan to handle ops
? Event format strings can have defaults if the key is missing in the event. See: https://github.com/elastic/beats/blob/master/libbeat/common/fmtstr/formatevents.go#L280
One can use %{[my.field]:defaultValue}
in event format strings.
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.
For now to keep it as simple as possible I suggest to return an error in case any ops are used.
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.
Tested this one manually, looks good 👍
With the current template loading is was not possible to overload the pattern used as name and pattern were mixed. For example in the case where someone wanted to define pattern name `a` that applies to the indice `a` this was not possible because the pattern generated was `a-*` so it didn't apply to the index `a`. This change now allows to set pattern and name separately. To make sure index pattern and templates are in sync, the beat will not start in case the index pattern was modified but the template patterns not. We should figure out later some automated mechanisms here. We should find a better solution for 6.x to require less config options and also include dashboard generation in this.
a67bb03
to
3ea9c88
Compare
Rebased and squashed again. |
jenkins, test it |
jenkins, retest it |
With the current template loading is was not possible to overload the pattern used as name and pattern were mixed. For example in the case where someone wanted to define pattern name `a` that applies to the indice `a` this was not possible because the pattern generated was `a-*` so it didn't apply to the index `a`. This change now allows to set pattern and name separately. To make sure index pattern and templates are in sync, the beat will not start in case the index pattern was modified but the template patterns not. We should figure out later some automated mechanisms here. We should find a better solution for 6.x to require less config options and also include dashboard generation in this. (cherry picked from commit 02a59a1)
With the current template loading is was not possible to overload the pattern used as name and pattern were mixed. For example in the case where someone wanted to define pattern name `a` that applies to the indice `a` this was not possible because the pattern generated was `a-*` so it didn't apply to the index `a`. This change now allows to set pattern and name separately. To make sure index pattern and templates are in sync, the beat will not start in case the index pattern was modified but the template patterns not. We should figure out later some automated mechanisms here. We should find a better solution for 6.x to require less config options and also include dashboard generation in this. (cherry picked from commit 02a59a1)
Changes: * Add support for cloud id. See elastic/beats#4964 for more details. This could simplify the onboard for users that use apm-server with the Cloud in the future. * Be able to overwrite index pattern in the index template. See elastic/beats#4769 for more details. This allows to clean up our system tests.
Important changes / additions: * Add support for cloud id. See elastic/beats#4964 for more details. This could simplify the onboard for users that use apm-server with the Cloud in the future. * Be able to overwrite index pattern in the index template. See elastic/beats#4769 for more details. This allows to clean up our system tests.
Important changes / additions: * Add support for cloud id. See elastic/beats#4964 for more details. This could simplify the onboard for users that use apm-server with the Cloud in the future. * Be able to overwrite index pattern in the index template. See elastic/beats#4769 for more details. This allows to clean up our system tests.
Important changes / additions: * Add support for cloud id. See elastic/beats#4964 for more details. This could simplify the onboard for users that use apm-server with the Cloud in the future. * Be able to overwrite index pattern in the index template. See elastic/beats#4769 for more details. This allows to clean up our system tests.
Removing needs_docs labels because template.name and template.pattern options are now documented. If additional doc work is required, please open an issue against the docs. |
With the current template loading is was not possible to overload the pattern used as name and pattern were mixed. For example in the case where someone wanted to define pattern name `a` that applies to the indice `a` this was not possible because the pattern generated was `a-*` so it didn't apply to the index `a`. This change now allows to set pattern and name separately. To make sure index pattern and templates are in sync, the beat will not start in case the index pattern was modified but the template patterns not. We should figure out later some automated mechanisms here. We should find a better solution for 6.x to require less config options and also include dashboard generation in this. (cherry picked from commit 2a8f795)
With the current template loading is was not possible to overload the pattern used as name and pattern were mixed. For example in the case where someone wanted to define pattern name
a
that applies to the indicea
this was not possible because the pattern generated wasa-*
so it didn't apply to the indexa
. This change now allows to set pattern and name separately.To make sure index pattern and templates are in sync, the beat will not start in case the index pattern was modified but the template patterns not. We should figure out later some automated mechanisms here.
We should find a better solution for 6.x to require less config options and also include dashboard generation in this.