-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[pkg/ottl] adapt mapGetter to handle nested map items within slices
#37408
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 30 commits
5e16669
af876fe
4d8ab84
cd28214
d21702e
f92e743
674887f
659705e
09518c1
86ebd2b
a376ab4
38a56d6
1ca8c3c
e8528af
65dddf6
9cb30b1
c97ca85
755bb08
18780d3
371185c
fd07e48
3631f49
cde18ff
820efc7
8266862
f310cf5
b3778fb
22ee599
6b6711a
b4065f8
f82503e
676d591
525dd97
c300c29
e98bfba
9c343b0
015e84b
8227837
35e21a8
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,27 @@ | ||
| # Use this changelog template to create an entry for release notes. | ||
|
|
||
| # One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
| change_type: bug_fix | ||
|
|
||
| # The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
| component: pkg/ottl | ||
|
|
||
| # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
| note: Fix limitation of map literals within slice literals not being handled correctly | ||
|
|
||
| # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
| issues: [37405] | ||
|
|
||
| # (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: | ||
|
|
||
| # If your change doesn't affect end users or the exported elements of any package, | ||
| # you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
| # 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: [] |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -12,6 +12,7 @@ import ( | |||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| "github.com/alecthomas/participle/v2" | ||||||||||||||||||||||||||||
| "go.opentelemetry.io/collector/component" | ||||||||||||||||||||||||||||
| "go.opentelemetry.io/collector/pdata/pcommon" | ||||||||||||||||||||||||||||
| "go.uber.org/zap" | ||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
@@ -480,6 +481,29 @@ func (p *Parser[K]) ParseValueExpression(raw string) (*ValueExpression[K], error | |||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| return &ValueExpression[K]{ | ||||||||||||||||||||||||||||
| getter: getter, | ||||||||||||||||||||||||||||
| getter: &StandardGetSetter[K]{ | ||||||||||||||||||||||||||||
|
Contributor
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. If we end up stick to this approach, considering the
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. I'd be fine with that, however there are also arguments for returning the raw types here (#37280 (comment)). I think I would also prefer to consistently return
Contributor
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. Judging by #37280 (comment), we probably need to survey this a bit more to make sure we're either consistent everywhere, or can translate at any given point in the chain. I'm not sure I have a strong opinion here, but it sounds like at a minimum we could potentially use more tests. Do the same issues apply to slices with
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. for slices, this issue doesn't apply, as the opentelemetry-collector-contrib/pkg/ottl/expression.go Lines 164 to 176 in ee2d165
Member
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. I agree with @edmocosta that we should continue returning pcommon.Map
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. Alright, I now changed it again to return pcommon.Map |
||||||||||||||||||||||||||||
| Getter: func(ctx context.Context, tCtx K) (any, error) { | ||||||||||||||||||||||||||||
| val, err := getter.Get(ctx, tCtx) | ||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||
| return nil, err | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| switch v := val.(type) { | ||||||||||||||||||||||||||||
| case pcommon.Map: | ||||||||||||||||||||||||||||
| return v.AsRaw(), nil | ||||||||||||||||||||||||||||
| case pcommon.Slice: | ||||||||||||||||||||||||||||
| return v.AsRaw(), nil | ||||||||||||||||||||||||||||
| case []any: | ||||||||||||||||||||||||||||
| for index, elem := range v { | ||||||||||||||||||||||||||||
| // make sure also nested maps within a slice are returned in their raw form | ||||||||||||||||||||||||||||
| if m, ok := elem.(pcommon.Map); ok { | ||||||||||||||||||||||||||||
| v[index] = m.AsRaw() | ||||||||||||||||||||||||||||
TylerHelmuth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| return v, nil | ||||||||||||||||||||||||||||
| default: | ||||||||||||||||||||||||||||
| return v, nil | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||
| }, nil | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.