Commit 20d3551
authored
[pkg/ottl] Add new
<!--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.mdottl.ValueComparator API and support for slices comparison (open-telemetry#40370)1 parent 1ac8280 commit 20d3551
File tree
6 files changed
+272
-58
lines changed- .chloggen
- pkg/ottl
6 files changed
+272
-58
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
274 | 274 | | |
275 | 275 | | |
276 | 276 | | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
288 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
289 | 291 | | |
290 | 292 | | |
291 | 293 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
| 87 | + | |
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| |||
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
0 commit comments