-
Notifications
You must be signed in to change notification settings - Fork 2.8k
[pkg/ottl] add ability to compare maps #38611
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
Merged
evan-bradley
merged 3 commits into
open-telemetry:main
from
TylerHelmuth:ottl.map-comparison
Mar 13, 2025
Merged
[pkg/ottl] add ability to compare maps #38611
evan-bradley
merged 3 commits into
open-telemetry:main
from
TylerHelmuth:ottl.map-comparison
Mar 13, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
edmocosta
approved these changes
Mar 13, 2025
evan-bradley
approved these changes
Mar 13, 2025
atoulme
pushed a commit
that referenced
this pull request
Jun 4, 2025
…comparison (#40370) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR introduces two related changes and contains 2 change logs because of that. **1 - Comparator API** Exposes the internal OTTL comparators logic as a new API (`ottl.ValueComparator`), which can be used by API consumers to compare raw values following the same OTTL [comparison rules ](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/LANGUAGE.md#comparison-rules). **Why?** Existing and new functions that needs to compare values can be leveraging this new API to compare them, and keep it consistent with the OTTL comparison logic. For example, the new [`Contains`](#40193) function for slices, can be using this API to determine whether an slice contains a particular value, following the same comparison logic the grammar does. ```go // Exported interface: type ValueComparator interface { // Equal compares two values for equality, returning true if they are equals // according to the OTTL comparison rules. Equal(a any, b any) bool // NotEqual compares two values for equality, returning true if they are different // according to the OTTL comparison rules. NotEqual(a any, b any) bool // Less compares two values, returning true if the first value is less than the second // value, using the OTTL comparison rules. Less(a any, b any) bool // LessEqual compares two values, returning true if the first value is less or equal // to the second value, using the OTTL comparison rules. LessEqual(a any, b any) bool // Greater compares two values, returning true if the first value is greater than the // second value, using the OTTL comparison rules. Greater(a any, b any) bool // GreaterEqual compares two values, returning true if the first value is greater or // equal to the second value, using the OTTL comparison rules. GreaterEqual(a any, b any) bool } // Usage: comp := ottl.NewValueComparator() ``` **2 - Add ability to compare slices** We currently don't have the ability to compare slices, which means conditions like `attributes["slice"] == attributes["slice"]` returns false. This PR also adds the ability to compare slices/pcommon.Slices, similar to the maps support (#38611). <!--Describe what testing was performed and which tests were added.--> #### Testing Manual and unit tests <!--Describe the documentation added.--> #### Documentation Updated LANGUAGE.md
rockdaboot
pushed a commit
to rockdaboot/opentelemetry-collector-contrib
that referenced
this pull request
Jun 10, 2025
…comparison (open-telemetry#40370) <!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description This PR introduces two related changes and contains 2 change logs because of that. **1 - Comparator API** Exposes the internal OTTL comparators logic as a new API (`ottl.ValueComparator`), which can be used by API consumers to compare raw values following the same OTTL [comparison rules ](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/pkg/ottl/LANGUAGE.md#comparison-rules). **Why?** Existing and new functions that needs to compare values can be leveraging this new API to compare them, and keep it consistent with the OTTL comparison logic. For example, the new [`Contains`](open-telemetry#40193) function for slices, can be using this API to determine whether an slice contains a particular value, following the same comparison logic the grammar does. ```go // Exported interface: type ValueComparator interface { // Equal compares two values for equality, returning true if they are equals // according to the OTTL comparison rules. Equal(a any, b any) bool // NotEqual compares two values for equality, returning true if they are different // according to the OTTL comparison rules. NotEqual(a any, b any) bool // Less compares two values, returning true if the first value is less than the second // value, using the OTTL comparison rules. Less(a any, b any) bool // LessEqual compares two values, returning true if the first value is less or equal // to the second value, using the OTTL comparison rules. LessEqual(a any, b any) bool // Greater compares two values, returning true if the first value is greater than the // second value, using the OTTL comparison rules. Greater(a any, b any) bool // GreaterEqual compares two values, returning true if the first value is greater or // equal to the second value, using the OTTL comparison rules. GreaterEqual(a any, b any) bool } // Usage: comp := ottl.NewValueComparator() ``` **2 - Add ability to compare slices** We currently don't have the ability to compare slices, which means conditions like `attributes["slice"] == attributes["slice"]` returns false. This PR also adds the ability to compare slices/pcommon.Slices, similar to the maps support (open-telemetry#38611). <!--Describe what testing was performed and which tests were added.--> #### Testing Manual and unit tests <!--Describe the documentation added.--> #### Documentation Updated LANGUAGE.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I realized today we don't have the ability to compare maps. So a condition like
attributes == attributes
returns false. This PR adds the ability to compare maps/pcommon.Maps.Testing
manual testing and unit tests
Documentation
updated docs