-
Notifications
You must be signed in to change notification settings - Fork 812
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 ability to support strict JSON unmarshal for limits
#4298
Add ability to support strict JSON unmarshal for limits
#4298
Conversation
41628b6
to
7d5919a
Compare
This is the default behaviour for YAML now. ``` in := `{"unknown_fields": 100}` l := cortex.Limits{} fmt.Println(yaml.UnmarshalStrict([]byte(in), &l)) // yaml: unmarshal errors: // line 1: field unknown_fields not found in type validation.plain ``` This PR adds same behaviour if unmarshalled from JSON input as well. Signed-off-by: Kaviraj <[email protected]>
Signed-off-by: Kaviraj <[email protected]>
7d5919a
to
e74e600
Compare
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.
Looks fine assuming this is the behavior we want, but some points to consider:
- Does mean that we lose forward compatibility? i.e. a "newer" configuration file (with unknown fields) cannot be parsed by an older version of Cortex. Whatever is producing the limits/overrides files, must be perfectly in sync with the Cortex version. This may be an acceptable trade-off.
Correct me if I'm wrong, but does this now mean that JSON parsing does not accept unknown fields, whilst the YAML parsing does? This perhaps is a little odd, I would expect both to have the same behavior.Also [unrelated curiosity], given runtime_config.go:65, I wonder if it was actually intentional for the YAML parsing to accept unknown fields...
As you point out in your next point, we already use strict parsing for YAML runtime config (which includes overrides), so this PR actually unifies both YAML and JSON parsing to strict. Cortex itself doesn't use JSON parsing for limits, as far as I know. |
Ah my mistake, I misread the |
Thanks @stevesg @pstibrany!. Yes that's right this PR unifies both JSON and YAML strict with unknown fields! |
Co-authored-by: Steve Simpson <[email protected]> Signed-off-by: Kaviraj <[email protected]>
c0bd56f
to
53b51fb
Compare
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.
Great job!
What this PR does:
Main problem is currently we cannot strict unmarshal JSON for
Limits
struct using json.DisallowUnknownFields(). Because customUnmarshalJSON
uses simplejson.Unmarshal()
function. (is it intentional?)This PR Adds ability to support strict JSON unmarshal for
limits
structThis is the default behaviour for YAML now.
This PR adds same behaviour if unmarshalled from JSON input as well.
Which issue(s) this PR fixes:
Fixes NA
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]