-
Notifications
You must be signed in to change notification settings - Fork 1.8k
[confmap][fix] Correctly differentiate between nil and empty slices in ToStringMap
#11755
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
Changes from 11 commits
400205f
aadb6b6
0436e81
c9b7c46
b5fd43b
370bf34
5fb775c
4c21de0
7de2ad3
490c188
3fb5cae
1985c95
2ae04e1
dfdfcbb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: 'breaking' | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. otlpreceiver) | ||
| component: confmap | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: "Correctly differentiate between a nil and empty slice in `ToStringMap`" | ||
|
|
||
| # One or more tracking issues or pull requests related to the change | ||
| issues: [11749] | ||
|
|
||
| # (Optional) One or more lines of additional information to render under the primary note. | ||
| # These lines will be padded with 2 spaces and then inserted directly into the document. | ||
| # Use pipe (|) for multiline entries. | ||
| subtext: | ||
|
|
||
| # Optional: The change log or logs in which this entry should be included. | ||
| # e.g. '[user]' or '[user, api]' | ||
| # Include 'user' if the change is relevant to end users. | ||
| # Include 'api' if there is a change to a library API. | ||
| # Default: '[user]' | ||
| change_logs: [api] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -133,6 +133,10 @@ | |
| return c | ||
| case []any: | ||
| var newSlice []any | ||
| if m == nil { | ||
| return newSlice | ||
| } | ||
|
Comment on lines
+136
to
+138
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mx-psi This block is currently not covered by tests because we're not decoding nil values in this PR (that will happen in #11734). We could (1) remove this if block here and add it in the following PR; (2) leave it in here but merge with missing code coverage; (3) add a unit test for this function directly. Let me know what you think. |
||
| newSlice = []any{} | ||
| for _, e := range m { | ||
| newSlice = append(newSlice, sanitizeExpanded(e, useOriginal)) | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| slice: [] # empty slices are sanitized to nil in ToStringMap | ||
| slice: [] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| slice: |
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 was okay merging this with the expectation that we do not consider this a breaking change, but rather a change in an unspecified part of
confmap. If we think this is a breaking change, then I am against merging this, since confmap is 1.0There 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'm a bit on the fence here.
Uh oh!
There was an error while loading. Please reload this page.
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've finally spent some time digging into this, and I think we should consider merging this after we define what we want to be the correct behavior. In my opinion, the current behavior is undefined and that's a bug in confmap, even if changing the existing behavior will break users. Personally, I'd like to keep a 1:1 mapping between YAML <->
map[string]any<->confmap.Conf<-> Config struct as much as is reasonable.I'm also not sure if we should keep
zeroSliceHookFunc: removing it from our list of decoder hooks only breaks a single test in cmd/mdatagen, and that test passes with the hook removed if the changes in this PR are applied. In general, we should likely try to keep a distinction between[]any(nil)andany{}, whereas the hook currently maps[]any(nil)to[]any{}(andToStringMap, without the changes in this PR, maps[]any{}to[]any(nil)). Additionally, if I understand the changes in #11734, I'm not 100% sure the hook does much anymore.Edit: I see now that the hook will clear out a slice during unmarshaling. I will look into how we can confirm this with a test case.
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 created a PR to illustrate a little of what I have in mind here: #11882.
I ran the k8s attributes processor tests with this change and didn't see any failing tests from removing
zeroSliceHookFunc.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.
@evan-bradley thanks for the great explanation and the illustration in the PR. Let me know how you think we should proceed here. Do we want to replace my PR with the one you have open?