-
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] Add the ottl.ParserCollection utility #36174
[pkg/ottl] Add the ottl.ParserCollection utility #36174
Conversation
Hi @TylerHelmuth! I've replaced the generic type In addition to that, I've also exposed a default Please let me know your thoughts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edmocosta I like the way this looks without the extra generic. I'd like to continue moving forward with this work because it will really help end users so I suggest we add Experimental
to the new public API in this PR in cases we end up changing it later (which wouldn't affect end users, only component developers). We've used this strategy a bit in Core and while I don't want to leave the comment for a long time it will give us some coverage over the next couple releases.
@evan-bradley I plan to merge this PR on Friday unless you have any objections. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @edmocosta for continuing to work on this. Everything looks good to me, I only have wording suggestions.
Co-authored-by: Evan Bradley <[email protected]>
Co-authored-by: Evan Bradley <[email protected]>
Co-authored-by: Tyler Helmuth <[email protected]> Co-authored-by: Evan Bradley <[email protected]>
Co-authored-by: Tyler Helmuth <[email protected]> Co-authored-by: Evan Bradley <[email protected]>
Co-authored-by: Tyler Helmuth <[email protected]> Co-authored-by: Evan Bradley <[email protected]>
Description
This PR is part of #29017, and adds the parser collection utility into the
ottl
package.This utility is based on the existing
transformprocessor
'sParserCollection
concept and is used to group context's parsers, abstracting the logic to infer the context from the statements, and/or rewriting them adding their paths's context if necessary.In summary, the general idea is: given the configured contexts, parsers and statements converters, pick the right parser, and transform the parsed result (
ottl.Statements[K]
) into something common to the parser collection ([R]
). For more details, please have a look at the transformprocessor` refactoring on the draft using this utility.Given the
ottl.Parser[K]
's have different type restrictions/generics (e.g.TransformContext
), this utility heavily rely on the Go's reflection api, being the exposed interface type-safe, but manipulating untyped objects under the hood.Considering this code is only executed during the bootstrap, IMO, it should be fine using reflection. I couldn't think about any other solution that would make this utility as generic as it's without reflection. Another approach would be hard-code all the existing ottl contexts's parsers on the collection, having fixed
WithParserX
functions per context and generating a direct dependency on theottl/contexts
package.Link to tracking issue
#29017
Testing
Unit tests
Documentation
No changes