-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
[builder] Add strict versioning #9897
Conversation
Codecov ReportAttention: Patch coverage is
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. |
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.
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
9f4c731
to
102319b
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.
Thanks for the change! I left a few comments :)
8e501c2
to
5c43c8a
Compare
cbda7d5
to
49d2832
Compare
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
4013dda
to
90b000f
Compare
@mx-psi, thanks for the review! I think I addressed everything. 🙂 Let me know what you think. |
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.
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 :)
cmd/builder/internal/builder/main.go
Outdated
} | ||
|
||
corePath, coreVersion := cfg.coreModuleAndVersion() | ||
if dependencyVersions[corePath] != coreVersion { |
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 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
cmd/builder/internal/builder/main.go
Outdated
continue | ||
} | ||
|
||
if dependencyVersions[module] != version { |
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.
Ditto here, IMO we should do the explicit check for presence in dependencyVersions
if !ok { | ||
return fmt.Errorf("component %w: '%s'. %s", ErrDepNotFound, module, skipStrictMsg) | ||
} | ||
if moduleDepVersion != version { |
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.
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 { |
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.
It'll be easier to add a test for this in #9631, so I'd prefer to wait and add it then.
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 { |
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 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) { |
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 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 { |
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.
It'll be easier to add a test for this in #9631, so I'd prefer to wait and add it then.
@mx-psi, let me know your thoughts on my unit test comments. 🙂 |
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.
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)
c0f792f
to
d821f83
Compare
<!--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
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>
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