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] Add the ottl.ParserCollection utility #36174

Merged

Conversation

edmocosta
Copy link
Contributor

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's ParserCollection 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 the ottl/contexts package.

Link to tracking issue

#29017

Testing

Unit tests

Documentation

No changes

@edmocosta edmocosta marked this pull request as ready for review November 4, 2024 18:32
@edmocosta edmocosta requested a review from a team as a code owner November 4, 2024 18:32
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
@edmocosta
Copy link
Contributor Author

Hi @TylerHelmuth! I've replaced the generic type S by the ottl.StatementsGetter interface (b63c5ac) as suggested in a few comments, the only drawback I can think of was explained at #36174 (comment), which finally wouldn't be a big deal for consumers to handle it.

In addition to that, I've also exposed a default ottl.StatementsGetter implementation so it does not required consumers to create their own type only to satisfy the interface.

Please let me know your thoughts.

Copy link
Member

@TylerHelmuth TylerHelmuth left a 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.

pkg/ottl/parser_collection.go Show resolved Hide resolved
pkg/ottl/parser_collection.go Show resolved Hide resolved
@TylerHelmuth
Copy link
Member

@evan-bradley I plan to merge this PR on Friday unless you have any objections.

Copy link
Contributor

@evan-bradley evan-bradley left a 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.

.chloggen/ottl-add-parser-collection-utility.yaml Outdated Show resolved Hide resolved
.chloggen/ottl-add-parser-collection-utility.yaml Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
pkg/ottl/parser_collection_test.go Show resolved Hide resolved
pkg/ottl/parser_collection.go Outdated Show resolved Hide resolved
@TylerHelmuth TylerHelmuth added the ready to merge Code review completed; ready to merge by maintainers label Dec 4, 2024
@evan-bradley evan-bradley merged commit bf85471 into open-telemetry:main Dec 4, 2024
167 of 168 checks passed
@github-actions github-actions bot added this to the next release milestone Dec 4, 2024
shivanthzen pushed a commit to shivanthzen/opentelemetry-collector-contrib that referenced this pull request Dec 5, 2024
ZenoCC-Peng pushed a commit to ZenoCC-Peng/opentelemetry-collector-contrib that referenced this pull request Dec 6, 2024
sbylica-splunk pushed a commit to sbylica-splunk/opentelemetry-collector-contrib that referenced this pull request Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg/ottl ready to merge Code review completed; ready to merge by maintainers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants