-
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
Add support for setting fields in the config file #6024
Conversation
I like the idea 🌮, it will enable users to map their own stuff, which is nice. I would call it I'm worried about allowing overwrites, I cannot think of any case that doesn't break our events. I would say you can override fully y replacing |
Two thoughts on this:
I was working/thinking of a similar development for the Filebeat modules pipelines. In that case, as a solution to the issue above, we could allow the user to provide a custom string to add to the pipeline ID. So something like this:
Then the pipeline ID created would be of the form: I'm not sure if we can translate this idea to the templates as well, but just wanted to put it out there. Naming suggestion: the config setting could be called |
I agree we should only append fields and not even allow to overwrite them. As template inheritance might still be around in the future in ES, we potentially could load separate templates for these additional fields. Like this we would only have to overwrite the additional template. I agree the support for seems to be most important inside modules. So far I was mainly thinking of prometheus or http module in metricbeat, but Filebeat is also a good use case. Long term I'm hoping the As soon as we have the It would be nice if we could detect on the beat side if the template in ES is identical to the local one or not. Or if we have multiple templates, if one does not exist or one has changed. So in the default case we could at least report that the template is not identical or one of the templates does not exist or is not identical. Then we could offer the user to only add non existing templates or overwrite the ones which are not identical which would mainly be used for development I hope. Moving forward I suggest to put the feature on a global level out there to see how people use it and disallow overwriting existing fields. I would start with |
e2bc475
to
cf91f5f
Compare
libbeat/common/field.go
Outdated
@@ -134,3 +134,26 @@ func (f Fields) hasKey(keys []string) bool { | |||
} | |||
return false | |||
} | |||
|
|||
func (f Fields) GetKeys() []string { |
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.
exported method Fields.GetKeys should have comment or be unexported
6978561
to
3e402ca
Compare
3e402ca
to
32f7d0d
Compare
This is now ready for a round of reviews. I added the feature as experimental for now so we can start playing around with it. |
libbeat/common/field.go
Outdated
@@ -99,6 +99,44 @@ func (f Fields) HasKey(key string) bool { | |||
return f.hasKey(keys) | |||
} | |||
|
|||
// HasNode checks if inside fields the given node exists | |||
// In contrast to HasKey it not only compares the leave nodes but |
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.
s/leave/leaf/
since it's singular in this context.
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
libbeat/template/template_test.go
Outdated
for _, test := range tests { | ||
_, err := appendFields(test.fields, test.appendFields) | ||
if test.error { | ||
fmt.Printf("%v\n\n", test.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.
t.Logf
instead?
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.
I just removed it, was only for debugging and a left over.
32f7d0d
to
9889546
Compare
@andrewkroh Ready for an other look, please squash. |
7302a11
to
07312fa
Compare
So far if the user wanted to modify the generated template, he either had to create his own template.json file or modify our `fields.yml` file. The problem with changing the `fields.yml` file is that with new versions it was hard to keep these up-to-date. This change allows to specify the few fields which should be set as part of the config. Setting fields is especially useful in the case of Metricbeat for modules like Http or Prometheus where the data is user specific and we don't know the structure in advance. This change also has affects on the generation of the index pattern in Kibana. The configuration looks as following: ``` setup.template.append_fields: - name: test.name type: keyword - name: test.hostname type: long ``` I would have preferred to use `setup.template.fields:` but that is already taken by the path to the file. Notes: * For this change to happen the template and index pattern must be overwritten * Overwriting existing fields is not allowed
07312fa
to
a52f65f
Compare
@@ -82,3 +82,7 @@ setup.template.overwrite: false | |||
setup.template.settings: | |||
_source.enabled: false | |||
---------------------------------------------------------------------- | |||
|
|||
*`setup.template.append_fields`*:: A list of of fields to be added to the template and Kibana index 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.
Based on the changelog comment this should probably be marked as experimental.
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.
experimental flag added.
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.
LGTM
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.
LGTM, happy to have this feature in.
The rename processor allows to rename fields before they are indexed to standardise on names or move fields around. This becomes useful when building filebeat modules which read from json files. With the rename processor no ingest pipeline is needed to follow the naming schema. This should make some modules simpler to build. It's also useful in combination with elastic#6024 to rename some fields according to the schema. ``` processors: - rename: fields: - from: "a" to: "b" ``` Intention of rename * Adjust fields to mapping * Prevent conflicts like `a` and `a.b` by renaming `a` to `a.value` Limitations * Will not overwrite keys
* Add rename fields processor The rename processor allows to rename fields before they are indexed to standardise on names or move fields around. This becomes useful when building filebeat modules which read from json files. With the rename processor no ingest pipeline is needed to follow the naming schema. This should make some modules simpler to build. It's also useful in combination with #6024 to rename some fields according to the schema. ``` processors: - rename: fields: - from: "a" to: "b" ``` Intention of rename * Adjust fields to mapping * Prevent conflicts like `a` and `a.b` by renaming `a` to `a.value` Limitations * Will not overwrite keys
So far if the user wanted to modify the generated template, he either had to create his own template.json file or modify our
fields.yml
file. The problem with changing thefields.yml
file is that with new versions it was hard to keep these up-to-date. This change allows to specify the few fields which should be set as part of the config.Setting fields is especially useful in the case of Metricbeat for modules like Http or Prometheus where the data is user specific and we don't know the structure in advance.
This change also has affects on the generation of the index pattern in Kibana.
The configuration looks as following:
I would have preferred to use
setup.template.fields:
but that is already taken by the path to the file.Notes: