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

Check fields type and format #13188

Merged
merged 14 commits into from
Aug 15, 2019
Merged

Conversation

jsoriano
Copy link
Member

@jsoriano jsoriano commented Aug 7, 2019

field.yml files contain fields information that is used to build index templates,
Kibana index patterns and documentation. type and format settings for the
fields in these files have proven to be confusing to contributors, specially by the
reason that some unexpected values are ignored, or not used as expected.
This change adds a check so we can earlier detect unexpected values, and
provide feedback on the valid values.

@jsoriano jsoriano added the in progress Pull request is currently in progress. label Aug 7, 2019
@jsoriano jsoriano self-assigned this Aug 7, 2019
@jsoriano jsoriano changed the title Check fields format Check fields type and format Aug 7, 2019
@jsoriano jsoriano added review libbeat and removed in progress Pull request is currently in progress. labels Aug 7, 2019
@jsoriano jsoriano marked this pull request as ready for review August 7, 2019 18:41
@jsoriano jsoriano requested review from a team as code owners August 7, 2019 18:41
@jsoriano jsoriano added Team:Integrations Label for the Integrations team [zube]: In Review labels Aug 7, 2019
}
groupFormats, ok := validFormats[group]
if !ok {
panic("unexpected type group " + group)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can return an error, is a panic necessary?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a function only used internally, where group can only be set in validateType, so an incorrect value here is probably a bug.
In any case, I have modified it so a type group has its own type and so it can be checked by the compiller, that is its job 🙂
Let me know what you think.

@fearful-symmetry
Copy link
Contributor

Yay! This is long-needed. The logic LGTM.

@@ -110,6 +110,9 @@ func (d *DynamicType) Unpack(s string) error {

// Validate ensures objectTypeParams are not mixed with top level objectType configuration
func (f *Field) Validate() error {
if err := f.validateType(); err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning here error trying to check 'type' field in 'fields.yml' fike '%s'. Check the 'fields.yml' in the module you are modifying for an incorrect or unknonwn 'type' value

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I have reordered error wrapping a little bit, this is what is printed now:

Generated global fields.yml file for metricbeat is invalid: incorrect type configuration for field 'max.bytes': unexpected formatter for number type, expected one of: string, url, bytes, duration, number, percent, color accessing '52.fields.0.fields.0.fields.1.fields.2.fields.0' (source:'fields.yml')
exit status 3

This is not ideal, but I haven't found a way to get more info from the underlying parsing library. In any case it is much better than what we have now.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree. It's much better. Sorry for asking you a bit more 😅 maybe it's worth to just add (source: 'beats/metricbeat/module/{your-module}/_meta/fields.yml') or something similar. A new contributor won't know where the fields.yml is gonna be located.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This part of the message is generated by the library, we are a bit limitated by that.

Also take into account that code in this PR only checks the global fields.yml, fields.yml files in modules and metricsets are not valid YAML by design, so they are not so easy to parse and check (and we don't). They are concatenated to create the global fields.yml and only this should be a valid YAML, but we are actually not even checking that, and this is not detected at all unless something mysteriously breaks in some integration test.

In summary, yes, at the moment it is not possible to easily know the module of the fields causing the problems, but hopefully a PR will only touch a limited number of fields, so it shouldn't be so hard to spot.

libbeat/mapping/field.go Outdated Show resolved Hide resolved
Copy link
Contributor

@sayden sayden left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Left a couple of comments that might improve a bit but logic seems ok

@jsoriano
Copy link
Member Author

jsoriano commented Aug 9, 2019

jenkins, test this again please

@jsoriano
Copy link
Member Author

jenkins, test this again please

@jsoriano
Copy link
Member Author

jenkins, test this again please

@jsoriano jsoriano merged commit dc83b95 into elastic:master Aug 15, 2019
@jsoriano jsoriano deleted the check-fields-format branch August 15, 2019 15:12
jsoriano added a commit to jsoriano/beats that referenced this pull request Aug 16, 2019
On elastic#13188 a check is added on global fields generator to check that the
generated fields file is valid. This check was done by reading the
result from disk, but this file is not available when output is stdout.

Modify the check so it is done over the buffered result before writing
to file or stdout.
jsoriano added a commit that referenced this pull request Aug 19, 2019
On #13188 a check is added on global fields generator to check that the
generated fields file is valid. This check was done by reading the
result from disk, but this file is not available when output is stdout.

Modify the check so it is done over the buffered result before writing
to file or stdout.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libbeat review Team:Integrations Label for the Integrations team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants