Skip to content
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

[pkg/ottl]: add SliceToMap function #35412

Merged

Conversation

bacherfl
Copy link
Contributor

@bacherfl bacherfl commented Sep 25, 2024

Description: This PR adds a function that converts slices to maps, as described in the linked issue. Currently still WIP, but creating a draft PR already to show how this could be implemented and used

Link to tracking Issue: #35256

Testing: Added unit and end to end tests

Documentation: Added description for the new function in the readme file

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@bacherfl bacherfl changed the title [pkg/ottl]: add Associate function [pkg/ottl]: add SliceToMap function Sep 27, 2024
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@@ -84,12 +94,29 @@ func Test_e2e_editors(t *testing.T) {
m.PutStr("test.foo.flags", "pass")
m.PutStr("test.foo.slice.0", "val")
m.PutStr("test.foo.nested.test", "pass")

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@evan-bradley @TylerHelmuth - This is not related to the function implemented in this PR, but after adding a slice of nested objects to the test attributes I found that the flatten function seems to not flatten the attributes of nested objects within a slice, but rather leaves the objects within the slice unchanged - is this intended or is this a bug in that function?

Also, when setting the depth to 0 (as in the test case below), slices at the top level of the input of the flatten function will still be flattened.

Please let me know if this behavior is intended or if this may be a bug - If it's the latter, I can create an issue for that and work on a fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sound like bugs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These sound like bugs to me, too. Could you file an issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have created two issues (I believe these are two distinct bugs):

#36161
#36162

Copy link
Member

@djaglowski djaglowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall the functionality looks correct to me. Just a few nits

pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
bacherfl and others added 2 commits October 4, 2024 06:53
Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@bacherfl
Copy link
Contributor Author

bacherfl commented Oct 4, 2024

Overall the functionality looks correct to me. Just a few nits

Thanks a lot for the review @djaglowski ! I have updated the PR with the suggested changes now

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@bacherfl bacherfl marked this pull request as ready for review October 16, 2024 11:46
@bacherfl bacherfl requested a review from a team as a code owner October 16, 2024 11:46
@evan-bradley evan-bradley removed the request for review from atoulme October 17, 2024 18:45
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved

`SliceToMap(target, keyPath, Optional[valuePath])`

The `SliceToMap` converter converts a slice of objects to a map. The name of the keys for the map entries
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we describe how this could be used to address slice items? I think we should highlight the fact that this allows limited list manipulation in OTTL.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have added a small sample for how the converted map could be used afterwards now.

bacherfl and others added 3 commits October 24, 2024 07:11
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
pkg/ottl/ottlfuncs/README.md Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/README.md Outdated Show resolved Hide resolved
pkg/ottl/ottlfuncs/func_slice_to_map.go Outdated Show resolved Hide resolved
bacherfl and others added 2 commits November 4, 2024 11:53
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@djaglowski djaglowski merged commit ba20b05 into open-telemetry:main Nov 4, 2024
158 checks passed
@github-actions github-actions bot added this to the next release milestone Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants