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

[builder] Add --go-build-flags cli flag #12589

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

braydonk
Copy link
Contributor

@braydonk braydonk commented Mar 9, 2025

Description

This PR adds the --go-build-flags cli flag which will allow the user to pass additional flags for the go build command used to compile the collector.

While doing the refactor, I also made it so that the default binary name now adds the .exe extension when building for Windows.

Link to tracking issue

Fixes #12588
Fixes #12591

Testing

New unit tests were added to verify the build command args based on the config. A new CompileAndGenerate test case was added as well.

Documentation

A section has been added to the README.

This PR adds the `--go-build-flags` cli flag which will allow the user
to pass additional flags for the `go build` command used to compile the
collector.
@braydonk braydonk requested a review from a team as a code owner March 9, 2025 16:13
@braydonk braydonk requested a review from codeboten March 9, 2025 16:13
@@ -113,6 +113,7 @@ var replaceModules = []string{
func newTestConfig(tb testing.TB) *Config {
cfg, err := NewDefaultConfig()
require.NoError(tb, err)
cfg.Distribution.Name = "test_distribution"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, the integration tests are running with a blank name field, which means the args end up being build -o 'ldflags=-s -w' .... So it's building a binary with the name 'ldflags=-s -w' instead of applying the ldflags. It didn't break any tests but is probably not intentional.

braydonk added 3 commits March 9, 2025 12:20
I had removed these because I didn't understand what they did at first,
and forgot to add them back once I realized why they were there.
@braydonk braydonk marked this pull request as draft March 9, 2025 17:00
Copy link

codecov bot commented Mar 9, 2025

Codecov Report

Attention: Patch coverage is 92.30769% with 3 lines in your changes missing coverage. Please review.

Project coverage is 92.21%. Comparing base (7d3e03e) to head (4a52b1e).

Files with missing lines Patch % Lines
cmd/builder/internal/builder/config.go 90.90% 2 Missing and 1 partial ⚠️

❌ Your patch check has failed because the patch coverage (92.30%) 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   #12589      +/-   ##
==========================================
+ Coverage   92.18%   92.21%   +0.02%     
==========================================
  Files         469      469              
  Lines       25394    25408      +14     
==========================================
+ Hits        23409    23429      +20     
+ Misses       1574     1570       -4     
+ Partials      411      409       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@braydonk braydonk marked this pull request as ready for review March 10, 2025 01:38
gcflags := ""
executableName := c.Distribution.Name
if runtime.GOOS == "windows" {
executableName += ".exe"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codecov seems to think these aren't covered, but I think they are covered by TestGetGoBuildArgs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason you're getting this warning is because the body of the if statement isn't being run in codecov because it's not running in windows. I think this finding should probably be ignored because the test TestGetGoBuildArgs explicitly tests correctly on windows systems

gcflags := ""
executableName := c.Distribution.Name
if runtime.GOOS == "windows" {
executableName += ".exe"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the reason you're getting this warning is because the body of the if statement isn't being run in codecov because it's not running in windows. I think this finding should probably be ignored because the test TestGetGoBuildArgs explicitly tests correctly on windows systems

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants