- Notifications
You must be signed in to change notification settings - Fork 3.5k
Add the idea of a jar manager to handle jar_dependencies #2980
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
Conversation
| This test scenario has been successful for me.
🍏 |
lib/logstash/environment.rb Outdated
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 suppose you could also remove this line, JAR_DIR is not used anymore in 1.5
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.
makes sense @wiibaa
|
|
| Agreed about bundler code not belonging in the On the other hand since the For the jars dir, first, let's make the default relevant to the logstash environment. Once we agree and where we should store the jars, let's change the defaults to that. For the |
|
| +1 for vendor/jars |
d1f076c to 2cc9a4a Compare | @jsvd did you mean |
| why not |
| yes. yes I did. |
| @purbon |
| what happen when we have also other dependencies for test? for example. |
| All related code in here has been adapted to the last review comments, including the dependants PR's on the plugins side. |
| @jsvd I agree I should add them, but before I wanted us to agree on the API, although it seems there is no concern with it. |
| @jsvd simple unit test suite added. |
56d3fd1 to c4510a7 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.
In the plugins we do:
ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..")) LogStash::Environment.load_runtime_jars! File.join(ROOT_DIR, "vendor")But that's a lot of unecessary code we need on each plugin. At most, we need LogStash::Environment.load_runtime_jars! File.dirname(__FILE__) and even that we could somehow find by ourselves.
If we reduce this to just LogStash::Environment.load_runtime_jars!, we no longer need this extra file and can just include the require call in the plugin code. thoughts?
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 agree with you in part, however I did it this way in order to provide more flexibility, keep in mind now this file has a ROOT_DIR just one level below the file that load the jars, but it can happen to be in another location. Or that for some jars, we aim to store them in another place.
In my opinion, even if It might make sense, I find it too restrictive.
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 understand the flexibility argument, but don't really see a practical use case for it. The jars should be in a predetermined folder, and all .jar files we find in that folder and its subfolders get loaded.
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.
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.
Good @jsvd, this is a good discussion :-)
94644d4 to c72aee6 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.
double dragon quotes +1
| So if I understand correctly this code, this will load all the jars in the vendor directory? |
| @ph it load the plugins whenever this functions are used, in the current case from a file within each plugins, so no, it will load the jars whenever the plugins are used for first time. |
| @ph can you make sure the code I took from here related to maven makes sense? |
| Well, in my current checkout this PR breaks |
| @ph good you have test with kafka now, might be is because i removed the maven code, because I tested before that and it was working ... see thanks for the review man |
| @ph I checked with the change and with master and I see the same number of files for the kafka input, I see no change in this plugin ... I must say there was actually no change with this plugin for this PR |
| Did a test with this PR, Jars are in jruby-kafka. LGTM. |
| ok, merging this in |
958789d to 23554d4 Compare make the jar manager to have some of the checks already present in the old load_elasticsearch_jars removed the load_elasticsearch_jars! method as it's a legacy code from when ES was delivered within LS, nowadays this comes within the differents plugins clean up Environment::JAR_DIR as is another legacy variable not used anymore move the jar loading code within the environment module ammend previous commit adding more clear code ammend previous commits added a few simple unit test for the jar manager in the environment module refactor spec naming dry out common code for loading jars clean up env_spec bein in the util dir cleaning up logstash-core dependencies related to jar-dependencies ammend stale maen patches created for the LS way of using maven plugins applied some comments coming from the review by @ph bring back the maven tools and jar-dependency code as we still need some code like this for the kafka plugins Revert "bring back the maven tools and jar-dependency code as we still need some code like this for the kafka plugins" This reverts commit c23f456.
23554d4 to 83d6235 Compare | Merged sucessfully into master 1.5! |
make the jar manager to have some of the checks already present in the old load_elasticsearch_jars removed the load_elasticsearch_jars! method as it's a legacy code from when ES was delivered within LS, nowadays this comes within the differents plugins clean up Environment::JAR_DIR as is another legacy variable not used anymore move the jar loading code within the environment module ammend previous commit adding more clear code ammend previous commits added a few simple unit test for the jar manager in the environment module refactor spec naming dry out common code for loading jars clean up env_spec bein in the util dir cleaning up logstash-core dependencies related to jar-dependencies ammend stale maen patches created for the LS way of using maven plugins applied some comments coming from the review by @ph bring back the maven tools and jar-dependency code as we still need some code like this for the kafka plugins Revert "bring back the maven tools and jar-dependency code as we still need some code like this for the kafka plugins" This reverts commit c23f456. Fixes #2980
| Related to this change, it looks like the documentation describing how to add jar dependencies to a logstash plugin is now out of date: https://www.elastic.co/guide/en/logstash/current/_how_to_write_a_logstash_input_plugin.html#_jar_dependencies Is there guidance on the new correct way of doing things? I'm trying to update my plugin https://github.com/codekitchen/logstash-input-kinesis to work with logstash 1.5.1, but I'm not clear on how to get my jars properly vendored now. Thanks. |
| @codekitchen you are right, documentation should be updated. Do you mind opening an issue for that? On the other side, you can see how to add you own jars if you take a look for example at https://github.com/logstash-plugins/logstash-input-log4j/tree/master/lib , there you will see a final named Jars are then placed into the gem, in the case of the Makes sense? /cheers |
| I very rarely work with the JVM, so it actually took me a little while to figure out a good method for getting the jars I need into Eventually I ended up getting it working by adding a |
| @codekitchen good you figure it out, basically nowadays we just drop all need jars in a folder, even if not the best solution, In the meanwhile this is a necessary pain point to handle plugins who need jars. In a nutshell you should grab all jars you need and put them in the runtime folder. Thanks a lot for filling #3455, this would help our documentation efforts. |

In #2937 and #2954 we discussed the idea to build a jar manager in order to change the way we're loading the jar dependencies within our code base.
This PR add the concept of a jar manager responsible of finding and loading jars as dependencies.
Collaterally this PR also removed the load_elasticsearch_jars! method as it's a legacy code that was there from the early days when the ES jars were shipped with LS and not in the plugins.
This new jar manager is in use in
Relates to #2974
For now it still need a bit more test to be sure everything is working as expected.