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] unexpected behavior of flatten function when handling slice attributes at top level #36161

Closed
bacherfl opened this issue Nov 4, 2024 · 5 comments · Fixed by #36198
Labels
bug Something isn't working pkg/ottl priority:p2 Medium

Comments

@bacherfl
Copy link
Contributor

bacherfl commented Nov 4, 2024

Component(s)

pkg/ottl

What happened?

Description

Currently, when setting the depth to 0, slices at the top level of the input of the flatten function will still be flattened.

Steps to Reproduce

Consider the following input for the flatten function:

{
  "things": [
    {
       "name": "a"
    }
  ]
}

And use the flatten function with a depth of 0:

flatten(attributes, depth=0)

Expected Result

According to the docs, there should be no flattening when the depth is set to 0, i.e. the input should be left unchanged:

{
  "things": [
    {
       "name": "a"
    }
  ]
}

Actual Result

The slice elements are flattened, regardless of the depth

{
  "things.0": {
    "name": "a"
  }
}

Collector version

v0.112.0

Environment information

Environment

OS: (e.g., "Ubuntu 20.04")
Compiler(if manually compiled): (e.g., "go 14.2")

OpenTelemetry Collector configuration

No response

Log output

No response

Additional context

No response

@bacherfl bacherfl added bug Something isn't working needs triage New item requiring triage labels Nov 4, 2024
Copy link
Contributor

github-actions bot commented Nov 4, 2024

Pinging code owners:

See Adding Labels via Comments if you do not have permissions to add labels yourself.

@bacherfl bacherfl changed the title [pkg/ottl] unexpected behavior of flatten function when handling slice attributes [pkg/ottl] unexpected behavior of flatten function when handling slice attributes at top level Nov 4, 2024
@TylerHelmuth
Copy link
Member

It kinda feels like a bug to let you set a depth of 0. That is the same as not calling the function.

@bacherfl
Copy link
Contributor Author

bacherfl commented Nov 8, 2024

It kinda feels like a bug to let you set a depth of 0. That is the same as not calling the function.

Yes that seemed a bit odd to me that setting the depth to 0 is a supported option. Is it possible to set this parameter dynamically as well, based on e.g. another attribute or the result of another transformation? In this case it may be justified to also support 0, even though I cannot think of a realistic use case where this might be required

@TylerHelmuth
Copy link
Member

TylerHelmuth commented Nov 8, 2024

@bacherfl the depth parameter has to be a static value, it is not defined as a getter:

I think the best fix to this issue is to not allow a depth to be < 1

@VihasMakwana VihasMakwana removed the needs triage New item requiring triage label Nov 10, 2024
@bacherfl
Copy link
Contributor Author

@bacherfl the depth parameter has to be a static value, it is not defined as a getter:

I think the best fix to this issue is to not allow a depth to be < 1

Got it - in this case I will adapt the PR accordingly

@TylerHelmuth TylerHelmuth added the priority:p2 Medium label Nov 15, 2024
RutvikS-crest pushed a commit to RutvikS-crest/opentelemetry-collector-contrib that referenced this issue 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 issue 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
bug Something isn't working pkg/ottl priority:p2 Medium
Projects
None yet
3 participants