Skip to content

Commit

Permalink
Sets elastic_integration plugin default back. When removing locally i…
Browse files Browse the repository at this point in the history
…nstalled gems, Gem::Specification doesn't recognize the gem. We have Bundle::setup in the removal logic but it is causing an issue when we re-use the bundle.
  • Loading branch information
mashhurs committed Jan 30, 2024
1 parent 214fbcd commit 38ccd1f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
26 changes: 17 additions & 9 deletions lib/pluginmanager/remove.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@ class LogStash::PluginManager::Remove < LogStash::PluginManager::Command
def execute
signal_error("File #{LogStash::Environment::GEMFILE_PATH} does not exist or is not writable, aborting") unless File.writable?(LogStash::Environment::GEMFILE_PATH)

##
# Need to setup the bundler status to enable uninstall of plugins
# installed as local_gems, otherwise gem:specification is not
# finding the plugins
##
LogStash::Bundler.setup!({:without => [:build, :development]})
LogStash::Bundler.prepare({:without => [:build, :development]})

if LogStash::PluginManager::ALIASES.has_key?(plugin)
unless LogStash::PluginManager.installed_plugin?(plugin, gemfile)
Expand All @@ -49,9 +44,22 @@ def execute
signal_error("This plugin is already provided by '#{integration_plugin.name}' so it can't be removed individually")
end

# make sure this is an installed plugin and present in Gemfile.
# it is not possible to uninstall a dependency not listed in the Gemfile, for example a dependent codec
signal_error("This plugin has not been previously installed") unless LogStash::PluginManager.installed_plugin?(plugin, gemfile)
not_installed_message = "This plugin has not been previously installed"
plugin_gem_spec = LogStash::PluginManager.find_plugins_gem_specs(plugin).any?
if plugin_gem_spec
# make sure this is an installed plugin and present in Gemfile.
# it is not possible to uninstall a dependency not listed in the Gemfile, for example a dependent codec
signal_error(not_installed_message) unless LogStash::PluginManager.installed_plugin?(plugin, gemfile)
else
# locally installed plugins are not recoginized by ::Gem::Specification
# we may ::Bundler.setup to reload but it resets all dependencies so we get error message for future bundler operations
# error message: `Bundler::GemNotFound: Could not find rubocop-1.60.2... in locally installed gems`
# instead we make sure Gemfile has a definition and ::Gem::Specification recognizes local gem
signal_error(not_installed_message) unless !!gemfile.find(plugin)

local_gem = gemfile.locally_installed_gems.detect { |local_gem| local_gem.name == plugin }
signal_error(not_installed_message) unless local_gem
end

exit(1) unless ::Bundler::LogstashUninstall.uninstall!(plugin)
LogStash::Bundler.genericize_platform
Expand Down
3 changes: 2 additions & 1 deletion rakelib/plugin.rake
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ namespace "plugin" do

LogStash::RakeLib::OSS_EXCLUDED_PLUGINS.each do |plugin|
remove_plugin(plugin)
# gem folder and spec file still stay after removing the plugin
# gem folder, spec file and cache still stay after removing the plugin
FileUtils.rm_r(Dir.glob("#{LogStash::Environment::BUNDLE_DIR}/**/gems/#{plugin}*"))
FileUtils.rm_r(Dir.glob("#{LogStash::Environment::BUNDLE_DIR}/**/specifications/#{plugin}*.gemspec"))
FileUtils.rm_r(Dir.glob("#{LogStash::Environment::BUNDLE_DIR}/**/cache/#{plugin}*"))
end
task.reenable # Allow this task to be run again
end
Expand Down
2 changes: 1 addition & 1 deletion rakelib/plugins-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
"skip-list": false
},
"logstash-filter-elastic_integration": {
"default-plugins": false,
"default-plugins": true,
"skip-list": false,
"skip-oss": true
},
Expand Down

0 comments on commit 38ccd1f

Please sign in to comment.