-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[Builder] Add package option to support generating library (non-main) Go packages and improve build logging #13296
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
base: main
Are you sure you want to change the base?
Conversation
This should be tested. |
Added two improvements in the unit tests:
|
# Conflicts: # cmd/builder/internal/config/default.yaml
@@ -5,6 +5,9 @@ package builder | |||
|
|||
import ( | |||
"fmt" | |||
"go/ast" | |||
"go/parser" | |||
"go/token" |
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'm a bit dubious about parsing Go code in a test to ensure it compiles. That seems a bit brittle.
How about doing something similar to the test folder that actually generates a collector and ensure it can run, to generate a library collector and ensure golangci-lint
passes?
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.
There is a problem: the generated library collector cannot be run directly. Instead, it should be used as a referenced code library. Therefore, I only check whether the generated code meets our expectations, rather than whether it runs independently.
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.
The library collector can be compiled, but it cannot run because it lacks a main package. That’s why, at https://github.com/open-telemetry/opentelemetry-collector/pull/13296/files#diff-117127e4cf9f6587102dc92a7240d1e2c00944ee47ce23e02731f3a41466bdb1R109-R112 in the compline function, I exit if the package is not main and do not proceed with compilation.
In my program, I manually create an export.go file, which defines an exportable function that calls the main method. This allows the upper layer to import and use it.
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.
Can you create the main func in your test directory and call the library?
Codecov ReportAttention: Patch coverage is
❌ Your patch check has failed because the patch coverage (37.50%) is below the target coverage (95.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## main #13296 +/- ##
==========================================
- Coverage 91.64% 91.60% -0.05%
==========================================
Files 522 522
Lines 29183 29189 +6
==========================================
- Hits 26746 26739 -7
- Misses 1920 1929 +9
- Partials 517 521 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
This PR adds a new package option to the builder configuration, allowing the generated OpenTelemetry Collector sources to use a custom package name instead of main. When the package is set to a value other than main, the build process is updated to recognize that the output is intended as a Go library for import by other Go modules, rather than an executable binary.
Logging is improved to provide clear messaging about this build mode.
Link to tracking issue
Fixes #
Testing
Documentation
Added documentation for the new package option in the example builder configuration and usage docs.
Clarified build output expectations when using non-main packages.