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 strict versioning #9897

Merged
merged 6 commits into from
Apr 18, 2024

Conversation

kristinapathak
Copy link
Contributor

@kristinapathak kristinapathak commented Apr 5, 2024

Description:
Adds strict version checking in the builder. This enables users to ensure that the versions specified in the builder config are the versions used in the go.mod when building the collector binary. This can be disabled with --skip-strict-versioning.

Link to tracking Issue: #9896

Testing: Added unit tests

Documentation: Added to builder README

Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 75.34247% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 91.76%. Comparing base (f1a7475) to head (d821f83).
Report is 31 commits behind head on main.

Files Patch % Lines
cmd/builder/internal/builder/main.go 74.28% 11 Missing and 7 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9897      +/-   ##
==========================================
- Coverage   91.93%   91.76%   -0.18%     
==========================================
  Files         357      358       +1     
  Lines       16501    16604     +103     
==========================================
+ Hits        15171    15236      +65     
- Misses       1001     1041      +40     
+ Partials      329      327       -2     

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

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

Thanks for filing this separately. I think this should be the default behavior, we have had people confused about this in the past (see #8692) and I think it is better to spit out an error than to silently do the wrong thing.

I would therefore prefer to make this PR into a breaking change and add a temporary flag (--skip-strict-versioning?) to temporarily allow users to revert this check and allow them to migrate. We can mention this flag in the error message and remove it after a few versions.

Would you mind switching from --strict-versioning to --skip-strict-versioning and updating the release note?

Thanks!

cc @open-telemetry/collector-approvers for visibility

@kristinapathak kristinapathak force-pushed the builder-strict-versioning branch from 9f4c731 to 102319b Compare April 10, 2024 04:03
@kristinapathak kristinapathak changed the title [builder] Add --strict-versioning flag [builder] Add strict versioning Apr 10, 2024
@kristinapathak kristinapathak marked this pull request as ready for review April 10, 2024 04:14
@kristinapathak kristinapathak requested review from a team and Aneurysm9 April 10, 2024 04:14
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

Thanks for the change! I left a few comments :)

cmd/builder/internal/builder/main.go Outdated Show resolved Hide resolved
cmd/builder/internal/builder/main.go Outdated Show resolved Hide resolved
.chloggen/builder-strict-versioning.yaml Outdated Show resolved Hide resolved
cmd/builder/README.md Outdated Show resolved Hide resolved
cmd/builder/README.md Outdated Show resolved Hide resolved
cmd/builder/internal/builder/modfile/modfile.go Outdated Show resolved Hide resolved
cmd/builder/internal/builder/config.go Outdated Show resolved Hide resolved
cmd/builder/internal/builder/main.go Outdated Show resolved Hide resolved
cmd/builder/internal/builder/main.go Show resolved Hide resolved
cmd/builder/internal/builder/main.go Outdated Show resolved Hide resolved
@kristinapathak kristinapathak force-pushed the builder-strict-versioning branch from 8e501c2 to 5c43c8a Compare April 10, 2024 21:20
@kristinapathak kristinapathak force-pushed the builder-strict-versioning branch from cbda7d5 to 49d2832 Compare April 11, 2024 19:35
Kristina Pathak and others added 3 commits April 11, 2024 14:59
Co-authored-by: Pablo Baeyens <pbaeyens31+github@gmail.com>
- add back hardcoding retries
- update strict mode error wording
- use modfile pkg
- update some config versions
- consolidate runGoCommand funcs
- swap function order, update comment
@kristinapathak kristinapathak force-pushed the builder-strict-versioning branch from 4013dda to 90b000f Compare April 11, 2024 22:01
@kristinapathak
Copy link
Contributor Author

@mx-psi, thanks for the review! I think I addressed everything. 🙂 Let me know what you think.

@kristinapathak kristinapathak requested a review from mx-psi April 11, 2024 22:03
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

Code LGTM, I left a couple small suggestions to improve the error messages. Would love to increase the code coverage a bit. If that's too hard on this PR, just let me know, we can postpone to your second PR :)

}

corePath, coreVersion := cfg.coreModuleAndVersion()
if dependencyVersions[corePath] != coreVersion {
Copy link
Member

Choose a reason for hiding this comment

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

The error here and below would be a bit confusing if corePath is not on dependencyVersions. While this would be a weird situation that I don't think we can encounter now, IMO for future-proofing we should do the full check (corePathVersion, ok := dependencyVersions[corePath]) and provide a more appropriate error message if ok is false

continue
}

if dependencyVersions[module] != version {
Copy link
Member

Choose a reason for hiding this comment

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

Ditto here, IMO we should do the explicit check for presence in dependencyVersions

cmd/builder/internal/builder/main.go Show resolved Hide resolved
if !ok {
return fmt.Errorf("component %w: '%s'. %s", ErrDepNotFound, module, skipStrictMsg)
}
if moduleDepVersion != version {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll be easier to add a test for this in #9631, so I'd prefer to wait and add it then.

if !ok {
return fmt.Errorf("core collector %w: '%s'. %s", ErrDepNotFound, corePath, skipStrictMsg)
}
if coreDepVersion != coreVersion {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll be easier to add a test for this in #9631, so I'd prefer to wait and add it then.

cmd/builder/internal/builder/main.go Show resolved Hide resolved
cmd/builder/internal/builder/main.go Show resolved Hide resolved
cfg.Logger.Info("Getting go modules")
// basic retry if error from go mod command (in case of transient network error). This could be improved
// retry 3 times with 5 second spacing interval
retries := 3
failReason := "unknown"
for i := 1; i <= retries; i++ {
if err := runGoCommand(cfg, "mod", "download"); err != nil {
if _, err := runGoCommand(cfg, "mod", "download"); err != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't been able to add coverage for this because if I would expect this to fail, the previous go get command fails first.

c.Connectors...)...)...)...)
}

func (c *Config) readGoModFile() (string, map[string]string, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't been able to add coverage for this function because in the code path, if I would expect this to fail, the previous go get command fails first.

I can add a separate test that targets this function directly, otherwise not sure how to test this.

}

moduleDepVersion, ok := dependencyVersions[module]
if !ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'll be easier to add a test for this in #9631, so I'd prefer to wait and add it then.

@kristinapathak
Copy link
Contributor Author

@mx-psi, let me know your thoughts on my unit test comments. 🙂

Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

Thanks for taking a thorough look at coverage. We can address the remaining easy cases in the next PR.

This LGTM, but in order to merge, I need you to fix the linter error:

 internal/builder/main.go:131:49: non-wrapping format verb for fmt.Errorf. Use `%w` to format errors (errorlint)
		return fmt.Errorf("%w: %v", errCompileFailed, err)

@kristinapathak kristinapathak force-pushed the builder-strict-versioning branch from c0f792f to d821f83 Compare April 17, 2024 20:54
@mx-psi mx-psi merged commit e9b432d into open-telemetry:main Apr 18, 2024
48 of 49 checks passed
@github-actions github-actions bot added this to the next release milestone Apr 18, 2024
@kristinapathak kristinapathak deleted the builder-strict-versioning branch April 18, 2024 16:42
mx-psi added a commit that referenced this pull request Apr 19, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description

Improves `TestVersioning` added on #9897.

The configurations were not what one would usually find, since when
running the builder we do some validation and setup.
This makes it closer to the real case.

In the process I removed the 'invalid' cases, since these error out
today already
codeboten added a commit that referenced this pull request Apr 19, 2024
Partially reverts #9897. This was not documented on the original PR and
is IMO too strict.
We likely want to allow for some skew between versions.

Mentioned on
#9513 (comment)

---------

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants