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] Support for append #33017

Merged
merged 37 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
657da3c
Support for append
michalpristas May 13, 2024
c45dd97
readme
michalpristas May 13, 2024
acf1fdc
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
michalpristas May 13, 2024
8083a80
added changelog fragment
michalpristas May 13, 2024
48dceaf
allow mixed types
michalpristas May 14, 2024
274d6ee
check fromRaw errors
michalpristas May 14, 2024
fe40206
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
michalpristas May 14, 2024
303b0cd
type check when appending. guarantee of same type
michalpristas May 15, 2024
8e20659
Revert "type check when appending. guarantee of same type"
michalpristas May 25, 2024
5d7d59c
resolved conflicts with main
michalpristas May 25, 2024
04f0ff1
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
michalpristas May 30, 2024
526d88b
Update pkg/ottl/ottlfuncs/func_append.go
michalpristas May 30, 2024
df0f75e
Merge branch 'ottl/append' of github.com:michalpristas/opentelemetry-…
michalpristas May 30, 2024
148f77a
cleanup
michalpristas May 30, 2024
a1d124c
updated append tests
michalpristas May 30, 2024
859b095
added e2e tests for append
michalpristas May 30, 2024
d5764a1
Merge branch 'main' into ottl/append
michalpristas May 30, 2024
781a848
Merge branch 'main' into ottl/append
michalpristas May 31, 2024
8dfaa8b
Merge branch 'main' into ottl/append
michalpristas May 31, 2024
de7248c
do not export Append
michalpristas May 31, 2024
4461d62
Merge branch 'ottl/append' of github.com:michalpristas/opentelemetry-…
michalpristas May 31, 2024
b4e1f34
pass res as tCtx
michalpristas May 31, 2024
5b47882
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
michalpristas May 31, 2024
7e337fe
use transform context for res
michalpristas May 31, 2024
b78e8ee
fix lint
michalpristas May 31, 2024
2c7a5b6
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
michalpristas May 31, 2024
be2932c
Merge branch 'main' into ottl/append
michalpristas Jun 3, 2024
2c388bf
Apply suggestions from code review
michalpristas Jun 5, 2024
b7cbd71
target type tests
michalpristas Jun 5, 2024
f132e48
Merge branch 'main' into ottl/append
michalpristas Jun 5, 2024
3d85d05
linting issue fixed
michalpristas Jun 6, 2024
0a50d04
Merge branch 'main' of github.com:open-telemetry/opentelemetry-collec…
michalpristas Jun 6, 2024
4cda3ce
Merge branch 'ottl/append' of github.com:michalpristas/opentelemetry-…
michalpristas Jun 6, 2024
24fb99b
Update pkg/ottl/ottlfuncs/README.md
michalpristas Jun 6, 2024
77d851c
Merge branch 'main' into ottl/append
michalpristas Jun 7, 2024
e18633f
Update pkg/ottl/ottlfuncs/README.md
michalpristas Jun 10, 2024
37ae200
Update pkg/ottl/ottlfuncs/README.md
michalpristas Jun 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/ottl/ottlfuncs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Available Editors:

`append(target, Optional[value], Optional[values])`
TylerHelmuth marked this conversation as resolved.
Show resolved Hide resolved

The `append` function appens single or multiple string values to target.
`append` converts scalar values into an array if the field exists but is not an array and creates an array containing the provided values if the field doesn’t exist.
The `append` function appends single or multiple string values to `target`.
`append` converts scalar values into an array if the field exists but is not an array, and creates an array containing the provided values if the field doesn’t exist.

Resulting field is always of type `pcommon.Slice` keeping types of existing values appending values as set not performing any conversions.
Resulting field is always of type `pcommon.Slice` and will not convert the types of existing or new items in the slice.
michalpristas marked this conversation as resolved.
Show resolved Hide resolved

- `append(attributes["tags"], "prod")`
- `append(attributes["tags"], values = ["staging", "staging:east"])`
Expand Down
6 changes: 3 additions & 3 deletions pkg/ottl/ottlfuncs/func_append.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func createAppendFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments) (

func appendTo[K any](target ottl.GetSetter[K], value ottl.Optional[ottl.Getter[K]], values ottl.Optional[[]ottl.Getter[K]]) (ottl.ExprFunc[K], error) {
if value.IsEmpty() && values.IsEmpty() {
return nil, fmt.Errorf("at least one of the optional arguments must be provided be provided")
return nil, fmt.Errorf("at least one of the optional arguments ('value' or 'values') must be provided")
}

return func(ctx context.Context, tCtx K) (any, error) {
Expand Down Expand Up @@ -63,7 +63,7 @@ func appendTo[K any](target ottl.GetSetter[K], value ottl.Optional[ottl.Getter[K
case pcommon.ValueTypeSlice:
res = append(res, targetType.Slice().AsRaw()...)
default:
return nil, fmt.Errorf("unsupported type of target field")
return nil, fmt.Errorf("unsupported type of target field: %q", targetType.Type())
}

case []string:
Expand All @@ -88,7 +88,7 @@ func appendTo[K any](target ottl.GetSetter[K], value ottl.Optional[ottl.Getter[K
case any:
res = append(res, targetType)
default:
return nil, fmt.Errorf("unsupported type of target field")
return nil, fmt.Errorf("unsupported type of target field: '%T'", t)
}
}

Expand Down
Loading