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

Move bwcVersions extension property to BuildParams #56206

Merged
merged 4 commits into from
May 7, 2020

Conversation

breskeby
Copy link
Contributor

@breskeby breskeby commented May 5, 2020

@breskeby breskeby added >enhancement :Delivery/Build Build or test infrastructure Team:Core/Infra Meta label for core/infra team labels May 5, 2020
@breskeby breskeby self-assigned this May 5, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (:Core/Infra/Build)

@breskeby breskeby requested a review from mark-vieira May 5, 2020 15:21
Copy link
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

One comment on error handling but otherwise LGTM.

List<String> versionLines = IOUtils.readLines(new FileInputStream(versionsFile), "UTF-8");
return new BwcVersions(versionLines);
} catch (IOException e) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should rethrow as an UncheckedIOException. If we aren't able to determine BWC versions this is likely to cause all sorts of build issues so we should treat this as a fatal error. I believe this might already be the case as BuildParams will validate we aren't setting the value to null, but then we end up losing the original exception cause which is not ideal.

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 thought about it but didn’t want to fail fatal here to make testing easier. I needed to touch the testkit Test builds and wanted to keep the ability to direct configure the bwcVersion in via BuildParamd there instead of introducing sth like a test only override property in the plugin itself to pass a configurable file path to resolve versions from

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 thought about it but didn’t want to fail fatal here to make testing easier. I needed to touch the testkit Test builds and wanted to keep the ability to direct configure the bwcVersion in via BuildParamd there instead of introducing sth like a test only override property in the plugin itself to pass a configurable file path to resolve versions from

Copy link
Contributor

@mark-vieira mark-vieira May 5, 2020

Choose a reason for hiding this comment

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

Gotcha, we should at least log the original exception then, so if it does barf we get a better message than just bwcVersions cannot be null or whatever.

Copy link
Member

Choose a reason for hiding this comment

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

Why does not failing with an exception make this easier to test? Tests can use expectThrows to catch an exception?

Copy link
Contributor

Choose a reason for hiding this comment

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

That doesn't work with testKit tests since it's not the test that's throwing the exception, it's the build and those don't get propagated to the test. You just get a "your build failed" type exception returned by teskit.

@breskeby
Copy link
Contributor Author

breskeby commented May 5, 2020 via email

@breskeby
Copy link
Contributor Author

breskeby commented May 5, 2020 via email

@mark-vieira
Copy link
Contributor

Yeah, since this is now done by a plugin instead of the by root build script those plugin tests include this logic so the only other way to override would be to create a Version.java file in the appropriate place or include some other way to override this behavior for tests.

That brings up a good point though. Will external users of GlobalBuildInfoPlugin barf if we can't load bwc versions? I think it will since things like the PluginBuildPlugin end up applying the GlobalBuildInfoPlugin.

I think we have a couple options here:

  1. In the case where bwc information is unavailable, fail on read instead of eagerly when loading the info.
  2. Move this into a separate plugin, and apply that plugin only to projects which require bwc version information.

@rjernst
Copy link
Member

rjernst commented May 5, 2020

Will external users of GlobalBuildInfoPlugin barf if we can't load bwc versions?

We have a guard on this already. In all the places we use bwcVersions, we check isInternal. This is something we should fix, either by having a buildSrc build time copy of Version.java into buildSrc resources, or read Version.java at that time and generating a json resource file that can be loaded more directly, but that we don't need to worry about bad formatting or anything missing (my preferred approach).

@mark-vieira
Copy link
Contributor

This is something we should fix, either by having a buildSrc build time copy of Version.java into buildSrc resources, or read Version.java at that time and generating a json resource file that can be loaded more directly

What would be the benefit of this if we never intend external users to need BWC information?

@rjernst
Copy link
Member

rjernst commented May 6, 2020

The bwc information is needed to run any kind of bwc tests. It's reasonable to assume external plugin authors will want to test compatibility of their own plugin against other versions when we finally break lockstep plugin versioning.

@mark-vieira
Copy link
Contributor

Sure, but right now we have no kind of guarantees on how this works, and there exists no documentation or guidance on how one might integration BWC testing into their plugin build.

I'd say until we officially support such a thing we make bwcversions a purely internal mechanism (guarded like it is as you mention) and simply blow up if you try to access it outside the Elasticsearch build.

@rjernst
Copy link
Member

rjernst commented May 6, 2020

That's fair, but don't external plugin authors still load GlobalBuildInfoPlugin? How can we blow up in trying to load it outside of ES without causing all plugin authors builds to fail?

@mark-vieira
Copy link
Contributor

mark-vieira commented May 6, 2020

We do as Rene has done here and gracefully handle a missing Version.java file on load, and instead assertNotNull on read.

This behavior is essentially no different than trying to read BuildParams w/o having applied the GlobalBuildInfoPlugin.

@rjernst
Copy link
Member

rjernst commented May 6, 2020

Can't we use isInternal to determine whether we should fail?

@mark-vieira
Copy link
Contributor

Can't we use isInternal to determine whether we should fail?

Good call. @rene, let's do what @rjernst suggests. If we detect that this is an "internal" build (meaning we are running in the elasticsearch project vs the build-tools jar being pulled in by an external project) and we fail to parse Version.java for any reason let's explode, otherwise return null as we do now and then fail on read.

@breskeby
Copy link
Contributor Author

breskeby commented May 6, 2020 via email

@breskeby
Copy link
Contributor Author

breskeby commented May 6, 2020

I tweaked the implementation to only set the BuildParams.bwcVersions property for internal builds and fail early when 1. sth goes wrong in parsing the version file and 2. if a passed bwcVersion to BuildParams.setBwcVersion(...) is null. IMO this is the most robust approach.

@breskeby
Copy link
Contributor Author

breskeby commented May 6, 2020

@elasticmachine update branch

@breskeby
Copy link
Contributor Author

breskeby commented May 6, 2020

@elasticmachine test this please

@breskeby
Copy link
Contributor Author

breskeby commented May 6, 2020

@elasticmachine update branch

@breskeby
Copy link
Contributor Author

breskeby commented May 6, 2020

@elasticmachine test this please

Copy link
Member

@rjernst rjernst left a comment

Choose a reason for hiding this comment

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

LGTM

BuildParams.init(params -> {
// Initialize global build parameters
boolean internalUse = GlobalBuildInfoPlugin.class.getResource("/buildSrc.marker") != null;
Copy link
Member

Choose a reason for hiding this comment

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

nit: I would name this isInternal since that is the property we are setting

@mark-vieira
Copy link
Contributor

Changes LGTM.

breskeby added 3 commits May 7, 2020 09:15
- resolved in GlobalBuildInfoPlugin
- TODO: probably more bwc related work can be moved from build scripts into
certain plugins.
- propagate exception if version file cannot be resolved
- add null check when setting bwcVersions
@breskeby breskeby deleted the fix/build/move-bwcVersions-to-build-params branch May 7, 2020 10:08
original-brownbear added a commit to original-brownbear/elasticsearch that referenced this pull request May 7, 2020
I think we missed this spot in elastic#56206 breaking the task and thus Gradle imports into Idea.
original-brownbear added a commit that referenced this pull request May 7, 2020
I think we missed this spot in #56206 breaking the task and thus Gradle imports into Idea.
@mark-vieira
Copy link
Contributor

@breskeby can you please ensure this change is backported to 7.x, 7.8 and 7.7 branches, and appropriate version labels are added to this PR?

breskeby added a commit to breskeby/elasticsearch that referenced this pull request May 7, 2020
- resolved in GlobalBuildInfoPlugin
- propagate exception if version file cannot be resolved
- add null check when setting bwcVersions
breskeby pushed a commit to breskeby/elasticsearch that referenced this pull request May 7, 2020
I think we missed this spot in elastic#56206 breaking the task and thus Gradle imports into Idea.
@breskeby
Copy link
Contributor Author

breskeby commented May 7, 2020

7.x Backport PR: #56381

breskeby added a commit to breskeby/elasticsearch that referenced this pull request May 7, 2020
- resolved in GlobalBuildInfoPlugin
- propagate exception if version file cannot be resolved
- add null check when setting bwcVersions
breskeby pushed a commit to breskeby/elasticsearch that referenced this pull request May 7, 2020
I think we missed this spot in elastic#56206 breaking the task and thus Gradle imports into Idea.
breskeby added a commit to breskeby/elasticsearch that referenced this pull request May 7, 2020
- resolved in GlobalBuildInfoPlugin
- propagate exception if version file cannot be resolved
- add null check when setting bwcVersions
breskeby pushed a commit to breskeby/elasticsearch that referenced this pull request May 7, 2020
I think we missed this spot in elastic#56206 breaking the task and thus Gradle imports into Idea.
@breskeby
Copy link
Contributor Author

breskeby commented May 7, 2020

7.8 backport PR #56382

@breskeby
Copy link
Contributor Author

breskeby commented May 7, 2020

7.7 backport PR #56383

breskeby added a commit that referenced this pull request May 11, 2020
* Move bwcVersions extension property to BuildParams (#56206)
* Fix :qa Task Using Broken BwC Versions Resolution (#56332)

Co-authored-by: Armin Braun <[email protected]>
breskeby added a commit that referenced this pull request May 11, 2020
* Move bwcVersions extension property to BuildParams (#56206)
* Fix :qa Task Using Broken BwC Versions Resolution (#56332)

Co-authored-by: Armin Braun <[email protected]>
breskeby added a commit that referenced this pull request May 11, 2020
* Move bwcVersions extension property to BuildParams (#56206)
* Fix :qa Task Using Broken BwC Versions Resolution (#56332)
Co-authored-by: Armin Braun <[email protected]>
@mark-vieira mark-vieira added Team:Delivery Meta label for Delivery team and removed Team:Core/Infra Meta label for core/infra team labels Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure Team:Delivery Meta label for Delivery team v7.7.1 v7.8.1 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants