Skip to content

[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

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

rockdaboot
Copy link
Contributor

@rockdaboot rockdaboot commented Apr 15, 2025

Description

Some OTTL functions do not call the accessor.setter function, but instead change the variable directly.
This doesn't work with the profiles signal where non-trivial processing is needed.

For example, attributes are split into a lookup table and arrays of indices (the rationale is de-duplication). While the accessor.getter function returns a pcommon.Map for attributes, any changes made to that map require passing the map to the accessor.setter function.

Link to tracking issue

Fixes #39100

Testing

Documentation

@rockdaboot rockdaboot force-pushed the fix-39100 branch 4 times, most recently from 13994d2 to 83fe3d3 Compare April 22, 2025 15:15
@rockdaboot rockdaboot changed the title [pkg/ottl] Fix OTTL replace functions [pkg/ottl] Fix OTTL functions by using setters Apr 22, 2025
@rockdaboot rockdaboot force-pushed the fix-39100 branch 2 times, most recently from 0ac9801 to 6a2fc36 Compare April 22, 2025 15:23
@rockdaboot rockdaboot force-pushed the fix-39100 branch 3 times, most recently from 2584f30 to 409957f Compare April 23, 2025 07:18
@rockdaboot rockdaboot marked this pull request as ready for review April 23, 2025 08:31
@rockdaboot rockdaboot requested a review from a team as a code owner April 23, 2025 08:31
@rockdaboot
Copy link
Contributor Author

@TylerHelmuth Can you please also review #39657, which became a requirement for this PR?

vincentfree pushed a commit to ing-bank/opentelemetry-collector-contrib that referenced this pull request May 20, 2025
…y#39657)

#### Description
Adds PMapGetSetter interface and StandardPMapGetSetter to improve
type-safety in OTTL functions.

Split out of
open-telemetry#39416
where this changes are already in use.
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 19, 2025
@rockdaboot
Copy link
Contributor Author

The existing e2e tests give me confidence for all the non-profiles context. Would it be worth adding e2e tests for profiles specifically since it behaves different that the other contexts? Right now the e2e tests only use ottllog since they all behaved in the same general way.

For useful profiles based e2e tests, we first should merge #39681, because the current e2e tests heavily rely on attributes accessors. Without attributes processors, e2e test would look completely different to the logs based e2e tests. That's a) hardly to compare and b) lot of work and c) more code to maintain (no de-duplication of code possible).

@edmocosta
Copy link
Contributor

edmocosta commented Jun 19, 2025

For useful profiles based e2e tests, we first should merge #39681, because the current e2e tests heavily rely on attributes accessors. Without attributes processors, e2e test would look completely different to the logs based e2e tests. That's a) hardly to compare and b) lot of work and c) more code to maintain (no de-duplication of code possible).

I agree it would have more value testing the editors with the paths that makes the profile context different, such as the attributes, and I'd be okay handling it in a separate issue(#40738).

Before moving forward with this one, I really think we should add a few more tests cases to ensure that the problem this PR fixes won't happen again. We can do that by verifying that the setter function was actually called, and that the result is correct not just because the editor is directly modifying the object reference, but also because of setter call.

@rockdaboot
Copy link
Contributor Author

For useful profiles based e2e tests, we first should merge #39681, because the current e2e tests heavily rely on attributes accessors. Without attributes processors, e2e test would look completely different to the logs based e2e tests. That's a) hardly to compare and b) lot of work and c) more code to maintain (no de-duplication of code possible).

I agree it would have more value testing the editors with the paths that makes the profile context different, such as the attributes, and I'd be okay handling it in a separate issue(#40738).

Before moving forward with this one, I really think we should add a few more tests cases to ensure that the problem this PR fixes won't happen again. We can do that by verifying that the setter function was actually called, and that the result is correct not just because the editor is directly modifying the object reference, but also because of setter call.

Added a check that the setter got actually called. This still doesn't check whether the editor was directly modifying the object as well. @edmocosta Would is the preferred way of doing that?

@github-actions github-actions bot removed the Stale label Jun 20, 2025
rockdaboot added a commit to rockdaboot/opentelemetry-collector-contrib that referenced this pull request Jun 24, 2025
@edmocosta
Copy link
Contributor

Added a check that the setter got actually called. This still doesn't check whether the editor was directly modifying the object as well. @edmocosta Would is the preferred way of doing that?

We currently don't have any efficient mechanism to enforce the immutability of those returned maps - and my PData PR got some pushback - so I think it would be fine to keep it as it's for now, and tackle it later when we decide how to deal with that in the OTTL core.

@TylerHelmuth please let me know if you agree with this, and with moving this PR forward.

Thanks!

@rockdaboot
Copy link
Contributor Author

@edmocosta @TylerHelmuth We now have OTTL e2e tests based on profiles.
The tests uncovered an issue in accessAttributesKey(), which is fixed in this PR.
Please let me know what you think.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[pkg/ottl] Fix replace functions for profiles
5 participants