-
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] Use generics to avoid context cast in getters and funcs #14482
Conversation
a41e660
to
4df0b89
Compare
3e9aaa8
to
5b8a030
Compare
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.
I'll do an in-depth review over the next week, but no feedback so far.
5b8a030
to
927b8e2
Compare
if err != nil { | ||
errors = multierr.Append(errors, err) | ||
} | ||
|
||
ottlp = ottl.NewParser( | ||
ottllogsp := ottl.NewParser[ottllogs.TransformContext]( |
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.
Maybe a followup change, but instead of a generic NewParser, should contexts provide a Parser specific to their context? Something like ottllogs.NewParser(logs.Functions(), component.TelemetrySettings{}
)?
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.
I like that more, since 2 arguments are always coming from that package. Will address it in the next PR.
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.
Sweet, do you plan to work on that or do we need an issue?
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.
Will do after you approve this 🗡️
@@ -26,7 +26,7 @@ import ( | |||
) | |||
|
|||
type Processor struct { | |||
queries []ottl.Statement | |||
queries []ottl.Statement[ottllogs.TransformContext] |
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.
Maybe we could do something similar here as proposed for NewParser
? Have []ottllogs.Statements
so that we don't have to have the processor pass in the Generic itself.
Hopefully we can make it so that the only place a processor would need to directly interact with the generic is when creating its own functions.
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.
So essentially have a TracesStatements
?
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.
I can also look into this for the next PR when I look into the Parser.
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.
Ya something like that. Since the generic introduce some complexity, will be great to hide that complexity inside the Contexts as much as possible since, at least at the moment, we need a Parser and set of Statements per context.
@bogdandrutu I'll give this a final look over tomorrow. |
793114f
to
e0db77d
Compare
e0db77d
to
bddb670
Compare
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.
Looks good to me. Nice use of generics!
This PR also improves number of allocations (by 2, if I am not wrong is because of the removing of the ottl.TransformContext interface use, which requires a heap allocation) and overall performance of the transform processor.
Before:
After: