Skip to content

Reject unknown fields in mapping configuration#695

Closed
highlyavailable wants to merge 1 commit into
prometheus:masterfrom
highlyavailable:strict-yaml-mapping-config
Closed

Reject unknown fields in mapping configuration#695
highlyavailable wants to merge 1 commit into
prometheus:masterfrom
highlyavailable:strict-yaml-mapping-config

Conversation

@highlyavailable

Copy link
Copy Markdown

InitFromYAMLString used yaml.Unmarshal, which silently drops keys that don't match a struct field. A typo in a mapping or defaults key would be ignored, so the config quietly behaved differently than intended (see #544).

This switches to yaml.UnmarshalStrict so unknown keys are reported as an error. The deprecated timer_type, buckets and quantiles keys still work, since the alias structs the custom unmarshalers use already declare them. Added tests for an unknown key at the top level, in defaults, and in a mapping.

As noted in the issue this is technically a breaking change, in the sense that a config which silently did the wrong thing now fails loudly, so it probably wants a [CHANGE] changelog line at release.

Closes #546

InitFromYAMLString used yaml.Unmarshal, which silently ignores keys
that do not match a struct field. A typo in a mapping or defaults key
would be dropped without warning, so the config would quietly behave
differently than intended.

Switch to yaml.UnmarshalStrict so unknown keys are reported as an
error. The deprecated timer_type, buckets and quantiles keys are still
accepted, since the alias structs used by the custom unmarshalers
already declare them.

Signed-off-by: highlyavailable <pwbryant1@gmail.com>
@highlyavailable

Copy link
Copy Markdown
Author

Closing this as a duplicate. I missed that #608, #673, and #687 already address this issue. Apologies for the extra noise.

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.

Reject configuration with unknown fields

1 participant