Skip to content

Yaml UnmarshalStrict implementation.#4033

Merged
brian-brazil merged 15 commits intoprometheus:masterfrom
manosf:yamlStrict
Apr 4, 2018
Merged

Yaml UnmarshalStrict implementation.#4033
brian-brazil merged 15 commits intoprometheus:masterfrom
manosf:yamlStrict

Conversation

@manosf
Copy link
Contributor

@manosf manosf commented Mar 31, 2018

This resolves #4017.
As suggested, I updated configuration to call UnmarshalStrict() over simple
unmarshalling, thus rendering util/yaml/yaml.go no longer needed.
The original vendor package gopkg.in/yaml.v2 was updated and used (https://godoc.org/gopkg.in/yaml.v2#UnmarshalStrict).
Tests ran successfully against config/ and using make test with go1.10.
Edit: As @krasi-georgiev pointed out, this also fixes #1275.

Copy link
Contributor

@krasi-georgiev krasi-georgiev left a comment

Choose a reason for hiding this comment

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

best to add one more test to check for duplicated fields.

config/config.go Outdated
}

return yaml_util.CheckOverflow(c.XXX, "remote_write")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return c.HTTPClientConfig.Validate()

config/config.go Outdated
}

return yaml_util.CheckOverflow(c.XXX, "remote_read")
return nil
Copy link
Contributor

Choose a reason for hiding this comment

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

return c.HTTPClientConfig.Validate()

@krasi-georgiev
Copy link
Contributor

krasi-georgiev commented Apr 2, 2018

noticed that https://github.com/prometheus/common/tree/master/config also uses thecheckOverflow workaround so I opened a follow up issue prometheus/common#126 to remove to update that package as well.

@krasi-georgiev
Copy link
Contributor

LGTM

waiting for one more LGTM and will merge.

@brian-brazil
Copy link
Contributor

There seems to be quite a few unrelated cleanup changes in here. Considering the breadth of this change, I'd prefer this be limited to just the core change.

@krasi-georgiev
Copy link
Contributor

all changes are related to the UnmarshalStrict usage.

@brian-brazil
Copy link
Contributor

No, there's quite a few other changes in here.

@krasi-georgiev
Copy link
Contributor

can you put a comment next to the line you think is unrelated and will double check.

@brian-brazil
Copy link
Contributor

There are multiple unrelated changes to error handling and scoping.

@manosf
Copy link
Contributor Author

manosf commented Apr 2, 2018

I reverted some of the changes, if there are any more to be reverted please let me know which ones when you have the time. Thank you.

@manosf manosf force-pushed the yamlStrict branch 2 times, most recently from 10c506d to 0786d1f Compare April 2, 2018 21:36
}
case ".yml", ".yaml":
if err := yaml.Unmarshal(content, &targetGroups); err != nil {
if err := yaml.UnmarshalStrict(content, &targetGroups); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we don't have unittests for this, can you add one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a static configuration check for yaml files, sorry for taking too long to push.

@brian-brazil brian-brazil merged commit 25f929b into prometheus:master Apr 4, 2018
@brian-brazil
Copy link
Contributor

Thanks!

@manosf manosf deleted the yamlStrict branch April 4, 2018 10:53
gouthamve pushed a commit to gouthamve/prometheus that referenced this pull request Aug 1, 2018
* Updated yaml vendor package.

* remove checkOverflow duplicate in rulefmt

* remove duplicated HTTPClientConfig.Validate()

* Added yaml static check.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use UnmarshalStrict for yaml Unmarshalling Config parser does not complain about overriden parts of configuration

3 participants