Skip to content

[META] Native support for Java plugins #9215

Description

@andrewvc

This tracks the phases of the Native support for Java plugins Project.

Experimental phase:

Beta phase (#10232):

  • Plugin config validation
  • Java codecs
    • API consistency between encode and decode methods?
  • Support flush method for Java filters
  • Create Logstash API package with interfaces ('logstash-api') under co.elastic.logstash.api
    • Extract Java interface from Event class
    • Ensure that implementation is dependent on API interfaces, not concrete classes

GA (#10620):

Beyond GA?

Activity

  1. zivziv77 commented on Dec 1, 2018

    @zivziv77

    Hi,
    Sorry for the lake of knowledge. I need to write a Java input and output for logstash. I wonder if writing it directly with the new java plugin api.

    I will need it to production in 4-5 months.

    Where can I find documentation about this new java plugin?

    When it should be in production ready stage?

    Thanks a lot!

    In addition I would to contribute from my knowledge to convert some of the plugin from ruby to java.

    Thanks

    Ziv

  2. danhermann commented on Dec 3, 2018

    @danhermann
    Contributor

    @zivziv77, the current plan for this work is to release the Java Plugin API in a series of phases. The first phase is the experimental phase in which we'll solicit feedback on its basic functionality. After that, it would progress to the beta phase where we'd evaluate its stability and then it would be released as GA. I would hope that we would have something within your target timeframe, but I cannot commit to any specific release date.

    Right now, that work is happening in the java-api branch of the Logstash repository. You can see the current state of the Java Plugin API in the org.logstash.plugins.api package here.

    It may also be worth mentioning that we do already have a number of hybrid Ruby/Java plugins in which the bulk of the code is Java using Ruby shims to interface with the Ruby plugin API in Logstash. The TCP, date, and DLQ plugins are examples of hybrid Ruby/Java plugins if you'd like some examples of how those work.

  3. danhermann commented on Dec 3, 2018

    @danhermann
    Contributor

    @zivziv77, I should also add that we'd be happy to have any contributions you might make in converting plugins from Ruby to Java!

  4. zivziv77 commented on Dec 3, 2018

    @zivziv77

    Hi

    Thanks for your detailed answer.
    The main plugin that I need is Input Redis with cluster support with one of the java Redis client. I thought writing it myself and give it to you also.

    Where can I find documentation about how the java api works?

    I just think it doesn’t make sense writing hybrid plugin java and ruby if there’s going to be support for full java plugin without ruby.

    Thanks

  5. danhermann commented on Dec 3, 2018

    @danhermann
    Contributor

    @zivziv77, we don't have docs for the Java API, yet. It's pretty simple, so perhaps a brief explanation will provide what you need. (Note that these APIs are subject to change, though it is unlikely that they will change significantly.)

    Your Redis input will need to implement the Input interface. Within the start method, you should create a loop that retrieves messages from Redis and writes them to the supplied QueueWriter instance as a Map<String, Object> that will be later converted to an Event within the Logstash event processing pipeline. In your stop method, you should disconnect from Redis and perform whatever cleanup actions might be required. You can see a very simple example of this basic pattern in the StreamInput class in that same file.

    You will also need to provide a constructor that takes two parameters of type Configuration and Context. The Configuration instance should provide your input with configuration values such as the connection parameters for your Redis cluster. You probably won't need to do anything with the provided Context instance.

    Let me know if that helps or if you have additional questions.

  6. zivziv77 commented on Dec 3, 2018

    @zivziv77

    Thank you!
    That sounds pretty straight forward.
    One question I didn’t notice where should I register my plugin to be loaded ?
    How can I work with logstash on the java api nad mark to load for example Redis-input from java and not from ruby?

  7. danhermann commented on Dec 3, 2018

    @danhermann
    Contributor

    Oh, right. You'll need to add the @LogstashPlugin(name = "myRedisPluginName") annotation to your class. If you then add input { myRedisPluginName {} } (or whatever you call it) to your Logstash config, it will run your Java plugin. Note that you will need to do this with Logstash built from the java-api branch as that code has not yet been merged into the master branch.

  8. nielsbasjes commented on Feb 6, 2019

    @nielsbasjes

    I wanted to try to create a filter for two of my (Java) projects (Yauaa and Logparser) so I decided to start by simply trying to build the java filter example.
    Apparently the current documentation (yes I know, experimental) assumes more inside knowledge than I currently have.
    So the first attempt failed miserably:

    * What went wrong:
    A problem occurred evaluating root project 'logstash-filter-java_filter_example'.
    > Could not get unknown property 'LOGSTASH_CORE_PATH' for object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.
    

    So I download logstash 6.6.0 and hardcoded the path into the build.gradle file.
    Now the build runs a bit better but fails with lots of errors indicating it cannot find anything it needs

    error: package co.elastic.logstash.api does not exist
    error: cannot find symbol
    import org.logstash.Event;
    

    It would really help me if you can point me a bit more into the right direction (preferably by updating the readme in the example project).
    Note that I do not have any experience in Ruby and/or Gradle yet.

    Thanks.

  9. 19 remaining items

  10. danhermann commented on May 29, 2019

    @danhermann
    Contributor

    Just wondering: Why don't you simply push the current "much too large" dependency to Maven Central as a part of the beta?

    @nielsbasjes, that was an option but a big part of the reason we did not do that is that not all of the public classes in the logstash-core jar are part of the plugin API and are therefore not subject to the backward compatibility guarantees within major versions that we make for the plugin API itself. We did not want to give that impression by publishing a jar that contains nearly all of the Java source code for Logstash.

  11. danhermann commented on Jul 6, 2019

    @danhermann
    Contributor

    @YSZYCF, yes, third-party jars are definitely supported. The example Java plugins use those in several places. For example, see the Apache Commons and Log4j2 dependencies in the Java filter:

    https://github.com/logstash-plugins/logstash-filter-java_filter_example/blob/master/build.gradle

  12. dkm199 commented on Jul 12, 2019

    @dkm199

    @danhermann hi.. i am working on a filter plugin in java. I chose to write some part of it in scala classes(for ease of coding) and used that code in java code. Unit tests works fine..configured gradle to compile scala first and then java code.. gem file generated has only one single jar. I was able to install the gem successfully into logstash 7.2 locally.
    But while testing the java filter plugin, I noticed, that java part of filter plugin code executes fine, but
    scala part of plugin code is not executed at all(I tracked this by setting debug fields into event in java code and scala code)... Do you know what might be going on here? any workarounds are appreciated. Thanks
    Java code accesses scala code(ExpressionEvaluator is a scala class) like below and it works fine, in the unit tests that I wrote.
    Boolean result = ExpressionEvaluator$.MODULE$.evaluateExpression(event, someString);
    also tried accessing scala class like below as well, it didn't help
    Boolean result = ExpressionEvaluator.evaluateExpression(event, someString);

  13. dkm199 commented on Jul 13, 2019

    @dkm199

    nevermind, I figured out the issue, it needed scala library packaged into the jar as well, once that included, it worked fine.

  14. damozhizhou commented on Jul 25, 2019

    @damozhizhou

    @danhermann ,hello,I used the example you supplyed in “https://www.elastic.co/guide/en/logstash/current/java-codec-plugin.html”,and success get the result by the java_stdin。However,when i set input from kafka,I got the error:
    image
    here is my config:
    image

    Need your help, thank you very much~

  15. danhermann commented on Jul 25, 2019

    @danhermann
    Contributor

    @damozhizhou, if you'll post your question in the Logstash forums and tag me (@danhermann) on it, I'll reply to you there.

  16. danhermann commented on Jul 25, 2019

    @danhermann
    Contributor

    Closing this as Java plugins went GA in Logstash 7.2.0. Any additional work on Java plugins will be tracked in new issues.

    For help with developing your own Java plugins for Logstash, please post in the Logstash forums. You may tag me (@danhermann) on your post there and I'll try to respond. If you've encountered a bug related to Java plugins, you can create a GitHub issue here.

  17. nielsbasjes commented on Jul 29, 2019

    @nielsbasjes

    @danhermann
    Congratulations this is now GA.
    What is the issue I can track about stripping and deploying the API library to maven?

    The current process cannot be ran in a CI environment because of this missing jar.

  18. danhermann commented on Jul 29, 2019

    @danhermann
    Contributor

    @nielsbasjes, could you open an issue here so we can track that effort separately?

  19. karthikdeiva commented on Dec 18, 2020

    @karthikdeiva

    Hi,

    I built a custom JAVA Input plugin using the example JAVA plugin. I am able to install the GEM in the Logstash in my local. When I tried to install the custom plugin -the generated GEM file in my Dev server, getting the below exception,

    Received fatal alert: handshake_failure

    Could anyone brief on the process of installing the plugin developed in one machine in another Logstash instance.

    Thanks,
    KarthikDeiva

  20. nielsbasjes commented on Dec 18, 2020

    @nielsbasjes

    Have a look at how I did it here https://www.github.com/nielsbasjes/yauaa/tree/master/udfs/logstash/logstash-filter/src/test/docker

    I simply install everything in a docker image and check if the output meets my expectations.

  21. Jesse-so-cool commented on Sep 2, 2021

    @Jesse-so-cool

    Hi,
    I want to get the @metadata(like %{[@metadata][kafka][topic]} in my custom java output plugin,how can i do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions