Skip to content

[pkg/ottl] Fix handling of slice values in flatten function by considering depth option#36198

Merged
evan-bradley merged 6 commits into
open-telemetry:mainfrom
bacherfl:fix/36161/flatten-function
Nov 15, 2024
Merged

[pkg/ottl] Fix handling of slice values in flatten function by considering depth option#36198
evan-bradley merged 6 commits into
open-telemetry:mainfrom
bacherfl:fix/36161/flatten-function

Conversation

@bacherfl
Copy link
Copy Markdown
Contributor

@bacherfl bacherfl commented Nov 5, 2024

Description

This PR adapts the flatten function to also consider the depth option when handling slice values. Before this change, the function flattened slice values beyond the given depth.

Link to tracking issue

Fixes #36161

Testing

Added unit and e2e tests

Documentation

No changes here, as the docs already mention the expected behavior of the function when the depth option is set

…ering depth option

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>
Comment thread .chloggen/ottl-flatten-fix-top-level-slice-handling.yaml Outdated
Comment thread .chloggen/ottl-flatten-fix-top-level-slice-handling.yaml Outdated
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add a new test for the new error condition of depth=0

Comment thread pkg/ottl/e2e/e2e_test.go
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you add an e2e test for flattening a slice and a map with a set depth

Copy link
Copy Markdown
Contributor Author

@bacherfl bacherfl Nov 13, 2024

Choose a reason for hiding this comment

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

I believe this should already be covered by https://github.com/open-telemetry/opentelemetry-collector-contrib/pull/36198/files#diff-90b6e27c60a80c3c831576a03b3bd0a47839bfb606a9d2876d8ccf6bf1370c92R109 - this test contains both a slice and a map and has been adjusted since the flattening previously did not stop at level 1 for the slice.

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
@evan-bradley evan-bradley merged commit f6cebd2 into open-telemetry:main Nov 15, 2024
@github-actions github-actions Bot added this to the next release milestone Nov 15, 2024
rshiyani pushed a commit to rshiyani/opentelemetry-collector-contrib that referenced this pull request Dec 9, 2024
…idering `depth` option (open-telemetry#36198)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This PR adapts the `flatten` function to also consider the `depth`
option when handling slice values. Before this change, the function
flattened slice values beyond the given depth.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#36161 

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Added unit and e2e tests

<!--Describe the documentation added.-->
#### Documentation

No changes here, as the docs already mention the expected behavior of
the function when the `depth` option is set
<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
…idering `depth` option (open-telemetry#36198)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

This PR adapts the `flatten` function to also consider the `depth`
option when handling slice values. Before this change, the function
flattened slice values beyond the given depth.

<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes open-telemetry#36161 

<!--Describe what testing was performed and which tests were added.-->
#### Testing

Added unit and e2e tests

<!--Describe the documentation added.-->
#### Documentation

No changes here, as the docs already mention the expected behavior of
the function when the `depth` option is set
<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com>
Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
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.

[pkg/ottl] unexpected behavior of flatten function when handling slice attributes at top level

4 participants