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

Script to run all plugins tests and try an install, rooting in local Logstash #15018

Merged

Conversation

andsel
Copy link
Contributor

@andsel andsel commented Apr 21, 2023

Release notes

[rn:skip]

What does this PR do?

Implements a script to test all supported plugins against Logstash/JRuby, in particular it uses the JRuby(and JDK) bundled with Logstash to execute the unit tests, create the gem and install the gem on local Logstash.

This doesn't start a real pipeline run into the local Logstash, but should be enough to reveal macroscopic Ruby syntax compatibility errors.

Why is it important/What is the impact to the user?

The introduced script permit to test supported plugins in the context of Logstash.
It provides a couple of command line options to select the plugins to test.
Using -p followed by a plugin name verify only that plugin. To test logstash-integration-jdbc it can be specified as:

ci/test_supported_plugins.sh -p logstash-integration-jdbc

Using -t (tier) and -k (kind) a set of plugins can be selected, for example: all input and output plugins of tier1 and tier2 could expressed as

ci/test_supported_plugins.sh -k input,output -t tier1,tier2

-h (halt) option is a boolean switch to stop on the first error instead of continue with all the plugins.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • [ ] I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@andsel andsel self-assigned this Apr 21, 2023
@andsel andsel changed the title First rough idea Script to run all plugins tests and try an install, rooting in local Logstash May 17, 2023
@andsel andsel marked this pull request as ready for review May 18, 2023 10:22
Copy link
Member

@yaauie yaauie left a comment

Choose a reason for hiding this comment

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

I think this will be super useful, and spent a bit of time bike-shedding where the list of supported plugins should be (I don't believe the current nested structured embedding is the "right" place).

I ran into a bit of a problem though because this script pollutes the Gemfile and Gemfile.lock files that are used by Logstash's plugin manager, and the ci/test_supported_plugins.sh entry-point invokes ./gradlew installDefaultGems which ensures that most (all?) of these gems are already previously installed from their relevant rubygems artifact.

Questions to that end:

  1. do we expect this to run on top of the default gem installation, and if so, what are we doing to validate that the local-git-checkout of the plugin is what is effectively installed?
  2. are we trying to test installing each in isolation (that is, snapshot the Gemfile and Gemfile.lock before each plugin we are validating and restore the snapshot before proceeding to the next), or are we trying to test installing them together (if so, we should likely randomize the order in which we do so)

ci/test_supported_plugins.rb Outdated Show resolved Hide resolved
ci/test_supported_plugins.rb Outdated Show resolved Hide resolved
@andsel
Copy link
Contributor Author

andsel commented May 22, 2023

Thanks @yaauie for reviewing it!

I ran into a bit of a problem though because this script pollutes the Gemfile and Gemfile.lock files that are used by Logstash's plugin manager, and the ci/test_supported_plugins.sh entry-point invokes ./gradlew installDefaultGems which ensures that most (all?) of these gems are already previously installed from their relevant rubygems artifact.

Ahh right, but the bundle install executed during the testing phase shouldn't overwrite with the latest dependencies required by the plugin itself? https://github.com/elastic/logstash/pull/15018/files#diff-a23b8397e5c96e0774b4b531cb29933248fb8278670d575b0acd4a5575985770R59 in that case it should test the plugin with the right dependencies, I think.

  1. do we expect this to run on top of the default gem installation, and if so, what are we doing to validate that the local-git-checkout of the plugin is what is effectively installed?

You are right, maybe before installing the locally created gem the script should remove the plugin from Logstash with a bin/logstash-plugin uninstall <plugin pre-installed>, WDYT, coule be enough?

  1. are we trying to test installing each in isolation..., or are we trying to test installing them together
    Actually the script install one after the other without isolation of installs a "copy & restore" of Gemfile and Gemfile.lock would help a lot into this.

@andsel andsel force-pushed the feature/create_utility_to_bulk_test_all_plugins branch from 2d5568d to 0d263fb Compare May 31, 2023 15:35
Copy link
Member

@yaauie yaauie left a comment

Choose a reason for hiding this comment

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

Excellent.

It would be good to have a singular canonical reference of plugins by support tier that can be referenced by this script instead of hard-coding it, but that can be deferred to a separate effort.

ci/test_supported_plugins.rb Outdated Show resolved Hide resolved
def git_clone
if File.directory?(plugin_name)
puts "#{plugin_name} already cloned locally"
return
Copy link
Member

Choose a reason for hiding this comment

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

should we git pull in this case? do we need to worry about "dirty" repositories with untracked or modified files?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, great idea thanks. Implemented with commit e23677b


# it has to be out of logstash local close else plugins' Gradle script
# would interfere with Logstash's one
base_folder = "/tmp"
Copy link
Member

Choose a reason for hiding this comment

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

  1. I would rather avoid dumping into /tmp, so maybe an environment variable would be a good hook point?
  2. We should use the OS-independent Dir::tmpdir instead of hard-coding /tmp:
Suggested change
base_folder = "/tmp"
base_folder = ENV['LOGSTASH_PLUGINS_TMP'] || (require 'tmpdir'; Dir.tmpdir)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, fixed with commit d3df637

Comment on lines +3 to +10
# Test the
# - build (rspec),
# - packaging (gem build)
# - and deploy (bin/logstash-plugin install)
# of a plugins inside the current Logstash, using its JRuby
# Usage example:
# bin/ruby ci/test_supported_plugins.rb -p logstash-integration-jdbc
# bin/ruby ci/test_supported_plugins.rb -t tier1 -k input,codec,integration
Copy link
Member

Choose a reason for hiding this comment

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

🤔 the usage is missing a note about needing a clean bootstrap + installDevelopmentGems.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we need the Logstash JRuby to be present, so at least here we should execute ./gradlew assemble, to setup the environment to be able to run the Ruby script.

We can split this in 2:

  • in the shell script invoke the minimal Gradle task that setup the environment to be able to run the Ruby script
  • in the Ruby script executes all the steps that are fundamental to have Logstash in right posture to execute the tests; which means executing the Gradle's installDevelopmentGems tasks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

handled with b30ad38

Comment on lines 2 to 5
export JRUBY_OPTS="-J-Xmx1g"
export GRADLE_OPTS="-Xmx4g -Dorg.gradle.jvmargs=-Xmx4g -Dorg.gradle.daemon=false -Dorg.gradle.logging.level=info -Dfile.encoding=UTF-8"

./gradlew installDevelopmentGems
Copy link
Member

Choose a reason for hiding this comment

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

would it be simpler to move this pre-requisite over to the ruby script so that everything is all in one place?

andsel and others added 4 commits June 1, 2023 10:48
@andsel
Copy link
Contributor Author

andsel commented Jun 1, 2023

Hi @yaauie

It would be good to have a singular canonical reference of plugins by support tier that can be referenced by this script instead of hard-coding it, but that can be deferred to a separate effort.

I agree with you. My idea would be to move those tiers and plugins inventory into a separate YAML file, maybe in the root of the Logstash project.

A sample could be:

tier1:
  inputs:
    - logstash-input-azure_event_hubs
    - logstash-input-beats
  codecs:
   - logstash-codec-generator
  filters:
    - ...
  outputs:
   - ...
  integrations:
   - logstash_integration_kafka

tier2: ...    

I think that would be better addressed in a follow up PR. WDYT?

@andsel andsel requested a review from yaauie June 1, 2023 10:48
@andsel
Copy link
Contributor Author

andsel commented Jun 1, 2023

Eventually we could use this: https://github.com/elastic/logstash/blob/main/rakelib/plugins-metadata.json as plugin repository. Every plugins that has default-plugins to true is bundled in Logstash default distribution, so it's supported plugin.

@andsel
Copy link
Contributor Author

andsel commented Jun 14, 2023

Hi @yaauie , sorry to nudge you, let me know what you think about latest changes to this PR

Copy link
Member

@yaauie yaauie left a comment

Choose a reason for hiding this comment

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

Implementation LGTM.

Let's merge as-is file an issue about the shared source-of-truth for plugins and their tiers so we don't lose track of it.

@andsel
Copy link
Contributor Author

andsel commented Jul 18, 2023

Created the follow up issue #15190 to track the request to use a common plugins inventory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a script to unit test all supported plugins
3 participants