-
Notifications
You must be signed in to change notification settings - Fork 2.9k
[pkg/ottl] Fix OTTL functions by using setters #39416
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
c68cc6a
6b38c4c
903a86d
2ffa616
2a50ad1
b508ca4
dabd3bb
1c315d5
8ac77ad
5437b1b
402aeed
c9e5756
15921d0
30358f0
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 OTTL functions by using setters. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [39100] | ||
|
||
# (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: [user] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ import ( | |
) | ||
|
||
type FlattenArguments[K any] struct { | ||
Target ottl.PMapGetter[K] | ||
Target ottl.PMapGetSetter[K] | ||
Prefix ottl.Optional[string] | ||
Depth ottl.Optional[int64] | ||
ResolveConflicts ottl.Optional[bool] | ||
|
@@ -43,7 +43,7 @@ func createFlattenFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) | |
return flatten(args.Target, args.Prefix, args.Depth, args.ResolveConflicts) | ||
} | ||
|
||
func flatten[K any](target ottl.PMapGetter[K], p ottl.Optional[string], d ottl.Optional[int64], c ottl.Optional[bool]) (ottl.ExprFunc[K], error) { | ||
func flatten[K any](target ottl.PMapGetSetter[K], p ottl.Optional[string], d ottl.Optional[int64], c ottl.Optional[bool]) (ottl.ExprFunc[K], error) { | ||
depth := int64(math.MaxInt64) | ||
if !d.IsEmpty() { | ||
depth = d.Get() | ||
|
@@ -72,7 +72,7 @@ func flatten[K any](target ottl.PMapGetter[K], p ottl.Optional[string], d ottl.O | |
flattenData.flattenMap(m, prefix, 0) | ||
flattenData.result.MoveTo(m) | ||
|
||
return nil, nil | ||
return nil, target.Set(ctx, tCtx, m) | ||
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. The call to 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. @TylerHelmuth Calling 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. Anyway, addressed this in func_flatten as it makes sense to me. 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'm wondering if we could extend the Example: func (m Map) AsReadOnly() Map {
state := internal.StateReadOnly
return newMap(m.getOrig(), &state)
} With that functionality, we could either make the func (path StandardPMapGetSetter[K]) Get(ctx context.Context, tCtx K) (pcommon.Map, error) {
m, err := return path.Getter(ctx, tCtx)
// ...
return m.AsReadOnly(), nil
} Thoughts? 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. @edmocosta thats a good idea to enforce what we want. @rockdaboot what I meant is that if we're trying to enforce that maps be set via the context's setter instead of via pdata functions, we should be consistent. In the case of flatten (and I think a majority of our editors that work on maps) we are calling ether Since we're being consistent calling the context's setter, we need to remove the additional 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. @edmocosta Good idea. Are you going to create an issue/PR? Does this PR has to wait for the new functionality or can we add read-only maps later? Just looking for clarity here. 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. Maybe check merge_maps and the replace_all_patterns key scenario. 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 don't think we need to block this PR because of that, those changes might take some time to get through, so I'd do it later. I'll be opening the issues for implementing that soon. 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.
@TylerHelmuth In both functions, the 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. FYI, I've opened a PR adding the read-only functions: open-telemetry/opentelemetry-collector#12995 |
||
}, nil | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.