[9.1] (backport #18340) Remove duplicate gems when producting logstash artifacts#18483
Closed
mergify[bot] wants to merge 1 commit into9.1from
Closed
[9.1] (backport #18340) Remove duplicate gems when producting logstash artifacts#18483mergify[bot] wants to merge 1 commit into9.1from
mergify[bot] wants to merge 1 commit into9.1from
Conversation
* Remove duplicate gems when producting logstash artifacts Bundler is used to manage a gem environment that is shipped with logstash artifacts. By default, bundler will install newer/duplicate gems than shipped with ruby distributions (in logstash's case jruby). Duplicate gems in the shipped environment can cause issues with code loading with ambiguous gem specs or gem activation issues. This commit adds a step to compute the duplicate gems managed with bundler (and therefore direct/transitive dependencies of logstash/plugins) and *removes* copies shipped with jruby. Note that there are two locations to do the deduplication at. Both the stdlib gems as well as what jruby refers to as "bundled" gems. The existing pattern for excluding files from artifacts is used to implement the deduplication. * only remove gemspecs for duplicated stdlib gems * Make deduplicate a separate rake task and prevent gradle errors Deduplication should happen as a depenedency of installing default gems. In the current workflow we have a top level gradle task for packaging which calls out to rake. Rake then invokes a *separate* gradle process. When we modify the jruby default, when the separate gradle process goes to check of jruby is installed, it sees a modified jruby and tries to re-install. We work around this by changing how gradle detects if jruby is required to be installed. * Ensure the set of gems tested at unit level matches packages This commit adds the installDefaultGems task to the unit test tasks. This ensures that the gem env tested at the unit level matches the deduplicated one at the integration/acceptance level. Takes over #18330 * WIP: Use logstash_gem_home for gemInstaller This commit changes gemInstaller such that the centralized gem_home from Logstash::Environment is used instead of hard coding in a fragile path. The tests were the only consumer of the optional positional parameter in the `install` class method. * Fix gem env setup for ruby unit tests After some deeeeeeeep diving into comparing the state of running logstash from a compiled artifact vs the unit tests i finally figured out that the use of the bundler `setup!` method in unit tests is imcompatible with a couple of tests. Specifically that method puts bundler installed gems ahead of the standard lib gems in the load path. This commit solves that by re-positioning the standarl lib back to the front of the load path. * Show how using `--prefer-local` causes issues Ideally bundler will consider default/stdlib gems when doing dependency resolution to avoid duplication in the first place. this seems to break the pluginmanager. Verify this happens in CI... * Revert "Show how using `--prefer-local` causes issues" This reverts commit 5a3b2bb. * fix rebase error (cherry picked from commit e08abb8)
Contributor
🤖 GitHub commentsJust comment with:
|
💚 Build Succeeded
cc @donoghuc |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Release notes
Removal of duplicated gems in logstash artifacts.
What does this PR do?
Bundler is used to manage a gem environment that is shipped with logstash
artifacts. By default, bundler will install newer/duplicate gems than shipped
with ruby distributions (in logstash's case jruby). Duplicate gems in the
shipped environment can cause issues with code loading with ambiguous gem specs
or gem activation issues. This commit adds a step to compute the duplicate gems
managed with bundler (and therefore direct/transitive dependencies of
logstash/plugins) and removes copies shipped with jruby. Note that there are
two locations to do the deduplication at. Both the stdlib gems as well as what
jruby refers to as "bundled" gems. The existing pattern for excluding files from
artifacts is used to implement the deduplication. Note that for the standard lib
gems only remove duplicate gemspec files as removal of the code itself triggers
noisy warning from ruby and code loading problems.
Why is it important/What is the impact to the user?
In some cases security scanners would pick up vendored/standard lib gems which typically trail in version shipped with the jruby distrubuted with logstash artifacts. While the newer code was loaded for logstash (and therefore not a practical threat) the scanner would still produce noise and require justifications. By removing old/duplicated gems we remove the false positives on the scanners.
How to test this PR locally
Build a container artifact and look for duplicated gems:
Related issues
This is an automatic backport of pull request #18340 done by [Mergify](https://mergify.com).