-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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 |
I'm not totally clear on what problems we're solving, but I acknowledge that this transformation could be possible. I'd like to talk some more about edge cases:
I also think the name needs to be more direct. |
Here's an example of where this would be useful. Windows Event Logs contain content like the following: <EventData>
<Data Name='SubjectUserSid'>S-1-0-0</Data>
<Data Name='SubjectUserName'>-</Data>
<Data Name='SubjectDomainName'>-</Data>
<Data Name='SubjectLogonId'>0x0</Data>
<Data Name='TargetUserSid'>S-1-0-0</Data>
<Data Name='TargetUserName'>mr_rogers</Data>
<Data Name='TargetDomainName'>-</Data>
<Data Name='Status'>0xc000006d</Data>
<Data Name='FailureReason'>%%2313</Data>
<Data Name='SubStatus'>0xc0000064</Data>
<Data Name='LogonType'>3</Data>
<Data Name='LogonProcessName'>NtLmSsp </Data>
<Data Name='AuthenticationPackageName'>NTLM</Data>
<Data Name='WorkstationName'>D-508</Data>
<Data Name='TransmittedServices'>-</Data>
<Data Name='LmPackageName'>-</Data>
<Data Name='KeyLength'>0</Data>
<Data Name='ProcessId'>0x0</Data>
<Data Name='ProcessName'>-</Data>
<Data Name='IpAddress'>194.169.175.45</Data>
<Data Name='IpPort'>0</Data>
</EventData> We could debate which way this should be parsed but one reasonable representation would be a slice of "Data" maps, where each contains a key "Name" and a value. Given such a scenario, it is very difficult to work with the slice in OTTL. I cannot for example refer directly to the "ProcessId" field unless I know exactly where to expect it in the slice, and even then this would be fragile. Converting this to a map allows me to refer to it in a standard way, e.g. In practice, folks at my company have run into many similar situations. As you noted, not all cases can be solved by this because slices may contain varying data. Still, I would think that a function like this could be very useful without being fragile.
I would think this is a requirement. The function could validate this before doing anything and then nop if not satisfied.
I think this is covered if it must be
It can probably be a requirement. In theory we could tostring some other types but I doubt that would be very useful.
Seems reasonable to me. |
@djaglowski what would you say makes more sense in case one of the slice items is not a a) Return an error and exit the function In my draft I went with option |
I can see users wanting either option, but personally I would typically prefer a best effort transformation. There may be subsequent statements which depend on a struct, or on a particular key/value in the struct which could be available in spite of the error. For example, say I think there would be a wide variety of use cases here, with some being broken by any error, and others being fairly resilient. |
Thanks @djaglowski, that makes sense - I will adapt the implementation accordingly |
@bacherfl, although we still need buy in, the implementation looks good to me. |
@evan-bradley curious on your thoughts. |
I'm okay adding this. The design for loops in OTTL is still unclear, and until then working with list-like structures will require functions like this that do it inside a single statement. I also think that while imperfect, this function would be a workable patch on top of some situations OTTL is currently unable to solve:
We should probably revisit the design and utility of this function once we have loops, but in the meantime I think we could probably make this roughly approximate loops for a reasonable number of use-cases. For the use-cases this doesn't solve, we can document where this function is limited, and solve those situations with proper loops later on. |
If there's agreement, the PR is ready to review here: #35412 |
@TylerHelmuth, any further thoughts on this? |
I am ok moving forward with this concept since we haven't solved loops yet. |
**Description:** This PR adds a function that converts slices to maps, as described in the linked issue. Currently still WIP, but creating a draft PR already to show how this could be implemented and used **Link to tracking Issue:** #35256 **Testing:** Added unit and end to end tests **Documentation:** Added description for the new function in the readme file --------- Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com> Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com> Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
Closed by #35412 |
**Description:** This PR adds a function that converts slices to maps, as described in the linked issue. Currently still WIP, but creating a draft PR already to show how this could be implemented and used **Link to tracking Issue:** open-telemetry#35256 **Testing:** Added unit and end to end tests **Documentation:** Added description for the new function in the readme file --------- Signed-off-by: Florian Bacher <florian.bacher@dynatrace.com> Co-authored-by: Daniel Jaglowski <jaglows3@gmail.com> Co-authored-by: Evan Bradley <11745660+evan-bradley@users.noreply.github.com>
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: