-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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] Function which converts slice into map #35256
Comments
Pinging code owners:
See Adding Labels via Comments if you do not have permissions to add labels yourself. |
Another option would be useful as well, to allow the value to simultaneously be specified via a sub-path. attributes:
hello: world
things:
- name: foo
details:
value: 2
- name: bar
details:
value: 5
attributes:
hello: world
things:
foo: 2
bar: 5 |
I would gladly work on a PR if this function should be added |
I would be glad if this gets implemented |
I have created a draft PR now to outline how this could be implemented. Will keep it in draft mode for now, until the code owners have agreed that this should be added |
Component(s)
pkg/ottl
Is your feature request related to a problem? Please describe.
I often hear from users that it's difficult to work with slices in OTTL and/or backends. Issues such as #29289 may alleviate this to some extent, but I believe in many cases users would prefer to work around slices by converting them to maps. This obviously comes with some assumptions, but I think there may be a reasonable way to provide this functionality.
Describe the solution you'd like
A new function called
Associate
, which requires two parameters:e.g. Given a log record with the following attributes:
A user could write something like
Associate(attributes["things"], ["name"])
and expect the following output:A slightly more complicated example highlights the notion of a sub-path. I'm not sure if OTTL has a mechanism for this, but if the array contains more complicated values, it may be necessary to drill further into the object to find its key.
In the above case,
Associate(attributes["things"], ["details", "name"])
would produce:It may make sense for users to specify, using an optional boolean, whether they wish to delete the key field, since it becomes redundant. (Or maybe this is just the default/only behavior.) Using the previous example, we'd expect:
Finally, this comes with some caveats about uniqueness of keys. I think since arrays are ordered it is simple enough to say that in the case of duplicates, the first or last one wins.
Describe alternatives you've considered
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: